From 6b1e67ca071df3e4f1e40bd1f12ddb74677a5eec Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sun, 22 Nov 2026 11:23:42 -0500 Subject: [PATCH 1/3] Reuse initialization structure during Bayesian fitting Update fixed symbolic parameters through a copied parameter buffer. Use symbolic remaking for initialized parameters and other parameter forms. Co-Authored-By: Chris Rackauckas Co-Authored-By: Codex Agent-Harness: Codex CLI 0.170.0 Agent-Model: gpt-6.2-sol Agent-Job: 353-codex Agent-Session: local session 01a20359-5251-7513-b44c-d53b08e08abc (no session URL) --- Project.toml | 4 ++++ src/EasyModelAnalysis.jl | 2 ++ src/datafit.jl | 16 ++++++++++++++-- test/Datafit/datafit.jl | 12 ++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index c8ffe91..a5f26ae 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ GlobalSensitivity = "af5da776-676b-467e-8baf-acd8249e4f0f" Integrals = "de52edbc-65ea-441a-8357-d3a637375a31" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" +ModelingToolkitBase = "7771a370-6774-4173-bd38-47e70ca0b839" NLopt = "76087f3c-5699-56af-9a33-bf431cd00edd" Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba" OptimizationBBO = "3e6eede4-6085-4f62-9a71-46d9bc1eb92b" @@ -18,6 +19,7 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" SciMLExpectations = "afe9f18d-7609-4d0e-b7b7-af0cb72b8ea8" +SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b" Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" @@ -29,6 +31,7 @@ GlobalSensitivity = "2" Integrals = "5" LinearAlgebra = "1" ModelingToolkit = "11.26" +ModelingToolkitBase = "1" NLopt = "1.1" Optimization = "5.6" OptimizationBBO = "0.4.11" @@ -38,6 +41,7 @@ PrecompileTools = "1" SafeTestsets = "0.1" SciMLBase = "3.5" SciMLExpectations = "2" +SymbolicIndexingInterface = "0.3.45" SymbolicUtils = "4" SciMLTesting = "2.13" Test = "1" diff --git a/src/EasyModelAnalysis.jl b/src/EasyModelAnalysis.jl index f22cfaa..3c752ec 100644 --- a/src/EasyModelAnalysis.jl +++ b/src/EasyModelAnalysis.jl @@ -15,6 +15,7 @@ using Plots using LinearAlgebra: LinearAlgebra, I, norm using DifferentialEquations: DifferentialEquations, remake, solve using ModelingToolkit: ModelingToolkit, Num, Symbolics +using ModelingToolkitBase: ModelingToolkitBase, Initial, MTKParameters using Distributions: Distributions, InverseGamma, MvNormal, product_distribution using Plots: Plots, @layout, bar, plot, plot!, scatter! using PrecompileTools: @compile_workload, @setup_workload @@ -29,6 +30,7 @@ using SciMLExpectations: SciMLExpectations, ExpectationProblem, GenericDistribut Koopman, SystemMap using SciMLBase: SciMLBase, ContinuousCallback, EnsembleProblem, EnsembleSerial, EnsembleSolution, EnsembleThreads, ODESolution, terminate! +using SymbolicIndexingInterface: is_parameter, remake_buffer using SymbolicUtils: SymbolicUtils include("basics.jl") diff --git a/src/datafit.jl b/src/datafit.jl index e1cd300..e2d6186 100644 --- a/src/datafit.jl +++ b/src/datafit.jl @@ -269,12 +269,24 @@ function bayes_unpack_data(p) return (pdist, pkeys) end +function _bayesian_parameters(prob, keys, values) + # The symbolic remake updates Initial parameters along with their corresponding values. + if prob.p isa MTKParameters && + all( + key -> key isa Num && is_parameter(prob, key) && + !is_parameter(prob, Initial(key)), keys + ) + return remake_buffer(prob, prob.p, keys, values) + end + return Pair.(keys, values) +end + Turing.@model function bayesianODE(prob, t, pdist, pkeys, data, noise_prior) σ ~ noise_prior pprior ~ product_distribution(pdist) - prob = remake(prob, tspan = (prob.tspan[1], t[end]), p = Pair.(pkeys, pprior)) + prob = remake(prob; tspan = (prob.tspan[1], t[end]), p = _bayesian_parameters(prob, pkeys, pprior)) sol = solve(prob, saveat = t) if !SciMLBase.successful_retcode(sol) Turing.@addlogprob! -Inf @@ -300,7 +312,7 @@ Turing.@model function bayesianODE( pprior ~ product_distribution(pdist) - prob = remake(prob, tspan = (prob.tspan[1], lastt), p = Pair.(pkeys, pprior)) + prob = remake(prob; tspan = (prob.tspan[1], lastt), p = _bayesian_parameters(prob, pkeys, pprior)) sol = solve(prob) if !SciMLBase.successful_retcode(sol) Turing.@addlogprob! -Inf diff --git a/test/Datafit/datafit.jl b/test/Datafit/datafit.jl index 5e23258..bb145c6 100644 --- a/test/Datafit/datafit.jl +++ b/test/Datafit/datafit.jl @@ -125,3 +125,15 @@ p_posterior = @time bayesian_datafit( niter = 200 ) @test var.(getfield.(p_prior, :second)) >= var.(getfield.(p_posterior, :second)) + +@testset "Parameter-dependent initialization during Bayesian remakes" begin + @parameters offset = 2.0 slope = 1.0 + @variables state(t) [guess = 1.0] + @named system = System( + [D(state) ~ offset + slope], t; initialization_eqs = [state ~ offset] + ) + problem = ODEProblem(mtkcompile(system), Pair[], (0.0, 1.0)) + p = EasyModelAnalysis._bayesian_parameters(problem, [offset, slope], [3.0, 4.0]) + solution = solve(remake(problem; p), Tsit5(); saveat = [0.0, 1.0]) + @test solution[state] ≈ [3.0, 10.0] +end From 99d432a1db9df01bfa5043a634be40fa94695be6 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sun, 22 Nov 2026 11:23:42 -0500 Subject: [PATCH 2/3] Check the sensitivity dictionary key set Verify the exact Sobol key names independently of hash-table traversal order. Co-Authored-By: Chris Rackauckas Co-Authored-By: Codex Agent-Harness: Codex CLI 0.170.0 Agent-Model: gpt-6.2-sol Agent-Job: 353-codex Agent-Session: local session 01a20359-5251-7513-b44c-d53b08e08abc (no session URL) --- test/sensitivity.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sensitivity.jl b/test/sensitivity.jl index 14ee935..cac5463 100644 --- a/test/sensitivity.jl +++ b/test/sensitivity.jl @@ -35,8 +35,8 @@ sensres = EasyModelAnalysis.get_sensitivity(prob, 100.0, y, pbounds) @test_nowarn create_sensitivity_plot(sensres, pbounds) @test length(sensres) == 5 -@test collect(keys(sensres)) == - [:ρ_first_order, :β_first_order, :ρ_total_order, :β_total_order, :ρ_β_second_order] +@test keys(sensres) == + Set((:ρ_first_order, :β_first_order, :ρ_total_order, :β_total_order, :ρ_β_second_order)) sensres_max = get_sensitivity_of_maximum(prob, 100.0, y, pbounds, samples = 50) @test length(sensres) == 5 From 8b8ba39010bff8c6f7297d16fa97bcb06cc5433e Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sun, 22 Nov 2026 11:23:42 -0500 Subject: [PATCH 3/3] Run threshold tests in a dedicated CI group Schedule Threshold on both Julia architectures so its tests use a fresh process after Core. Co-Authored-By: Chris Rackauckas Co-Authored-By: Codex Agent-Harness: Codex CLI 0.170.0 Agent-Model: gpt-6.2-sol Agent-Job: 353-codex Agent-Session: local session 01a20359-5251-7513-b44c-d53b08e08abc (no session URL) --- test/{ => Threshold}/threshold.jl | 0 test/test_groups.toml | 10 ++++++++++ 2 files changed, 10 insertions(+) rename test/{ => Threshold}/threshold.jl (100%) diff --git a/test/threshold.jl b/test/Threshold/threshold.jl similarity index 100% rename from test/threshold.jl rename to test/Threshold/threshold.jl diff --git a/test/test_groups.toml b/test/test_groups.toml index 064d37b..83f8b8a 100644 --- a/test/test_groups.toml +++ b/test/test_groups.toml @@ -13,5 +13,15 @@ arch = "x86" versions = ["1"] num_threads = 4 +[Threshold] +versions = ["1"] +num_threads = 4 + +["Threshold 32-bit"] +group = "Threshold" +versions = ["1"] +os = ["ubuntu-latest"] +arch = "x86" + [QA] versions = ["lts", "1"]