A Python toolkit for integrating nonsmooth dynamical systems
Project description
solve_nivp
A Python library for time integration of nonsmooth ODE/DAE systems—models with abrupt changes such as impacts, switching, or inequality constraints. Such models arise in frictional contact mechanics, piecewise and switching behaviour in circuits, sliding-mode control, and discontinuous rules in finance and energy markets. Classical solvers, which assume smoothness, often require regularisation or very small steps due to the inherent stiffness of these models. solve_nivp builds nonsmooth rules directly into the implicit time-stepping scheme, enabling users to encode constraints and advance the state robustly.
Key features
-
Projection-based constraint encoding. Users express set-valued or nonsmooth relations as projections onto convex sets (Coulomb friction cone, sign / normal cone, second-order cone, algebraic constraints). Custom projections need only implement
project()and an optionaltangent_cone(). -
Nonlinear solvers for nonsmooth problems. A semismooth Newton method with Armijo line search and a variational-inequality (VI) fixed-point iteration, both with standard tolerances, safeguards, and iteration diagnostics.
-
Implicit integrators. Backward Euler, Trapezoidal, θ-method, a composite TR–BE scheme (Bathe-type, second-order), and an embedded BE–TR error estimator.
-
Adaptive step-size control with Richardson extrapolation.
-
Optional RL add-on. Exposes the time integrator as a Gym-style environment for learning adaptive step-size policies (TD3 / TQC via Stable Baselines 3).
The library is organised around three interchangeable components—projection, nonlinear solver, and integrator—so that swapping algorithms during experimentation is straightforward. Linear-algebra routines operate on dense or sparse arrays in the SciPy ecosystem.
Installation
Recommended developer install:
python3 -m venv .venv && source .venv/bin/activate
pip install -U pip
pip install -e .[test]
Optional extras:
# RL experiments
pip install -e .[rl]
Quickstart
import numpy as np
from solve_nivp import solve_ivp_ns
# simple smooth rhs: y' = -y
rhs = lambda t, y: -y
t_span = (0.0, 1.0)
y0 = np.array([1.0])
# identity projection, VI solver via composite integrator
sol = solve_ivp_ns(
fun=rhs,
t_span=t_span,
y0=y0,
method='composite',
projection='identity',
solver='VI',
)
print(sol[0][:5], sol[1][:5]) # t, y samples
See examples/ for notebooks on friction stick–slip, bouncing ball (contact/impact), SOC constraints, and sliding-mode control.
Running tests
pytest -q
Building the documentation
cd docs
make clean html
Open docs/_build/html/index.html.
RL experiments (optional)
The RL_Adaption/ folder contains optional experiments (TD3/TQC) for learned adaptivity on challenging nonsmooth problems. Large artifacts are ignored by Git and not required for core installation or testing.
Citation
See CITATION.cff. If you use this software, please cite the JOSS paper once available.
License
MIT License (see LICENSE).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file solve_nivp-0.1.2.tar.gz.
File metadata
- Download URL: solve_nivp-0.1.2.tar.gz
- Upload date:
- Size: 61.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3ba4774d170d9309ce72eda3fced698cec1a10e2cddcd00e079cc1fb260bb24
|
|
| MD5 |
d4397deae81d870cfedc72de6ce9ac8b
|
|
| BLAKE2b-256 |
34021a00c615903808d9c34dd48dda3db48cc0db94528bd30f4272972dd843ec
|
Provenance
The following attestation bundles were made for solve_nivp-0.1.2.tar.gz:
Publisher:
publish.yml on ERC-INJECT/solve_nivp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
solve_nivp-0.1.2.tar.gz -
Subject digest:
c3ba4774d170d9309ce72eda3fced698cec1a10e2cddcd00e079cc1fb260bb24 - Sigstore transparency entry: 1186392258
- Sigstore integration time:
-
Permalink:
ERC-INJECT/solve_nivp@994632d25b581ad34864f959a348df4d2661ae61 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/ERC-INJECT
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@994632d25b581ad34864f959a348df4d2661ae61 -
Trigger Event:
push
-
Statement type:
File details
Details for the file solve_nivp-0.1.2-py3-none-any.whl.
File metadata
- Download URL: solve_nivp-0.1.2-py3-none-any.whl
- Upload date:
- Size: 67.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
649763c57e9faecf6ea657cb4650e9fbba3f555fe851f4bc04031283657be394
|
|
| MD5 |
d1dba37c2987eb776022890515e0d8d0
|
|
| BLAKE2b-256 |
4231e28d77c4ed92305bcddde48328f28196d18105920d36eba10cbc2d5b4d9e
|
Provenance
The following attestation bundles were made for solve_nivp-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on ERC-INJECT/solve_nivp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
solve_nivp-0.1.2-py3-none-any.whl -
Subject digest:
649763c57e9faecf6ea657cb4650e9fbba3f555fe851f4bc04031283657be394 - Sigstore transparency entry: 1186392260
- Sigstore integration time:
-
Permalink:
ERC-INJECT/solve_nivp@994632d25b581ad34864f959a348df4d2661ae61 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/ERC-INJECT
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@994632d25b581ad34864f959a348df4d2661ae61 -
Trigger Event:
push
-
Statement type: