TorchDAE
Numerical Differential-Algebraic Equation solvers in PyTorch. Autodifferentiable and GPU-capable.
TorchDAE is a PyTorch-based library providing numerical Differential-Algebraic Equation (DAE) solvers.
Features include:
- Implicit Solvers: Multiple stiff solvers (including BDF1, BDF2, SDIRK TR-BDF2, and 5th-order Radau IIA);
- Automatic Index Reduction: lowering high-index DAEs to Index-1 using Pantelides' algorithm and Mattsson-Söderlind Dummy Derivatives;
- Manifold Stabilization: Coordinate Projection Method (CPM) and Baumgarte feedback to eliminate numerical constraint drift;
- Events & Resets: Vectorized, differentiable event handling with continuous-time Hermite state interpolation and resets;
- Adjoint Methods: Continuous adjoint sensitivity backward-in-time for constant-memory backpropagation;
- Vmap support: Full support for PyTorch
vmapand batched input on GPU and CPU pipelines.
Installation
pip install torchdae
Requires Python 3.8+ and PyTorch 2.0+.
Documentation
Available at https://yousef-rafat.github.io/torchdae/.
Quick Example
A simple example of how to solve an Index-1 DAE with BDF2.
import torch
from torchdae import solve_bdf2
# Define a simple Index-1 DAE: F(t, y, yp) = 0
def physics(t, y, yp):
# supporting batching
y1, y2 = y[..., 0], y[..., 1]
y1p, _ = yp[..., 0], yp[..., 1]
# f1 (differential): y1' + y1 - y2 = 0
f1 = y1p + y1 - y2
# f2 (algebraic): y1 + y2 - sin(t) = 0
t_tensor = torch.as_tensor(t, dtype=y.dtype, device=y.device)
f2 = y1 + y2 - torch.sin(t_tensor)
return torch.stack([f1, f2], dim=-1)
y0 = torch.tensor([[0.5, -0.5]])
sol = solve_bdf2(physics, t_span=(0.0, 1.0), y0=y0, h=0.01)
print("Solved states at t=1.0:", sol.ys[-1, 0].numpy())
Release files for torchdae 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torchdae-0.1.1.tar.gz | 35.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torchdae-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.9 kB
Release files / torchdae-0.1.1.tar.gz
| Download URL | torchdae-0.1.1.tar.gz |
|---|---|
| Size | 35.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2c6907d87ddaf9994d7e83ca36c7dcbef7ff28e3777c62304774d4866d6086b
|
|
BLAKE2b-256 checksum How to use checksums |
a6d520b88a5995539a2c297fc8af020d00d65a441a0d656df570b95e9a4865cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / torchdae-0.1.1-py3-none-any.whl
| Download URL | torchdae-0.1.1-py3-none-any.whl |
|---|---|
| Size | 27.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cef15a53d37e83bafb6b4692caadd00882f4fcf07ef22d98f7d626a141635568
|
|
BLAKE2b-256 checksum How to use checksums |
6cc7ed2d02a1c88294df1c6d6d67546bf4c720783cdc2733c7fb57df1c0e8eb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|