From a99c3063b18199271a0e8521e3c5d88421774b15 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Tue, 15 Apr 2025 11:18:50 +0200 Subject: [PATCH 1/2] ODE -> ODETsit5 --- Project.toml | 5 ++--- docs/src/examples/dc_motor_pi.md | 2 +- docs/src/examples/onoffcontroller.md | 2 +- docs/src/examples/sliding_mode_control.md | 7 ++++--- test/test_discrete_blocks.jl | 10 +++++----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index a1053f5..ed8fbb3 100644 --- a/Project.toml +++ b/Project.toml @@ -8,16 +8,15 @@ DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def" JuliaSimCompiler = "8391cb6b-4921-5777-4e45-fd9aab8cb88d" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739" -OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" [compat] DiffEqCallbacks = "~3.8" -JuliaSimCompiler = "0.1.19" ModelingToolkit = "9" ModelingToolkitStandardLibrary = "2" -OrdinaryDiffEq = "6.89" +OrdinaryDiffEqTsit5 = "1.1.0" Random = "1" StableRNGs = "1" julia = "1.10" diff --git a/docs/src/examples/dc_motor_pi.md b/docs/src/examples/dc_motor_pi.md index d4d1fd7..5093caf 100644 --- a/docs/src/examples/dc_motor_pi.md +++ b/docs/src/examples/dc_motor_pi.md @@ -20,7 +20,7 @@ using ModelingToolkit: t_nounits as t using ModelingToolkitStandardLibrary.Electrical using ModelingToolkitStandardLibrary.Mechanical.Rotational using ModelingToolkitStandardLibrary.Blocks -using OrdinaryDiffEq +using OrdinaryDiffEqTsit5 using Plots R = 0.5 # [Ohm] armature resistance diff --git a/docs/src/examples/onoffcontroller.md b/docs/src/examples/onoffcontroller.md index 0c24872..06610fa 100644 --- a/docs/src/examples/onoffcontroller.md +++ b/docs/src/examples/onoffcontroller.md @@ -7,7 +7,7 @@ where ``τ = 100`` is a time constant. The controller ``u = f(x)`` is an on/off ```@example ONOFF -using ModelingToolkit, ModelingToolkitSampledData, OrdinaryDiffEq, Plots +using ModelingToolkit, ModelingToolkitSampledData, OrdinaryDiffEqTsit5, Plots using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks using JuliaSimCompiler diff --git a/docs/src/examples/sliding_mode_control.md b/docs/src/examples/sliding_mode_control.md index 57cfb12..62493e9 100644 --- a/docs/src/examples/sliding_mode_control.md +++ b/docs/src/examples/sliding_mode_control.md @@ -10,7 +10,7 @@ ė = -e which yields the switching variable ``s = ė + e``, encoded in the function ``s = σ(x, t)`` ```@example ONOFF -using ModelingToolkit, ModelingToolkitSampledData, OrdinaryDiffEq, Plots +using ModelingToolkit, ModelingToolkitSampledData, OrdinaryDiffEqTsit5, Plots using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks using JuliaSimCompiler @@ -42,7 +42,7 @@ end end @parameters begin k = 1, [description = "Control gain"] - k2 = 1.1, [description = "Tuning parameter, often set to 1.1"] + k2 = 0.5, [description = "Tuning parameter"] end @variables begin s(t) = 0.0, [description = "Sliding surface"] @@ -85,7 +85,8 @@ prob = ODEProblem(ssys, [m.plant.x => -1, m.plant.xd => 0, m.controller.x(z-1) = sol = solve(prob, Tsit5(), dtmax=0.01) figy = plot(sol, idxs=[m.plant.x]) plot!(sol.t, qr.(sol.t), label="Reference") -figu = plot(sol, idxs=[m.zoh.y, m.disturbance], label=["Control signal" "Disturbance"]) +figu = plot(sol, idxs=m.controller.y, label="Control signal") +plot!(sol, idxs=m.disturbance, label="Disturbance") plot(figy, figu, layout=(2,1)) ``` diff --git a/test/test_discrete_blocks.jl b/test/test_discrete_blocks.jl index 6e9188f..896d3e8 100644 --- a/test/test_discrete_blocks.jl +++ b/test/test_discrete_blocks.jl @@ -1,8 +1,8 @@ using ModelingToolkitSampledData -using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEq +using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEqTsit5 using ModelingToolkitStandardLibrary.Blocks using ModelingToolkit: t_nounits as t, D_nounits as D -using OrdinaryDiffEq: ReturnCode.Success +using OrdinaryDiffEqTsit5: ReturnCode.Success using JuliaSimCompiler using Test Difference = ModelingToolkitSampledData.Difference @@ -56,7 +56,7 @@ end sys = structural_simplify(IRSystem(model)) prob = ODEProblem(sys, Pair[int.x(k - 1) => 1 int.u(k - 1) => 0], (0.0, 1.0)) - sol = solve(prob, Rodas4()) + sol = solve(prob, Tsit5()) @test sol.retcode == Success @test_skip sol.prob.kwargs[:disc_saved_values][1].t ≈ 0:sampletime(clock):1 @test sol[model.int.x] ≈ range(1.1, step = sampletime(clock), length = 11) @@ -73,7 +73,7 @@ end sys = structural_simplify(IRSystem(model)) prob = ODEProblem(sys, Pair[int.x(k - 1) => 1 int.u(k - 1) => 0], (0.0, 1.0)) - sol = solve(prob, Rodas4()) + sol = solve(prob, Tsit5()) @test sol.retcode == Success @test_skip sol.prob.kwargs[:disc_saved_values][1].t ≈ 0:sampletime(clock):1 @test sol[model.int.x] ≈ @@ -91,7 +91,7 @@ end sys = structural_simplify(IRSystem(model)) prob = ODEProblem(sys, Pair[int.x(k - 1) => 1 int.u(k - 1) => 0], (0.0, 1.0)) - sol = solve(prob, Rodas4()) + sol = solve(prob, Tsit5()) @test sol.retcode == Success @test_skip sol.prob.kwargs[:disc_saved_values][1].t ≈ 0:sampletime(clock):1 @test sol[model.int.x] ≈ From a6248edf4e7e4d7caf2912c5e0bcf7d22d804790 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Tue, 15 Apr 2025 11:35:08 +0200 Subject: [PATCH 2/2] WIP change from JSC to SynchToolkit --- Project.toml | 7 +++-- docs/src/examples/dc_motor_pi.md | 6 ++-- docs/src/examples/onoffcontroller.md | 4 +-- docs/src/examples/sliding_mode_control.md | 4 +-- docs/src/tutorials/SampledData.md | 7 +++-- docs/src/tutorials/noise.md | 10 +++--- src/ModelingToolkitSampledData.jl | 4 +-- src/discrete_blocks.jl | 5 ++- test/runtests.jl | 2 +- test/test_discrete_blocks.jl | 38 +++++++++++------------ 10 files changed, 43 insertions(+), 44 deletions(-) diff --git a/Project.toml b/Project.toml index ed8fbb3..fa7b08d 100644 --- a/Project.toml +++ b/Project.toml @@ -4,21 +4,22 @@ authors = ["Fredrik Bagge Carlson"] version = "0.1.1" [deps] -DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def" -JuliaSimCompiler = "8391cb6b-4921-5777-4e45-fd9aab8cb88d" +HeptagonToolkit = "530fcfb7-09ad-4628-8fc4-9627497dc745" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739" OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" +SynchToolkit = "f500ffa8-9682-42ac-8d34-0ca7926c2e94" [compat] -DiffEqCallbacks = "~3.8" +HeptagonToolkit = "1.0.0" ModelingToolkit = "9" ModelingToolkitStandardLibrary = "2" OrdinaryDiffEqTsit5 = "1.1.0" Random = "1" StableRNGs = "1" +SynchToolkit = "0.1.0" julia = "1.10" [extras] diff --git a/docs/src/examples/dc_motor_pi.md b/docs/src/examples/dc_motor_pi.md index 5093caf..8751f35 100644 --- a/docs/src/examples/dc_motor_pi.md +++ b/docs/src/examples/dc_motor_pi.md @@ -110,7 +110,7 @@ Below, we re-model the system, this time with a discrete-time controller: [`Disc ```@example dc_motor_pi using ModelingToolkitSampledData -using JuliaSimCompiler +using SynchToolkit z = ShiftIndex() @mtkmodel DiscreteClosedLoop begin @@ -159,7 +159,7 @@ end @named disc_model = DiscreteClosedLoop() disc_model = complete(disc_model) -ssys = structural_simplify(IRSystem(disc_model)) # Conversion to an IRSystem from JuliaSimCompiler is required for sampled-data systems +ssys = structural_simplify(disc_model; additional_passes=[SynchToolkit.compile_lustre]) disc_prob = ODEProblem(ssys, [unknowns(disc_model) .=> 0.0; disc_model.pi_controller.I(z-1) => 0; disc_model.pi_controller.eI(z-1) => 0], (0, 2.0)) disc_sol = solve(disc_prob, Tsit5()) @@ -213,7 +213,7 @@ end @named cascade = Cascade() cascade = complete(cascade) -ssys = structural_simplify(IRSystem(cascade)) +ssys = structural_simplify(cascade; additional_passes=[SynchToolkit.compile_lustre]) i = cascade.inner cascade_prob = ODEProblem(ssys, [ unknowns(cascade) .=> 0.0; diff --git a/docs/src/examples/onoffcontroller.md b/docs/src/examples/onoffcontroller.md index 06610fa..ad1e2a4 100644 --- a/docs/src/examples/onoffcontroller.md +++ b/docs/src/examples/onoffcontroller.md @@ -10,7 +10,7 @@ where ``τ = 100`` is a time constant. The controller ``u = f(x)`` is an on/off using ModelingToolkit, ModelingToolkitSampledData, OrdinaryDiffEqTsit5, Plots using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks -using JuliaSimCompiler +using SynchToolkit cl = Clock(1) z = ShiftIndex(cl) @mtkmodel OnOffModel begin @@ -29,7 +29,7 @@ z = ShiftIndex(cl) end @named m = OnOffModel() m = complete(m) -ssys = structural_simplify(IRSystem(m)) +ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.onoff.y(z-1) => 0], (0.0, 40.0)) sol = solve(prob, Tsit5(), dtmax=0.1) plot(sol, idxs=[m.x, m.onoff.y], title="On-off control of an unstable first-order system") diff --git a/docs/src/examples/sliding_mode_control.md b/docs/src/examples/sliding_mode_control.md index 62493e9..5cd57e6 100644 --- a/docs/src/examples/sliding_mode_control.md +++ b/docs/src/examples/sliding_mode_control.md @@ -13,7 +13,7 @@ which yields the switching variable ``s = ė + e``, encoded in the function ``s using ModelingToolkit, ModelingToolkitSampledData, OrdinaryDiffEqTsit5, Plots using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks -using JuliaSimCompiler +using SynchToolkit dt = 0.01 clock = Clock(dt) z = ShiftIndex(clock) @@ -80,7 +80,7 @@ end end @named m = ClosedLoopModel() m = complete(m) -ssys = structural_simplify(IRSystem(m)) +ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.plant.x => -1, m.plant.xd => 0, m.controller.x(z-1) => 0], (0.0, 2π)) sol = solve(prob, Tsit5(), dtmax=0.01) figy = plot(sol, idxs=[m.plant.x]) diff --git a/docs/src/tutorials/SampledData.md b/docs/src/tutorials/SampledData.md index 12240df..a8c2cc2 100644 --- a/docs/src/tutorials/SampledData.md +++ b/docs/src/tutorials/SampledData.md @@ -226,10 +226,11 @@ connections = [r ~ (t >= 5) # reference signal cl = complete(cl) ``` -We can now simulate the system. JuliaSimCompiler is required to simulate hybrid continuous/discrete systems, we thus convert the system to an `JuliaSimCompiler.IRSystem` before calling `structural_simplify` +We can now simulate the system. ```@example clocks -using JuliaSimCompiler, Plots -ssys = structural_simplify(IRSystem(cl)) +using Plots +using SynchToolkit +ssys = structural_simplify(cl; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [ cl.f.x(k-1) => 0, diff --git a/docs/src/tutorials/noise.md b/docs/src/tutorials/noise.md index 6323559..7cceca9 100644 --- a/docs/src/tutorials/noise.md +++ b/docs/src/tutorials/noise.md @@ -14,7 +14,7 @@ using ModelingToolkitStandardLibrary.Electrical using ModelingToolkitStandardLibrary.Mechanical.Rotational using ModelingToolkitStandardLibrary.Blocks using ModelingToolkitSampledData -using JuliaSimCompiler +using SynchToolkit using OrdinaryDiffEq using Plots @@ -72,7 +72,7 @@ end @named noisy_model = NoisyClosedLoop() noisy_model = complete(noisy_model) -ssys = structural_simplify(IRSystem(noisy_model)) # Conversion to an IRSystem from JuliaSimCompiler is required for sampled-data systems +ssys = structural_simplify(noisy_model; additional_passes=[SynchToolkit.compile_lustre]) noise_prob = ODEProblem(ssys, [unknowns(noisy_model) .=> 0.0; noisy_model.pi_controller.I(z-1) => 0; noisy_model.pi_controller.eI(z-1) => 0; noisy_model.noise.y(z-1) => 0], (0, 2.0)) noise_sol = solve(noise_prob, Tsit5()) @@ -105,7 +105,7 @@ A signal may be quantized to a fixed number of levels (e.g., 8-bit) using the [` using ModelingToolkit, ModelingToolkitSampledData, OrdinaryDiffEq, Plots using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks -using JuliaSimCompiler + z = ShiftIndex(Clock(0.1)) @mtkmodel QuantizationModel begin @components begin @@ -123,7 +123,7 @@ z = ShiftIndex(Clock(0.1)) end @named m = QuantizationModel() m = complete(m) -ssys = structural_simplify(IRSystem(m)) +ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [], (0.0, 2.0)) sol = solve(prob, Tsit5()) plot(sol, idxs=m.input.output.u) @@ -170,7 +170,7 @@ The block [`SampleWithADEffects`](@ref) combines an ideal [`Sampler`](@ref), a [ end @named m = PracticalSamplerModel() m = complete(m) -ssys = structural_simplify(IRSystem(m)) +ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.sampling.noise.y(z-1) => 0], (0.0, 2.0)) sol = solve(prob, Tsit5()) plot(sol, idxs=m.input.output.u) diff --git a/src/ModelingToolkitSampledData.jl b/src/ModelingToolkitSampledData.jl index 494d160..e8b9951 100644 --- a/src/ModelingToolkitSampledData.jl +++ b/src/ModelingToolkitSampledData.jl @@ -1,6 +1,6 @@ module ModelingToolkitSampledData using ModelingToolkit -using JuliaSimCompiler +using SynchToolkit using StableRNGs export get_clock @@ -14,6 +14,4 @@ export DiscreteOnOffController include("discrete_blocks.jl") -runtime(ssys::JuliaSimCompiler.ScheduledSystem) = ssys.discrete_info.callback.affect!.affect!.x - end diff --git a/src/discrete_blocks.jl b/src/discrete_blocks.jl index 2f0ac95..83406d2 100644 --- a/src/discrete_blocks.jl +++ b/src/discrete_blocks.jl @@ -343,7 +343,6 @@ end """ @mtkmodel ClockChanger begin begin - isdefined(Main, :JuliaSimCompiler) || error("JuliaSimCompiler must be defined in the Main module for the ClockChanger component to work. Run `import JuliaSimCompiler`.") @warn "The ClockChanger component is experimental and has known correctness issues. Please use with caution." end @extend u, y = siso = SISO() @@ -355,7 +354,7 @@ end O = 0 # This is just a dummy to workaround a bug in JSComp end @equations begin - y(ShiftIndex(to)) ~ Main.JuliaSimCompiler.ClockChange(; to, from)(u(ShiftIndex(from))) + O + y(ShiftIndex(to)) ~ ClockChange(; to, from)(u(ShiftIndex(from))) + O end end @@ -918,7 +917,7 @@ z = ShiftIndex(cl) end @named m = SlweRateLimiterModel() m = complete(m) -ssys = structural_simplify(IRSystem(m)) +ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.limiter.y(z-1) => 0], (0.0, 2.0)) sol = solve(prob, Tsit5(), dtmax=0.01) plot(sol, idxs=[m.input.output.u, m.limiter.y], title="Slew rate limited sine wave") diff --git a/test/runtests.jl b/test/runtests.jl index 9347222..35248ef 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using ModelingToolkitSampledData using ModelingToolkit -using JuliaSimCompiler +using SynchToolkit using Test @testset "ModelingToolkitSampledData.jl" begin diff --git a/test/test_discrete_blocks.jl b/test/test_discrete_blocks.jl index 896d3e8..e08e38e 100644 --- a/test/test_discrete_blocks.jl +++ b/test/test_discrete_blocks.jl @@ -3,7 +3,7 @@ using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEqTsit5 using ModelingToolkitStandardLibrary.Blocks using ModelingToolkit: t_nounits as t, D_nounits as D using OrdinaryDiffEqTsit5: ReturnCode.Success -using JuliaSimCompiler +using SynchToolkit using Test Difference = ModelingToolkitSampledData.Difference @@ -31,7 +31,7 @@ an integrator with a constant input is often used together with the system under @named model = TestDiscreteOnly() model = complete(model) - ssys = structural_simplify(IRSystem(model)) + ssys = structural_simplify(model; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [model.x(k-1) => 1.0], (0.0, 10.0)) sol = solve(prob, Tsit5()) @test sol[model.x] == dt .^ (1:21) @@ -53,7 +53,7 @@ end t, systems = [sampler, int, intc, c]) model = complete(iosys) - sys = structural_simplify(IRSystem(model)) + sys = structural_simplify(model; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(sys, Pair[int.x(k - 1) => 1 int.u(k - 1) => 0], (0.0, 1.0)) sol = solve(prob, Tsit5()) @@ -70,7 +70,7 @@ end t, systems = [sampler, int, intc, c]) model = complete(iosys) - sys = structural_simplify(IRSystem(model)) + sys = structural_simplify(model; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(sys, Pair[int.x(k - 1) => 1 int.u(k - 1) => 0], (0.0, 1.0)) sol = solve(prob, Tsit5()) @@ -88,7 +88,7 @@ end t, systems = [sampler, int, intc, c]) model = complete(iosys) - sys = structural_simplify(IRSystem(model)) + sys = structural_simplify(model; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(sys, Pair[int.x(k - 1) => 1 int.u(k - 1) => 0], (0.0, 1.0)) sol = solve(prob, Tsit5()) @@ -128,7 +128,7 @@ end @named model = ClosedLoop() model = complete(model) # ci, varmap = infer_clocks(expand_connections(model)) -ssys = structural_simplify(IRSystem(model)) +ssys = structural_simplify(model; additional_passes=[SynchToolkit.compile_lustre]) Tf = 5 timevec = 0:(dt):Tf @@ -197,7 +197,7 @@ end @named model = ClosedLoop() model = complete(model) # ci, varmap = infer_clocks(expand_connections(model)) -ssys = structural_simplify(IRSystem(model)) +ssys = structural_simplify(model; additional_passes=[SynchToolkit.compile_lustre]) Tf = 5 timevec = 0:(dt):Tf @@ -256,7 +256,7 @@ end @named m = DelayModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem( ssys, [m.delay.u(k - 3) => 0, m.delay.u(k - 2) => 0, m.delay.u(k - 1) => 0], ( 0.0, 10.0)) @@ -289,7 +289,7 @@ using ModelingToolkitStandardLibrary.Blocks @named m = DiffModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, Dict(m.diff.u(k - 1) => 0), (0.0, 10.0)) sol = solve(prob, Tsit5(), dtmax = 0.01) @test reduce(vcat, sol((0:10) .+ 1e-2))[:]≈[zeros(2); 1; zeros(8)] atol=1e-2 @@ -319,7 +319,7 @@ using Statistics @named m = NoiseModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.noise.y(k-1) => 0], (0.0, 10.0)) sol = solve(prob, Tsit5()) @test !all(iszero, sol.u) @@ -345,7 +345,7 @@ end @named m = NoiseModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.noise.y(k-1) => 0], (0.0, 10.0)) sol = solve(prob, Tsit5()) @test !all(iszero, sol.u) @@ -375,7 +375,7 @@ end # @named m = PlantModel() # m = complete(m) -# ssys = structural_simplify(IRSystem(m)) +# ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) # prob = ODEProblem(ssys, Dict(m.plant.u(k - 1) => 0), (0.0, 10.0)) # sol = solve(prob, Tsit5(), dtmax = 0.01) # @test reduce(vcat, sol((0:10) .+ 1e-2))[:]≈[zeros(2); 1; zeros(8)] atol=1e-2 @@ -401,7 +401,7 @@ end end @named m = SlewRateLimiterModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.limiter.y(z-1) => 0], (0.0, 2.0)) sol = solve(prob, Tsit5(), dtmax=0.01) # plot(sol, idxs=[m.input.output.u, m.limiter.y], title="Slew rate limited sine wave") @@ -457,7 +457,7 @@ end end @named m = QuantizationModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [], (0.0, 10.0)) sol = solve(prob, Tsit5(), dtmax=0.01) y = sol[m.quant.y] @@ -476,7 +476,7 @@ end end @named m = QuantizationModel2() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [], (0.0, 10.0)) sol = solve(prob, Tsit5(), dtmax=0.01) y = sol[m.quant.y] @@ -505,7 +505,7 @@ end end @named m = OnOffModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.onoff.y(z-1) => 0], (0.0, 4.0)) sol = solve(prob, Tsit5(), dtmax=0.1) # plot(sol, idxs=[m.x, m.onoff.y], title="On-off control of an unstable first-order system") @@ -530,7 +530,7 @@ end end @named m = ExponentialFilterModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.filter.y(z-1) => 0], (0.0, 10.0)) sol = solve(prob, Tsit5(), dtmax=0.1) @test sol(10, idxs=m.filter.y) ≈ 1 atol=0.001 @@ -558,7 +558,7 @@ end @named m = MovingAverageFilterModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.filter.u(z-i) => 0 for i = 0:3], (0.0, 2.0)) sol = solve(prob, Tsit5(), dtmax=0.1) # plot(sol, idxs=m.filter.y) @@ -587,7 +587,7 @@ end end @named m = PracticalSamplerModel() m = complete(m) - ssys = structural_simplify(IRSystem(m)) + ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre]) prob = ODEProblem(ssys, [m.sampling.noise.y(z-1) => 0], (0.0, 2.0)) sol = solve(prob, Tsit5())