Skip to main content

Lyapunov exponents and Covariant Lyapunov Vectors utilities

Project description

clvlib

clvlib is a library for computing Lyapunov exponents and Covariant Lyapunov Vectors (CLVs) with NumPy and PyTorch. Lyapunov exponents are computed using Benettin's algorithm [1]. The NumPy implementation uses a sign-corrected Householder QR step for re-orthonormalisation, and the CLVs are computed using Ginelli's algorithm [2].

The variational stepper used to integrate the variational system is modular. Standard Euler, RK2, RK4, and discrete-time steppers are bundled, but you can register your own functions for the integrators.

Installation

pip install clvlib

Quickstart

import numpy as np
from clvlib.numpy import lyap_analysis_from_ic

# Lorenz '63 system ----------------------------------------------------------
SIGMA = 10.0
RHO = 28.0
BETA = 8.0 / 3.0

def lorenz(t: float, x: np.ndarray) -> np.ndarray:
    return np.array(
        [
            SIGMA * (x[1] - x[0]),
            x[0] * (RHO - x[2]) - x[1],
            x[0] * x[1] - BETA * x[2],
        ],
        dtype=float,
    )

def jacobian(t: float, x: np.ndarray) -> np.ndarray:
    return np.array(
        [
            [-SIGMA, SIGMA, 0.0],
            [RHO - x[2], -1.0, -x[0]],
            [x[1], x[0], -BETA],
        ],
        dtype=float,
    )

times = np.linspace(0.0, 40.0, 4001)
x0 = np.array([8.0, 0.0, 30.0], dtype=float)

LE, LE_history, Q_history, R_history, clv_history, D_history, traj = lyap_analysis_from_ic(
    lorenz,
    jacobian,
    x0,
    times,
    stepper="rk4",
)

print("Asymptotic Lyapunov exponents:", LE)

See tutorials/lorenz_numpy_quickstart.ipynb for the NumPy walkthrough, and tutorials/lorenz_pytorch_quickstart.ipynb for the PyTorch version.

Want only the most unstable directions? Pass n_lyap=k to any of the Lyapunov helpers (lyap_exp, lyap_analysis, and their _from_ic counterparts) to compute just the leading k exponents/BLVs/CLVs.

Angles and instantaneous CLVs

from clvlib.numpy import compute_angles, principal_angles, compute_ICLE

# Pairwise vector angles
cosine, theta = compute_angles(clv_history[:, :, 0], clv_history[:, :, 1])

# Principal angles between subspaces
angles = principal_angles(clv_history[:, :, -1:], clv_history[:, :, :-1])

# Instantaneous covariant exponents sampled every k_step iterations
icle = compute_ICLE(jacobian, traj, times, clv_history, k_step=1)

Citation

If clvlib contributes to your published work, please cite it as:

@misc{consonni_clvlib_2025,
  author    = {Riccardo Consonni},
  title     = {clvlib},
  year      = {2025},
  url       = {https://github.com/riccardo-consonni/clvlib},
}

License

Published under the MIT License. See LICENSE for the full text.

References

[1] Benettin, G., Galgani, L., Giorgilli, A., & Strelcyn, J.-M. (1980). Lyapunov characteristic exponents for smooth dynamical systems and for Hamiltonian systems; a method for computing all of them. Part 1: Theory. Meccanica, 15(1), 9–20.

[2] Ginelli, F., Poggi, P., Turchi, A., Chaté, H., Livi, R., & Politi, A. (2007). Characterizing dynamics with covariant Lyapunov vectors. Physical Review Letters, 99(13), 130601.

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

clvlib-0.1.2.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

clvlib-0.1.2-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file clvlib-0.1.2.tar.gz.

File metadata

  • Download URL: clvlib-0.1.2.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clvlib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 37fff1bbd92868616f0b68f2700ef638e93ae9ff261a883ad77d9406d6814645
MD5 a2407e7434b5a5e28d9848ab35dfe5c6
BLAKE2b-256 35fdcd63d3229b6438bb290642a0816f884d540a5bcb723c3f34e29bfa16dc34

See more details on using hashes here.

Provenance

The following attestation bundles were made for clvlib-0.1.2.tar.gz:

Publisher: publish.yml on MagriLab/clvlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clvlib-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: clvlib-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clvlib-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cd648328862577fc971f1dd958eb036fa716812bda8996f8119e397295b9ba26
MD5 c71638d306d13bdf0bb00efc631f967e
BLAKE2b-256 d0942f46b5c98131da3f082a818dd059bb7b952850b25e3c3e0f3f150781118c

See more details on using hashes here.

Provenance

The following attestation bundles were made for clvlib-0.1.2-py3-none-any.whl:

Publisher: publish.yml on MagriLab/clvlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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