Skip to content

Commit e32cd4d

Browse files
authored
* Updates due to JuliaDiff/TaylorSeries.jl#361 * Remove comments and small fix * Update CI (use TaylorSeries branch from fork); use `diffeq!` in non-parsed jetcoeffs! methods * Update CI * Use diffeq! in preamble * Retain only `local` declarations in preamble * Trigger CI * Update CI * Update Project.toml * Update CI * Rename diffeq! -> ode! * Update ci.yml * Trigger CI * Update README.md * Rename ode! -> solcoeff! * Bump patch version
1 parent 7b4082a commit e32cd4d

File tree

7 files changed

+85
-37
lines changed

7 files changed

+85
-37
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
- 'LICENSE.md'
66
- 'README.md'
77
pull_request:
8+
branches:
9+
- main
10+
tags: '*'
11+
812
jobs:
913
pre_job:
1014
runs-on: ubuntu-latest
@@ -54,6 +58,8 @@ jobs:
5458
${{ runner.os }}-test-${{ env.cache-name }}-
5559
${{ runner.os }}-test-
5660
${{ runner.os }}-
61+
### Uncomment line below to test using a dependency branch
62+
# - run: julia --project=. -e 'import Pkg; Pkg.add(url="https://github.com/PerezHz/TaylorSeries.jl", rev="jp/evaluate-tn"); Pkg.instantiate()'
5763
- uses: julia-actions/julia-buildpkg@v1
5864
- uses: julia-actions/julia-runtest@v1
5965
- uses: julia-actions/julia-processcoverage@v1

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TaylorIntegration"
22
uuid = "92b13dbe-c966-51a2-8445-caca9f8a7d42"
33
repo = "https://github.com/PerezHz/TaylorIntegration.jl.git"
4-
version = "0.15.2"
4+
version = "0.15.3"
55

66
[deps]
77
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
@@ -38,7 +38,7 @@ RecursiveArrayTools = "2, 3"
3838
Reexport = "1"
3939
Requires = "1"
4040
StaticArrays = "0.12.5, 1"
41-
TaylorSeries = "0.17"
41+
TaylorSeries = "0.18"
4242
Test = "<0.0.1, 1"
4343
julia = "1.6"
4444

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ Comments, suggestions, contributions and improvements are welcome and appreciate
4444

4545
## Acknowledgments
4646

47-
We acknowledge financial support from DGAPA-PAPIIT grants IG-100616 and IG-100819.
47+
We acknowledge financial support from DGAPA-PAPIIT grants IG-100616, IG-100819 and IG-101122.

src/TaylorIntegration.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,27 @@ function __init__()
2828
end
2929
end
3030

31+
@inline function solcoeff!(a::Taylor1{T}, b::Taylor1{T}, k::Int) where {T<:TaylorSeries.NumberNotSeries}
32+
a[k] = b[k-1]/k
33+
return nothing
34+
end
35+
36+
@inline function solcoeff!(res::Taylor1{Taylor1{T}}, a::Taylor1{Taylor1{T}},
37+
k::Int) where {T<:TaylorSeries.NumberNotSeries}
38+
for l in eachindex(a[k-1])
39+
res[k][l] = a[k-1][l]/k
40+
end
41+
return nothing
42+
end
43+
44+
@inline function solcoeff!(res::Taylor1{TaylorN{T}}, a::Taylor1{TaylorN{T}},
45+
k::Int) where {T<:TaylorSeries.NumberNotSeries}
46+
for l in eachindex(a[k-1])
47+
for m in eachindex(a[k-1][l])
48+
res[k][l][m] = a[k-1][l][m]/k
49+
end
50+
end
51+
return nothing
52+
end
53+
3154
end #module

src/integrator.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ function jetcoeffs!(eqsdiff::Function, t::Taylor1{T}, x::Taylor1{U}, params) whe
2727
ordnext = ord+1
2828

2929
# # Set `taux`, `xaux`, auxiliary Taylor1 variables to order `ord`
30-
# @inbounds taux = Taylor1( t.coeffs[1:ordnext] )
3130
@inbounds xaux = Taylor1( x.coeffs[1:ordnext] )
3231

