Parallel Ensemble Simulations

Performing Monte Carlo simulations, solving with a predetermined set of initial conditions, and GPU-parallelizing a parameter search all fall under the ensemble simulation interface. This interface allows one to declare a template DEProblem to parallelize, tweak the template in trajectories for many trajectories, solve each in parallel batches, reduce the solutions down to specific answers, and compute summary statistics on the results.

Performing an Ensemble Simulation

Building a Problem

To perform a simulation on an ensemble of trajectories, define a EnsembleProblem. The constructor is:

EnsembleProblem(prob::DEProblem;
    output_func = (sol, i) -> (sol, false),
    prob_func = (prob, i, repeat) -> (prob),
    reduction = (u, data, I) -> (append!(u, data), false),
    u_init = [], safetycopy = prob_func !== DEFAULT_PROB_FUNC)
  • output_func: The function determines what is saved from the solution to the output array. Defaults to saving the solution itself. The output is (out,rerun) where out is the output and rerun is a boolean which designates whether to rerun.
  • prob_func: The function by which the problem is to be modified. prob is the problem, i is the unique id 1:trajectories for the problem, and repeat is the iteration of the repeat. At first, it is 1, but if rerun was true this will be 2, 3, etc. counting the number of times problem i has been repeated.
  • reduction: This function determines how to reduce the data in each batch. Defaults to appending the data into u, initialised via u_data, from the batches. I is a range of indices giving the trajectories corresponding to the batches. The second part of the output determines whether the simulation has converged. If true, the simulation will exit early. By default, this is always false.
  • u_init: The initial form of the object that gets updated in-place inside the reduction function.
  • safetycopy: Determines whether a safety deepcopy is called on the prob before the prob_func. By default, this is true for any user-given prob_func, as without this, modifying the arguments of something in the prob_func, such as parameters or caches stored within the user function, are not necessarily thread-safe. If you know that your function is thread-safe, then setting this to false can improve performance when used with threads. For nested problems, e.g., SDE problems with custom noise processes, deepcopy might be insufficient. In such cases, use a custom prob_func.

One can specify a function prob_func which changes the problem. For example:

function prob_func(prob, i, repeat)
    @. prob.u0 = randn() * prob.u0
    prob
end

modifies the initial condition for all of the problems by a standard normal random number (a different random number per simulation). Notice that since problem types are immutable, it uses .=. Otherwise, one can just create a new problem type:

function prob_func(prob, i, repeat)
    @. prob.u0 = u0_arr[i]
    prob
end

If your function is a ParameterizedFunction, you can do similar modifications to prob.f to perform a parameter search. The output_func is a reduction function. Its arguments are the generated solution and the unique index for the run. For example, if we wish to only save the 2nd coordinate at the end of each solution, we can do:

output_func(sol, i) = (sol[end, 2], false)

Thus, the ensemble simulation would return as its data an array which is the end value of the 2nd dependent variable for each of the runs.

Solving the Problem

sim = solve(prob, alg, ensemblealg, kwargs...)

The keyword arguments take in the arguments for the common solver interface and will pass them to the differential equation solver. The ensemblealg is optional, and will default to EnsembleThreads(). The special keyword arguments to note are:

  • trajectories: The number of simulations to run. This argument is required.
  • batch_size : The size of the batches on which the reductions are applies. Defaults to trajectories.
  • pmap_batch_size: The size of the pmap batches. Default is batch_size÷100 > 0 ? batch_size÷100 : 1

EnsembleAlgorithms

The choice of ensemble algorithm allows for control over how the multiple trajectories are handled. Currently, the ensemble algorithm types are:

  • EnsembleSerial() - No parallelism
  • EnsembleThreads() - The default. This uses multithreading. It's local (single computer, shared memory) parallelism only. Fastest when the trajectories are quick.
  • EnsembleDistributed() - Uses pmap internally. It will use as many processors as you have Julia processes. To add more processes, use addprocs(n). See Julia's documentation for more details. Recommended for the case when each trajectory calculation isn't “too quick” (at least about a millisecond each?).
  • EnsembleSplitThreads() - This uses threading on each process, splitting the problem into nprocs() even parts. This is for solving many quick trajectories on a multi-node machine. It's recommended you have one process on each node.
  • EnsembleGPUArray() - Requires installing and using DiffEqGPU. This uses a GPU for computing the ensemble with hyperparallelism. It will automatically recompile your Julia functions to the GPU. A standard GPU sees a 5x performance increase over a 16 core Xeon CPU. However, there are limitations on what functions can auto-compile in this fashion, please see the DiffEqGPU README for more details

For example, EnsembleThreads() is invoked by:

solve(ensembleprob, alg, EnsembleThreads(); trajectories = 1000)

Solution Type

The resulting type is a EnsembleSimulation, which includes the array of solutions.

Plot Recipe

There is a plot recipe for a AbstractEnsembleSimulation which composes all of the plot recipes for the component solutions. The keyword arguments are passed along. A useful argument to use is linealpha which will change the transparency of the plots. An additional argument is idxs which allows you to choose which components of the solution to plot. For example, if the differential equation is a vector of 9 values, idxs=1:2:9 will plot only the solutions of the odd components. Another additional argument is zcolors (an alias of marker_z) which allows you to pass a zcolor for each series. For details about zcolor see the Series documentation for Plots.jl.

Analyzing an Ensemble Experiment

Analysis tools are included for generating summary statistics and summary plots for a EnsembleSimulation.

To use this functionality, import the analysis module via:

using DifferentialEquations.EnsembleAnalysis

(or more directly SciMLBase.EnsembleAnalysis).

Time steps vs time points

For the summary statistics, there are two types. You can either summarize by time steps or by time points. Summarizing by time steps assumes that the time steps are all the same time point, i.e. the integrator used a fixed dt or the values were saved using saveat. Summarizing by time points requires interpolating the solution.

Analysis at a time step or time point

get_timestep(sim, i) # Returns an iterator of each simulation at time step i
get_timepoint(sim, t) # Returns an iterator of each simulation at time point t
componentwise_vectors_timestep(sim, i) # Returns a vector of each simulation at time step i
componentwise_vectors_timepoint(sim, t) # Returns a vector of each simulation at time point t

Summary Statistics

Single Time Statistics

The available functions for time steps are:

timestep_mean(sim, i) # Computes the mean of each component at time step i
timestep_median(sim, i) # Computes the median of each component at time step i
timestep_quantile(sim, q, i) # Computes the quantile q of each component at time step i
timestep_meanvar(sim, i)  # Computes the mean and variance of each component at time step i
timestep_meancov(sim, i, j) # Computes the mean at i and j, and the covariance, for each component
timestep_meancor(sim, i, j) # Computes the mean at i and j, and the correlation, for each component
timestep_weighted_meancov(sim, W, i, j) # Computes the mean at i and j, and the weighted covariance W, for each component

The available functions for time points are:

timepoint_mean(sim, t) # Computes the mean of each component at time t
timepoint_median(sim, t) # Computes the median of each component at time t
timepoint_quantile(sim, q, t) # Computes the quantile q of each component at time t
timepoint_meanvar(sim, t) # Computes the mean and variance of each component at time t
timepoint_meancov(sim, t1, t2) # Computes the mean at t1 and t2, the covariance, for each component
timepoint_meancor(sim, t1, t2) # Computes the mean at t1 and t2, the correlation, for each component
timepoint_weighted_meancov(sim, W, t1, t2) # Computes the mean at t1 and t2, the weighted covariance W, for each component

Full Timeseries Statistics

Additionally, the following functions are provided for analyzing the full timeseries. The mean and meanvar versions return a DiffEqArray which can be directly plotted. The meancov and meancor return a matrix of tuples, where the tuples are the (mean_t1,mean_t2,cov or cor).

The available functions for the time steps are:

timeseries_steps_mean(sim) # Computes the mean at each time step
timeseries_steps_median(sim) # Computes the median at each time step
timeseries_steps_quantile(sim, q) # Computes the quantile q at each time step
timeseries_steps_meanvar(sim) # Computes the mean and variance at each time step
timeseries_steps_meancov(sim) # Computes the covariance matrix and means at each time step
timeseries_steps_meancor(sim) # Computes the correlation matrix and means at each time step
timeseries_steps_weighted_meancov(sim) # Computes the weighted covariance matrix and means at each time step

The available functions for the time points are:

timeseries_point_mean(sim, ts) # Computes the mean at each time point in ts
timeseries_point_median(sim, ts) # Computes the median at each time point in ts
timeseries_point_quantile(sim, q, ts) # Computes the quantile q at each time point in ts
timeseries_point_meanvar(sim, ts) # Computes the mean and variance at each time point in ts
timeseries_point_meancov(sim, ts) # Computes the covariance matrix and means at each time point in ts
timeseries_point_meancor(sim, ts) # Computes the correlation matrix and means at each time point in ts
timeseries_point_weighted_meancov(sim, ts) # Computes the weighted covariance matrix and means at each time point in ts

EnsembleSummary

The EnsembleSummary type is included to help with analyzing the general summary statistics. Two constructors are provided:

EnsembleSummary(sim; quantiles = [0.05, 0.95])
EnsembleSummary(sim, ts; quantiles = [0.05, 0.95])

The first produces a (mean,var) summary at each time step. As with the summary statistics, this assumes that the time steps are all the same. The second produces a (mean,var) summary at each time point t in ts. This requires the ability to interpolate the solution. Quantile is used to determine the qlow and qhigh quantiles at each timepoint. It defaults to the 5% and 95% quantiles.

Plot Recipe

The EnsembleSummary comes with a plot recipe for visualizing the summary statistics. The extra keyword arguments are:

  • idxs: the solution components to plot. Defaults to plotting all components.
  • error_style: The style for plotting the error. Defaults to ribbon. Other choices are :bars for error bars and :none for no error bars.
  • ci_type : Defaults to :quantile which has (qlow,qhigh) quantiles whose limits were determined when constructing the EnsembleSummary. Gaussian CI 1.96*(standard error of the mean) can be set using ci_type=:SEM.

One useful argument is fillalpha which controls the transparency of the ribbon around the mean.

Example 1: Solving an ODE With Different Initial Conditions

Random Initial Conditions

Let's test the sensitivity of the linear ODE to its initial condition. To do this, we would like to solve the linear ODE 100 times and plot what the trajectories look like. Let's start by opening up some extra processes so that way the computation will be parallelized. Here we will choose to use distributed parallelism, which means that the required functions must be made available to all processes. This can be achieved with @everywhere macro:

using Distributed
using DifferentialEquations
using Plots

addprocs()
@everywhere using DifferentialEquations

Now let's define the linear ODE, which is our base problem:

# Linear ODE which starts at 0.5 and solves from t=0.0 to t=1.0
prob = ODEProblem((u, p, t) -> 1.01u, 0.5, (0.0, 1.0))

For our ensemble simulation, we would like to change the initial condition around. This is done through the prob_func. This function takes in the base problem and modifies it to create the new problem that the trajectory actually solves. Here, we will take the base problem, multiply the initial condition by a rand(), and use that for calculating the trajectory:

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

Now we build and solve the EnsembleProblem with this base problem and prob_func:

ensemble_prob = EnsembleProblem(prob, prob_func = prob_func)
sim = solve(ensemble_prob, Tsit5(), EnsembleDistributed(), trajectories = 10)

We can use the plot recipe to plot what the 10 ODEs look like:

plot(sim, linealpha = 0.4)

We note that if we wanted to find out what the initial condition was for a given trajectory, we can retrieve it from the solution. sim[i] returns the ith solution object. sim[i].prob is the problem that specific trajectory solved, and sim[i].prob.u0 would then be the initial condition used in the ith trajectory.

Note: If the problem has callbacks, the functions for the condition and affect! must be named functions (not anonymous functions).

Using multithreading

The previous ensemble simulation can also be parallelized using a multithreading approach, which will make use of the different cores within a single computer. Because the memory is shared across the different threads, it is not necessary to use the @everywhere macro. Instead, the same problem can be implemented simply as:

using DifferentialEquations
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
ensemble_prob = EnsembleProblem(prob, prob_func = prob_func)
sim = solve(ensemble_prob, Tsit5(), EnsembleThreads(), trajectories = 10)
using Plots;
plot(sim);
Example block output

The number of threads to be used has to be defined outside of Julia, in the environmental variable JULIA_NUM_THREADS (see Julia's documentation for details).

Pre-Determined Initial Conditions

Often, you may already know what initial conditions you want to use. This can be specified by the i argument of the prob_func. This i is the unique index of each trajectory. So, if we have trajectories=100, then we have i as some index in 1:100, and it's different for each trajectory.

So, if we wanted to use a grid of evenly spaced initial conditions from 0 to 1, we could simply index the linspace type:

initial_conditions = range(0, stop = 1, length = 100)
function prob_func(prob, i, repeat)
    remake(prob, u0 = initial_conditions[i])
end
prob_func (generic function with 1 method)

It's worth noting that if you run this code successfully, there will be no visible output.

Example 2: Solving an SDE with Different Parameters

Let's solve the same SDE, but with varying parameters. Let's create a Lotka-Volterra system with multiplicative noise. Our Lotka-Volterra system will have as its drift component:

function f(du, u, p, t)
    du[1] = p[1] * u[1] - p[2] * u[1] * u[2]
    du[2] = -3 * u[2] + u[1] * u[2]
end
f (generic function with 1 method)

For our noise function, we will use multiplicative noise:

function g(du, u, p, t)
    du[1] = p[3] * u[1]
    du[2] = p[4] * u[2]
end
g (generic function with 1 method)

Now we build the SDE with these functions:

using DifferentialEquations
p = [1.5, 1.0, 0.1, 0.1]
prob = SDEProblem(f, g, [1.0, 1.0], (0.0, 10.0), p)
SDEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 10.0)
u0: 2-element Vector{Float64}:
 1.0
 1.0

This is the base problem for our study. What would like to do with this experiment is keep the same parameters in the deterministic component each time, but vary the parameters for the amount of noise using 0.3rand(2) as our parameters. Once again, we do this with a prob_func, and here we modify the parameters in prob.p:

# `p` is a global variable, referencing it would be type unstable.
# Using a let block defines a small local scope in which we can
# capture that local `p` which isn't redefined anywhere in that local scope.
# This allows it to be type stable.
prob_func = let p = p
    (prob, i, repeat) -> begin
        x = 0.3rand(2)
        remake(prob, p = [p[1], p[2], x[1], x[2]])
    end
end
#1 (generic function with 1 method)

Now we solve the problem 10 times and plot all of the trajectories in phase space:

ensemble_prob = EnsembleProblem(prob, prob_func = prob_func)
sim = solve(ensemble_prob, SRIW1(), trajectories = 10)
using Plots;
plot(sim, linealpha = 0.6, color = :blue, idxs = (0, 1), title = "Phase Space Plot");
plot!(sim, linealpha = 0.6, color = :red, idxs = (0, 2), title = "Phase Space Plot")
Example block output

We can then summarize this information with the mean/variance bounds using a EnsembleSummary plot. We will take the mean/quantile at every 0.1 time units and directly plot the summary:

summ = EnsembleSummary(sim, 0:0.1:10)
plot(summ, fillalpha = 0.5)
Example block output

Note that here we used the quantile bounds, which default to [0.05,0.95] in the EnsembleSummary constructor. We can change to standard error of the mean bounds using ci_type=:SEM in the plot recipe.

Example 3: Using the Reduction to Halt When Estimator is Within Tolerance

In this problem, we will solve the equation just as many times as needed to get the standard error of the mean for the final time point below our tolerance 0.5. Since we only care about the endpoint, we can tell the output_func to discard the rest of the data.

function output_func(sol, i)
    last(sol), false
end
output_func (generic function with 1 method)

Our prob_func will simply randomize the initial condition:

using DifferentialEquations
# Linear ODE which starts at 0.5 and solves from t=0.0 to t=1.0
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
prob_func (generic function with 1 method)

Our reduction function will append the data from the current batch to the previous batch, and declare convergence if the standard error of the mean is calculated as sufficiently small:

using Statistics
function reduction(u, batch, I)
    u = append!(u, batch)
    finished = (var(u) / sqrt(last(I))) / mean(u) < 0.5
    u, finished
end
reduction (generic function with 1 method)

Then we can define and solve the problem:

prob2 = EnsembleProblem(prob, prob_func = prob_func, output_func = output_func,
    reduction = reduction, u_init = Vector{Float64}())
sim = solve(prob2, Tsit5(), trajectories = 10000, batch_size = 20)
EnsembleSolution Solution of length 20 with uType:
Float64

Since batch_size=20, this means that every 20 simulations, it will take this batch, append the results to the previous batch, calculate (var(u)/sqrt(last(I)))/mean(u), and if that's small enough, exit the simulation. In this case, the simulation exits only after 20 simulations (i.e. after calculating the first batch). This can save a lot of time!

In addition to saving time by checking convergence, we can save memory by reducing between batches. For example, say we only care about the mean at the end once again. Instead of saving the solution at the end for each trajectory, we can instead save the running summation of the endpoints:

function reduction(u, batch, I)
    u + sum(batch), false
end
prob2 = EnsembleProblem(prob, prob_func = prob_func, output_func = output_func,
    reduction = reduction, u_init = 0.0)
sim2 = solve(prob2, Tsit5(), trajectories = 100, batch_size = 20)
EnsembleSolution Solution of length 1 with uType:
Float64

this will sum up the endpoints after every 20 solutions, and save the running sum. The final result will have sim2.u as simply a number, and thus sim2.u/100 would be the mean.

Example 4: Using the Analysis Tools

In this example, we will show how to analyze a EnsembleSolution. First, let's generate a 10 solution Monte Carlo experiment. For our problem, we will use a 4x2 system of linear stochastic differential equations:

function f(du, u, p, t)
    for i in 1:length(u)
        du[i] = 1.01 * u[i]
    end
end
function σ(du, u, p, t)
    for i in 1:length(u)
        du[i] = 0.87 * u[i]
    end
end
using DifferentialEquations
prob = SDEProblem(f, σ, ones(4, 2) / 2, (0.0, 1.0)) #prob_sde_2Dlinear
SDEProblem with uType Matrix{Float64} and tType Float64. In-place: true
timespan: (0.0, 1.0)
u0: 4×2 Matrix{Float64}:
 0.5  0.5
 0.5  0.5
 0.5  0.5
 0.5  0.5

To solve this 10 times, we use the EnsembleProblem constructor and solve with trajectories=10. Since we wish to compare values at the timesteps, we need to make sure the steps all hit the same times. We thus set adaptive=false and explicitly give a dt.

