Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: ArgumentError: column indices J[k] must satisfy 1 <= J[k] <= n #333

Closed
wwucl2019 opened this issue Nov 12, 2021 · 6 comments · Fixed by #357
Closed

ERROR: ArgumentError: column indices J[k] must satisfy 1 <= J[k] <= n #333

wwucl2019 opened this issue Nov 12, 2021 · 6 comments · Fixed by #357

Comments

@wwucl2019
Copy link

wwucl2019 commented Nov 12, 2021

Hi,

I am new to Circuitscape. I am jus trying to run the calculations in the network mode. I am sure I have followed the spirit of the input files given in the instructions, but kept getting the following error. I attached my input files here. Thanks.
mgNetworkVerify1_grounds_resistances.txt
mgNetworkVerify1_graph_resistances.txt
mgNetworkVerify1_sources.txt

julia> compute("/Users/weiwu/Documents/MATLAB/200/mgNetworkVerify1.ini")
[ Info: 2021-11-12 11:24:48 : Precision used: Double
┌ Info: 2021-11-12 11:24:48 : Circuitscape.jl starts counting nodes from 1, 
└ not 0. This will be reflected in the outputs.
ERROR: ArgumentError: column indices J[k] must satisfy 1 <= J[k] <= n
Stacktrace:
 [1] sparse!(I::Vector{Int64}, J::Vector{Int64}, V::Vector{Float64}, m::Int64, n::Int64, combine::typeof(+), klasttouch::Vector{Int64}, csrrowptr::Vector{Int64}, csrcolval::Vector{Int64}, csrnzval::Vector{Float64}, csccolptr::Vector{Int64}, cscrowval::Vector{Int64}, cscnzval::Vector{Float64})
   @ SparseArrays /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:889
 [2] sparse(I::Vector{Int64}, J::Vector{Int64}, V::Vector{Float64}, m::Int64, n::Int64, combine::Function)
   @ SparseArrays /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:798
 [3] sparse
   @ /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:987 [inlined]
 [4] compute_advanced_data(data::Circuitscape.NetworkData{Float64, Int64}, flags::Circuitscape.NetworkFlags, cfg::Dict{String, String})
   @ Circuitscape ~/.julia/packages/Circuitscape/a9Quh/src/network/advanced.jl:30
 [5] network_advanced(T::Type, V::Type, cfg::Dict{String, String})
   @ Circuitscape ~/.julia/packages/Circuitscape/a9Quh/src/network/advanced.jl:10
 [6] _compute(T::Type, V::Type, cfg::Dict{String, String})
   @ Circuitscape ~/.julia/packages/Circuitscape/a9Quh/src/run.jl:55
 [7] macro expansion
   @ ./timing.jl:299 [inlined]
 [8] compute(path::String)
   @ Circuitscape ~/.julia/packages/Circuitscape/a9Quh/src/run.jl:31
 [9] top-level scope
   @ REPL[19]:1
@wwucl2019
Copy link
Author

@andreasnoack @ViralBShah @tanmaykm @yeesian , any expert can help with this issue?

@francescmolne
Copy link

Hi @wwucl2019 , I'm having the same problem. Have you already found a solution? I'm trying, I'll keep you updated if I find a way...👍

@csadorf
Copy link

csadorf commented Mar 15, 2022

@francescmolne Have you been able to resolve the problem?

@wwucl2019
Copy link
Author

@francescmolne , no I haven't. CS@julia not working for me, but GUI on Mac and Windows works fine. So strange.

@unkcpz
Copy link

unkcpz commented Mar 31, 2022

Hi @wwucl2019, I give a quick look at this issue and the data you provided. It seems there is a 'j' index (j=92 from the file mgNetworkVerify1_graph_resistances.txt) of your data that exceeding the upbound of the J[end]=91 . Can you also describe how you get the input data? I think this is the source of the issue. But I only look it from data side with zero knowledge of how Circuitscape works.

Anyway, I think there should be an easy fix for the issue, maybe from Circuitscape side you can check the code below to see whether you can set the sparse matrix dimension based on the i,j index as default? (sparse(i,j,v,m,m) -> sparse(i,j,v))

function compute_advanced_data(data::NetworkData{T,V}, 
                            flags, cfg)::AdvancedProblem{T,V} where {T,V}


    i,j,v = data.coords


    idx = findfirst(x -> x < 1, i)
    idx != nothing && throw("Indices no good")
    idx = findfirst(x -> x < 1, j)
    idx != nothing && throw("Indices no good")


    m = max(i[end], j[end])
    A = sparse(i,j,v,m,m)

@ranjanan
Copy link
Member

ranjanan commented Apr 2, 2022

As @unkcpz helpfully points out, the issue is in the sparse matrix construction. #357 should fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants