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

output functions fail on interpolated solution because of constrained types #165

Open
alaindanet opened this issue Nov 21, 2024 · 0 comments

Comments

@alaindanet
Copy link
Contributor

The output functions defined in src/output-analysis.jl, e.g. total_biomass() fail when using interpolated solution.

A solution might be to add DiffEqArray to accepted types or to relax the type constrain?

A reproducible example:

vegan = Foodweb([:ours => :plant])
m = default_model(vegan)
sol = simulate(m, rand(length(get_species_names(m))), 100)
# Works
julia> total_biomass(sol[:, end])
0.5795782663712777
# Interpolate the solution to get equally sized time steps
last_t = round(sol.t[end])
sol2 = sol(collect(last_t-50:1:last_t))

# Fail because sol2 is of type DiffEqArray
julia> total_biomass(sol2)
ERROR: MethodError: no method matching total_biomass(::DiffEqArray{Float64, 2, Vector{…}, Vector{…}, @NamedTuple{…}, ODESolution{…}, Nothing})

Closest candidates are:
  total_biomass(::AbstractVector)
   @ EcologicalNetworksDynamics ~/.julia/packages/EcologicalNetworksDynamics/R3OJZ/src/output-analysis.jl:125
  total_biomass(::SciMLBase.AbstractODESolution)
   @ EcologicalNetworksDynamics ~/.julia/packages/EcologicalNetworksDynamics/R3OJZ/src/output-analysis.jl:111

Stacktrace:
 [1] top-level scope
   @ REPL[180]:1
 [2] top-level scope
   @ none:1
Some type information was truncated. Use `show(err)` to see complete types.
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

No branches or pull requests

1 participant