Skip to content

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

Description

@alaindanet

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions