Skip to content
This repository was archived by the owner on Jun 14, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ddf6719
A start on the road to adaptive BDF/NDF in Leap
cmikida2 May 5, 2021
abb63d4
Sigh
cmikida2 May 5, 2021
51f0910
Adds two-reactor test case
cmikida2 May 7, 2021
25892ff
Fix some flake8 stuff in testing
cmikida2 May 7, 2021
0c0167e
Add fixed-order BDF ability with quasi-bootstrapping, add fixed
cmikida2 May 7, 2021
47abb0d
Add NDF runs to the BDF tests, placate flake8
cmikida2 May 7, 2021
ecffad5
Quell testing errors until Cantera, Pyrometheus, and Jax are added to
cmikida2 May 7, 2021
3a3252e
Remove needless perturbation from reactor case
cmikida2 May 10, 2021
3c4463e
Remove unused variables from BDF support function
cmikida2 May 10, 2021
ca97ffd
Remove unused standard norm from adaptive order mixin
cmikida2 May 10, 2021
87f8daf
Simplify testing to include existing convergence utility
cmikida2 May 10, 2021
71b0f18
Propagate testing utility improvement to test_imex
cmikida2 May 10, 2021
977d836
Continue folding common tests into utilities
cmikida2 May 10, 2021
6606465
Remove outdated commented section in tests
cmikida2 May 12, 2021
b0543b1
Fix error in the case of order change
cmikida2 May 12, 2021
4c5c73a
Merge branch 'main' into adaptive-bdf
cmikida2 May 12, 2021
d026228
Merge branch 'main' into adaptive-bdf
inducer May 12, 2021
aa0c0d4
Merge branch 'adaptive-bdf' of https://github.com/cmikida2/leap into …
cmikida2 May 12, 2021
0212350
Fight the bugbear
cmikida2 May 12, 2021
fef0c4c
Merge branch 'main' into adaptive-bdf
inducer May 12, 2021
01f6f8a
Install jax and cantera for CI
inducer May 12, 2021
08017c2
Install pyrometheus for CI
inducer May 12, 2021
a38620c
Drop pyrometheus from req.txt
inducer May 12, 2021
7e0d1b9
Add pyrometheus to requirements.txt only for Conda CI
inducer May 12, 2021
edb330a
Remove cumulative product and reshape builtins
cmikida2 May 12, 2021
a274f64
Point pyro for Conda CI to jax branch for now
inducer May 13, 2021
5d05a63
Adds tmate to debug CI
cmikida2 May 14, 2021
bec75b3
Add tmate on the actually failing workflow (d'oh)
cmikida2 May 14, 2021
5d2443e
Reverts apparently erroneous tmate attempt
cmikida2 May 18, 2021
cf95914
Another attempt
cmikida2 May 18, 2021
2735638
Do not use parallel execution on conda test
inducer May 19, 2021
483c53c
Inject tmate into conda pytest
inducer May 20, 2021
d3fc2cf
Add dummy Fortran generation test
cmikida2 May 26, 2021
21cff0b
Tracks Pyrometheus-Jax changes
cmikida2 Jun 1, 2021
e64d8b5
Removes UserTypeArray multiply builtin
cmikida2 Jun 1, 2021
90307ff
Removes WRMS builtin and creates WRMS norm from 2-norm
cmikida2 Jun 1, 2021
c8a447c
Merge branch 'main' into adaptive-bdf
cmikida2 Jun 1, 2021
1008f39
Jiggle the CI to do another tmate run
cmikida2 Jun 1, 2021
8f63372
Fix issue with tmate CI
cmikida2 Jun 1, 2021
d24b86f
Continue tmate CI tinkering
cmikida2 Jun 2, 2021
65bc4b5
Incorporate new elementwise absolute value builtin
cmikida2 Jun 10, 2021
61c8377
Differentiate a few variable names, avoid need for usertype arrays to be
cmikida2 Jun 11, 2021
ebfe487
Minor changes to reactor test case
cmikida2 Aug 31, 2021
0637fc1
Merge branch 'main' into adaptive-bdf
cmikida2 Aug 31, 2021
a96067d
Remove tmate
cmikida2 Aug 31, 2021
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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ jobs:
- name: "Main Script"
run: |
CONDA_ENVIRONMENT=.test-conda-env-py3.yml
#echo "git+https://github.com/ecisneros8/pyrometheus.git#egg=pyrometheus" >> requirements.txt
echo "git+https://github.com/cmikida2/pyrometheus.git@jax#egg=pyrometheus" >> requirements.txt

curl -L -O -k https://tiker.net/ci-support-v0
. ./ci-support-v0
build_py_project_in_conda_env
Expand Down Expand Up @@ -109,6 +112,9 @@ jobs:
- name: "Main Script"
run: |
CONDA_ENVIRONMENT=.test-conda-env-py3.yml
#echo "git+https://github.com/ecisneros8/pyrometheus.git#egg=pyrometheus" >> requirements.txt
echo "git+https://github.com/cmikida2/pyrometheus.git@jax#egg=pyrometheus" >> requirements.txt

curl -L -O -k https://tiker.net/ci-support-v0
. ./ci-support-v0
build_py_project_in_conda_env
Expand Down
3 changes: 3 additions & 0 deletions .test-conda-env-py3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ dependencies:
- git
- numpy
- scipy
- matplotlib
- jax
- cantera
- matplotlib-base

- pip
130 changes: 130 additions & 0 deletions leap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,136 @@ def norm(expr):
# }}}


# {{{ adaptivity w/order changing

class AdaptiveOrderMethodBuilderMixin(MethodBuilder):
"""
This class expected the following members to be defined: state, t, dt.
"""

def __init__(self, atol=0, rtol=0, max_dt_growth=None,
min_dt_shrinkage=None, error_const=None):
self.adaptive = bool(atol or rtol)
self.atol = atol
self.rtol = rtol

if max_dt_growth is None:
max_dt_growth = 5

if min_dt_shrinkage is None:
min_dt_shrinkage = 0.1

self.max_dt_growth = max_dt_growth
self.min_dt_shrinkage = min_dt_shrinkage

self.error_const = error_const

def finish_nonadaptive(self, cb, high_order_estimate, low_order_estimate):
raise NotImplementedError()

def rotate_history(self, cb, high_order_estimate, low_order_estimate):
raise NotImplementedError()

def rescale_interval(self, cb):
raise NotImplementedError()

def finish_adaptive(self, cb, high_order_estimate, low_order_estimate,
hist, order, factor, equal_steps):
from pymbolic import var
from pymbolic.primitives import Comparison, LogicalOr, Max, Min
from dagrt.expression import IfThenElse

rel_error_raw = var("rel_error_raw")
rel_error = var("rel_error")
rel_error_p1 = var("rel_error_p1")
rel_error_m1 = var("rel_error_m1")
factor_p1 = var("factor_p1")
factor_m1 = var("factor_m1")

def norm(expr):
return var("<builtin>norm_2")(expr)

def weighted_norm(x, y):
# Weighted RMS norm.
# FIXME: need to support array of relative tolerances?
denom = self.rtol * var("<builtin>elementwise_abs")(y) + self.atol
length = var("<builtin>len")(y)
return norm(x/denom) / length ** 0.5

cb(rel_error_raw, weighted_norm(
self.error_const[order]*(high_order_estimate - low_order_estimate),
high_order_estimate))

cb(rel_error, IfThenElse(Comparison(rel_error_raw, "==", 0),
1.0e-14, rel_error_raw))

with cb.if_(LogicalOr((Comparison(rel_error, ">", 1),
var("<builtin>isnan")(rel_error)))):

with cb.if_(var("<builtin>isnan")(rel_error)):
cb(self.dt, self.min_dt_shrinkage * self.dt)
with cb.else_():
# Default Scipy BDF safety factor.
cb(self.dt, Max((0.81 * self.dt
* rel_error ** (-1.0 / (order + 1)),
self.min_dt_shrinkage * self.dt)))
cb(factor, Max((0.81
* rel_error ** (-1.0 / (order + 1)),
self.min_dt_shrinkage)))
self.rescale_interval(cb)
cb(self.dt_monitor, self.dt)
cb(equal_steps, 0)
with cb.if_(self.t + self.dt, "==", self.t):
cb.raise_(TimeStepUnderflow)
with cb.else_():
cb.fail_step()

with cb.else_():
# Rotate state history.
self.rotate_history(cb, high_order_estimate, low_order_estimate)
cb(equal_steps, equal_steps+1)
cb(factor, 1)
cb(factor_p1, 0)
cb(factor_m1, 0)
with cb.if_(Comparison(equal_steps, ">=", order+1)):

# Now we need to use the history to determine if we should
# update order.
with cb.if_(Comparison(order, ">", 1)):
cb(rel_error_m1, weighted_norm(
self.error_const[order-1]*hist[order],
high_order_estimate))
cb(factor_m1, 0.81
* rel_error_m1 ** (-1.0 / (order)))
with cb.else_():
cb(factor_m1, 0)
with cb.if_(Comparison(order, "<", 5)):
cb(rel_error_p1, weighted_norm(
self.error_const[order+1]*hist[order+2],
high_order_estimate))
cb(factor_p1, 0.81
* rel_error_p1 ** (-1.0 / (order + 2)))
with cb.else_():
cb(rel_error_p1, 0)
# Based on these new error norms, do we modify the order?
cb(factor, 0.81 * rel_error ** (-1.0 / (order + 1)))
cb(factor, Max((factor, factor_p1, factor_m1)))
with cb.if_(Comparison(factor, "==", factor_p1)):
cb(order, order + 1)
with cb.if_(Comparison(factor, "==", factor_m1)):
cb(order, order - 1)
cb(factor, Min((self.max_dt_growth, factor)))
self.rescale_interval(cb)
cb(equal_steps, 0)
# This updates <t>: <dt> should not be set before this is called.
self.finish_nonadaptive(cb, high_order_estimate,
low_order_estimate)
cb(self.dt, self.dt * factor)
cb(self.dt_monitor, self.dt)

# }}}


# {{{ diagnostics

class TimeStepUnderflow(RuntimeError):
Expand Down
Loading