From dbd9ed819e3e93965dbbe05b97bc0c90de11fc40 Mon Sep 17 00:00:00 2001 From: rusandris Date: Mon, 28 Oct 2024 19:22:53 +0200 Subject: [PATCH 1/7] add smap for pds systems --- src/derived_systems/parallel_systems.jl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/derived_systems/parallel_systems.jl b/src/derived_systems/parallel_systems.jl index 8be652ec..fa32dcaa 100644 --- a/src/derived_systems/parallel_systems.jl +++ b/src/derived_systems/parallel_systems.jl @@ -63,10 +63,23 @@ function ParallelDynamicalSystem(ds::CoreDynamicalSystem, states::Vector{<:Abstr pds = CoupledODEs(prob, ds.diffeq; internalnorm = inorm) end M = ds isa CoupledODEs && isinplace(ds) - prob = referrenced_sciml_prob(ds) + prob = referrenced_sciml_prob(ds) return ParallelDynamicalSystemAnalytic{typeof(pds), M}(pds, dynamic_rule(ds), prob) end +function ParallelDynamicalSystem(smap::StroboscopicMap,states::Vector{<:AbstractArray{<:Real}}) + f, st = parallel_rule(smap.ds, states) + T = eltype(first(st)) + prob = ODEProblem{true}(f, st, (T(initial_time(smap)), T(Inf)), current_parameters(smap)) + inorm = prob.u0 isa Matrix ? matrixnorm : vectornorm + cont_pds = CoupledODEs(prob, smap.ds.diffeq; internalnorm = inorm) + pds = StroboscopicMap(cont_pds,smap.period) + + M = smap.ds isa CoupledODEs && isinplace(smap.ds) + prob = referrenced_sciml_prob(smap.ds) + return ParallelDynamicalSystemAnalytic{typeof(pds), M}(pds, dynamic_rule(smap), prob) +end + function ParallelDynamicalSystem(ds::CoreDynamicalSystem, mappings::Vector{<:Dict}) # convert to vector of arrays: u = Array(current_state(ds)) From e437d92fff148a799a67e7c90cc0503690de4206 Mon Sep 17 00:00:00 2001 From: rusandris Date: Tue, 29 Oct 2024 09:39:56 +0200 Subject: [PATCH 2/7] fix param setting for generic fallback --- src/derived_systems/parallel_systems.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/derived_systems/parallel_systems.jl b/src/derived_systems/parallel_systems.jl index fa32dcaa..63b84055 100644 --- a/src/derived_systems/parallel_systems.jl +++ b/src/derived_systems/parallel_systems.jl @@ -223,7 +223,7 @@ current_states(pdtds::PDTDS) = [current_state(ds) for ds in pdtds.systems] initial_states(pdtds::PDTDS) = [initial_state(ds) for ds in pdtds.systems] # Set stuff -set_parameter!(pdtds::PDTDS) = for ds in pdtds.systems; set_parameter!(ds, args...); end +set_parameter!(pdtds::PDTDS,index,value) = for ds in pdtds.systems; set_parameter!(ds, index,value); end function set_state!(pdtds::PDTDS, u, i::Int = 1) # We need to set state in all systems, in case this does # some kind of resetting, e.g., the `u_modified!` stuff. From 96d41f1440ca4bef9b9a46b13d02278ce9b64956 Mon Sep 17 00:00:00 2001 From: rusandris Date: Mon, 4 Nov 2024 18:07:58 +0200 Subject: [PATCH 3/7] add modified set_state! for smap --- src/derived_systems/parallel_systems.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/derived_systems/parallel_systems.jl b/src/derived_systems/parallel_systems.jl index 63b84055..0c46fc8b 100644 --- a/src/derived_systems/parallel_systems.jl +++ b/src/derived_systems/parallel_systems.jl @@ -177,6 +177,14 @@ function set_state!(pdsa::PDSAM, u::AbstractArray, i::Int = 1) return pdsa end + +function set_state!(pdsa::PDSAM{<: StroboscopicMap}, u::AbstractArray, i::Int = 1) where D + current_state(pdsa, i) .= u + u_modified!(pdsa.ds.ds.integ, true) + return pdsa +end + + # We make one more extension here: for continuous time, in place systems # the state is a matrix (each column a parallel state) for performance. # re-init will not work because there is no way to do the recursive copy. we do it ourselves From 6acc2f45a56f14203dfb2fdf246a02304a5685fa Mon Sep 17 00:00:00 2001 From: rusandris Date: Sat, 16 Nov 2024 16:53:20 +0200 Subject: [PATCH 4/7] fix smap psys dispatch --- src/derived_systems/parallel_systems.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/derived_systems/parallel_systems.jl b/src/derived_systems/parallel_systems.jl index 0c46fc8b..b2c410be 100644 --- a/src/derived_systems/parallel_systems.jl +++ b/src/derived_systems/parallel_systems.jl @@ -67,7 +67,7 @@ function ParallelDynamicalSystem(ds::CoreDynamicalSystem, states::Vector{<:Abstr return ParallelDynamicalSystemAnalytic{typeof(pds), M}(pds, dynamic_rule(ds), prob) end -function ParallelDynamicalSystem(smap::StroboscopicMap,states::Vector{<:AbstractArray{<:Real}}) +function ParallelDynamicalSystem(smap::StroboscopicMap,states) f, st = parallel_rule(smap.ds, states) T = eltype(first(st)) prob = ODEProblem{true}(f, st, (T(initial_time(smap)), T(Inf)), current_parameters(smap)) @@ -178,7 +178,7 @@ function set_state!(pdsa::PDSAM, u::AbstractArray, i::Int = 1) end -function set_state!(pdsa::PDSAM{<: StroboscopicMap}, u::AbstractArray, i::Int = 1) where D +function set_state!(pdsa::PDSAM{<: StroboscopicMap}, u::AbstractArray, i::Int = 1) current_state(pdsa, i) .= u u_modified!(pdsa.ds.ds.integ, true) return pdsa From 0fa47d8a9b6c7a9b3aaaf3c796c93fbec62d422e Mon Sep 17 00:00:00 2001 From: rusandris Date: Thu, 26 Dec 2024 12:55:57 +0200 Subject: [PATCH 5/7] add parallel specific tests --- test/parallel.jl | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/parallel.jl b/test/parallel.jl index 808521ec..90bed795 100644 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -1,3 +1,4 @@ +using Revise #remove this using DynamicalSystemsBase, Test using LinearAlgebra: norm @@ -98,7 +99,7 @@ for (ds, idt, iip) in zip( end @testset "parallel stroboscopic" begin -# Generic Parallel + @inbounds function duffing_rule(x, p, t) ω, f, d, β = p dx1 = x[2] @@ -122,9 +123,41 @@ states = [u0, u0 .+ 0.01] pds_cont_oop = ParallelDynamicalSystem(duffing_oop, states) pds_cont_iip = ParallelDynamicalSystem(duffing_iip, deepcopy(states)) +#generic ds test @testset "IIP=$iip" for (ds, iip) in zip((pds_cont_oop, pds_cont_iip,), (true, false)) test_dynamical_system(ds, u0, p0; idt = true, iip = true, test_trajectory = false) end + +#tests for multistate stuff + +#alteration +states = [ones(2) for i in 1:2] +p = p0 .+ 0.1 +for i in 1:2 + set_state!(pds_cont_oop,states[i],i) + set_state!(pds_cont_iip,states[i],i) +end +set_parameters!(pds_cont_oop,p) +set_parameters!(pds_cont_iip,p) + +#obtaining info +@test all(current_states(pds_cont_oop) .== states) +@test all(current_states(pds_cont_iip) .== states) +@test all(current_parameters(pds_cont_oop) .== p) +@test all(current_parameters(pds_cont_iip) .== p) + +#time evolution +step!(pds_cont_oop) +@test all(current_states(pds_cont_oop)[1] .== current_states(pds_cont_oop)[2]) +step!(pds_cont_iip) +@test all(current_states(pds_cont_iip)[1] .== current_states(pds_cont_iip)[2]) + +#reinit! +reinit!(pds_cont_oop) +reinit!(pds_cont_iip) +@test all(current_states(pds_cont_oop) .== initial_states(pds_cont_oop)) +@test all(current_states(pds_cont_iip) .== initial_states(pds_cont_iip)) + end # TODO: Test that Lyapunovs of this match the original system From 0d10e7742106dad77f0691d07f72d59dd7e74464 Mon Sep 17 00:00:00 2001 From: rusandris Date: Thu, 26 Dec 2024 13:15:42 +0200 Subject: [PATCH 6/7] remove Revise --- test/parallel.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/parallel.jl b/test/parallel.jl index 90bed795..430b51b7 100644 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -1,4 +1,3 @@ -using Revise #remove this using DynamicalSystemsBase, Test using LinearAlgebra: norm @@ -161,4 +160,6 @@ reinit!(pds_cont_iip) end # TODO: Test that Lyapunovs of this match the original system -# But test this in ChaosTools.jl \ No newline at end of file +# But test this in ChaosTools.jl + +#benchmarks, comparison with old version \ No newline at end of file From 61af69775627d89d59c50ddb00a673f02b77711c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Rusu?= <62118955+rusandris@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:04:42 +0200 Subject: [PATCH 7/7] increase patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 21f28355..a15e627f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DynamicalSystemsBase" uuid = "6e36e845-645a-534a-86f2-f5d4aa5a06b4" repo = "https://github.com/JuliaDynamics/DynamicalSystemsBase.jl.git" -version = "3.13.1" +version = "3.13.2" [deps] ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"