prob2 = EnsembleProblem(prob)
sim = solve(prob2, SRIW1(), dt = 1 // 2^(3), trajectories = 10, adaptive = false)
EnsembleSolution Solution of length 10 with uType:
RODESolution{Float64, 3, Vector{Matrix{Float64}}, Nothing, Nothing, Vector{Float64}, DiffEqNoiseProcess.NoiseProcess{Float64, 3, Float64, Matrix{Float64}, Matrix{Float64}, Vector{Matrix{Float64}}, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Matrix{Float64}, Matrix{Float64}}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Matrix{Float64}, Matrix{Float64}}, true}, DiffEqNoiseProcess.RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDEProblem{Matrix{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, Nothing, SDEFunction{true, SciMLBase.FullSpecialize, typeof(Main.f), typeof(Main.σ), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, typeof(Main.σ), Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, StochasticDiffEq.SRIW1, StochasticDiffEq.LinearInterpolationData{Vector{Matrix{Float64}}, Vector{Float64}}, SciMLBase.DEStats, Nothing}

Note that if you don't do the timeseries_steps calculations, this code is compatible with adaptive timestepping. Using adaptivity is usually more efficient!

We can compute the mean and the variance at the 3rd timestep using:

using DifferentialEquations.EnsembleAnalysis
m, v = timestep_meanvar(sim, 3)
([0.5506190629242435 0.6672064569154652; 0.6961720331049391 0.5214548363508695; 0.8502775041230826 0.6042637707201114; 0.6002154718862941 0.5752276675184219], [0.02761681709519405 0.04692023212652919; 0.05365708153527612 0.02718994949917868; 0.12708769618994692 0.0506792270792336; 0.08216515992251766 0.051761874226391114])

or we can compute the mean and the variance at the t=0.5 using:

m, v = timepoint_meanvar(sim, 0.5)
([0.7466380405676284 0.878941776512219; 1.1738176076614544 0.8038416868500019; 1.099265926229651 0.7154513199947582; 0.6152832949466037 0.7376458644914277], [0.11523279986772465 0.31129023944787904; 1.1467378673418283 0.38458004545840413; 0.2580651213492129 0.1747735994571226; 0.07948261418374124 0.19464426131543316])

We can get a series for the mean and the variance at each time step using:

m_series, v_series = timeseries_steps_meanvar(sim)
(RecursiveArrayTools.DiffEqArray{Float64, 3, Vector{Matrix{Float64}}, Vector{Float64}, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing}([[0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.4876650624742329 0.5306114171773346; 0.5926807520390198 0.5226890070561306; 0.6241782033226562 0.5393494355835698; 0.495036442256917 0.5290815048554732], [0.5506190629242435 0.6672064569154652; 0.6961720331049391 0.5214548363508695; 0.8502775041230826 0.6042637707201114; 0.6002154718862941 0.5752276675184219], [0.6702524430397212 0.7859703294657083; 0.8709986646046868 0.70291882295531; 0.9973486199211636 0.6264924469314748; 0.6133230206278314 0.6041580652276861], [0.7466380405676284 0.878941776512219; 1.1738176076614544 0.8038416868500019; 1.099265926229651 0.7154513199947582; 0.6152832949466037 0.7376458644914277], [0.7831525451362263 0.9732713851658679; 1.3818151747690983 1.121908422115349; 1.2795743289597215 0.8330264652420213; 0.8166709838105145 0.8554409466753511], [0.7802491784633377 1.054230589863179; 1.3548833956353348 1.443773903830294; 1.80823825742904 1.005220107637759; 0.9574507709854342 1.0492884502619257], [0.8512032670983968 1.229447452683503; 1.4195237350488765 1.4797861040299485; 2.723582809188949 1.28842534639494; 0.9279096016485644 1.2989650574167606], [0.8215224145119218 1.346824008987746; 1.7617897533204492 1.46701050523968; 2.7421727953858364 1.3523549654334024; 0.8277058286429858 1.2082613738822758]], [0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0], SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}(nothing, nothing, nothing), nothing, nothing), RecursiveArrayTools.DiffEqArray{Float64, 3, Vector{Matrix{Float64}}, Vector{Float64}, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing, Nothing}([[0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0], [0.013025028686165521 0.019614928606800995; 0.019833947548672442 0.01806274194332081; 0.021725092592587297 0.022756049618683792; 0.015773144094633443 0.028076382690712158], [0.02761681709519405 0.04692023212652919; 0.05365708153527612 0.02718994949917868; 0.12708769618994692 0.0506792270792336; 0.08216515992251766 0.051761874226391114], [0.06318489707872106 0.2052156697367047; 0.3516118335857383 0.09862030845751235; 0.15316169170714147 0.053524223869857696; 0.10175539008083043 0.1226481557482667], [0.11523279986772465 0.31129023944787904; 1.1467378673418283 0.38458004545840413; 0.2580651213492129 0.1747735994571226; 0.07948261418374124 0.19464426131543316], [0.14390925299485155 0.43418769383878597; 0.9901545246338102 0.797860042010038; 0.9163261917402755 0.25774272428130485; 0.2614678880522816 0.3392130543751165], [0.11063400004133384 0.5631838312433827; 0.5846085267829678 2.563037353627663; 2.515493937513877 0.34285105456567955; 0.42968017996281316 0.7509022699902369], [0.14968488018496925 0.9531857048705766; 0.42166137207132764 2.81586341443704; 6.913080567979828 0.9608068224529922; 0.45893998642006 1.4876660345009123], [0.12966252376319531 1.4033944029044187; 1.3084733320534125 3.4216893288903907; 10.708017423079985 1.4486608068848572; 0.2778775622571986 1.1358999202202897]], [0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0], SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}(nothing, nothing, nothing), nothing, nothing))

or at chosen values of t:

ts = 0:0.1:1
m_series = timeseries_point_mean(sim, ts)
t: 0.0:0.1:1.0
u: 11-element Vector{Matrix{Float64}}:
 [0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5]
 [0.4901320499793863 0.5244891337418677; 0.574144601631216 0.5181512056449045; 0.5993425626581248 0.5314795484668557; 0.49602915380553353 0.5232652038843786]
 [0.5254374627442392 0.612568441020213; 0.6547755206785715 0.521948504632974; 0.759837783802912 0.5782980366654947; 0.5581438600345432 0.5567692024532425]
 [0.5984724149704347 0.7147120059355625; 0.7661026857048381 0.5940404309926457; 0.909105950442315 0.6131552412046567; 0.6054584913829091 0.5867998266021276]
 [0.6855295625453028 0.8045646188750105; 0.9315624532160403 0.7231033957342483; 1.0177320811828612 0.6442842215441315; 0.6137150754915858 0.6308556250804344]
 [0.7466380405676283 0.8789417765122188; 1.1738176076614546 0.8038416868500018; 1.099265926229651 0.7154513199947583; 0.6152832949466038 0.7376458644914277]
 [0.7758496442225067 0.9544054634351381; 1.3402156613475698 1.0582950750622797; 1.2435126484137073 0.8095114361925686; 0.7763934460377323 0.8318819302385665]
 [0.7814105251324932 1.0218469079842545; 1.36565610728884 1.3150277111443158; 1.5967726860413127 0.9363426506794637; 0.9011388561154663 0.9717494488272955]
 [0.8086308139173614 1.1243173349913087; 1.3807395314007516 1.4581787839101557; 2.1743760781330037 1.1185022031406315; 0.9456343032506862 1.1491590931238596]
 [0.8452670965811018 1.2529227639443519; 1.487976938703191 1.477230984271895; 2.727300806428327 1.3012112702026326; 0.9078688470474485 1.2808243207098635]
 [0.8215224145119218 1.3468240089877461; 1.7617897533204494 1.46701050523968; 2.742172795385837 1.3523549654334024; 0.8277058286429858 1.2082613738822756]

Note that these mean and variance series can be directly plotted. We can compute covariance matrices similarly:

timeseries_steps_meancov(sim) # Use the time steps, assume fixed dt
timeseries_point_meancov(sim, 0:(1 // 2^(3)):1, 0:(1 // 2^(3)):1) # Use time points, interpolate
9×9 Matrix{Tuple{Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}}:
 ([0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])                                          …  ([0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])
 ([0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.487665 0.530611; 0.592681 0.522689; 0.624178 0.539349; 0.495036 0.529082], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])     ([0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.487665 0.530611; 0.592681 0.522689; 0.624178 0.539349; 0.495036 0.529082], [0.0269468 0.0647867; 0.0763753 0.0624775; 0.213533 0.0268011; 0.00394887 0.000118495])
 ([0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.550619 0.667206; 0.696172 0.521455; 0.850278 0.604264; 0.600215 0.575228], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])     ([0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.550619 0.667206; 0.696172 0.521455; 0.850278 0.604264; 0.600215 0.575228], [0.018754 0.0601622; 0.0449531 0.0896402; 0.782397 0.102437; 0.0991887 0.0765765])
 ([0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.670252 0.78597; 0.870999 0.702919; 0.997349 0.626492; 0.613323 0.604158], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])      ([0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.670252 0.78597; 0.870999 0.702919; 0.997349 0.626492; 0.613323 0.604158], [0.0210728 0.215438; 0.0710373 0.478138; 1.17138 0.17057; 0.115887 0.25137])
 ([0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.746638 0.878942; 1.17382 0.803842; 1.09927 0.715451; 0.615283 0.737646], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])       ([0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.746638 0.878942; 1.17382 0.803842; 1.09927 0.715451; 0.615283 0.737646], [0.0367732 0.288211; 0.127954 1.08189; 0.969318 0.237509; 0.097822 0.411863])
 ([0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.783153 0.973271; 1.38182 1.12191; 1.27957 0.833026; 0.816671 0.855441], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])     …  ([0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.783153 0.973271; 1.38182 1.12191; 1.27957 0.833026; 0.816671 0.855441], [0.0389731 0.505926; 0.515628 1.50389; 2.82981 0.422616; 0.174062 0.604753])
 ([0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.780249 1.05423; 1.35488 1.44377; 1.80824 1.00522; 0.957451 1.04929], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])           ([0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.780249 1.05423; 1.35488 1.44377; 1.80824 1.00522; 0.957451 1.04929], [0.0516086 0.802496; 0.546401 2.91873; 4.90451 0.520031; 0.290338 0.888937])
 ([0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.851203 1.22945; 1.41952 1.47979; 2.72358 1.28843; 0.92791 1.29897], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])            ([0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.851203 1.22945; 1.41952 1.47979; 2.72358 1.28843; 0.92791 1.29897], [0.0969855 1.02565; 0.638363 3.04721; 8.53992 1.1261; 0.329947 1.26386])
 ([0.5 0.5; 0.5 0.5; 0.5 0.5; 0.5 0.5], [0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.0 0.0; 0.0 0.0; 0.0 0.0; 0.0 0.0])           ([0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.821522 1.34682; 1.76179 1.46701; 2.74217 1.35235; 0.827706 1.20826], [0.129663 1.40339; 1.30847 3.42169; 10.708 1.44866; 0.277878 1.1359])

For general analysis, we can build a EnsembleSummary type.

summ = EnsembleSummary(sim)
EnsembleSolution Solution of length 9 with uType:
Float64

will summarize at each time step, while

summ = EnsembleSummary(sim, 0.0:0.1:1.0)
EnsembleSolution Solution of length 11 with uType:
Float64

will summarize at the 0.1 time points using the interpolations. To visualize the results, we can plot it. Since there are 8 components to the differential equation, this can get messy, so let's only plot the 3rd component:

using Plots;
plot(summ; idxs = 3);
Example block output

We can change to errorbars instead of ribbons and plot two different indices:

plot(summ; idxs = (3, 5), error_style = :bars)
Example block output

Or we can simply plot the mean of every component over time:

plot(summ; error_style = :none)
Example block output