# GSA with the Sobol method for steady-state solution error

**URL:** <https://discourse.julialang.org/t/gsa-with-the-sobol-method-for-steady-state-solution-error/122264>\
**Category:** Modelling & Simulations\
**Created:** [November 4, 2024, 10:40pm UTC](https://discourse.julialang.org/t/gsa-with-the-sobol-method-for-steady-state-solution-error/122264 "2024-11-04T22:40:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.julialang.org/u/Nick1)\
**Post date:** [November 4, 2024, 10:40pm UTC](https://discourse.julialang.org/t/gsa-with-the-sobol-method-for-steady-state-solution-error/122264/1 "2024-11-04T22:40:14Z")

</div>

I perform GSA with the Sobol method for a system of ODEs for steady-state but I get the following error:

> ERROR: TaskFailedException
> 
> ```
> nested task error: MethodError: Cannot `convert` an object of type Vector{Float64} to an object of type Float64
> 
> Closest candidates are:
> convert(::Type{T}, ::VectorizationBase.AbstractSIMD) where T<:Union{Bool, Float16, Float32, Float64, Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8, SIMDTypes.Bit}
> 
> ```

Here is the function I use for the Sobol method:

```julia
# GSA using chunks
ensemble_chunked = function (p)
    global parameterset = p
  
    Np::Int64 = size(p,2)
  
    println("Running ", Np, " cases.")
  
    chunksize::Int64 = Np/chunks
  
    println("Using ", chunks, " chunk(s) of size ", chunksize, ".")
  
  
    out = zeros(10,Np)
  
    for k in 1:chunks
        offset = Int((k - 1) * Np/chunks)
        startindx = Int(offset + 1)
        endindx = Int(k * Np/chunks)
  
        println("Starting chunk ", k, ", from ", startindx, " to ", endindx, " with offset ", offset, ".")
  
        pchunk = p[:,startindx:endindx]
  

        function prob_func(prob,i,repeat)
            # p[:,i] is the ith set of parameters

            p_pop = deepcopy(param);
            p_pop[param_names] = pchunk[:,i];
            remake(prob_ss;p=collect(p_pop))
        end
        
  
        ensemble_prob = EnsembleProblem(prob_ss,prob_func=prob_func)
  
        @time " ODE Ensemble solved in " sol_ss = solve(ensemble_prob, alg=DynamicSS(AutoTsit5(Rosenbrock23(autodiff=false))), EnsembleThreads();trajectories=chunksize)
  
        @time " Results processed in " Threads.@threads for i in 1:chunksize
            out[1,i+offset] = sol_ss[63] + sol_ss[68] + sol_ss[69];   
            out[2,i+offset] = sol_ss[65] + sol_ss[66] + sol_ss[69];   
            out[3,i+offset] = sol_ss[67] + sol_ss[68];   
            out[4,i+offset] = sol_ss[42];   
            out[5,i+offset] = sol_ss[14] + sol_ss[18];  
            out[6,i+offset] = sol_ss[30] + sol_ss[60];  
            out[7,i+offset] = sol_ss[25];  
            out[8,i+offset] = sol_ss[72];  
            out[9,i+offset] = sol_ss[3];  
            out[10,i+offset] = sol_ss[31];  

        end
    end
    out
end

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 5, 2024, 8:48am UTC](https://discourse.julialang.org/t/gsa-with-the-sobol-method-for-steady-state-solution-error/122264/2 "2024-11-05T08:48:02Z")

</div>

What line is it pointing to? You dropped the stack trace.

---

<div class="post-metadata">

**Author:** ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.julialang.org/u/Nick1)\
**Post date:** [November 5, 2024, 8:28pm UTC](https://discourse.julialang.org/t/gsa-with-the-sobol-method-for-steady-state-solution-error/122264/3 "2024-11-05T20:28:48Z")

</div>

My bad. Here is the stack track

> Closest candidates are:  
> convert(::Type{T}, ::VectorizationBase.AbstractSIMD) where T\<:Union{Bool, Float16, Float32, Float64, Int16, Int32, Int64, Int8, UInt16, UInt32, UInt64, UInt8, SIMDTypes.Bit}  
> @ VectorizationBase C:\Users\memmo.julia\packages\VectorizationBase\LqJbS\src\base\_defs.jl:201  
> convert(::Type{T}, ::VectorizationBase.LazyMulAdd{M, O, I}) where {M, O, I, T\<:Number}  
> @ VectorizationBase C:\Users\memmo.julia\packages\VectorizationBase\LqJbS\src\lazymul.jl:25  
> convert(::Type{T}, ::Union{Static.StaticBool{N}, Static.StaticFloat64{N}, Static.StaticInt{N}} where N) where T\<:Number  
> @ Static C:\Users\memmo.julia\packages\Static\1Mvph\src\Static.jl:427  
> …
> 
> ```
> Stacktrace:
> [1] setindex!
> @ .\array.jl:1024 [inlined]
> [2] macro expansion
> @ c:\Users\memmo\Desktop\papers \parameter estimation\msi\steady state\sobol_experimental.jl:199 [inlined]
> [3] (::var"#23#threadsfor_fun#15"{var"#23#threadsfor_fun#12#16"{…}})(tid::Int64; onethread::Bool)
> @ Main .\threadingconstructs.jl:215
> [4] #23#threadsfor_fun
> @ .\threadingconstructs.jl:182 [inlined]
> [5] (::Base.Threads.var"#1#2"{var"#23#threadsfor_fun#15"{var"#23#threadsfor_fun#12#16"{…}}, Int64})()
> @ Base.Threads .\threadingconstructs.jl:154
> 
> ```
> 
> Stacktrace:  
> [1] threading\_run(fun::var"#23#threadsfor\_fun#15"{var"#23#threadsfor\_fun#12#16"{…}}, static::Bool)  
> @ Base.Threads .\threadingconstructs.jl:172  
> [2] macro expansion  
> @ .\threadingconstructs.jl:220 [inlined]  
> [3] macro expansion  
> @ .\timing.jl:279 [inlined]  
> [4] (::var"#11#13")(p::Matrix{Float64})  
> @ Main c:\Users\memmo\Desktop\papers \parameter estimation\msi\steady state\sobol\_experimental.jl:198  
> [5] gsa(f::var"#11#13", method::Sobol, A::Matrix{…}, B::Matrix{…}; batch::Bool, Ei\_estimator::Symbol, distributed::Val{…}, kwargs::@Kwargs{})  
> @ GlobalSensitivity C:\Users\memmo.julia\packages\GlobalSensitivity\fxoe7\src\sobol\_sensitivity.jl:138  
> [6] top-level scope  
> @ c:\Users\memmo\Desktop\papers\parameter estimation\msi\steady state\sobol\_experimental.jl:216

I think it points to this line:

```julia
out[1,i+offset] = sol_ss[63] + sol_ss[68] + sol_ss[69];

```

Is it possibly related to the form of the output when I use a steady-state solver?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 5, 2024, 10:21pm UTC](https://discourse.julialang.org/t/gsa-with-the-sobol-method-for-steady-state-solution-error/122264/4 "2024-11-05T22:21:50Z")

</div>

If you’re using an ensemble problem, then `sol_ss` is an EnsembleSolution. This means that `sol_ss[63]` (which should be updated to the form `sol_ss.u[63]`, you should be seeing a deprecation warning) is the 63rd solution. If you have a vector-valued nonlinear problem (system of equations), then `sol_ss.u[63]` is a vector. `out[1,i+offset]` is presumably looking for a float, so that is your issue then.

I think what you really mean then is:

```julia
out[1,i+offset] = sol_ss.u[i][63] + sol_ss.u[i][68] + sol_ss.u[i][69]; 

```

---

<div class="post-metadata">

**Author:** ![Nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@Nick1](https://discourse.julialang.org/u/Nick1)\
**Post date:** [November 7, 2024, 6:04pm UTC](https://discourse.julialang.org/t/gsa-with-the-sobol-method-for-steady-state-solution-error/122264/5 "2024-11-07T18:04:36Z")

</div>

You are right! Thanks!
