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.

VectorContinuousCallback with duplicate events causes infinite loop #889

Closed

Description

@pepijndevos

MWE:

using OrdinaryDiffEq

f = function (u, p, t)
    -u + sin(-t)
end

prob = ODEProblem(f, 1.0, (0.0, -10.0))

condition(out, u, t, integrator) = out[:] = [-t - 2.95, -t - 2.95]

function affect!(integrator, idx)
    @show integrator, idx
    integrator.u = integrator.u + 2
end

callback = VectorContinuousCallback(condition, affect!, 2)

sol = solve(prob, Tsit5(), callback = callback)

Of course for trivial cases the answer is "don't do that" but when different components or computations end up with the same event, this causes problems.

I've been looking into it a little bit and it seems that find_callback_time gets a vector of all the callbacks that changed sign, so I imagine it should check if after the rootfinding it can "check off" multiple events and move on, but I don't fully understand the code yet, and maybe it's a lot more complicated than that, judging by all the comment about floating point details.

Activity

  1. DaniGlez commented on Mar 11, 2025

    @DaniGlez
    Contributor

    I think the main discussion regarding handling of simulteaneous events is in SciML/OrdinaryDiffEq.jl#3220 as of now, linking it to connect the discussions (and maybe use this MWE for a test in the future). FWIW, this example kind of works as of DiffEqBase 6.164.2 with right-sided rootfinding (but it will only detect a triggering event instead of both of them, which would be the correct behavior).

    callback = VectorContinuousCallback(condition, affect!, 2, rootfind=SciMLBase.RightRootFind)
  2. ChrisRackauckas commented on Mar 11, 2025

    @ChrisRackauckas
    Member

    Ben has a PR that should be coming rather soon, like in the next few weeks.

  3. ChrisRackauckas-Claude commented on Mar 24, 2026

    @ChrisRackauckas-Claude
    Member

    Triage: This appears to be fixed. The MWE with duplicate events in VectorContinuousCallback now solves successfully with retcode=Success on DiffEqBase v6.211.0 / Julia 1.10.11. No infinite loop occurs. Recommend closing.

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

Metadata

Metadata

Assignees

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