Skip to content

Commit 7ac5b82

Browse files
authored
Enforce Δt::Int in discrete trajectory; fix set_parameter! for generalized ds (#144)
* assert `Δt::Int` in `trajectory`. Welp, this was missed since the dawn of time. No clue how many things it may break. But it certainly has to be done as I now realize it led to silently incorrect behavior. * fix set-parameter not working for projected integrator
1 parent 3fc5d4b commit 7ac5b82

5 files changed

Lines changed: 23 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v2.7.2
2+
- Integer Δt is now enforced in trajectory calculation of discrete systems. Not doing so led to silently incorrect behavior that the user wouldn't expect.
3+
- Fixed `set_parameter!` not working for `projected_integrator`.
4+
15
# v2.7
26
* New function `get_states` that returns an iterator over states contained in a `parallel_integrator`.
37
# v2.6

Project.toml

Lines changed: 1 addition & 1 deletion
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 = "2.7.1"
4+
version = "2.7.2"
55

66
[deps]
77
DelayEmbeddings = "5732040d-69e3-5649-938a-b6b4f237613f"

src/core/api_docstrings.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ adaptive time-stepping. Use `(alg = SimpleTsit5(), dt = your_step_size)` as keyw
151151
for a non-adaptive time stepping solver.
152152
"""
153153
function trajectory(integ, args...; kwargs...)
154-
if isdiscretetime(integ)
155-
return trajectory_discrete(integ, args...; kwargs...)
156-
else
157-
return trajectory_continuous(integ, args...; kwargs...)
158-
end
154+
if isdiscretetime(integ)
155+
return trajectory_discrete(integ, args...; kwargs...)
156+
else
157+
return trajectory_continuous(integ, args...; kwargs...)
158+
end
159159
end
160160

161161

src/core/discrete.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ end
257257

258258
# This version of trajectory is for any discrete integrator: Poincare map,
259259
# stroboscopic map, or standard MinimalDiscreteIntegrator.
260-
function trajectory_discrete(integ, t, u0 = nothing; Δt=1, Ttr=0, a=nothing, diffeq=nothing)
260+
function trajectory_discrete(integ, t, u0 = nothing;
261+
Δt::Int = 1, Ttr = 0, a = nothing, diffeq = nothing
262+
)
261263
!isnothing(u0) && reinit!(integ, u0)
262264
Δt = round(Int, Δt)
263265
T = eltype(get_state(integ))

src/core/dynamicalsystem.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,20 @@ In this case do `p .= values` (which only works for abstract array `p`).
182182
183183
The same function also works for any integrator.
184184
"""
185-
function set_parameter!(ds, index, value)
186-
if ds.p isa Union{AbstractArray, AbstractDict}
187-
setindex!(ds.p, value, index)
185+
set_parameter!(ds::DynamicalSystem, args...) = _set_parameter!(ds.p, args...)
186+
# Generalized system case
187+
set_parameter!(x, args...) = _set_parameter!(x.integ.p, args...)
188+
189+
function _set_parameter!(p, index, value)
190+
if p isa Union{AbstractArray, AbstractDict}
191+
setindex!(p, value, index)
188192
else
189-
setproperty!(ds.p, index, value)
193+
setproperty!(p, index, value)
190194
end
191195
end
192196

193-
set_parameter!(ds, values) = (ds.p .= values)
197+
_set_parameter!(p, values) = (p .= values)
198+
194199

195200

196201
#####################################################################################

0 commit comments

Comments
 (0)