Julia 1.10 and Ensemble Summary command error

I updated to Julia 1.10 and was checking my past codes. Everything works fine, except for the EnsembleSummary function. I get the following error:

ERROR: type NamedTuple has no field u

The previous Julia version was 1.9.1. Here is the code:

using DifferentialEquations
using OrderedCollection, ComponentArrays
using QuasiMonteCarlo, Random

# Add ODE function file
include("pk_model.jl");

# Add parameter file 
include("parameters.jl");

# Set intiaal conditions/Parameters
# Extravascular compartment EV has an initial bolus dose of 100 mg 
Dose_mg = 100.0;
u0 = [Dose_mg, 0.0, 0.0];

#Define the simulation timespan
T = 30;
tspan = (0.0, T); #days

prob = ODEProblem(pk_model!, u0, tspan, collect(param));

#Ensemble Simulations
Random.seed!(1235)
sampler = SobolSample();

#define parameters to be explored and their ranges
params = OrderedDict(:CL=>[0.1, 10.0], :KA=>[0.01, 10.0]);
param_names = collect(keys(params));
param_values = collect(values(params));

# lower and upper bound for model parameters
lb = reduce(hcat,param_values)[1,:];
ub = reduce(hcat,param_values)[2,:];

Num = 1000; 
vals = QuasiMonteCarlo.sample(Num, lb, ub, sampler);
CL_vals = vals[1,:];
KA_vals = vals[2,:];

params = OrderedDict(:CL=>CL_vals, 
              :KA=>KA_vals);
param_names = collect(keys(params));
param_values = reduce(hcat,collect(values(params)));

# create problem function to pass different values
function prob_func(prob,i,repeat)
    p_pop = deepcopy(param);
    p_pop[param_names] = param_values[i,:];
    remake(prob, u0=u0, tspan = tspan, p=collect(p_pop));
end

# create an output function for things that need to be summarized
function output_func(sol,i)
    ((ev = sol[1,:], cp=sol[2,:], t=sol.t), false)
end

# create an ensemble problem to perform the simulations
t = collect(range(0, stop=20.0, length=200));
ensemble_prob = EnsembleProblem(prob, prob_func=prob_func, output_func=output_func);
ensemble_sol = solve(ensemble_prob, saveat=t, EnsembleSerial(), trajectories=Num);  

summ = EnsembleSummary(ensemble_sol;quantiles=[0.05,0.95]);

Thanks!

have you also updated all the packages in your environment? or only the julia version

I updated the packages that I am using regularly. I just checked the DifferentialEquations package and the version I have is v7.12.0, which is the most recent.

@SebastianM-C fix deprecated indexing in EnsembleSummary plot recipe by SebastianM-C · Pull Request #604 · SciML/SciMLBase.jl · GitHub was incorrect, it needed to check for AbstractVectorOfArray before the .u.

Ah, that’s because of the output_func, sorry for the bug, I’m trying to have make a MWE to add as a test to avoid further regressions.

So when we we don’t have AbstractVectorOfArray, we should assume linear indexing working directly?

Oh, I think fix: fix EnsembleAnalysis methods for RAT v3 (again) by AayushSabharwal · Pull Request #599 · SciML/SciMLBase.jl · GitHub broke this (too), as

using OrdinaryDiffEq

prob = ODEProblem((u, p, t) -> 1.01u, 0.5, (0.0, 1.0))

function prob_func(prob, i, repeat)
    remake(prob, u0=rand() * prob.u0)
end


function output_func(sol, i)
    (x = sol[1,:], t = sol.t), false
end

ensemble_prob = EnsembleProblem(prob; prob_func, output_func)
sim = solve(ensemble_prob, Tsit5(), EnsembleThreads(), trajectories=10)

summ = EnsembleSummary(sim)

gives

ERROR: type NamedTuple has no field u
Stacktrace:
  [1] getproperty
    @ .\Base.jl:37 [inlined]
  [2] (::SciMLBase.EnsembleAnalysis.var"#1#2"{Int64})(sol::@NamedTuple{x::Vector{Float64}, t::Vector{Float64}})
    @ SciMLBase.EnsembleAnalysis .\none:0
  [3] iterate
    @ .\generator.jl:47 [inlined]
  [4] first(itr::Base.Generator{EnsembleSolution{Vector{…}, 1, Vector{…}}, SciMLBase.EnsembleAnalysis.var"#1#2"{Int64}})
    @ Base .\abstractarray.jl:469
  [5] componentwise_meanvar(A::Base.Generator{EnsembleSolution{…}, SciMLBase.EnsembleAnalysis.var"#1#2"{…}}; bessel::Bool)
    @ SciMLBase.EnsembleAnalysis C:\Users\sebastian\.julia\dev\SciMLBase\src\ensemble\ensemble_analysis.jl:210
  [6] componentwise_meanvar(A::Base.Generator{EnsembleSolution{…}, SciMLBase.EnsembleAnalysis.var"#1#2"{…}})
    @ SciMLBase.EnsembleAnalysis C:\Users\sebastian\.julia\dev\SciMLBase\src\ensemble\ensemble_analysis.jl:209
  [7] timestep_meanvar(sim::EnsembleSolution{Vector{Float64}, 1, Vector{@NamedTuple{x::Vector{…}, t::Vector{…}}}}, i::Int64)
    @ SciMLBase.EnsembleAnalysis C:\Users\sebastian\.julia\dev\SciMLBase\src\ensemble\ensemble_analysis.jl:46
  [8] timeseries_steps_meanvar(sim::EnsembleSolution{Vector{Float64}, 1, Vector{@NamedTuple{x::Vector{…}, t::Vector{…}}}})
    @ SciMLBase.EnsembleAnalysis C:\Users\sebastian\.julia\dev\SciMLBase\src\ensemble\ensemble_analysis.jl:73
  [9] EnsembleSummary(sim::EnsembleSolution{Vector{…}, 1, Vector{…}}, t::Vector{Float64}; quantiles::Vector{Float64})
    @ SciMLBase.EnsembleAnalysis C:\Users\sebastian\.julia\dev\SciMLBase\src\ensemble\ensemble_analysis.jl:132
 [10] EnsembleSummary(sim::EnsembleSolution{Vector{Float64}, 1, Vector{@NamedTuple{…}}}, t::Vector{Float64})
    @ SciMLBase.EnsembleAnalysis C:\Users\sebastian\.julia\dev\SciMLBase\src\ensemble\ensemble_analysis.jl:124
 [11] EnsembleSummary(sim::EnsembleSolution{Vector{Float64}, 1, Vector{@NamedTuple{x::Vector{Float64}, t::Vector{Float64}}}})
    @ SciMLBase.EnsembleAnalysis C:\Users\sebastian\.julia\dev\SciMLBase\src\ensemble\ensemble_analysis.jl:124
 [12] top-level scope
    @ c:\Users\sebastian\Documents\JuliaSim\bugs\ensemble.jl:17
Some type information was truncated. Use `show(err)` to see complete types.

Due to SciMLBase.jl/src/ensemble/ensemble_analysis.jl at e46e49152958b314a8c277ec4ce1c7469cb9e686 · SciML/SciMLBase.jl · GitHub

assuming AbstractVectorOfArray in indexing across timesteps.

But yeah, my PR would also introduce bugs too :sweat_smile: , I’m working on a fix.

Edit: Fix PR [WIP] Fix Ensemble indexing when `output_func` is used by SebastianM-C · Pull Request #607 · SciML/SciMLBase.jl · GitHub