Skip to content

Commit 80a35d2

Browse files
github-actions[bot]CompatHelper JuliaDatseris
authored
CompatHelper: bump compat for StateSpaceSets to 2, (keep existing compat) (#217)
* CompatHelper: bump compat for StateSpaceSets to 2, (keep existing compat) * allow `container` keyword * changelog * fix incorrect usage of size * use exclusively only v2 of SSEts * use dimension for poincaresos * simplify field t of PoincareMap * and fix incorrect AA type annotation * final typo fix * revert type annotation * correct reinit * changelog --------- Co-authored-by: CompatHelper Julia <[email protected]> Co-authored-by: Datseris <[email protected]>
1 parent bb56a96 commit 80a35d2

File tree

6 files changed

+36
-23
lines changed

6 files changed

+36
-23
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
# v3.10.0
2+
3+
- OrdinaryDiffEq.jl dependency reduced to OrdinaryDiffEqTsit5.jl.
4+
- Updated to StateSpaceSets.jl v2: now the keyword `container` can be given to
5+
the `trajectory` function.
6+
17
# v3.9.0
28

3-
A new function `jacobian` that generates Jacobian rule for any `ds<:CoreDynamicalSystem` via
9+
A new function `jacobian` that generates Jacobian rule for any `ds<:CoreDynamicalSystem` via
410
automatic differentiation with `ForwardDiff.jl`.
511

612
# v3.8.0

Project.toml

Lines changed: 2 additions & 2 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 = "3.10.0"
4+
version = "3.10.1"
55

66
[deps]
77
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
@@ -21,7 +21,7 @@ OrdinaryDiffEqTsit5 = "1.1"
2121
Reexport = "1"
2222
Roots = "1, 2"
2323
SciMLBase = "1.19.5, 2"
24-
StateSpaceSets = "1"
24+
StateSpaceSets = "2"
2525
Statistics = "1"
2626
SymbolicIndexingInterface = "0.3.4"
2727
julia = "1.9"

src/core/trajectory.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ export trajectory
44
trajectory(ds::DynamicalSystem, T [, u0]; kwargs...) → X, t
55
66
Evolve `ds` for a total time of `T` and return its trajectory `X`, sampled at equal time
7-
intervals, and corresponding time vector.
7+
intervals, and corresponding time vector. `X` is a `StateSpaceSet`.
88
Optionally provide a starting state `u0` which is `current_state(ds)` by default.
99
1010
The returned time vector is `t = (t0+Ttr):Δt:(t0+Ttr+T)`.
1111
12-
If time evolution diverged before `T`, the remaining of the trajectory is set
13-
to the last valid point.
12+
If time evolution diverged, or in general failed, before `T`,
13+
the remaining of the trajectory is set to the last valid point.
1414
1515
`trajectory` is a very simple function provided for convenience.
1616
For continuous time systems, it doesn't play well with callbacks,
1717
use `DifferentialEquations.solve` if you want a trajectory/timeseries
18-
that works with callbacks.
18+
that works with callbacks, or in general you want more flexibility in the generated
19+
trajectory (but remember to convert the output of `solve` to a `StateSpaceSet`).
1920
2021
## Keyword arguments
2122
@@ -24,6 +25,8 @@ that works with callbacks.
2425
have access to unicode, the keyword `Dt` can be used instead.
2526
* `Ttr = 0`: Transient time to evolve the initial state before starting saving states.
2627
* `t0 = initial_time(ds)`: Starting time.
28+
* `container = SVector`: Type of vector that will represent the state space points
29+
that will be included in the `StateSpaceSet` output. See `StateSpaceSet` for valid options.
2730
* `save_idxs::AbstractVector`: Which variables to output in `X`. It can be
2831
any type of index that can be given to [`observe_state`](@ref).
2932
Defaults to `1:dimension(ds)` (all dynamic variables).
@@ -43,7 +46,8 @@ function trajectory(ds::DynamicalSystem, T, u0 = initial_state(ds);
4346
end
4447

4548
function trajectory_discrete(ds, T;
46-
Dt::Integer = 1, Δt::Integer = Dt, Ttr::Integer = 0, accessor = nothing
49+
Dt::Integer = 1, Δt::Integer = Dt, Ttr::Integer = 0, accessor = nothing,
50+
kw... # container keyword
4751
)
4852
ET = eltype(current_state(ds))
4953
t0 = current_time(ds)
@@ -65,10 +69,10 @@ function trajectory_discrete(ds, T;
6569
break
6670
end
6771
end
68-
return StateSpaceSet(data), tvec
72+
return StateSpaceSet(data; kw...), tvec
6973
end
7074

71-
function trajectory_continuous(ds, T; Dt = 0.1, Δt = Dt, Ttr = 0.0, accessor = nothing)
75+
function trajectory_continuous(ds, T; Dt = 0.1, Δt = Dt, Ttr = 0.0, accessor = nothing, kw...)
7276
D = dimension(ds)
7377
t0 = current_time(ds)
7478
tvec = (t0+Ttr):Δt:(t0+T+Ttr)
@@ -92,7 +96,7 @@ function trajectory_continuous(ds, T; Dt = 0.1, Δt = Dt, Ttr = 0.0, accessor =
9296
end
9397

9498
end
95-
return StateSpaceSet(sol), tvec
99+
return StateSpaceSet(sol; kw...), tvec
96100
end
97101

98102
# Util functions for `trajectory` to make indexing static vectors

src/derived_systems/poincare/hyperplane.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ are the same as in [`PoincareMap`](@ref).
8484
function poincaresos(A::AbstractStateSpaceSet, plane;
8585
direction = -1, warning = true, save_idxs = 1:dimension(A)
8686
)
87-
check_hyperplane_match(plane, size(A, 2))
87+
check_hyperplane_match(plane, dimension(A))
8888
i = typeof(save_idxs) <: Int ? save_idxs : SVector{length(save_idxs), Int}(save_idxs...)
8989
planecrossing = PlaneCrossing(plane, direction > 0)
9090
data = poincaresos(A, planecrossing, i)

src/derived_systems/poincare/poincaremap.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ A discrete time dynamical system that produces iterations over the Poincaré map
1919
of the given continuous time `ds`. This map is defined as the sequence of points on the
2020
Poincaré surface of section, which is defined by the `plane` argument.
2121
22+
Iterating `pmap` also mutates `ds` which is referrenced in `pmap`.
23+
2224
See also [`StroboscopicMap`](@ref), [`poincaresos`](@ref).
2325
2426
## Keyword arguments
@@ -67,8 +69,8 @@ and root finding from Roots.jl, to create a high accuracy estimate of the sectio
6769
surface of section. [`initial_time`](@ref) is always `0` and [`current_time`](@ref)
6870
is current iteration number.
6971
3. A new function [`current_crossing_time`](@ref) returns the real time corresponding
70-
to the latest crossing of the hyperplane, which is what the [`current_state(ds)`](@ref)
71-
corresponds to as well.
72+
to the latest crossing of the hyperplane. The corresponding state on the hyperplane
73+
is `current_state(pmap)` as expected.
7274
4. For the special case of `plane` being a `Tuple{Int, <:Real}`, a special `reinit!` method
7375
is allowed with input state of length `D-1` instead of `D`, i.e., a reduced state already
7476
on the hyperplane that is then converted into the `D` dimensional state.
@@ -95,7 +97,7 @@ mutable struct PoincareMap{I<:ContinuousTimeDynamicalSystem, F, P, R, V} <: Disc
9597
rootkw::R
9698
state_on_plane::V
9799
tcross::Float64
98-
t::Base.RefValue{Int}
100+
t::Int
99101
# These two fields are for setting the state of the pmap from the plane
100102
# (i.e., given a D-1 dimensional state, create the full D-dimensional state)
101103
dummy::Vector{Float64}
@@ -120,10 +122,10 @@ function PoincareMap(
120122
diffidxs = _indices_on_poincare_plane(plane, D)
121123
pmap = PoincareMap(
122124
ds, plane_distance, planecrossing, Tmax, rootkw,
123-
v, current_time(ds), Ref(0), dummy, diffidxs
125+
v, current_time(ds), 0, dummy, diffidxs
124126
)
125127
step!(pmap)
126-
pmap.t[] = 0 # first step is 0
128+
pmap.t = 0 # first step is 0
127129
return pmap
128130
end
129131

@@ -143,7 +145,7 @@ for f in (:initial_state, :current_parameters, :initial_parameters, :referrenced
143145
@eval $(f)(pmap::PoincareMap, args...) = $(f)(pmap.ds, args...)
144146
end
145147
initial_time(pmap::PoincareMap) = 0
146-
current_time(pmap::PoincareMap) = pmap.t[]
148+
current_time(pmap::PoincareMap) = pmap.t
147149
current_state(pmap::PoincareMap) = pmap.state_on_plane
148150

149151
"""
@@ -160,7 +162,7 @@ function SciMLBase.step!(pmap::PoincareMap)
160162
else
161163
pmap.state_on_plane = u # this is always a brand new vector
162164
pmap.tcross = t
163-
pmap.t[] = pmap.t[] + 1
165+
pmap.t += 1
164166
return pmap
165167
end
166168
end
@@ -169,7 +171,6 @@ SciMLBase.step!(pmap::PoincareMap, n::Int, s = true) = (for _ ∈ 1:n; step!(pma
169171
function SciMLBase.reinit!(pmap::PoincareMap, u0::AbstractArray = initial_state(pmap);
170172
t0 = initial_time(pmap), p = current_parameters(pmap)
171173
)
172-
isnothing(u0) && return pmap
173174
if length(u0) == dimension(pmap)
174175
u = u0
175176
elseif length(u0) == dimension(pmap) - 1
@@ -179,7 +180,7 @@ function SciMLBase.reinit!(pmap::PoincareMap, u0::AbstractArray = initial_state(
179180
end
180181
reinit!(pmap.ds, u; t0, p)
181182
step!(pmap) # always step once to reach the PSOS
182-
pmap.t[] = 0 # first step is 0
183+
pmap.t = 0 # first step is 0
183184
pmap
184185
end
185186

test/test_system_function.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ function test_dynamical_system(ds, u0, p0; idt, iip,
111111

112112
# obtain only first variable
113113
Z, t = trajectory(ds, 10; save_idxs = [1])
114-
@test size(Z) == (11, 1)
114+
@test length(Z) == 11
115+
@test dimension(Z) == 1
115116
@test Z[1][1] == u0[1]
116117
else
117118
reinit!(ds)
@@ -129,7 +130,8 @@ function test_dynamical_system(ds, u0, p0; idt, iip,
129130

130131
# obtain only first variable
131132
Z, t = trajectory(ds, 3; save_idxs = [1], Δt = 1)
132-
@test size(Z) == (4, 1)
133+
@test length(Z) == 4
134+
@test dimension(Z) == 1
133135
@test Z[1][1] == u0[1]
134136
end
135137
end

0 commit comments

Comments
 (0)