# EnsembleSummary of SDEProblem with output\_func gives incorrect dimensions

**URL:** https://discourse.julialang.org/t/ensemblesummary-of-sdeproblem-with-output-func-gives-incorrect-dimensions/130516
**Category:** General Usage
**Tags:** question, diffeq, sde, differentialequation
**Created:** [July 6, 2025, 4:58am UTC](https://discourse.julialang.org/t/ensemblesummary-of-sdeproblem-with-output-func-gives-incorrect-dimensions/130516 "2025-07-06T04:58:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Rodrigo\_Zepeda](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rodrigo_zepeda/32/17935_2.png) [@Rodrigo\_Zepeda](https://discourse.julialang.org/u/Rodrigo_Zepeda)
#### Post date: [July 6, 2025, 4:58am UTC](https://discourse.julialang.org/t/ensemblesummary-of-sdeproblem-with-output-func-gives-incorrect-dimensions/130516/1 "2025-07-06T04:58:30Z")

</div>

I’m using `DifferentialEquations.jl` to solve an `SDEProblem` with a custom `output_func`. I am then trying to summarize multiple trajectories with `EnsembleSummary`. However, the resulting summary has the wrong dimensions for the solution array (seems to be collapsing everything?), and I can’t figure out why or how I should change it.

Here is a toy example of what I am doing:

```julia
using DifferentialEquations

#Define a simple sde model
function f(du, u, p, t)
    du[1] = 1.01*u[1]
    du[2] = 0.99*u[2] 
    du[3] = u[2]*u[1] - u[3]
end

#Some noise
function noise!(du, u, p, t)
    du .= 0.1*u
end

u0 = [0.5, 1.0, 1.2]
prob = SDEProblem(f, noise!, u0, (0.0, 1.0))

#Add a custom output function that should return 4 values
function output_func(sol, i)

    #Some 1 dimensional outputs
    output1 = 3*sol[1,:]                   
    output2 = sol[1,:] + 2*sol[2,:]        

    #My problem has several of these where i am using multiple entries of 
    #solution at the same time
    output3 = 0.5*sol[1:2,:] - 0.4*sol[2:3,:]  

    (u = [output1, output2, output3], t = sol.t), false
end

#Works for running the problem
ensemble_prob = EnsembleProblem(prob; output_func=output_func)
sim = solve(ensemble_prob, SOSRI(), EnsembleThreads(); trajectories=10, saveat=0.1)

#However summ.u returns an object of size (11, 2)! (should be (11,4))
summ = EnsembleSummary(sim)

```

This is the problem:

```julia
julia> size(summ.u)
(11, 2)

```

My question is: **How should I structure the `output_func` so that `EnsembleSummary` combines trajectories correctly?**

## Additional info

This is my `summ.u` which for some reason is ignoring `output_3` (even if you change `output_3` to be a vector and not a matrix).

```julia
julia> summ.u
t: 11-element Vector{Float64}:
 0.0
 0.1
 0.2
 0.3
 0.4
 0.5
 0.6
 0.7
 0.8
 0.9
 1.0
u: 2-element Vector{Vector{Float64}}:
 [1.5, 1.6779729999930952, 1.882802689892928, 2.0791973541348807, 2.289813760785018, 2.522292007510237, 2.7381454998246877, 3.0130258988579692, 3.3164391128403614, 3.6792412500574008, 4.0170165276054375]
 [2.5, 2.7426439877742514, 3.037732776506048, 3.2959205715740034, 3.63409275722072, 3.979916259016065, 4.370649184574971, 4.792145677419358, 5.3130449045579144, 5.949865231659005, 6.497619744969697]

```

And this is additional info on the differential equations package:

```julia
julia> pkgversion(DifferentialEquations)
v"7.16.1"

```

---

<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: [July 6, 2025, 9:19pm UTC](https://discourse.julialang.org/t/ensemblesummary-of-sdeproblem-with-output-func-gives-incorrect-dimensions/130516/2 "2025-07-06T21:19:27Z")

</div>

Open up an issue on SciMLBase.jl

---

<div class="post-metadata">

### Author: ![Rodrigo\_Zepeda](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rodrigo_zepeda/32/17935_2.png) [@Rodrigo\_Zepeda](https://discourse.julialang.org/u/Rodrigo_Zepeda)
#### Post date: [July 7, 2025, 12:06am UTC](https://discourse.julialang.org/t/ensemblesummary-of-sdeproblem-with-output-func-gives-incorrect-dimensions/130516/3 "2025-07-07T00:06:14Z")

</div>

Will do, thanks
