Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

development #106

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bd844d4
added function clear\!
mattsignorelli Mar 29, 2024
c8ba8d2
Remove redundant warnings in show
mattsignorelli Mar 29, 2024
b7fdc00
indexing update, clear, copy
mattsignorelli Apr 1, 2024
0b170e2
slicing and par updated
mattsignorelli Apr 1, 2024
cc14187
lots of dev, reorganization, indexing
mattsignorelli Apr 2, 2024
052f7d1
bug fix
mattsignorelli Apr 2, 2024
75ba441
Methods revamped + documented
mattsignorelli Apr 2, 2024
df5e27e
export compose and translate
mattsignorelli Apr 2, 2024
4fa9c4b
Merge pull request #104 from bmad-sim/index1
mattsignorelli Apr 2, 2024
6756a5d
minor fixes
mattsignorelli Apr 2, 2024
1c11aa5
Merge pull request #105 from bmad-sim/index1
mattsignorelli Apr 2, 2024
b2239dd
Update Project.toml
mattsignorelli Apr 2, 2024
eca82e3
add empty getindex
mattsignorelli Apr 2, 2024
8c65336
fixed nothing getset
mattsignorelli Apr 2, 2024
a4c9d80
added zeros and ones for allocated TPSs
mattsignorelli Apr 3, 2024
e980385
fix getv complex
mattsignorelli Apr 6, 2024
f700c61
bump patch
mattsignorelli Apr 10, 2024
fba8920
loosened type requirements for grad/jacobian/hessian,fixed bug in jac…
mattsignorelli Apr 16, 2024
5e5f235
clean up of basic operators, added in-place add,sub,mul,div
mattsignorelli Apr 18, 2024
9379735
Merge branch 'dev-tpsa-new' into dev-tpsa-newlazy
mattsignorelli Apr 22, 2024
362a520
Update compare_MAD.jl
mattsignorelli Apr 22, 2024
5975751
sneaky compare_MAD bug fixed
mattsignorelli Apr 22, 2024
06dbc97
low-level agrees
mattsignorelli Apr 22, 2024
c61706c
tests passing
mattsignorelli Apr 22, 2024
a6b0ba0
tests passing:
mattsignorelli Apr 22, 2024
6793df9
added vectorized get/set for linear indexing:
mattsignorelli Apr 25, 2024
5f5b93a
rand TPS generator implemented
mattsignorelli Apr 25, 2024
84ee72c
random TPS generator
mattsignorelli Apr 29, 2024
f74bef0
Update Project.toml
mattsignorelli Apr 29, 2024
3520622
new GTPSA
mattsignorelli May 3, 2024
abb034b
Merge branch 'main' into dev-tpsa-newlazy
mattsignorelli May 3, 2024
6c9e55e
update benchmark
mattsignorelli May 3, 2024
8ec55c4
clearord
mattsignorelli May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name = "GTPSA"
uuid = "b27dd330-f138-47c5-815b-40db9dd9b6e8"
authors = ["Matt Signorelli"]
version = "0.4.0"
version = "0.6"


[deps]
GTPSA_jll = "a4739e29-4b97-5c0b-bbcf-46f08034c990"
Expand All @@ -11,7 +12,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

[compat]
GTPSA_jll = "1.2.1"
GTPSA_jll = "1.3"
PrettyTables = "2"
SpecialFunctions = "2.3.1"
julia = "1.9"
Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
[![Build Status](https://github.com/bmad-sim/GTPSA.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/bmad-sim/GTPSA.jl/actions/workflows/CI.yml?query=branch%3Amain)

## Overview

This package provides a full-featured Julia interface to the [Generalised Truncated Power Series Algebra (GTPSA) library](https://mad.web.cern.ch/mad/releases/madng/html/mad_mod_diffalg.html), which computes Taylor expansions, or Truncated Power Series (TPSs) of real and complex multivariable functions to arbitrary orders.

Truncated Power Series Algebra (TPSA) performs forward-mode automatic differentation (AD) similar to the dual-number implementation of `ForwardDiff.jl`. However, instead of nesting derivatives for higher orders, TPSA naturally extends to arbitary orders by directly using the power series expansions. This, paired with a highly optimized monomial indexing function/storage for propagating the partial derivatives, makes `GTPSA.jl` significantly faster for 2nd-order calculations and above (for 1st-order
calculations the performance is similar to `ForwardDiff.jl`).
See the [`benchmark/track.jl`](https://github.com/bmad-sim/GTPSA.jl/blob/main/benchmark/track.jl) example for a speed comparison of `GTPSA.jl` with `ForwardDiff.jl` in calculating the partial derivatives for a system with 58 inputs and 6 outputs. **In this example, GTPSA was nearly x3 faster than ForwardDiff to 2nd order, and x15 faster to 3rd order.**
Truncated Power Series Algebra (TPSA) performs forward-mode automatic differentation (AD) similar to the dual-number implementation of `ForwardDiff.jl`. However, instead of nesting derivatives for higher orders, TPSA naturally extends to arbitary orders by directly using the power series expansions. This, paired with a highly optimized monomial indexing function/storage for propagating the partial derivatives, makes `GTPSA.jl` significantly faster for 2nd-order calculations and above (for 1st-order calculations the performance is similar to `ForwardDiff.jl`).See the [`benchmark/track.jl`](https://github.com/bmad-sim/GTPSA.jl/blob/main/benchmark/track.jl) example for a speed comparison of `GTPSA.jl` with `ForwardDiff.jl` in calculating the partial derivatives for a system with 58 inputs and 6 outputs. **In this example, GTPSA was x3.3 faster than ForwardDiff to 2nd order, and x18.5 faster to 3rd order.**

GTPSA provides several advantages over current Julia AD packages:

1. **Speed**: `GTPSA.jl` is significantly faster than `ForwardDiff.jl` for 2nd-order calculations and above, and has similar performance at 1st-order
2. **Custom Orders in Individual Variables**: Other packages use a single maximum order for all variables. With GTPSA, the
maximum order can be set differently for different variables. For example, computing the Taylor expansion of $f(x_1,x_2)$ to 2nd order in $x_1$ and 6th order in $x_2$ is possible
1. **Speed**: `GTPSA.jl` is significantly faster than `ForwardDiff.jl` for 2nd-order calculations and above, and has very similar performance at 1st-order
2. **Custom Orders in Individual Variables**: Other packages use a single maximum order for all variables. With GTPSA, the maximum order can be set differently for individual variables, as well as for a separate part of the monomial. For example, computing the Taylor expansion of $f(x_1,x_2)$ to 2nd order in $x_1$ and 6th order in $x_2$ is possible
3. **Complex Numbers**: GTPSA natively supports complex numbers and allows for mixing of complex and real truncated power series
4. **Distinction Between State Variables and Parameters**: Distinguishing between dependent variables and parameters in the solution of a differential equation expressed as a power series in the dependent variables/parameters can be advantageous in analysis

Expand All @@ -42,7 +38,7 @@ x = vars()

# Manipulate the TPSs as you would any other mathematical variable in Julia
f = cos(x[1]) + im*sin(x[2])
# This creates a new TPS called f
# f is a new ComplexTPS
```

Note that scalars do not need to be defined as TPSs when writing expressions. Running `print(f)` gives the output
Expand Down
27 changes: 14 additions & 13 deletions benchmark/track.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@ using GTPSA
using ForwardDiff
using BenchmarkTools: @btime, @benchmark

# As of 02/19/2024 (Julia v1.10.1) on Mac M2 Ultra: Comparison with GTPSA for 58 inputs and 6 outputs
# As of 05/03/2024, Julia v1.10.2 on Mac M2 Ultra: Comparison with GTPSA for 58 inputs and 6 outputs
# Numbers calculated using BenchmarkTools.@btime
#
# 3rd Order ---------------------------------------------------------
# Using the @FastGTPSA macro:
# GTPSA: 271.137 ms
# ForwardDiff: 4.004 s
# GTPSA: 227.111 ms
# ForwardDiff: 4.212 s
#
# Without the @FastGTPSA macro (including ForwardDiff as control):
# GTPSA: 415.567 ms
# ForwardDiff: 3.916 s
# GTPSA: 371.465 ms
# ForwardDiff: 4.096 s
#
# 2nd Order ---------------------------------------------------------
# Using the @FastGTPSA macro:
# GTPSA: 8.599 ms
# ForwardDiff: 23.984 ms
# GTPSA: 7.024 ms
# ForwardDiff: 23.417 ms
#
# Without the @FastGTPSA macro (including ForwardDiff as control):
# GTPSA: 17.141 ms
# ForwardDiff: 23.391 ms
# GTPSA: 15.594 ms
# ForwardDiff: 23.318 ms
#
# 1st Order ---------------------------------------------------------
# Using the @FastGTPSA macro:
# GTPSA: 327.458 μs
# ForwardDiff: 189.417 μs
# GTPSA: 280.542 μs
# ForwardDiff: 188.792 μs
#
# Without the @FastGTPSA macro (including ForwardDiff as control):
# GTPSA: 707.916 μs
# ForwardDiff: 161.833 μs
# GTPSA: 697.625 μs
# ForwardDiff: 161.125 μs
#
# Note that @FastGTPSA is transparent to all types except TPS/ComplexTPS, so it can be
# inserted into functions while still maintaining generic code, as shown here
Expand Down
Loading
Loading