Skip to main content

modaldyn

A compact Dynamic Mode Decomposition toolkit with a NumPy CPU core and an optional PyTorch CPU/CUDA backend. It uses snapshot matrices of shape (features, snapshots) and makes device choice explicit.

Initial research release, version 0.1.0. CUDA execution is implemented; a passing CPU suite or skipped CUDA tests do not establish validation on GPU hardware. See limitations and the actual CI/benchmark results for the tested configurations. Documentación en español.

Install

Install the tagged source release:

python -m pip install 'git+https://github.com/giovannyTorres/dmd.git@v0.1.0'

Or from a cloned checkout:

python -m pip install .

Or install a built wheel from the release assets:

python -m pip install modaldyn-0.1.0-py3-none-any.whl

Python 3.10+ and NumPy 1.24+ are required. PyTorch is optional. Install the appropriate PyTorch build for your CPU or NVIDIA CUDA system, then install .[torch]. Installing this extra alone does not configure a CUDA driver. PyPI publication requires the separate release setup; a source release is not proof of a PyPI upload.

Fit, reconstruct and forecast

import numpy as np
from modaldyn import DMD

t = np.arange(160) * 0.1
snapshots = np.vstack((np.cos(1.3 * t), np.sin(1.3 * t)))
model = DMD(rank=2, dt=0.1, backend="numpy").fit(snapshots)

reconstruction = model.reconstruct()  # includes training index zero
future = model.forecast(20)          # starts after the final training snapshot
print(model.eigenvalues_)
print(model.diagnostics())

For PyTorch CPU or CUDA, use the same estimator and array orientation:

import torch
from modaldyn import DMD

x = torch.as_tensor(snapshots, dtype=torch.float64, device="cuda")
model = DMD(rank=2, backend="torch", device="cuda", dt=0.1).fit(x)
future = model.forecast(20)  # torch tensor on the selected device

An unavailable CUDA device raises an error. backend="auto" follows a tensor's backend/device; NumPy input defaults to NumPy unless CUDA is explicitly requested. Complex output is expected for oscillatory modes. Convert to real only when its imaginary residual is negligible for your application.

Select a variant

Estimator Intended use Main assumption or cost
DMD Exact spectral DMD Uniformly sampled snapshots; low-rank linear approximation
TLSqDMD Total-least-squares preprocessing Errors in both snapshot matrices; choose tlsq_rank
FbDMD Forward/backward noise correction Experimental principal-root convention; spectral ambiguity
RandomizedDMD A seeded randomized range finder Explicit integer rank; approximation trades accuracy for work
HankelDMD Delay coordinates for partially observed dynamics More memory; delay count selected on training/validation data
DMDc Measured exogenous controls Sufficiently exciting state/control data; dense state operator
RobustDMD RPCA preprocessing followed by DMD Low-rank signal plus sparse corruption; iterative dense SVDs
StreamingDMD Incremental paired snapshots without history Dense sufficient statistics use O(features²) memory

These are established algorithms, not a claim to cover every published DMD variant. Optimized/bagged DMD, EDMD, multiresolution and sparsity-promoting DMD are outside this release. See API and alignment rules.

What this package adds

GPU DMD already exists in flowTorch, and PyDMD has a substantially broader variant catalogue. This project's value is its combination of a small NumPy-only CPU installation, optional explicit device execution, shared input/rank checks, inspectable diagnostics and a reproducible comparison harness. Diagnostics are not unique to this package. No claim of universal speed or accuracy superiority is made. The source-backed comparison explains the evidence and qualifications for PyDMD, PyKoopman, datafold and flowTorch.

Use diagnostics() to inspect the retained rank, backend/device and each estimator's available numerical measures. Core DMD reports fitted one-step relative error, retained conditioning and spectral radius. A small training residual does not establish predictive performance; assess an untouched future interval as well.

Reproduce and contribute

python -m pip install -e '.[dev]'
python -m pytest -q
python examples/quickstart.py
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 python benchmarks/benchmark.py \
  --backends numpy torch-cpu torch-cuda --features 256 --snapshots 160 \
  --rank 12 --repeats 5 --output benchmarks/results/local.json

Optional backends are explicitly skipped when unavailable. The benchmark records software/hardware metadata, warmups, repetitions and accuracy; CUDA timings are synchronized. Add --pydmd after installing PyDMD for a matched exact-DMD comparison. See benchmark methodology.

CPU CI runs supported Python versions and a separate PyTorch CPU job. A manual CUDA job needs a provisioned GPU runner; it fails if CUDA is unavailable. Publications use an independently configured PyPI Trusted Publisher.

Attribution

Original implementation by Giovanny Torres, released under the MIT license. Algorithm and comparison references are listed in docs/comparison.md. Please cite the relevant algorithm papers when using these methods in research.

Metadata

Release files for modaldyn 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modaldyn 0.1.0
File Size Uploaded Provenance Actions
modaldyn-0.1.0.tar.gz 42.3 kB With provenance Details for modaldyn-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for modaldyn 0.1.0
File Interpreter ABI Platform Actions
modaldyn-0.1.0-py3-none-any.whl Python 3 none any Details for modaldyn-0.1.0-py3-none-any.whl

Total release size: 62.0 kB

Release files / modaldyn-0.1.0.tar.gz

Download URL modaldyn-0.1.0.tar.gz
Size 42.3 kB
Tags Source
SHA-256 checksum
How to use checksums
881a697d7d7b31cf279118b7be24132656b7e908fc0261310e7b21a2c56c6f0a
BLAKE2b-256 checksum
How to use checksums
c79fef47941021059adb9a4b6c7d39beecb711bce9c64c829a86120c56cee115
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / modaldyn-0.1.0-py3-none-any.whl

Download URL modaldyn-0.1.0-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bcc00997d6cae9a8e7c46829df05adcdac12bb014f10d88a70839840ae28119
BLAKE2b-256 checksum
How to use checksums
07aa4c39460edbc40d8c125f717897b1c8a4823be475db6e8c574b722db00ec9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Security for modaldyn 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for modaldyn-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page