From 1e2450a393491ae9b9ef879c21c27ab67ada1d1d Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 10:25:23 +0200 Subject: [PATCH 01/10] remove explicit imports --- Project.toml | 8 ++++++- src/CoupledSDEs.jl | 18 ++++++++++------ src/CriticalTransitions.jl | 44 +++++++++++++++++++++++++++++--------- test/runtests.jl | 24 +++++++++++++++++++++ 4 files changed, 77 insertions(+), 17 deletions(-) diff --git a/Project.toml b/Project.toml index 89d5451d..54dcf6b5 100644 --- a/Project.toml +++ b/Project.toml @@ -38,6 +38,7 @@ ChaosToolsExt = ["ChaosTools"] CoupledSDEsBaisin = ["ChaosTools", "Attractors"] [compat] +Aqua = "0.8" Attractors = "1.15.0" ChaosTools = "3.1.2" Dierckx = "0.5.3" @@ -46,10 +47,12 @@ DocStringExtensions = "0.9.3" Documenter = "1.4.1" DrWatson = "2.14.1" DynamicalSystemsBase = "3.7.1" +ExplicitImports = "1.6" Format = "1" ForwardDiff = "0.10.36" HDF5 = "0.17.1" IntervalRootFinding = "0.5.11" +JET = "0.9" JLD2 = "0.4.46" Markdown = ">=1.9.0" Optim = "1.9.3" @@ -67,11 +70,14 @@ julia = "1.9" Attractors = "f3fd9213-ca85-4dba-9dfd-7fc91308fec7" ChaosTools = "608a59af-f2a3-5ad4-90b4-758bdf3122a7" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "Random", "IntervalRootFinding", "ModelingToolkit", "Documenter", "Attractors", "ChaosTools", "StatsBase"] +test = ["Test", "Random", "IntervalRootFinding", "ModelingToolkit", "Documenter", "Attractors", "ChaosTools", "StatsBase", "ExplicitImports", "Aqua", "JET"] diff --git a/src/CoupledSDEs.jl b/src/CoupledSDEs.jl index 42ff12ee..4ef3de08 100644 --- a/src/CoupledSDEs.jl +++ b/src/CoupledSDEs.jl @@ -1,6 +1,12 @@ -using DynamicalSystemsBase: CoupledODEs, isinplace, __init, SciMLBase, correct_state -import DynamicalSystemsBase: successful_step, _set_parameter!, current_state -using StochasticDiffEq: SDEProblem, SDEIntegrator +using DynamicalSystemsBase.SciMLBase: __init +using DynamicalSystemsBase: + CoupledODEs, + isinplace, + SciMLBase, + correct_state, + _set_parameter!, + current_state +using StochasticDiffEq: SDEProblem using StochasticDiffEq: EM, SDEProblem ########################################################################################### @@ -53,7 +59,7 @@ If you want to specify a solver, do so by using the keyword `alg`, e.g.: `using OrdinaryDiffEq` to access the solvers. The default `diffeq` is: ```julia -$(CriticalTransitions.DEFAULT_DIFFEQ) +$(DEFAULT_DIFFEQ) ``` `diffeq` keywords can also include `callback` for [event handling @@ -197,7 +203,7 @@ SciMLBase.isinplace(::CoupledSDEs{IIP}) where {IIP} = IIP StateSpaceSets.dimension(::CoupledSDEs{IIP,D}) where {IIP,D} = D DynamicalSystemsBase.current_state(ds::CoupledSDEs) = current_state(ds.integ) -function set_parameter!(ds::CoupledSDEs, args...) +function DynamicalSystemsBase.set_parameter!(ds::CoupledSDEs, args...) _set_parameter!(ds, args...) u_modified!(ds.integ, true) return nothing @@ -216,7 +222,7 @@ SciMLBase.step!(ds::CoupledSDEs, args...) = (step!(ds.integ, args...); ds) # Besides, within DynamicalSystems.jl the integration is never expected to terminate. # Nevertheless here we extend explicitly only for ODE stuff because it may be that for # other type of DEIntegrators a different step interruption is possible. -function successful_step(integ::SciMLBase.AbstractSDEIntegrator) +function DynamicalSystemsBase.successful_step(integ::SciMLBase.AbstractSDEIntegrator) rcode = integ.sol.retcode return rcode == SciMLBase.ReturnCode.Default || rcode == SciMLBase.ReturnCode.Success end diff --git a/src/CriticalTransitions.jl b/src/CriticalTransitions.jl index b81ea638..9389491c 100644 --- a/src/CriticalTransitions.jl +++ b/src/CriticalTransitions.jl @@ -1,18 +1,42 @@ module CriticalTransitions -using Reexport -@reexport using DynamicalSystemsBase +# Base +using Statistics: Statistics, mean +using LinearAlgebra: LinearAlgebra, Diagonal, I, norm, tr +using StaticArrays: StaticArrays, SVector + +# core +using DynamicalSystemsBase: DynamicalSystemsBase, ContinuousTimeDynamicalSystem, + StateSpaceSets, dimension, dynamic_rule +using DiffEqNoiseProcess: DiffEqNoiseProcess +using OrdinaryDiffEq: OrdinaryDiffEq, Tsit5 +using StochasticDiffEq: StochasticDiffEq, DiscreteCallback, ODEProblem, + SDEFunction, SOSRA, remake, solve, step!, terminate!, + u_modified! + +using ForwardDiff: ForwardDiff +using IntervalRootFinding: IntervalRootFinding, dot, eltype +using Dierckx: Dierckx, ParametricSpline +using Optim: Optim, LBFGS +using Symbolics: Symbolics + +# io and documentation +using Format: Format +using Dates: Dates # are we using this? +using DrWatson: DrWatson # are we using this? +using Printf: Printf +using Markdown: Markdown +using DocStringExtensions: TYPEDSIGNATURES +using HDF5: HDF5, h5open, push! +using JLD2: JLD2, jldopen +using ProgressBars: ProgressBars, tqdm +using ProgressMeter: ProgressMeter + +# reexport +using Reexport: @reexport @reexport using StaticArrays -@reexport using OrdinaryDiffEq @reexport using StochasticDiffEq @reexport using DiffEqNoiseProcess -@reexport using LinearAlgebra -using Format, Dates, JLD2, HDF5, ProgressBars, ProgressMeter, DocStringExtensions -using IntervalRootFinding -using ForwardDiff -using Symbolics -using Optim, Dierckx -using Printf, DrWatson, Dates, Statistics, Markdown include("extention_functions.jl") include("utils.jl") diff --git a/test/runtests.jl b/test/runtests.jl index 8fffbc98..2f47e9da 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -16,6 +16,30 @@ function fitzhugh_nagumo(u, p, t) return SA[dx, dy] end +@testset "Code quality" begin + using ExplicitImports, Aqua + ignore_deps = [:Random, :LinearAlgebra, :Printf, :Test, :Pkg] + + @test check_no_stale_explicit_imports(CriticalTransitions) == nothing + @test check_all_explicit_imports_via_owners(CriticalTransitions) == nothing + # Aqua.test_ambiguities(CriticalTransitions) + # Aqua.test_all( + # CriticalTransitions; + # deps_compat=( + # ignore=ignore_deps, + # check_extras=(ignore=ignore_deps,), + # check_weakdeps=(ignore=ignore_deps,), + # ), + # piracies=(treat_as_own=[],), + # ambiguities=false, + # ) +end + +@testset "Code linting" begin + using JET + # JET.test_package(HarmonicBalance; target_defined_modules=true) +end + @testset "CoupledSDEs" begin include("CoupledSDEs.jl") end From 0a6cb3eb481c57880173e4c469ab8fe85e384237 Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 10:52:27 +0200 Subject: [PATCH 02/10] add Aqua tests --- Project.toml | 11 +++++------ ext/CoupledSDEsBaisin.jl | 2 +- ext/basin/edgetrack.jl | 4 +++- src/CriticalTransitions.jl | 33 ++++++++++++++++++++++----------- systems/CTLibrary.jl | 2 +- test/runtests.jl | 26 +++++++++++++++----------- 6 files changed, 47 insertions(+), 31 deletions(-) diff --git a/Project.toml b/Project.toml index 54dcf6b5..50fb7fb5 100644 --- a/Project.toml +++ b/Project.toml @@ -5,11 +5,9 @@ repo = "https://github.com/juliadynamics/CriticalTransitions.jl.git" version = "0.3.0" [deps] -Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94" DiffEqNoiseProcess = "77a26b50-5914-5dd7-bc55-306e6241c503" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -DrWatson = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1" DynamicalSystemsBase = "6e36e845-645a-534a-86f2-f5d4aa5a06b4" Format = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" @@ -45,7 +43,6 @@ Dierckx = "0.5.3" DiffEqNoiseProcess = "5.22.0" DocStringExtensions = "0.9.3" Documenter = "1.4.1" -DrWatson = "2.14.1" DynamicalSystemsBase = "3.7.1" ExplicitImports = "1.6" Format = "1" @@ -55,6 +52,8 @@ IntervalRootFinding = "0.5.11" JET = "0.9" JLD2 = "0.4.46" Markdown = ">=1.9.0" +ModelingToolkit = "9.16" +StatsBase = "0.33.0" Optim = "1.9.3" OrdinaryDiffEq = "6.74.1" ProgressBars = "1.5.1" @@ -67,16 +66,16 @@ Symbolics = "5.26.0" julia = "1.9" [extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Attractors = "f3fd9213-ca85-4dba-9dfd-7fc91308fec7" ChaosTools = "608a59af-f2a3-5ad4-90b4-758bdf3122a7" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" -JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" +ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7" IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807" +JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" -ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] diff --git a/ext/CoupledSDEsBaisin.jl b/ext/CoupledSDEsBaisin.jl index 3e4d708a..5f1c565a 100644 --- a/ext/CoupledSDEsBaisin.jl +++ b/ext/CoupledSDEsBaisin.jl @@ -14,6 +14,6 @@ include("basin/basinsofattraction.jl") include("basin/edgetrack.jl") include("basin/basinboundary.jl") -export basins, basboundary, basinboundary +export basins, basboundary, basinboundary, end # module CoupledSDEsBaisin diff --git a/ext/basin/edgetrack.jl b/ext/basin/edgetrack.jl index 2bdba236..4b5eac58 100644 --- a/ext/basin/edgetrack.jl +++ b/ext/basin/edgetrack.jl @@ -233,6 +233,8 @@ vector `attractors` containing as elements the state vectors of the stable fixed and a parameter `eps` to control the mapping algorithm. For more info, see the [`docs`](https://juliadynamics.github.io/Attractors.jl/dev/attractors/#Attractors.AttractorsViaProximity). """ -function attractor_mapper(sys::CoupledSDEs, attractors, eps=0.01; kwargs...) +function Attractors.AttractorsViaProximity( + sys::CoupledSDEs, attractors, eps=0.01; kwargs... +) return Attractors.AttractorsViaProximity(CoupledODEs(sys), attrs, eps; kwargs...) end diff --git a/src/CriticalTransitions.jl b/src/CriticalTransitions.jl index 9389491c..7cdfc14e 100644 --- a/src/CriticalTransitions.jl +++ b/src/CriticalTransitions.jl @@ -6,13 +6,25 @@ using LinearAlgebra: LinearAlgebra, Diagonal, I, norm, tr using StaticArrays: StaticArrays, SVector # core -using DynamicalSystemsBase: DynamicalSystemsBase, ContinuousTimeDynamicalSystem, - StateSpaceSets, dimension, dynamic_rule +using DynamicalSystemsBase: + DynamicalSystemsBase, + ContinuousTimeDynamicalSystem, + StateSpaceSets, + dimension, + dynamic_rule using DiffEqNoiseProcess: DiffEqNoiseProcess using OrdinaryDiffEq: OrdinaryDiffEq, Tsit5 -using StochasticDiffEq: StochasticDiffEq, DiscreteCallback, ODEProblem, - SDEFunction, SOSRA, remake, solve, step!, terminate!, - u_modified! +using StochasticDiffEq: + StochasticDiffEq, + DiscreteCallback, + ODEProblem, + SDEFunction, + SOSRA, + remake, + solve, + step!, + terminate!, + u_modified! using ForwardDiff: ForwardDiff using IntervalRootFinding: IntervalRootFinding, dot, eltype @@ -22,8 +34,6 @@ using Symbolics: Symbolics # io and documentation using Format: Format -using Dates: Dates # are we using this? -using DrWatson: DrWatson # are we using this? using Printf: Printf using Markdown: Markdown using DocStringExtensions: TYPEDSIGNATURES @@ -58,13 +68,14 @@ export CoupledSDEs, idfunc!, idfunc, add_noise_strength, noise_process, covariance_matrix, noise_strength # Methods -export equilib, fixedpoints, basins, basinboundary, basboundary +export equilib, basins, basinboundary, basboundary export simulate, relax export transition, transitions export fw_action, om_action, action, geometric_action export min_action_method, geometric_min_action_method -export basins, basinboundary -export edgetracking, bisect_to_edge, attractor_mapper export make_jld2, make_h5, intervals_to_box - +# export basins, basinboundary +# export edgetracking, bisect_to_edge, AttractorsViaProximity +# export fixedpoints +# ^ extention tests needed end # module CriticalTransitions diff --git a/systems/CTLibrary.jl b/systems/CTLibrary.jl index a1a91307..336d02e5 100644 --- a/systems/CTLibrary.jl +++ b/systems/CTLibrary.jl @@ -10,7 +10,7 @@ include("rooth.jl") include("stommel.jl") include("rivals.jl") -export fitzhughnagumo, fitzhughnagumo!, stommel, rivals!, rival, cessi, rooth_smooth +export fitzhugh_nagumo!, fitzhugh_nagumo, stommel, rivals!, rivals, cessi, rooth_smooth modifiedtruscottbrindleywithdimensions!, modifiedtruscottbrindleywithdimensions originaltruscottbrindley!, originaltruscottbrindley rampedoriginaltruscottbrindley!, rampedoriginaltruscottbrindley diff --git a/test/runtests.jl b/test/runtests.jl index 2f47e9da..50f627d0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,17 +22,21 @@ end @test check_no_stale_explicit_imports(CriticalTransitions) == nothing @test check_all_explicit_imports_via_owners(CriticalTransitions) == nothing - # Aqua.test_ambiguities(CriticalTransitions) - # Aqua.test_all( - # CriticalTransitions; - # deps_compat=( - # ignore=ignore_deps, - # check_extras=(ignore=ignore_deps,), - # check_weakdeps=(ignore=ignore_deps,), - # ), - # piracies=(treat_as_own=[],), - # ambiguities=false, - # ) + Aqua.test_ambiguities(CriticalTransitions) + Aqua.test_all( + CriticalTransitions; + deps_compat=( + ignore=ignore_deps, + check_extras=(ignore=ignore_deps,), + check_weakdeps=(ignore=ignore_deps,), + ), + piracies=( + treat_as_own=[ + CriticalTransitions.DynamicalSystemsBase.SciMLBase.AbstractSDEIntegrator + ], + ), + ambiguities=false, + ) end @testset "Code linting" begin From 210fb7808f9a6e6c5f5fe49da86bcceda0b5410a Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 12:28:12 +0200 Subject: [PATCH 03/10] interchange `IntervalRootFinding` for `IntervalArithmetic` --- Project.toml | 9 ++++----- ext/CoupledSDEsBaisin.jl | 3 ++- src/CoupledSDEs.jl | 5 ++++- src/CriticalTransitions.jl | 12 +++++++++--- src/trajectories/simulation.jl | 10 ++++------ src/utils.jl | 4 ++-- test/ModelingToolkit.jl | 4 ++-- test/trajactories/simulate.jl | 7 ++++++- test/trajactories/transition.jl | 2 +- test/utils.jl | 2 +- 10 files changed, 35 insertions(+), 23 deletions(-) diff --git a/Project.toml b/Project.toml index 50fb7fb5..e873a4bf 100644 --- a/Project.toml +++ b/Project.toml @@ -12,7 +12,7 @@ DynamicalSystemsBase = "6e36e845-645a-534a-86f2-f5d4aa5a06b4" Format = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" -IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807" +IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" @@ -48,12 +48,11 @@ ExplicitImports = "1.6" Format = "1" ForwardDiff = "0.10.36" HDF5 = "0.17.1" -IntervalRootFinding = "0.5.11" +IntervalArithmetic = "0.20" JET = "0.9" JLD2 = "0.4.46" Markdown = ">=1.9.0" ModelingToolkit = "9.16" -StatsBase = "0.33.0" Optim = "1.9.3" OrdinaryDiffEq = "6.74.1" ProgressBars = "1.5.1" @@ -61,6 +60,7 @@ ProgressMeter = "1.10.0" Reexport = "1.2.2" StaticArrays = "1.9.3" Statistics = ">=1.9" +StatsBase = "0.33.0" StochasticDiffEq = "6.65.1" Symbolics = "5.26.0" julia = "1.9" @@ -71,7 +71,6 @@ Attractors = "f3fd9213-ca85-4dba-9dfd-7fc91308fec7" ChaosTools = "608a59af-f2a3-5ad4-90b4-758bdf3122a7" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7" -IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" @@ -79,4 +78,4 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "Random", "IntervalRootFinding", "ModelingToolkit", "Documenter", "Attractors", "ChaosTools", "StatsBase", "ExplicitImports", "Aqua", "JET"] +test = ["Test", "Random", "ModelingToolkit", "Documenter", "Attractors", "ChaosTools", "StatsBase", "ExplicitImports", "Aqua", "JET"] diff --git a/ext/CoupledSDEsBaisin.jl b/ext/CoupledSDEsBaisin.jl index 5f1c565a..a8b789f8 100644 --- a/ext/CoupledSDEsBaisin.jl +++ b/ext/CoupledSDEsBaisin.jl @@ -8,12 +8,13 @@ using ProgressMeter using ProgressBars using DynamicalSystemsBase: ParallelDynamicalSystem using DocStringExtensions +using LinearAlgebra include("basin/planeofbox.jl") include("basin/basinsofattraction.jl") include("basin/edgetrack.jl") include("basin/basinboundary.jl") -export basins, basboundary, basinboundary, +export basins, basboundary, basinboundary end # module CoupledSDEsBaisin diff --git a/src/CoupledSDEs.jl b/src/CoupledSDEs.jl index 4ef3de08..8c2548c3 100644 --- a/src/CoupledSDEs.jl +++ b/src/CoupledSDEs.jl @@ -1,5 +1,6 @@ using DynamicalSystemsBase.SciMLBase: __init using DynamicalSystemsBase: + DynamicalSystemsBase, CoupledODEs, isinplace, SciMLBase, @@ -183,7 +184,9 @@ $(TYPEDSIGNATURES) Converts a [`CoupledSDEs`](@ref) into [`CoupledODEs`](https://juliadynamics.github.io/DynamicalSystems.jl/stable/tutorial/#DynamicalSystemsBase.CoupledODEs) from DynamicalSystems.jl. """ -function CoupledODEs(sys::CoupledSDEs; diffeq=DynamicalSystemsBase.DEFAULT_DIFFEQ, t0=0.0) +function DynamicalSystemsBase.CoupledODEs( + sys::CoupledSDEs; diffeq=DynamicalSystemsBase.DEFAULT_DIFFEQ, t0=0.0 +) return DynamicalSystemsBase.CoupledODEs( sys.integ.f, SVector{length(sys.integ.u)}(sys.integ.u), sys.p0; diffeq=diffeq, t0=t0 ) diff --git a/src/CriticalTransitions.jl b/src/CriticalTransitions.jl index 7cdfc14e..c1b58de7 100644 --- a/src/CriticalTransitions.jl +++ b/src/CriticalTransitions.jl @@ -2,7 +2,7 @@ module CriticalTransitions # Base using Statistics: Statistics, mean -using LinearAlgebra: LinearAlgebra, Diagonal, I, norm, tr +using LinearAlgebra: LinearAlgebra, Diagonal, I, norm, tr, dot using StaticArrays: StaticArrays, SVector # core @@ -27,7 +27,7 @@ using StochasticDiffEq: u_modified! using ForwardDiff: ForwardDiff -using IntervalRootFinding: IntervalRootFinding, dot, eltype +using IntervalArithmetic: interval, IntervalBox using Dierckx: Dierckx, ParametricSpline using Optim: Optim, LBFGS using Symbolics: Symbolics @@ -65,7 +65,13 @@ using .CTLibrary # Core types export CoupledSDEs, - idfunc!, idfunc, add_noise_strength, noise_process, covariance_matrix, noise_strength + idfunc!, + idfunc, + add_noise_strength, + noise_process, + covariance_matrix, + noise_strength, + CoupledODEs # Methods export equilib, basins, basinboundary, basboundary diff --git a/src/trajectories/simulation.jl b/src/trajectories/simulation.jl index c5c0b4dd..e8f03cdf 100644 --- a/src/trajectories/simulation.jl +++ b/src/trajectories/simulation.jl @@ -12,8 +12,8 @@ This function uses the [`SDEProblem`](https://diffeq.sciml.ai/stable/types/sde_t For more info, see [`SDEProblem`](https://diffeq.sciml.ai/stable/types/sde_types/#SciMLBase.SDEProblem). """ -function simulate(sys::CoupledSDEs, T, init=current_state(sys); - alg=sys.integ.alg, kwargs... +function simulate( + sys::CoupledSDEs, T, init=current_state(sys); alg=sys.integ.alg, kwargs... ) prob = remake(referrenced_sciml_prob(sys); u0=init, tspan=(0, T)) return solve(prob, alg; kwargs...) @@ -34,10 +34,8 @@ For more info, see [`ODEProblem`](https://diffeq.sciml.ai/stable/types/ode_types For stochastic integration, see [`simulate`](@ref). """ -function relax(sys::CoupledSDEs, T, init=current_state(sys); - alg=Tsit5(), kwargs... -) +function relax(sys::CoupledSDEs, T, init=current_state(sys); alg=Tsit5(), kwargs...) sde_prob = referrenced_sciml_prob(sys) prob = ODEProblem{isinplace(sde_prob)}(dynamic_rule(sys), init, (0, T), sys.p0) return solve(prob, alg; kwargs...) -end; \ No newline at end of file +end; diff --git a/src/utils.jl b/src/utils.jl index 2142f6b2..e871bd46 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -56,11 +56,11 @@ function intervals_to_box(bmin::Vector, bmax::Vector) intervals = [] dim = length(bmin) for i in 1:dim - push!(intervals, bmin[i] .. bmax[i]) + push!(intervals, interval(bmin[i], bmax[i])) end box = intervals[1] for i in 2:dim - box = box × intervals[i] + box = IntervalBox(box, intervals[i]) end return box end; diff --git a/test/ModelingToolkit.jl b/test/ModelingToolkit.jl index d0248653..5a413580 100644 --- a/test/ModelingToolkit.jl +++ b/test/ModelingToolkit.jl @@ -1,7 +1,7 @@ using ModelingToolkit @testset begin - @variables t + @independent_variables t D = Differential(t) sts = @variables x(t) y(t) z(t) ps = @parameters σ ρ @@ -35,7 +35,7 @@ end @testset begin using ModelingToolkit - @variables t + @independent_variables t ps = @parameters α β sts = @variables x(t) D = Differential(t) diff --git a/test/trajactories/simulate.jl b/test/trajactories/simulate.jl index 7846aa70..0e2dfd41 100644 --- a/test/trajactories/simulate.jl +++ b/test/trajactories/simulate.jl @@ -4,10 +4,15 @@ σ = 0.1 # Simulate sys = CoupledSDEs(fitzhugh_nagumo, idfunc, SA[1.0, 0.0], p, σ) - traj = trajectory(sys, 10) + traj = relax(sys, 10) sys = CoupledSDEs(fitzhugh_nagumo, idfunc, SA[1.0, 0.0], p, σ) sim = simulate(sys, 10) @test traj[1][1, 1] == 1.0 @test sim.u[1][1] == 1.0 # These tests could be improved - Reyk + + # using DynamicalSystemsBase + # sys = CoupledSDEs(fitzhugh_nagumo, idfunc, SA[1.0, 0.0], p, σ) + # trajectory(sys, 10) # works + # works? end diff --git a/test/trajactories/transition.jl b/test/trajactories/transition.jl index e9370522..1fe32fff 100644 --- a/test/trajactories/transition.jl +++ b/test/trajactories/transition.jl @@ -1,6 +1,6 @@ @testset "fitzhugh_nagumo" begin - using Random + using Random, LinearAlgebra Random.seed!(SEED) p = [1.0, 3.0, 1.0, 1.0, 1.0, 0.0] # Parameters (ϵ, β, α, γ, κ, I) diff --git a/test/utils.jl b/test/utils.jl index 405c49cf..8f86196e 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -26,7 +26,7 @@ end # Test for intervals_to_box @testset "intervals_to_box" begin - using IntervalRootFinding.IntervalArithmetic + using CriticalTransitions.IntervalArithmetic bmin = [-2, -1, 0] bmax = [2, 1, 1] expected = (Interval([-2, 2]...), Interval([-1, 1]...), Interval([0, 1]...)) From 4b118840f4912675451c1c1a631ac6d76d9c1272 Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 12:56:33 +0200 Subject: [PATCH 04/10] add Jet remove Dates compat interchange .. with interval in CTLibrary --- Project.toml | 1 + src/CoupledSDEs.jl | 2 +- src/CriticalTransitions.jl | 1 + src/largedeviations/action.jl | 6 +++--- src/largedeviations/geometric_min_action_method.jl | 2 ++ systems/CTLibrary.jl | 4 +++- systems/fitzhughnagumo.jl | 4 ---- systems/truscottbrindley_mod.jl | 4 ++-- systems/truscottbrindley_orig.jl | 4 ++-- systems/truscottbrindley_orig1.jl | 4 ++-- test/runtests.jl | 2 +- 11 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Project.toml b/Project.toml index e873a4bf..83e6891d 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ repo = "https://github.com/juliadynamics/CriticalTransitions.jl.git" version = "0.3.0" [deps] +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94" DiffEqNoiseProcess = "77a26b50-5914-5dd7-bc55-306e6241c503" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" diff --git a/src/CoupledSDEs.jl b/src/CoupledSDEs.jl index 8c2548c3..58d2dd7c 100644 --- a/src/CoupledSDEs.jl +++ b/src/CoupledSDEs.jl @@ -167,7 +167,7 @@ function CoupledSDEs( ) return CoupledSDEs( dynamic_rule(ds), - prob.g, + g, current_state(ds), p, noise_strength; diff --git a/src/CriticalTransitions.jl b/src/CriticalTransitions.jl index c1b58de7..3c21b97e 100644 --- a/src/CriticalTransitions.jl +++ b/src/CriticalTransitions.jl @@ -34,6 +34,7 @@ using Symbolics: Symbolics # io and documentation using Format: Format +using Dates: Dates using Printf: Printf using Markdown: Markdown using DocStringExtensions: TYPEDSIGNATURES diff --git a/src/largedeviations/action.jl b/src/largedeviations/action.jl index fc6c7dbd..b3cda6cf 100644 --- a/src/largedeviations/action.jl +++ b/src/largedeviations/action.jl @@ -75,11 +75,11 @@ Computes the action functional specified by `functional` for a given CoupledSDEs * `functional = "FW"`: Returns the Freidlin-Wentzell action ([`fw_action`](@ref)) * `functional = "OM"`: Returns the Onsager-Machlup action ([`om_action`](@ref)) """ -function action(sys::CoupledSDEs, path::Matrix, time, functional; kwargs...) +function action(sys::CoupledSDEs, path::Matrix, time, functional) if functional == "FW" - action = fw_action(sys, path, time; kwargs...) + action = fw_action(sys, path, time) elseif functional == "OM" - action = om_action(sys, path, time; kwargs...) + action = om_action(sys, path, time) end return action end; diff --git a/src/largedeviations/geometric_min_action_method.jl b/src/largedeviations/geometric_min_action_method.jl index 816f5435..d76099cb 100644 --- a/src/largedeviations/geometric_min_action_method.jl +++ b/src/largedeviations/geometric_min_action_method.jl @@ -141,6 +141,8 @@ function heymann_vandeneijnden_step(sys::CoupledSDEs, path, N, L; tau=0.1, diff_ lambdas, lambdas_prime = zeros(N), zeros(N) x_prime = path_velocity(path, 0:dx:L; order=diff_order) + A = inv(covariance_matrix(sys)) + for i in 2:(N - 1) lambdas[i] = anorm(drift(sys, path[:, i]), A) / anorm(path[:, i], A) end diff --git a/systems/CTLibrary.jl b/systems/CTLibrary.jl index 336d02e5..d125a256 100644 --- a/systems/CTLibrary.jl +++ b/systems/CTLibrary.jl @@ -1,6 +1,8 @@ module CTLibrary -using CriticalTransitions +using CriticalTransitions: CriticalTransitions, smoothabs +using IntervalArithmetic: interval +using StaticArrays: SA, SVector include("fitzhughnagumo.jl") include("truscottbrindley_mod.jl") diff --git a/systems/fitzhughnagumo.jl b/systems/fitzhughnagumo.jl index 79bb3ae4..75e52c0c 100644 --- a/systems/fitzhughnagumo.jl +++ b/systems/fitzhughnagumo.jl @@ -34,10 +34,6 @@ function fitzhugh_nagumo(u, p, t) return SA[dx, dy] end -# For backwards compatibility -FitzHughNagumo(u, p, t) = fitzhugh_nagumo(u, p, t) -FitzHughNagumo!(u, p, t) = fitzhugh_nagumo!(u, p, t) - # """ # fhn_ϵσ(ϵ,σ) # A shortcut command for returning a CoupledSDEs of the FitzHugh Nagumo system in a default setup with additive isotropic noise. diff --git a/systems/truscottbrindley_mod.jl b/systems/truscottbrindley_mod.jl index e7d58ca8..ff491b3d 100644 --- a/systems/truscottbrindley_mod.jl +++ b/systems/truscottbrindley_mod.jl @@ -82,7 +82,7 @@ function rampedmodifiedtruscottbrindley!(du, u, p, t) P₁ * (α * (P / P₁) * (1 - β * (P / P₁)) - γ * (Z / Z₁) * (P / P₁)^2 / (1 + (P / P₁)^2)) du[2] = ξ * Z₁ * ((Z / Z₁) * (P / P₁)^2 / (1 + (P / P₁)^2) - (Z / Z₁)^2) - return du[3] = t ∈ Ttrans .. (Ttrans + Tramp) ? v : 0 + return du[3] = t ∈ interval(Ttrans, (Ttrans + Tramp)) ? v : 0 end """ @@ -99,7 +99,7 @@ function rampedmodifiedtruscottbrindley(u, p, t) P₁ * (α * (P / P₁) * (1 - β * (P / P₁)) - γ * (Z / Z₁) * (P / P₁)^2 / (1 + (P / P₁)^2)) dZ = ξ * Z₁ * ((Z / Z₁) * (P / P₁)^2 / (1 + (P / P₁)^2) - (Z / Z₁)^2) - dα = t ∈ Ttrans .. (Ttrans + Tramp) ? v : 0 + dα = t ∈ interval(Ttrans, (Ttrans + Tramp)) ? v : 0 return SA[dP, dZ, dα] end diff --git a/systems/truscottbrindley_orig.jl b/systems/truscottbrindley_orig.jl index 78f2fde5..9ee02a39 100644 --- a/systems/truscottbrindley_orig.jl +++ b/systems/truscottbrindley_orig.jl @@ -46,7 +46,7 @@ function rampedoriginaltruscottbrindley!(du, u, p, t) du[1] = r * P * (1 - P / K) - Rₘ * Z * P^2 / (α^2 + P^2) du[2] = γ * Rₘ * Z * P^2 / (α^2 + P^2) - μ * Z - return du[3] = t ∈ Ttrans .. (Ttrans + Tramp) ? v : 0 + return du[3] = t ∈ interval(Ttrans, (Ttrans + Tramp)) ? v : 0 end """ @@ -61,7 +61,7 @@ function rampedoriginaltruscottbrindley(u, p, t) dP = r * P * (1 - P / K) - Rₘ * Z * P^2 / (α^2 + P^2) dZ = γ * Rₘ * Z * P^2 / (α^2 + P^2) - μ * Z - dr = t ∈ Ttrans .. (Ttrans + Tramp) ? v : 0 + dr = t ∈ interval(Ttrans, (Ttrans + Tramp)) ? v : 0 return SA[dP, dZ, dr] end diff --git a/systems/truscottbrindley_orig1.jl b/systems/truscottbrindley_orig1.jl index 46c4be66..b9c0e8ed 100644 --- a/systems/truscottbrindley_orig1.jl +++ b/systems/truscottbrindley_orig1.jl @@ -46,7 +46,7 @@ function rampedoriginaltruscottbrindley1!(du, u, p, t) du[1] = (1 / γ) * (r * P * (1 - P / K) - Rₘ * Z * P^2 / (α^2 + P^2)) du[2] = Rₘ * Z * P^2 / (α^2 + P^2) - μ * Z - return du[3] = t ∈ Ttrans .. (Ttrans + Tramp) ? v : 0 + return du[3] = t ∈ interval(Ttrans, (Ttrans + Tramp)) ? v : 0 end """ @@ -61,7 +61,7 @@ function rampedoriginaltruscottbrindley1(u, p, t) dP = (1 / γ) * (r * P * (1 - P / K) - Rₘ * Z * P^2 / (α^2 + P^2)) dZ = Rₘ * Z * P^2 / (α^2 + P^2) - μ * Z - dr = t ∈ Ttrans .. (Ttrans + Tramp) ? v : 0 + dr = t ∈ interval(Ttrans, (Ttrans + Tramp)) ? v : 0 return SA[dP, dZ, dr] end diff --git a/test/runtests.jl b/test/runtests.jl index 50f627d0..b4c7affb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -41,7 +41,7 @@ end @testset "Code linting" begin using JET - # JET.test_package(HarmonicBalance; target_defined_modules=true) + JET.test_package(CriticalTransitions; target_defined_modules=true) end @testset "CoupledSDEs" begin From f80fecabfff7c6956d82ce30433a3947c0aa4542 Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 13:09:30 +0200 Subject: [PATCH 05/10] remove StatsBase --- Project.toml | 5 ++--- test/CoupledSDEs.jl | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 83e6891d..e46552ab 100644 --- a/Project.toml +++ b/Project.toml @@ -61,7 +61,6 @@ ProgressMeter = "1.10.0" Reexport = "1.2.2" StaticArrays = "1.9.3" Statistics = ">=1.9" -StatsBase = "0.33.0" StochasticDiffEq = "6.65.1" Symbolics = "5.26.0" julia = "1.9" @@ -75,8 +74,8 @@ ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "Random", "ModelingToolkit", "Documenter", "Attractors", "ChaosTools", "StatsBase", "ExplicitImports", "Aqua", "JET"] +test = ["Test", "Random", "ModelingToolkit", "Documenter", "Attractors", "ChaosTools", "Statistics", "ExplicitImports", "Aqua", "JET"] diff --git a/test/CoupledSDEs.jl b/test/CoupledSDEs.jl index e6b13ba6..f85d3c5a 100644 --- a/test/CoupledSDEs.jl +++ b/test/CoupledSDEs.jl @@ -140,7 +140,7 @@ @test W.covariance == Γ @testset "covariance" begin - using DiffEqNoiseProcess, StatsBase + using DiffEqNoiseProcess, Statistics prob = NoiseProblem(W, (0.0, 1.0)) output_func = (sol, i) -> (sol.dW, false) ensemble_prob = EnsembleProblem(prob; output_func=output_func) From c750a76bbfd9a0bd94c47681fdc5d972b079bb10 Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 13:12:37 +0200 Subject: [PATCH 06/10] fix downgrade fix downgrade fix downgrade --- Project.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index e46552ab..60a24a80 100644 --- a/Project.toml +++ b/Project.toml @@ -38,14 +38,14 @@ CoupledSDEsBaisin = ["ChaosTools", "Attractors"] [compat] Aqua = "0.8" -Attractors = "1.15.0" -ChaosTools = "3.1.2" +Attractors = "1.15" +ChaosTools = "3.1" Dierckx = "0.5.3" -DiffEqNoiseProcess = "5.22.0" +DiffEqNoiseProcess = "5.22" DocStringExtensions = "0.9.3" -Documenter = "1.4.1" +Documenter = "^1.4.1" DynamicalSystemsBase = "3.7.1" -ExplicitImports = "1.6" +ExplicitImports = "1.6.0" Format = "1" ForwardDiff = "0.10.36" HDF5 = "0.17.1" @@ -53,16 +53,16 @@ IntervalArithmetic = "0.20" JET = "0.9" JLD2 = "0.4.46" Markdown = ">=1.9.0" -ModelingToolkit = "9.16" +ModelingToolkit = "9.17" Optim = "1.9.3" -OrdinaryDiffEq = "6.74.1" +OrdinaryDiffEq = "6.82" ProgressBars = "1.5.1" ProgressMeter = "1.10.0" Reexport = "1.2.2" StaticArrays = "1.9.3" Statistics = ">=1.9" StochasticDiffEq = "6.65.1" -Symbolics = "5.26.0" +Symbolics = "5.30" julia = "1.9" [extras] From ab50752a76c99cc46c4dbc4f80cce8bdb5783af7 Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 13:30:35 +0200 Subject: [PATCH 07/10] add Dates compat fix --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 60a24a80..fb6dc0f0 100644 --- a/Project.toml +++ b/Project.toml @@ -40,6 +40,7 @@ CoupledSDEsBaisin = ["ChaosTools", "Attractors"] Aqua = "0.8" Attractors = "1.15" ChaosTools = "3.1" +Dates = "1.10" Dierckx = "0.5.3" DiffEqNoiseProcess = "5.22" DocStringExtensions = "0.9.3" From 6c0a6514a776f7dcc7d5602825eed812cf565280 Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 13:43:35 +0200 Subject: [PATCH 08/10] weird downgrade error --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index fb6dc0f0..641bb07d 100644 --- a/Project.toml +++ b/Project.toml @@ -40,7 +40,7 @@ CoupledSDEsBaisin = ["ChaosTools", "Attractors"] Aqua = "0.8" Attractors = "1.15" ChaosTools = "3.1" -Dates = "1.10" +Dates = ">=1.9.0" Dierckx = "0.5.3" DiffEqNoiseProcess = "5.22" DocStringExtensions = "0.9.3" From 6d808e9a940d27086c547baf0112cc6a91d0a692 Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 13:51:27 +0200 Subject: [PATCH 09/10] remove unused import EM --- src/CoupledSDEs.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CoupledSDEs.jl b/src/CoupledSDEs.jl index 58d2dd7c..fdc63067 100644 --- a/src/CoupledSDEs.jl +++ b/src/CoupledSDEs.jl @@ -8,7 +8,6 @@ using DynamicalSystemsBase: _set_parameter!, current_state using StochasticDiffEq: SDEProblem -using StochasticDiffEq: EM, SDEProblem ########################################################################################### # DiffEq options From e6e8ecb51ed052568c4bac9622e2368d4044ba6d Mon Sep 17 00:00:00 2001 From: oameye Date: Tue, 23 Jul 2024 14:02:10 +0200 Subject: [PATCH 10/10] fix persistant_task in downgrade test --- Project.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 641bb07d..516d2021 100644 --- a/Project.toml +++ b/Project.toml @@ -37,8 +37,8 @@ ChaosToolsExt = ["ChaosTools"] CoupledSDEsBaisin = ["ChaosTools", "Attractors"] [compat] -Aqua = "0.8" -Attractors = "1.15" +Aqua = "0.8.7" +Attractors = "1.18" ChaosTools = "3.1" Dates = ">=1.9.0" Dierckx = "0.5.3" @@ -46,7 +46,7 @@ DiffEqNoiseProcess = "5.22" DocStringExtensions = "0.9.3" Documenter = "^1.4.1" DynamicalSystemsBase = "3.7.1" -ExplicitImports = "1.6.0" +ExplicitImports = "1.9" Format = "1" ForwardDiff = "0.10.36" HDF5 = "0.17.1"