From 95baf62f481574437eb9cebd6fc5ec5ba6dddc6b Mon Sep 17 00:00:00 2001 From: Alexander Spears Date: Wed, 28 May 2025 09:06:03 +0100 Subject: [PATCH 01/10] =?UTF-8?q?=F0=9F=92=A9=20Test=20whether=20removing?= =?UTF-8?q?=20time=20makes=20it=20type=20stable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Ensembles/Ensembles.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Ensembles/Ensembles.jl b/src/Ensembles/Ensembles.jl index c083c46c4..cdc3e0607 100644 --- a/src/Ensembles/Ensembles.jl +++ b/src/Ensembles/Ensembles.jl @@ -141,16 +141,14 @@ function run_dynamics( kwargs, :dt, 1.0 # dt should be a number / unitful qty - ) + )::Float64 ) |> first # Get the number or the first list entry. tspan_short = (0.0, short_time) - precompile_time = dynamics(tspan_short) - @debug "Reduction is" reduction=reduction + dynamics(tspan_short) if isa(reduction, FileReduction) - @debug "FileReduction wrote files, which will now be deleted. " rm(reduction.filename) end - @info "Pre-compiled dynamics in $(precompile_time.time) seconds." + # @info "Pre-compiled dynamics in $(precompile_time.time) seconds." end if trajectories == 1 From 25a91aece938263f94edbbf2862a2bebfbc65619 Mon Sep 17 00:00:00 2001 From: H Snowden <136097272+Snowd1n@users.noreply.github.com> Date: Wed, 28 May 2025 10:12:51 +0100 Subject: [PATCH 02/10] Trying to fix type-instability in run_dynamcis due to precompilation --- src/Ensembles/Ensembles.jl | 68 +++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 38 deletions(-) diff --git a/src/Ensembles/Ensembles.jl b/src/Ensembles/Ensembles.jl index cdc3e0607..cf215cbff 100644 --- a/src/Ensembles/Ensembles.jl +++ b/src/Ensembles/Ensembles.jl @@ -94,43 +94,18 @@ function run_dynamics( kwargs..., ) - """ - Due to how Julia compiles code, running the same dynamics for a single time step forces precompilation, which will make subsequent simulations faster. - This effect is negligible for smaller models, but begins to matter for more computationally intensive dynamics. + #@debug "Setting up dynamics with" tspan = tspan + if !(output isa Tuple) + output = (output,) + end - See this GitHub issue for discussion: https://github.com/NQCD/NQCDynamics.jl/issues/365 - """ - function dynamics(tspan) - @debug "Setting up dynamics with" tspan = tspan - if !(output isa Tuple) - output = (output,) - end - - kwargs = NQCBase.austrip_kwargs(; kwargs...) - trajectories = convert(Int, trajectories) - tspan = austrip.(tspan) - prob_func = Selection(distribution, selection, trajectories) - - u0 = sample_distribution(sim, distribution) - problem = DynamicsMethods.create_problem(u0, tspan, sim) - - output_func = EnsembleSaver(output, savetime) + kwargs = NQCBase.austrip_kwargs(; kwargs...) + trajectories = convert(Int, trajectories) + tspan = austrip.(tspan) + prob_func = Selection(distribution, selection, trajectories) + + u0 = sample_distribution(sim, distribution) - ensemble_problem = SciMLBase.EnsembleProblem( - problem; - prob_func = prob_func, - output_func = output_func, - reduction = deepcopy(reduction), # deepcopy reduction function because it's used twice - ) - return @timed SciMLBase.solve( - ensemble_problem, - algorithm, - ensemble_algorithm; - trajectories, - kwargs..., - ) - end - if precompile_dynamics @debug "Beginning to precompile dynamics" # Get a short time limit that runs through saving at least one time step of data @@ -144,20 +119,37 @@ function run_dynamics( )::Float64 ) |> first # Get the number or the first list entry. tspan_short = (0.0, short_time) - dynamics(tspan_short) + temp_prob = DynamicsMethods.create_problem(u0, tspan_short, sim) + precomp = SciMLBase.solve(temp_prob, algorithm, kwargs...) if isa(reduction, FileReduction) rm(reduction.filename) end - # @info "Pre-compiled dynamics in $(precompile_time.time) seconds." + @info "Pre-compiled dynamics in $(precompile_time.time) seconds." end + problem = DynamicsMethods.create_problem(u0, tspan, sim) + output_func = EnsembleSaver(output, savetime) + + ensemble_problem = SciMLBase.EnsembleProblem( + problem; + prob_func = prob_func, + output_func = output_func, + reduction = deepcopy(reduction), # deepcopy reduction function because it's used twice + ) + if trajectories == 1 @info "Performing 1 trajectory." else @info "Performing $trajectories trajectories." end - stats = dynamics(tspan) + stats = @timed SciMLBase.solve( + ensemble_problem, + algorithm, + ensemble_algorithm; + trajectories, + kwargs..., + ) log_simulation_duration(stats.time) if trajectories == 1 From 9e3dd9007ad6893d575b96cd849c4140360ebd84 Mon Sep 17 00:00:00 2001 From: H Snowden <136097272+Snowd1n@users.noreply.github.com> Date: Wed, 28 May 2025 10:56:52 +0100 Subject: [PATCH 03/10] I missed a comma :( --- src/Ensembles/Ensembles.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ensembles/Ensembles.jl b/src/Ensembles/Ensembles.jl index cf215cbff..2fbce713d 100644 --- a/src/Ensembles/Ensembles.jl +++ b/src/Ensembles/Ensembles.jl @@ -120,7 +120,7 @@ function run_dynamics( ) |> first # Get the number or the first list entry. tspan_short = (0.0, short_time) temp_prob = DynamicsMethods.create_problem(u0, tspan_short, sim) - precomp = SciMLBase.solve(temp_prob, algorithm, kwargs...) + precomp = SciMLBase.solve(temp_prob, algorithm, kwargs...,) if isa(reduction, FileReduction) rm(reduction.filename) end From 844dc20a3148e125f1926967ca982785d2fbd99c Mon Sep 17 00:00:00 2001 From: Alexander Spears Date: Wed, 28 May 2025 11:30:23 +0100 Subject: [PATCH 04/10] =?UTF-8?q?=F0=9F=90=9B=20Moved=20commas=20around?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Ensembles/Ensembles.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Ensembles/Ensembles.jl b/src/Ensembles/Ensembles.jl index 2fbce713d..c67f5c224 100644 --- a/src/Ensembles/Ensembles.jl +++ b/src/Ensembles/Ensembles.jl @@ -115,16 +115,16 @@ function run_dynamics( get( kwargs, :dt, - 1.0 # dt should be a number / unitful qty + 1.0 # dt should be a number )::Float64 ) |> first # Get the number or the first list entry. tspan_short = (0.0, short_time) temp_prob = DynamicsMethods.create_problem(u0, tspan_short, sim) - precomp = SciMLBase.solve(temp_prob, algorithm, kwargs...,) + precomp = SciMLBase.solve(temp_prob, algorithm; kwargs...) if isa(reduction, FileReduction) rm(reduction.filename) end - @info "Pre-compiled dynamics in $(precompile_time.time) seconds." + #@info "Pre-compiled dynamics in $(precompile_time.time) seconds." end problem = DynamicsMethods.create_problem(u0, tspan, sim) @@ -146,9 +146,9 @@ function run_dynamics( stats = @timed SciMLBase.solve( ensemble_problem, algorithm, - ensemble_algorithm; - trajectories, - kwargs..., + ensemble_algorithm, + trajectories; + kwargs... ) log_simulation_duration(stats.time) From de383a2d444adf7afafb135e72552fcc83f28b66 Mon Sep 17 00:00:00 2001 From: H Snowden <136097272+Snowd1n@users.noreply.github.com> Date: Wed, 28 May 2025 11:55:00 +0100 Subject: [PATCH 05/10] =?UTF-8?q?=F0=9F=A6=85More=20moving=20commas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Ensembles/Ensembles.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ensembles/Ensembles.jl b/src/Ensembles/Ensembles.jl index c67f5c224..ffd844e27 100644 --- a/src/Ensembles/Ensembles.jl +++ b/src/Ensembles/Ensembles.jl @@ -146,8 +146,8 @@ function run_dynamics( stats = @timed SciMLBase.solve( ensemble_problem, algorithm, - ensemble_algorithm, - trajectories; + ensemble_algorithm; + trajectories, kwargs... ) log_simulation_duration(stats.time) From 357ad7ff0d5987fa31c68df311fa0aefac659c3a Mon Sep 17 00:00:00 2001 From: H Snowden <136097272+Snowd1n@users.noreply.github.com> Date: Wed, 28 May 2025 12:17:05 +0100 Subject: [PATCH 06/10] Fixed Alex's type assertion --- src/Ensembles/Ensembles.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ensembles/Ensembles.jl b/src/Ensembles/Ensembles.jl index ffd844e27..7aeaf6c88 100644 --- a/src/Ensembles/Ensembles.jl +++ b/src/Ensembles/Ensembles.jl @@ -116,7 +116,7 @@ function run_dynamics( kwargs, :dt, 1.0 # dt should be a number - )::Float64 + )<:Real ) |> first # Get the number or the first list entry. tspan_short = (0.0, short_time) temp_prob = DynamicsMethods.create_problem(u0, tspan_short, sim) From d2fe62933b01a89dd101e137286c034ed0a69a65 Mon Sep 17 00:00:00 2001 From: H Snowden <136097272+Snowd1n@users.noreply.github.com> Date: Wed, 28 May 2025 14:01:22 +0100 Subject: [PATCH 07/10] =?UTF-8?q?I'm=20a=20idiot=20on=20type=20specificity?= =?UTF-8?q?=20=F0=9F=A4=A6=E2=80=8D=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Ensembles/Ensembles.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ensembles/Ensembles.jl b/src/Ensembles/Ensembles.jl index 7aeaf6c88..30f9dca5e 100644 --- a/src/Ensembles/Ensembles.jl +++ b/src/Ensembles/Ensembles.jl @@ -116,7 +116,7 @@ function run_dynamics( kwargs, :dt, 1.0 # dt should be a number - )<:Real + )::Real ) |> first # Get the number or the first list entry. tspan_short = (0.0, short_time) temp_prob = DynamicsMethods.create_problem(u0, tspan_short, sim) From c0820a49da1072497646cc774b34c300e6cc9dfb Mon Sep 17 00:00:00 2001 From: H Snowden <136097272+Snowd1n@users.noreply.github.com> Date: Wed, 28 May 2025 14:35:12 +0100 Subject: [PATCH 08/10] Fixed reduction error for Ensembles test --- src/Ensembles/Ensembles.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ensembles/Ensembles.jl b/src/Ensembles/Ensembles.jl index 30f9dca5e..aa6f7d28d 100644 --- a/src/Ensembles/Ensembles.jl +++ b/src/Ensembles/Ensembles.jl @@ -121,9 +121,9 @@ function run_dynamics( tspan_short = (0.0, short_time) temp_prob = DynamicsMethods.create_problem(u0, tspan_short, sim) precomp = SciMLBase.solve(temp_prob, algorithm; kwargs...) - if isa(reduction, FileReduction) +#= if isa(reduction, FileReduction) rm(reduction.filename) - end + end =# #@info "Pre-compiled dynamics in $(precompile_time.time) seconds." end From 71bb54878f53225b64f97f75dace461bbcead9b8 Mon Sep 17 00:00:00 2001 From: Alexander Spears Date: Fri, 30 May 2025 11:12:49 +0100 Subject: [PATCH 09/10] =?UTF-8?q?=F0=9F=90=9B=20Attempt=20fix=20for=20prec?= =?UTF-8?q?ompile=20and=20make=20compat=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project.toml | 8 +++++++- src/Ensembles/Ensembles.jl | 13 +++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index f2579b5f6..6fcd4b731 100644 --- a/Project.toml +++ b/Project.toml @@ -90,6 +90,11 @@ Unitful = "1" UnitfulAtomic = "1" julia = "≥1.9" +[sources] +NQCDInterfASE = {url = "https://github.com/NQCD/NQCDInterfASE.jl"} +NQCModels = {rev="main"} +NQCBase = {rev="main"} + [extras] CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" @@ -101,6 +106,7 @@ JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" JuLIP = "945c410c-986d-556a-acb1-167a618e0462" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" +NQCDInterfASE = "4606675f-2246-4a0b-99d5-75b910de637b" MKL = "33e6dc65-8f57-5167-99aa-e5a354878fb2" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d" @@ -110,4 +116,4 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "SafeTestsets", "CSV", "DataFrames", "DiffEqNoiseProcess", "FiniteDiff", "DiffEqDevTools", "Logging", "MKL", "PythonCall", "JuLIP", "Symbolics", "Statistics", "CairoMakie", "JLD2", "JSON"] +test = ["Test", "SafeTestsets", "CSV", "DataFrames", "DiffEqNoiseProcess", "FiniteDiff", "DiffEqDevTools", "Logging", "MKL", "PythonCall", "JuLIP", "Symbolics", "Statistics", "CairoMakie", "JLD2", "JSON", "NQCDInterfASE"] diff --git a/src/Ensembles/Ensembles.jl b/src/Ensembles/Ensembles.jl index aa6f7d28d..8ee3fe042 100644 --- a/src/Ensembles/Ensembles.jl +++ b/src/Ensembles/Ensembles.jl @@ -88,7 +88,7 @@ function run_dynamics( reduction = AppendReduction(), ensemble_algorithm = SciMLBase.EnsembleSerial(), algorithm = DynamicsMethods.select_algorithm(sim), - trajectories = 1, + trajectories::Int = 1, savetime = true, precompile_dynamics = true, kwargs..., @@ -100,7 +100,6 @@ function run_dynamics( end kwargs = NQCBase.austrip_kwargs(; kwargs...) - trajectories = convert(Int, trajectories) tspan = austrip.(tspan) prob_func = Selection(distribution, selection, trajectories) @@ -117,7 +116,7 @@ function run_dynamics( :dt, 1.0 # dt should be a number )::Real - ) |> first # Get the number or the first list entry. + )::Union{Vector{Real}, Real} |> first # Get the number or the first list entry. tspan_short = (0.0, short_time) temp_prob = DynamicsMethods.create_problem(u0, tspan_short, sim) precomp = SciMLBase.solve(temp_prob, algorithm; kwargs...) @@ -150,12 +149,14 @@ function run_dynamics( trajectories, kwargs... ) - log_simulation_duration(stats.time) + output = stats.value + time = stats.time + log_simulation_duration(time) if trajectories == 1 - return stats.value.u[1] + return output.u[1] else - return stats.value.u + return output.u end end From 7da1054582d1d07f641eee5559e7013c09bee751 Mon Sep 17 00:00:00 2001 From: Alexander Spears Date: Fri, 30 May 2025 11:34:03 +0100 Subject: [PATCH 10/10] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Fix=20deps=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 6fcd4b731..ceb223c47 100644 --- a/Project.toml +++ b/Project.toml @@ -92,8 +92,8 @@ julia = "≥1.9" [sources] NQCDInterfASE = {url = "https://github.com/NQCD/NQCDInterfASE.jl"} -NQCModels = {rev="main"} -NQCBase = {rev="main"} +NQCModels = {url="https://github.com/NQCD/NQCModels.jl", rev="main"} +NQCBase = {url="https://github.com/NQCD/NQCBase.jl", rev="main"} [extras] CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"