From b148ec1f0d1888e206f1e66d38a658446beba5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Koziorek?= <73384756+JonasKoziorek@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:22:38 +0100 Subject: [PATCH] Fix docs build (#31) * modify so that alg converges * probably a bug * decrease tolerance * decrease tolerance * change the tolerances * remove the constant redef warning * increase the period * use the same initial guess twice * increase period guess a lot * warn user * just keep the guess that works --- docs/src/examples.md | 2 +- docs/src/tutorial.md | 6 +++--- src/algorithms/continuous_time/optimized_shooting.jl | 3 +++ src/pretty_printing.jl | 2 +- test/algorithms/continuous_time/optimized_shooting.jl | 6 +++--- test/api.jl | 6 +++--- test/minimal_period.jl | 4 ++-- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/src/examples.md b/docs/src/examples.md index 506ef35..4167346 100644 --- a/docs/src/examples.md +++ b/docs/src/examples.md @@ -24,7 +24,7 @@ end ig = InitialGuess(SVector(2.0, 5.0, 10.0), 10.2) OSalg = OptimizedShooting(Δt=0.01, n=3) -ds = CoupledODEs(roessler_rule, [1.0, -2.0, 0.1], [0.15, 0.2, 3.5]) +ds = CoupledODEs(roessler_rule, [1.0, -2.0, 0.1], [0.15, 0.2, 3.5]; diffeq=(abstol=1e-10, reltol=1e-10)) res = periodic_orbit(ds, OSalg, ig) plot_result(res, ds; azimuth = 1.3pi, elevation=0.1pi) ``` diff --git a/docs/src/tutorial.md b/docs/src/tutorial.md index ad0769f..993e194 100644 --- a/docs/src/tutorial.md +++ b/docs/src/tutorial.md @@ -7,7 +7,7 @@ system itself. using PeriodicOrbits function lorenz(u0=[0.0, 10.0, 0.0]; σ = 10.0, ρ = 28.0, β = 8/3) - return CoupledODEs(lorenz_rule, u0, [σ, ρ, β]) + return CoupledODEs(lorenz_rule, u0, [σ, ρ, β]; diffeq=(abstol=1e-10, reltol=1e-10)) end @inbounds function lorenz_rule(u, p, t) du1 = p[1]*(u[2]-u[1]) @@ -22,8 +22,8 @@ ds = lorenz() Next, we give initial guess of the location of the periodic orbit and its period. ```@example MAIN -u0_guess = SVector(3.5, 3.0, 0.0) -T_guess = 5.2 +u0_guess = SVector(1.0, 2.0, 5.0) +T_guess = 4.2 ig = InitialGuess(u0_guess, T_guess) ``` Then we pick an appropriate algorithm that will detect the PO. In this case we can use diff --git a/src/algorithms/continuous_time/optimized_shooting.jl b/src/algorithms/continuous_time/optimized_shooting.jl index 8c254c2..9a3f120 100644 --- a/src/algorithms/continuous_time/optimized_shooting.jl +++ b/src/algorithms/continuous_time/optimized_shooting.jl @@ -38,6 +38,9 @@ is optimized by the Levenberg-Marquardt algorithm. In our implementation, the keyword argument `n` corresponds to ``n`` in the residual ``R``. The keyword argument `Δt` corresponds to ``\\Delta t`` in the residual ``R``. + +Note that for the algorithm to converge to a periodic orbit, the initial guess has to be +close to an existing periodic orbit. """ @kwdef struct OptimizedShooting{T} <: PeriodicOrbitFinder Δt::Float64 = 1e-6 diff --git a/src/pretty_printing.jl b/src/pretty_printing.jl index 0b2ae1e..66f0102 100644 --- a/src/pretty_printing.jl +++ b/src/pretty_printing.jl @@ -24,7 +24,7 @@ end function Base.summary(ig::InitialGuess) digits = 5 u0 = round.(ig.u0, digits=digits) - T = isnothing(ig.T) ? "nothing" : round(ig.T, digits=ig_round_digits) + T = isnothing(ig.T) ? "nothing" : round(ig.T, digits=digits) return "$(typeof(ig))($(u0), $(T))" end diff --git a/test/algorithms/continuous_time/optimized_shooting.jl b/test/algorithms/continuous_time/optimized_shooting.jl index e97c1b0..95c0e67 100644 --- a/test/algorithms/continuous_time/optimized_shooting.jl +++ b/test/algorithms/continuous_time/optimized_shooting.jl @@ -10,10 +10,10 @@ using LinearAlgebra: norm end @testset "Optimized shooting" begin - igs = [InitialGuess(SVector(1.0, 2.0, 5.0), 4.2), InitialGuess(SVector(1.0, 2.0, 5.0), 5.2)] + igs = [InitialGuess(SVector(1.0, 2.0, 5.0), 4.2), InitialGuess(SVector(1.0, 2.0, 5.0), 4.2)] ig = igs[1] - alg = OptimizedShooting(Δt=1e-3, n=3, nonlinear_solve_kwargs=(abstol=1e-6, reltol=1e-6)) - ds = CoupledODEs(lorenz_rule, [0.0, 10.0, 0.0], [10.0, 28.0, 8 / 3]; diffeq=(abstol=1e-10, reltol=1e-10)) + alg = OptimizedShooting(Δt=1e-4, n=3, nonlinear_solve_kwargs=(abstol=1e-7, reltol=1e-7)) + ds = CoupledODEs(lorenz_rule, [0.0, 10.0, 0.0], [10.0, 28.0, 8 / 3]; diffeq=(abstol=1e-11, reltol=1e-11)) res = periodic_orbit(ds, alg, ig) diff --git a/test/api.jl b/test/api.jl index cdcb653..aa99d67 100644 --- a/test/api.jl +++ b/test/api.jl @@ -16,9 +16,8 @@ end return SVector{3}(du1, du2, du3) end -const logistic_ = logistic() -const lorenz_ = lorenz() -const period3window = StateSpaceSet([SVector{1}(x) for x in [0.15933615523767342, 0.5128107111364378, 0.9564784814729845]]) +logistic_ = logistic() +period3window = StateSpaceSet([SVector{1}(x) for x in [0.15933615523767342, 0.5128107111364378, 0.9564784814729845]]) @testset "constructors of InitialGuess" begin # TODO @@ -66,6 +65,7 @@ end po = PeriodicOrbit(logistic_, SVector{1}([(r-1)/r]), 1) @test isdiscretetime(po) == true + lorenz_ = lorenz() po = PeriodicOrbit(lorenz_, current_state(lorenz_), 1.0) @test isdiscretetime(po) == false end \ No newline at end of file diff --git a/test/minimal_period.jl b/test/minimal_period.jl index 4a73199..c4120b5 100644 --- a/test/minimal_period.jl +++ b/test/minimal_period.jl @@ -12,8 +12,8 @@ function logistic(x0=0.4; r = 4.0) end logistic_rule(x, p, n) = @inbounds SVector(p[1]*x[1]*(1 - x[1])) -const logistic_ = logistic() -const period3window = StateSpaceSet([SVector{1}(x) for x in [0.15933615523767342, 0.5128107111364378, 0.9564784814729845]]) +logistic_ = logistic() +period3window = StateSpaceSet([SVector{1}(x) for x in [0.15933615523767342, 0.5128107111364378, 0.9564784814729845]]) @testset "minimal_period discrete" begin r = 1+sqrt(8)