Skip to main content

GPU-parallel, fully differentiable implicit DAE solvers in PyTorch.

Project description

TorchDAE

Numerical Differential-Algebraic Equation solvers in PyTorch. Autodifferentiable and GPU-capable.

torchdae_up

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 vmap and 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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchdae-0.1.1.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchdae-0.1.1-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file torchdae-0.1.1.tar.gz.

File metadata

  • Download URL: torchdae-0.1.1.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for torchdae-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f2c6907d87ddaf9994d7e83ca36c7dcbef7ff28e3777c62304774d4866d6086b
MD5 c979de530ff55c165b5fef3bd8a24141
BLAKE2b-256 a6d520b88a5995539a2c297fc8af020d00d65a441a0d656df570b95e9a4865cd

See more details on using hashes here.

File details

Details for the file torchdae-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: torchdae-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for torchdae-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cef15a53d37e83bafb6b4692caadd00882f4fcf07ef22d98f7d626a141635568
MD5 e7255799364655e93644c50b0d289d4a
BLAKE2b-256 6cc7ed2d02a1c88294df1c6d6d67546bf4c720783cdc2733c7fb57df1c0e8eb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page