Skip to main content

PyKoopman

Build Docs PyPI Codecov JOSS

PyKoopman is a Python package for computing data-driven approximations to the Koopman operator.

Data-driven approximation of Koopman operator

Koopman Operator

Given a nonlinear dynamical system,

$$x'(t) = f(x(t)),$$

the Koopman operator governs the temporal evolution of the measurement function. Unfortunately, it is an infinite-dimensional linear operator. Most of the time, one has to project the Koopman operator onto a finite-dimensional subspace that is spanned by user-defined/data-adaptive functions.

$$z = \Phi(x).$$

If the system state is also contained in such subspace, then effectively, the nonlinear dynamical system is (approximately) linearized in a global sense.

The goal of data-driven approximation of Koopman operator is to find such a set of functions that span such lifted space and the transition matrix associated with the lifted system.

Structure of PyKoopman

PyKoopman Structure

PyKoopman package is centered around the Koopman class and KoopmanContinuous class. It consists of two key components

  • observables: a set of observables functions, which spans the subspace for projection.

  • regressor: the optimization algorithm to find the best fit for the projection of Koopman operator.

After Koopman/KoopmanContinuous object has been created, it must be fit to data, similar to a scikit-learn model. We design PyKoopman such that it is compatible to scikit-learn objects and methods as much as possible.

Features implemented

  • Observable library for lifting the state into the observable space

    • Identity (for DMD/DMDc or in case users want to compute observables themselves): Identity
    • Multivariate polynomials: Polynomial
    • Time delay coordinates: TimeDelay
    • Radial basis functions: RadialBasisFunctions
    • Random Fourier features: RandomFourierFeatures
    • Custom library (defined by user-supplied functions): CustomObservables
    • Concatenation of observables: ConcatObservables
  • System identification method for performing regression

    • Dynamic mode decomposition: PyDMDRegressor
    • Dynamic mode decomposition with control: DMDc
    • Extended dynamic mode decomposition: EDMD
    • Extended dynamic mode decomposition with control: EDMDc
    • Kernel dynamic mode decomposition: KDMD
    • Hankel Alternative View of Koopman Analysis: HAVOK
    • Neural Network DMD: NNDMD
  • Sparse construction of Koopman invariant subspace

    • Multi-task learning based on linearity consistency

Examples

  1. Learning how to create observables

  2. Learning how to compute time derivatives

  3. Dynamic mode decomposition on two mixed spatial signals

  4. Dynamic mode decomposition with control on a 2D linear system

  5. Dynamic mode decomposition with control (DMDc) for a 128D system

  6. Dynamic mode decomposition with control on a high-dimensional linear system

  7. Successful examples of using Dynamic mode decomposition on PDE system

  8. Unsuccessful examples of using Dynamic mode decomposition on PDE system

  9. Extended DMD for Van Der Pol System

  10. Learning Koopman eigenfunctions on Slow manifold

  11. Comparing DMD and KDMD for Slow manifold dynamics

  12. Extended DMD with control for chaotic duffing oscillator

  13. Extended DMD with control for Van der Pol oscillator

  14. Hankel Alternative View of Koopman Operator for Lorenz System

  15. Hankel DMD with control for Van der Pol Oscillator

  16. Neural Network DMD on Slow Manifold

  17. EDMD and NNDMD for a simple linear system

  18. Sparisfying a minimal Koopman invariant subspace from EDMD for a simple linear system

Installation

Language

  • Python >= 3.11

Installing with pip

If you are using Linux or macOS you can install PyKoopman with pip:

pip install pykoopman

The tutorial notebooks also need Jupyter, which is not installed with PyKoopman:

pip install jupyter

We recommend using uv for environment management.

First clone this repository:

git clone https://github.com/dynamicslab/pykoopman
cd pykoopman

Create a virtual environment with Python 3.11 and install the package:

uv venv --python 3.11
uv pip install -e .

Alternatively, you can use the traditional venv approach:

python -m venv .venv
source ./.venv/bin/activate   # On Windows: .\.venv\Scripts\activate.ps1
pip install -e .

Installing with GPU support

The default installation uses the CPU-only version of PyTorch. If you need GPU support, please refer to the uv PyTorch integration guide for instructions on installing PyTorch with CUDA support.

Documentation

The documentation for PyKoopman is hosted on Read the Docs.

Community guidelines

Contributing code

We welcome contributions to PyKoopman. To contribute a new feature please submit a pull request. To get started we recommend installing the packages in "developer mode" via

python -m pip install -e ".[dev]"

The dev extra adds the test, documentation and notebook tools, so you can run the unit tests and format your code (.[test] is enough for the tests alone). With uv, uv sync --python 3.11 --extra dev sets up the same environment and uv run pytest runs the tests. To be accepted your code should conform to PEP8 and pass all unit tests. Code can be tested by invoking

pytest

We recommed using pre-commit to format your code. Once you have staged changes to commit

git add path/to/changed/file.py

you can run the following to automatically reformat your staged code

pre-commit run -a -v

Note that you will then need to re-stage any changes pre-commit made to your code.

Reporting issues or bugs

If you find a bug in the code or want to request a new feature, please open an issue.

Known issues:

  • Python 3.12 and 3.13 are not officially tested. We recommend Python 3.11.

Citing PyKoopman

@article{Pan2024, doi = {10.21105/joss.05881},
url = {https://doi.org/10.21105/joss.05881},
year = {2024},
publisher = {The Open Journal},
volume = {9},
number = {94},
pages = {5881},
author = {Shaowu Pan and Eurika Kaiser and Brian M. de Silva and J. Nathan Kutz and Steven L. Brunton},
title = {PyKoopman: A Python Package for Data-Driven Approximation of the Koopman Operator},
journal = {Journal of Open Source Software}}
  • PySINDy - A Python libray for the Sparse Identification of Nonlinear Dynamical systems (SINDy) method introduced in Brunton et al. (2016a).
  • Deeptime - A Python library for the analysis of time series data with methods for dimension reduction, clustering, and Markov model estimation.
  • PyDMD - A Python package using the Dynamic Mode Decomposition (DMD) for a data-driven model simplification based on spatiotemporal coherent structures. DMD is a great alternative to SINDy.
  • pykoop - a Koopman operator identification library written in Python
  • DLKoopman - a deep learning library for Koopman operator

Metadata

Release files for pykoopman 1.2.3

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

Source distribution (sdist)

Source distribution for pykoopman 1.2.3
File Size Uploaded Provenance Actions
pykoopman-1.2.3.tar.gz 84.9 kB Without provenance Details for pykoopman-1.2.3.tar.gz

Built distribution (wheel)

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

Total release size: 180.2 kB

Release files / pykoopman-1.2.3.tar.gz

Download URL pykoopman-1.2.3.tar.gz
Size 84.9 kB
Tags Source
SHA-256 checksum
How to use checksums
afd023d9db7a0b9c643d9c27b50d0b0c71802bbf26f6a8805c97bbcdabf2791d
BLAKE2b-256 checksum
How to use checksums
6314b3ebf39500fe67583d3c31b7eda8cbfd7b08d0d5fbff79c177e06766249e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / pykoopman-1.2.3-py3-none-any.whl

Download URL pykoopman-1.2.3-py3-none-any.whl
Size 95.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84012159809eca20d4c235e7c32c07008b8d460a66a5f5f13d38f022bc7a2963
BLAKE2b-256 checksum
How to use checksums
cafebf6338f52220b91da3e96df4b13f5e93f875b1a4752e496f7eaa33d12db8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for pykoopman 1.2.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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