3332
# Equations of motion
3433
dx = eqsdiff(xaux, params, t)
3534

3635
# Recursion relation
37-
@inbounds x[ordnext] = dx[ord]/ordnext
36+
@inbounds solcoeff!(x, dx, ordnext)
3837
end
3938
nothing
4039
end
@@ -67,8 +66,6 @@ function jetcoeffs!(eqsdiff!::Function, t::Taylor1{T},
6766
for ord in 0:order-1
6867
ordnext = ord+1
6968

70-
# # Set `taux`, auxiliary Taylor1 variable to order `ord`
71-
# @inbounds taux = Taylor1( t.coeffs[1:ordnext] )
7269
# Set `xaux`, auxiliary vector of Taylor1 to order `ord`
7370
for j in eachindex(x)
7471
@inbounds xaux[j] = Taylor1( x[j].coeffs[1:ordnext] )
@@ -79,7 +76,7 @@ function jetcoeffs!(eqsdiff!::Function, t::Taylor1{T},
7976

8077
# Recursion relations
8178
for j in eachindex(x)
82-
@inbounds x[j].coeffs[ordnext+1] = dx[j].coeffs[ordnext]/ordnext
79+
@inbounds solcoeff!(x[j], dx[j], ordnext)
8380
end
8481
end
8582
nothing

src/parse_eqs.jl

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ mutable struct BookKeeping
3535
v_array4 :: Vector{Symbol}
3636
v_preamb :: Vector{Union{Symbol,Expr}}
3737
retvar :: Symbol
38+
numaux :: Int
3839

3940
function BookKeeping()
4041
return new(Dict{Symbol, Expr}(), Dict{Union{Symbol,Expr}, Number}(),
4142
Dict{Symbol, Expr}(), Symbol[], Symbol[], Symbol[], Symbol[], Symbol[], Symbol[],
42-
Union{Symbol,Expr}[], :nothing)
43+
Union{Symbol,Expr}[], :nothing, 0)
4344
end
4445
end
4546

@@ -123,7 +124,7 @@ const _HEAD_ALLOC_TAYLOR1_VECTOR = sanitize(:(
123124
# Constants for the initial declaration and initialization of arrays
124125
const _DECL_ARRAY = sanitize( Expr(:block,
125126
:(__var1 = Array{Taylor1{_S}}(undef, __var2)),
126-
:( for i in CartesianIndices(__var1) __var1[i] = Taylor1( zero(constant_term(__x[1])), order ) end ))
127+
:( for i in eachindex(__var1) __var1[i] = Taylor1( zero(constant_term(__x[1])), order ) end ))
127128
);
128129

129130

@@ -147,25 +148,25 @@ function _make_parsed_jetcoeffs(ex::Expr)
147148
new_jetcoeffs, new_allocjetcoeffs = _newhead(fn, fnargs)
148149

149150
# Transform the graph representation of the body of the functions:
150-
# defspreamble: inicializations used for the zeroth order (preamble)
151+
# defspreamble: initializations used for the zeroth order (preamble)
151152
# defsprealloc: definitions (declarations) of auxiliary Taylor1's
152153
# fnbody: transformed function body, using mutating functions from TaylorSeries;
153154
# used later within the recursion loop
154155
# bkkeep: book-keeping structure having info of the variables
155156
defspreamble, defsprealloc, fnbody, bkkeep = _preamble_body(fnbody, fnargs)
156157

157158
# Create body of recursion loop; temporary assignements may be needed.
158-
# rec_preamb: recursion loop for the preamble (first order correction)
159-
# rec_fnbody: recursion loop for the body-function (recursion loop for higher orders)
160-
rec_preamb, rec_fnbody = _recursionloop(fnargs, bkkeep)
159+
# rec_fnbody: recursion loop for the body-function (recursion loop for all orders)
160+
rec_fnbody = _recursionloop(fnargs, bkkeep)
161161

162162
# Expr for the for-loop block for the recursion (of the `x` variable)
163-
forloopblock = Expr(:for, :(ord = 1:order-1), Expr(:block, :(ordnext = ord + 1)) )
164-
# Add rec_fnbody to forloopblock
163+
forloopblock = Expr(:for, :(ord = 0:order-1), Expr(:block, :(ordnext = ord + 1)) )
164+
165+
# Add rec_fnbody to `forloopblock`
165166
push!(forloopblock.args[2].args, fnbody.args[1].args..., rec_fnbody)
166167

167168
# Add preamble and recursion body to `new_jetcoeffs`
168-
push!(new_jetcoeffs.args[2].args, defspreamble..., rec_preamb)
169+
push!(new_jetcoeffs.args[2].args, defspreamble...)
169170

170171
# Push preamble and forloopblock to `new_jetcoeffs` and return line
171172
push!(new_jetcoeffs.args[2].args, forloopblock, Meta.parse("return nothing"))
@@ -337,11 +338,11 @@ of the original diferential equations function.
337338
338339
"""
339340
function _preamble_body(fnbody, fnargs)
340-
# Inicialize BookKeeping struct
341+
# Initialize BookKeeping struct
341342
bkkeep = BookKeeping()
342343

343344
# Rename vars to have the body in non-indexed form; bkkeep has different entries
344-
# for bookkeeping variables/symbolds, including indexed ones
345+
# for bookkeeping variables/symbols, including indexed ones
345346
fnbody, bkkeep.d_indx = _rename_indexedvars(fnbody)
346347

347348
# Create `newfnbody` which corresponds to `fnbody`, cleaned (without irrelevant comments)
@@ -362,15 +363,22 @@ function _preamble_body(fnbody, fnargs)
362363
preamble = subs(preamble, bkkeep.d_assign)
363364
prealloc = subs(prealloc, bkkeep.d_assign)
364365

365-
# Include the assignement of indexed auxiliary variables
366+
# Include the assignment of indexed auxiliary variables
366367
defsprealloc = _defs_allocs!(prealloc, fnargs, bkkeep, false)
367368
preamble = subs(preamble, bkkeep.d_indx)
368-
defspreamble = Expr[preamble.args...]
369+
370+
# Retain only `local` declarations from `preamble` in `new_preamble`
371+
new_preamble = Expr(:block,)
372+
for (i, arg) in enumerate(preamble.args)
373+
(arg.head == :local) && push!(new_preamble.args, arg)
374+
end
375+
defspreamble = Expr[new_preamble.args...]
376+
369377
# Bring back substitutions
370378
newfnbody = subs(newfnbody, bkkeep.d_indx)
371379

372380
# Define retvar; for scalar eqs is the last entry included in v_newvars
373-
bkkeep.retvar = length(fnargs) == 3 ? subs(bkkeep.v_newvars[end], bkkeep.d_indx) : fnargs[1]
381+
bkkeep.retvar = length(fnargs) == 3 ? subs(bkkeep.v_newvars[end-bkkeep.numaux], bkkeep.d_indx) : fnargs[1]
374382

375383
return defspreamble, defsprealloc, newfnbody, bkkeep
376384
end
@@ -834,7 +842,7 @@ function _replacecalls!(bkkeep::BookKeeping, fnold::Expr, newvar::Symbol)
834842
end
835843

836844
elseif ll == 3
837-
# Binary call; no auxiliary expressions needed
845+
# Binary call
838846
newarg2 = fnold.args[3]
839847

840848
# Replacements
@@ -859,6 +867,28 @@ function _replacecalls!(bkkeep::BookKeeping, fnold::Expr, newvar::Symbol)
859867
# Dict(:_res => newvar, :_arg1 => :(constant_term($(newarg1))),
860868
# :_arg2 => :(constant_term($(newarg2))), :_k => :ord))
861869

870+
# Auxiliary expression
871+
if aux_fnexpr.head != :nothing
872+
newaux = genname()
873+
874+
aux_alloc = :( _res = Taylor1($(aux_fnexpr.args[2]), order) )
875+
aux_alloc = subs(aux_alloc,
876+
Dict(:_res => newaux, :_arg1 => :(constant_term($(newarg1))), :_aux => newaux))
877+
878+
aux_fnexpr = Expr(:block,
879+
:(TaylorSeries.zero!(_res)),
880+
:(_res.coeffs[1] = $(aux_fnexpr.args[2])) )
881+
aux_fnexpr = subs(aux_fnexpr,
882+
Dict(:_res => newaux, :_arg1 => :(constant_term($(newarg1))), :_aux => newaux))
883+
884+
fnexpr = subs(fnexpr, Dict(:_aux => newaux))
885+
if newvar bkkeep.v_arraydecl
886+
push!(bkkeep.v_arraydecl, newaux)
887+
else
888+
bkkeep.numaux += 1
889+
push!(bkkeep.v_newvars, newaux)
890+
end
891+
end
862892
else
863893
# Recognized call, but not a unary or binary call; copy expression
864894
fnexpr = :($newvar = $fnold)
@@ -1037,27 +1067,21 @@ function _recursionloop(fnargs, bkkeep::BookKeeping)
10371067
ll = length(fnargs)
10381068

10391069
if ll == 3
1040-
rec_preamb = sanitize( :( $(fnargs[1]).coeffs[2] = $(bkkeep.retvar).coeffs[1] ) )
1041-
rec_fnbody = sanitize( :( $(fnargs[1]).coeffs[ordnext+1] = $(bkkeep.retvar).coeffs[ordnext]/ordnext ) )
1070+
rec_fnbody = sanitize( :( TaylorIntegration.solcoeff!($(fnargs[1]), $(bkkeep.retvar), ordnext) ) )
10421071

10431072
elseif ll == 4
10441073
bkkeep.retvar = fnargs[1]
1045-
rec_preamb = sanitize(:(
1046-
for __idx in eachindex($(fnargs[2]))
1047-
$(fnargs[2])[__idx].coeffs[2] = $(bkkeep.retvar)[__idx].coeffs[1]
1048-
end))
10491074
rec_fnbody = sanitize(:(
10501075
for __idx in eachindex($(fnargs[2]))
1051-
$(fnargs[2])[__idx].coeffs[ordnext+1] =
1052-
$(bkkeep.retvar)[__idx].coeffs[ordnext]/ordnext
1076+
TaylorIntegration.solcoeff!($(fnargs[2])[__idx], $(bkkeep.retvar)[__idx], ordnext)
10531077
end))
10541078

10551079
else
10561080
throw(ArgumentError(
10571081
"Wrong number of arguments in the definition of the function $fn"))
10581082
end
10591083

1060-
return rec_preamb, rec_fnbody
1084+
return rec_fnbody
10611085
end
10621086

10631087

test/taylorize.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ import Logging: Warn
221221
end
222222

223223

224-
# Pendulum integrtf = 100.0
224+
# Pendulum integration
225225
@testset "Integration of the pendulum and DiffEqs interface" begin
226226
@taylorize function pendulum!(dx::Array{T,1}, x::Array{T,1}, p, t) where {T}
227227
dx[1] = x[2]
@@ -1297,10 +1297,8 @@ import Logging: Warn
12971297

12981298
# Include not recognized functions as they appear
12991299
@test newex1.args[2].args[2] == :(aa = __ralloc.v0[1])
1300-
@test newex1.args[2].args[3] == :(aa = my_simple_function(q, p, t))
13011300
@test newex2.args[2].args[2] == :(aa = my_simple_function(q, p, t))
1302-
@test newex1.args[2].args[6].args[2].args[2] ==
1303-
:(aa = my_simple_function(q, p, t))
1301+
@test newex1.args[2].args[3].args[2].args[2] == :(aa = my_simple_function(q, p, t))
13041302

13051303
# Return line
13061304
@test newex1.args[2].args[end] == :(return nothing)
@@ -1331,7 +1329,7 @@ import Logging: Warn
13311329
end
13321330
end)
13331331

1334-
@test newex1.args[2].args[6].args[2].args[3] == Base.remove_linenums!(ex)
1332+
@test newex1.args[2].args[3].args[2].args[3] == Base.remove_linenums!(ex)
13351333

13361334
# Throws no error
13371335
ex = :(

0 commit comments

Comments
 (0)