From 1c78dee591ac5623a240084005545dbca04e2941 Mon Sep 17 00:00:00 2001 From: Benjamin Chung Date: Mon, 9 Dec 2024 03:16:24 -0800 Subject: [PATCH] Fix tests & update API usage --- src/systems/callbacks.jl | 2 +- src/systems/imperative_affect.jl | 4 ++-- test/symbolic_events.jl | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/systems/callbacks.jl b/src/systems/callbacks.jl index 4533534029..57db5e097c 100644 --- a/src/systems/callbacks.jl +++ b/src/systems/callbacks.jl @@ -818,7 +818,7 @@ function generate_vector_rootfinding_callback( let save_idxs = save_idxs custom_init = fn.initialize (i) -> begin - isnothing(custom_init) && custom_init(i) + !isnothing(custom_init) && custom_init(i) for idx in save_idxs SciMLBase.save_discretes!(i, idx) end diff --git a/src/systems/imperative_affect.jl b/src/systems/imperative_affect.jl index f20ad941da..19f7f7590d 100644 --- a/src/systems/imperative_affect.jl +++ b/src/systems/imperative_affect.jl @@ -175,7 +175,7 @@ function compile_user_affect(affect::ImperativeAffect, cb, sys, dvs, ps; kwargs. end obs_fun = build_explicit_observed_function( sys, Symbolics.scalarize.(obs_exprs); - array_type = Tuple) + mkarray = (es,_) -> MakeTuple(es)) obs_sym_tuple = (obs_syms...,) # okay so now to generate the stuff to assign it back into the system @@ -183,7 +183,7 @@ function compile_user_affect(affect::ImperativeAffect, cb, sys, dvs, ps; kwargs. mod_names = (mod_syms...,) mod_og_val_fun = build_explicit_observed_function( sys, Symbolics.scalarize.(first.(mod_pairs)); - array_type = Tuple) + mkarray = (es,_) -> MakeTuple(es)) upd_funs = NamedTuple{mod_names}((setu.((sys,), first.(mod_pairs))...,)) diff --git a/test/symbolic_events.jl b/test/symbolic_events.jl index 717d2438ac..858a30f4fd 100644 --- a/test/symbolic_events.jl +++ b/test/symbolic_events.jl @@ -936,7 +936,7 @@ end @named trigsys = ODESystem(eqs, t; continuous_events = [evt1, evt2]) trigsys_ss = structural_simplify(trigsys) prob = ODEProblem(trigsys_ss, [], (0.0, 2π)) - sol = solve(prob, Tsit5()) + sol = solve(prob, Tsit5(); dtmax=0.01) required_crossings_c1 = [π / 2, 3 * π / 2] required_crossings_c2 = [π / 6, π / 2, 5 * π / 6, 7 * π / 6, 3 * π / 2, 11 * π / 6] @test maximum(abs.(first.(cr1) .- required_crossings_c1)) < 1e-4 @@ -1079,8 +1079,8 @@ end @test sort(canonicalize(Discrete(), prob.p)[1]) == [0.0, 1.0, 2.0] sol = solve(prob, Tsit5()) - @test sol[a] == [-1.0] - @test sol[b] == [5.0, 5.0] + @test sol[a] == [1.0,-1.0] + @test sol[b] == [2.0,5.0, 5.0] @test sol[c] == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0] end @testset "Heater" begin @@ -1248,7 +1248,7 @@ end ss = structural_simplify(sys) prob = ODEProblem(ss, [theta => 0.0], (0.0, pi)) sol = solve(prob, Tsit5(); dtmax = 0.01) - @test getp(sol, cnt)(sol) == 197 # we get 2 pulses per phase cycle (cos 0 crossing) and we go to 100 cycles; we miss a few due to the initial state + @test getp(sol, cnt)(sol) == 198 # we get 2 pulses per phase cycle (cos 0 crossing) and we go to 100 cycles; we miss a few due to the initial state end @testset "Initialization" begin