Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.
This repository was archived by the owner on May 12, 2026. It is now read-only.

MonteCarloSummary for integer u0. #353

Closed

Description

@korsbo

This may not be a big issue, but I thought I'd report it.

MonteCarloSummary does not work if you have used an initial condition of integers. This error popped up for me when I was playing with jump equations. An obvious workaroud is to use floats in the u0 vector, so this problem is not very crippling. It would, however, be more pleasing if the function handled Integer input too.

using DifferentialEquations

rn = @reaction_network test begin
    (p, d), 0 ↔ x
    end p d
p = [100., 1]
u0 = [0]
tspan = (0., 10)

discrete_prob = DiscreteProblem(u0,tspan,p)
# discrete_prob = DiscreteProblem(float.(u0),tspan,p) # works
jump_prob = JumpProblem(discrete_prob,Direct(),rn)
mc_prob = MonteCarloProblem(jump_prob)
sol = solve(mc_prob,FunctionMap(); num_monte=10)
summary = MonteCarloSummary(sol)
InexactError: Int64(0.2)

Stacktrace:
 [1] Type at ./float.jl:703 [inlined]
 [2] convert at ./number.jl:7 [inlined]
 [3] setindex! at ./array.jl:767 [inlined]
 [4] macro expansion at ./broadcast.jl:843 [inlined]
 [5] macro expansion at ./simdloop.jl:73 [inlined]
 [6] copyto! at ./broadcast.jl:842 [inlined]
 [7] copyto! at ./broadcast.jl:797 [inlined]
 [8] materialize!(::Array{Int64,1}, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(+),Tuple{Array{Int64,1},Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(/),Tuple{Array{Int64,1},Int64}}}}) at ./broadcast.jl:756
 [9] #componentwise_meanvar#57(::Bool, ::Function, ::Base.Generator{MonteCarloSolution{Int64,3,Array{ODESolution{Int64,2,Array{Array{Int64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},DiscreteProblem{Array{Int64,1},Tuple{Float64,Float64},true,Array{Float64,1},DiscreteFunction{true,getfield(DiffEqBase, Symbol("##270#271")),Nothing},Nothing},FunctionMap{false},OrdinaryDiffEq.InterpolationData{DiscreteFunction{true,getfield(DiffEqBase, Symbol("##270#271")),Nothing},Array{Array{Int64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.FunctionMapCache{Array{Int64,1},Array{Int64,1}}}},1}},getfield(DiffEqMonteCarlo, Symbol("##14#15")){Float64}}) at /home/Niklas/.julia/packages/DiffEqMonteCarlo/c9ztK/src/analysis.jl:180
 [10] componentwise_meanvar at /home/Niklas/.julia/packages/DiffEqMonteCarlo/c9ztK/src/analysis.jl:170 [inlined]
 [11] timepoint_meanvar at /home/Niklas/.julia/packages/DiffEqMonteCarlo/c9ztK/src/analysis.jl:97 [inlined]
 [12] timeseries_point_meanvar(::MonteCarloSolution{Int64,3,Array{ODESolution{Int64,2,Array{Array{Int64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},DiscreteProblem{Array{Int64,1},Tuple{Float64,Float64},true,Array{Float64,1},DiscreteFunction{true,getfield(DiffEqBase, Symbol("##270#271")),Nothing},Nothing},FunctionMap{false},OrdinaryDiffEq.InterpolationData{DiscreteFunction{true,getfield(DiffEqBase, Symbol("##270#271")),Nothing},Array{Array{Int64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.FunctionMapCache{Array{Int64,1},Array{Int64,1}}}},1}}, ::Array{Float64,1}) at /home/Niklas/.julia/packages/DiffEqMonteCarlo/c9ztK/src/analysis.jl:131
 [13] #MonteCarloSummary#38(::Array{Float64,1}, ::Type, ::MonteCarloSolution{Int64,3,Array{ODESolution{Int64,2,Array{Array{Int64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},DiscreteProblem{Array{Int64,1},Tuple{Float64,Float64},true,Array{Float64,1},DiscreteFunction{true,getfield(DiffEqBase, Symbol("##270#271")),Nothing},Nothing},FunctionMap{false},OrdinaryDiffEq.InterpolationData{DiscreteFunction{true,getfield(DiffEqBase, Symbol("##270#271")),Nothing},Array{Array{Int64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.FunctionMapCache{Array{Int64,1},Array{Int64,1}}}},1}}, ::Array{Float64,1}) at /home/Niklas/.julia/packages/DiffEqMonteCarlo/c9ztK/src/analysis.jl:105
 [14] MonteCarloSummary(::MonteCarloSolution{Int64,3,Array{ODESolution{Int64,2,Array{Array{Int64,1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{Float64,1},1},1},DiscreteProblem{Array{Int64,1},Tuple{Float64,Float64},true,Array{Float64,1},DiscreteFunction{true,getfield(DiffEqBase, Symbol("##270#271")),Nothing},Nothing},FunctionMap{false},OrdinaryDiffEq.InterpolationData{DiscreteFunction{true,getfield(DiffEqBase, Symbol("##270#271")),Nothing},Array{Array{Int64,1},1},Array{Float64,1},Array{Array{Array{Float64,1},1},1},OrdinaryDiffEq.FunctionMapCache{Array{Int64,1},Array{Int64,1}}}},1}}, ::Array{Float64,1}) at /home/Niklas/.julia/packages/DiffEqMonteCarlo/c9ztK/src/analysis.jl:104 (repeats 2 times)
 [15] top-level scope at In[7]:13

Activity

  1. ChrisRackauckas commented on Feb 2, 2019

    @ChrisRackauckas
    Member

    We need to add float to some of the pre-allocations, since things like mean should always just use the float for completeness.

  2. ChrisRackauckas-Claude commented on Mar 24, 2026

    @ChrisRackauckas-Claude
    Member

    Triage: This is fixed. EnsembleSummary (renamed from MonteCarloSummary, now in SciMLBase) works with integer u0 on DiffEqBase v6.211.0 / SciMLBase v2.151.0 / Julia 1.10.11. Recommend closing.

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