Skip to content

Commit

Permalink
feat!: improve integrator stability and reliability (#416)
Browse files Browse the repository at this point in the history
This commit improves parameter choices for the integrators overall. In particular, we now make more similar choices to scipy.integrate.solve_ivp, which should lead to fewer surprises.

BREAKING: It was found out that the currently calculated analytical Jacobian leads to problems when implicit integrators are employed. This affects LSODA, Radau and BDF. **The usage of analytical Jacobians is then disabled for this version until we find a fix for the bug**. Even though it is a breaking chance per se, it is mild, as most of the change happened in places the user had previously no access.
  • Loading branch information
schneiderfelipe authored Apr 25, 2023
1 parent f4cfb00 commit 30a911d
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 93 deletions.
83 changes: 75 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Vim files
*~
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand All @@ -23,6 +24,7 @@ parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
Expand All @@ -41,14 +43,17 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
Expand All @@ -58,6 +63,7 @@ coverage.xml
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
Expand All @@ -67,21 +73,52 @@ instance/
.scrapy

# Sphinx documentation
docsrc/_build/
docs/.buildinfo
docs/.doctrees
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version
# IPython
profile_default/
ipython_config.py

# celery beat schedule file
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py
Expand All @@ -107,3 +144,33 @@ venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.9
6 changes: 3 additions & 3 deletions overreact/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__( # noqa: PLR0913
pressure=constants.atm,
bias=0.0,
tunneling="eckart",
method="LSODA",
method="RK23",
max_time=1 * 60 * 60,
rtol=1e-3,
atol=1e-6,
Expand Down Expand Up @@ -873,8 +873,8 @@ def main(arguments=None):
"--method",
help="integrator used in solving the ODE system of the microkinetic "
"simulation",
choices=["BDF", "Radau", "LSODA"],
default="LSODA",
choices=["RK23", "DOP853", "RK45", "LSODA", "BDF", "Radau"],
default="RK23",
)
parser.add_argument(
"--max-time",
Expand Down
2 changes: 1 addition & 1 deletion overreact/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def get_drc( # noqa: PLR0913
compounds,
y0,
t_span=None,
method="LSODA",
method="RK23",
qrrho=True, # noqa: FBT002
scale="l mol-1 s-1",
temperature=298.15,
Expand Down
11 changes: 7 additions & 4 deletions overreact/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,9 +1486,10 @@ def _operation(name, order=2, axis=None):

if name == "i":
return -np.eye(3)
elif name == "e": # noqa: RET505
if name == "e":
return np.eye(3)
elif name in {"c", "σ", "sigma", "s"}: # noqa: RUF001

if name in {"c", "σ", "sigma", "s"}: # noqa: RUF001
# normalize axis
axis = np.asarray(axis)
axis = axis / np.linalg.norm(axis)
Expand All @@ -1497,12 +1498,14 @@ def _operation(name, order=2, axis=None):
rotation = Rotation.from_rotvec(2.0 * np.pi * axis / order).as_matrix()
if name in {"σ", "sigma", "s"}: # noqa: RUF001
reflection = np.eye(3) - 2.0 * np.outer(axis, axis)

if name == "c":
return rotation
elif name in {"σ", "sigma"}: # noqa: RUF001
if name in {"σ", "sigma"}: # noqa: RUF001
return reflection
elif name == "s":
if name == "s":
return rotation @ reflection

raise ValueError(f"unknown operation: '{name}'") # noqa: EM102, TRY003


Expand Down
Loading

0 comments on commit 30a911d

Please sign in to comment.