A library of events for scipy.integrate.solve_ivp.
Project description
scipy_events
A library of events for scipy.integrate.solve_ivp
.
It provides the following events:
ChangeWhen
to apply a change when a given event happens.ChangeAt
to apply a change at some given times.
Usage
import numpy as np
from scipy_events import ChangeAt, solve_ivp
result = solve_ivp(
lambda t, y: -y,
t_span=(0, 16),
y0=[1],
events=[
ChangeAt(
times=[4, 8],
change=lambda t, y, args: (np.full_like(y, 1), args),
)
],
)
import numpy as np
from scipy_events import ChangeWhen, solve_ivp
result = solve_ivp(
lambda t, y: -y,
t_span=(0, 16),
y0=[1],
events=[
ChangeWhen(
condition=lambda t, y: y[0] - 1e-2,
change=lambda t, y, args: (np.full_like(y, 1), args),
)
],
)
Install
Using pixi, install from PyPI with:
pixi add --pypi scipy-events
or install the latest development version from GitHub with:
pixi add --pypi scipy-events@https://github.com/maurosilber/scipy-events.git
Otherwise,
use pip
or your pip
-compatible package manager:
pip install scipy-events # from PyPI
pip install git+https://github.com/maurosilber/scipy-events.git # from GitHub
Development
This project is managed by pixi. You can install it for development using:
git clone https://github.com/maurosilber/scipy-events
cd scipy-events
pixi run pre-commit-install
Pre-commit hooks are used to lint and format the project.
Testing
Run tests using:
pixi run test
Publishing to PyPI
When a tagged commit is pushed to GitHub,
the GitHub Action defined in .github/workflows/ci.yml
builds and publishes the package to PyPI.
Tag a commit and push the tags with:
git tag <my-tag>
git push --tags
Trusted publishing must be enabled once in PyPI Publishing. Fill the following values in the form:
PyPI Project Name: scipy-events
Owner: maurosilber
Repository name: scipy-events
Workflow name: ci.yml
Environment name: pypi