Skip to content

Commit 154c58e

Browse files
authored
Merge pull request #86 from JuliaDynamics/internalnorm
New internalnorm based on state only
2 parents 5d265d8 + 8329bd4 commit 154c58e

File tree

6 files changed

+76
-9
lines changed

6 files changed

+76
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Changelog of `DynamicalSystemsBase`.
22

3+
# v1.3
4+
* The specialized integrators (tangent & parallel) now implement an internal norm that only evaluates norm of the main state, instead of using the other parallel states or deviation vectors. (#86)
5+
* Bunch of bugfixes and performance improvements (see git history)
6+
37
# v1.2
48
In version `1.2` we have moved to `DiffEqBase 5.0+`. In addition to that we have changed the default integrator to `SimpleATsit5` from module `SimpleDiffEq`. This is not a breaking change and you can use any of the previous integrators. **It must be stated though that numeric results you obtained using the default integrator will now be slightly different**.
59

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicalSystemsBase"
22
uuid = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
33
repo = "https://github.com/JuliaDynamics/DynamicalSystemsBase.jl.git"
4-
version = "1.2.5"
4+
version = "1.3.0"
55

66
[deps]
77
DelayEmbeddings = "5732040d-69e3-5649-938a-b6b4f237613f"
@@ -15,12 +15,12 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1515
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1616

1717
[compat]
18-
DiffEqBase = "5.0.0"
18+
DiffEqBase = "5.10.0"
1919
DiffEqCallbacks = "≥ 2.1.0"
2020
ForwardDiff = "≥ 0.8.0"
2121
OrdinaryDiffEq = "≥ 5.0.0"
2222
Reexport = "≥ 0.1.0"
23-
SimpleDiffEq = "≥ 0.3.0"
23+
SimpleDiffEq = "≥ 0.4.0"
2424
StaticArrays = "≥ 0.8.0"
2525
julia = "≥ 1.0.0"
2626

src/continuous.jl

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,19 @@ function tangent_integrator(ds::CDS{IIP}, Q0::AbstractMatrix;
6363
tanprob = ODEProblem{IIP}(tangentf, hcat(u, Q), (t0, typeof(t0)(Inf)), ds.p)
6464

6565
solver = _get_solver(diffeq)
66-
return __init(tanprob, solver; DEFAULT_DIFFEQ_KWARGS...,
67-
save_everystep = false, diffeq...)
66+
return __init(tanprob, solver; DEFAULT_DIFFEQ_KWARGS..., internalnorm = _tannorm,
67+
save_everystep = false, diffeq...)
68+
end
69+
70+
function _tannorm(u::AbstractMatrix, t)
71+
s = size(u)[1]
72+
x = zero(eltype(u))
73+
for i in 1:s
74+
@inbounds x += u[i, 1]^2
75+
end
76+
return sqrt(x/length(x))
6877
end
78+
_tannorm(u::Real, t) = abs(u)
6979

7080
# Auto-diffed in-place version
7181
function tangent_integrator(ds::CDS{true, S, D, F, P, JAC, JM, true},
@@ -86,7 +96,7 @@ function tangent_integrator(ds::CDS{true, S, D, F, P, JAC, JM, true},
8696

8797
solver = _get_solver(diffeq)
8898
return __init(tanprob, solver; DEFAULT_DIFFEQ_KWARGS..., save_everystep = false,
89-
diffeq...)
99+
internalnorm = _tannorm, diffeq...)
90100
end
91101

92102
############################### Parallel ############################################
@@ -117,10 +127,18 @@ function parallel_integrator(ds::CDS, states; diffeq...)
117127
# if typeof(solver) ∈ STIFFSOLVERS
118128
# error("Stiff solvers can't support a parallel integrator.")
119129
# end
120-
return __init(pprob, solver; DEFAULT_DIFFEQ_KWARGS..., save_everystep = false,
121-
diffeq...)
130+
if !(typeof(ds) <: CDS{true})
131+
return __init(pprob, solver; DEFAULT_DIFFEQ_KWARGS..., save_everystep = false,
132+
internalnorm = _parallelnorm, diffeq...)
133+
else
134+
return __init(pprob, solver; DEFAULT_DIFFEQ_KWARGS..., save_everystep = false,
135+
internalnorm = _tannorm, diffeq...)
136+
end
122137
end
123138

139+
_parallelnorm(u::AbstractVector, t) = @inbounds DiffEqBase.ODE_DEFAULT_NORM(u[1], t)
140+
_parallelnorm(u::Real, t) = abs(u)
141+
124142
#####################################################################################
125143
# Trajectory #
126144
#####################################################################################

test/dynsys_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ for i in 1:8
6666

6767
# Currently the in-place version does not work from DiffEq's side:
6868
if i > 2
69-
pinteg = parallel_integrator(ds, [INITCOD[sysindx], INITCOD[sysindx]]; alg = alg)
69+
pinteg = parallel_integrator(ds, [copy(INITCOD[sysindx]), copy(INITCOD[sysindx])]; alg = alg)
7070
puprev = deepcopy(get_state(pinteg))
7171
step!(pinteg)
7272
@test get_state(pinteg, 1) == get_state(pinteg, 2) == get_state(pinteg)

test/norm_tests.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using DynamicalSystemsBase, SimpleDiffEq, DiffEqBase
2+
using Statistics, Test
3+
4+
ds = Systems.lorenz()
5+
ALG = SimpleATsit5()
6+
7+
# %%
8+
9+
i1 = tangent_integrator(ds, 3; alg = ALG)
10+
i2 = tangent_integrator(ds, 3; alg = ALG,
11+
internalnorm = DiffEqBase.ODE_DEFAULT_NORM)
12+
13+
step!(i1)
14+
step!(i2)
15+
dts = zeros(2, 500)
16+
for i in 1:500
17+
step!(i1); step!(i2)
18+
dts[:, i] .= (i1.dt, i2.dt)
19+
end
20+
21+
dt1 = mean(dts[1, :])
22+
dt2 = mean(dts[2, :])
23+
24+
@test dt1 > dt2
25+
26+
# %%
27+
s = [get_state(ds), get_state(ds) .+ rand(3)]
28+
i1 = parallel_integrator(ds, deepcopy(s);
29+
alg = ALG, internalnorm = DiffEqBase.ODE_DEFAULT_NORM)
30+
i2 = parallel_integrator(ds, deepcopy(s);
31+
alg = ALG)
32+
33+
step!(i1)
34+
step!(i2)
35+
dts = zeros(2, 1000)
36+
for i in 1:1000
37+
step!(i1); step!(i2)
38+
dts[:, i] .= (i1.dt, i2.dt)
39+
end
40+
41+
dt1 = mean(dts[1, :])
42+
dt2 = mean(dts[2, :])
43+
44+
@test dt2 > dt1

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ include("dynsys_inference.jl")
99
include("continuous_systems.jl")
1010
include("discrete_systems.jl")
1111
include("integrators_with_callbacks.jl")
12+
include("norm_tests.jl")
1213

1314
ti = time() - ti
1415
println("\nTest took total time of:")

0 commit comments

Comments
 (0)