Skip to main content

ODE system solver using dG(q), time-discontinuous Galerkin with Lobatto basis

Project description

pydgq

top language supported Python versions supported implementations CI status

version on PyPI PyPI package format dependency status

license open issues PRs welcome

Solve ordinary differential equation (ODE) systems using the time-discontinuous Galerkin method, with Cython acceleration.

We use semantic versioning.

For my stance on AI contributions, see the collaboration guidelines.

Lorenz attractor, dG(2)

Introduction

This is a Cython-accelerated library that integrates initial value problems (IVPs) of first-order ordinary differential equation (ODE) systems of the form u'(t) = f(u, t).

The main feature of the library is dG(q), i.e. the time-discontinuous Galerkin method using a Lobatto basis (a.k.a. hierarchical polynomial basis). Some classical explicit and implicit integrators (RK4, RK3, RK2, FE, SE, IMR, BE) are also provided, mainly for convenience.

Time-discontinuous Galerkin is a very accurate implicit method that often allows using a rather large timestep. Due to its Galerkin nature, it also models the behavior of the solution inside the timestep (although best accuracy is obtained at the endpoint of the timestep).

Arbitrary polynomial degrees q are supported, but often best results are obtained for q = 1 (dG(1)) or q = 2 (dG(2)). (The example image above has been computed using dG(2). Note the discontinuities at timestep boundaries.)

The focus of this library is on arbitrary nonlinear problems. All implicit methods are implemented using fixed-point (Banach/Picard) iteration, relying on the Picard-Lindelöf theorem (which itself relies on the Banach fixed point theorem).

For supplying the user code implementing the right-hand side (RHS) f(u, t) for a given problem, both Python and Cython interfaces are provided.

For material on the algorithms used, see the user manual.

Installation

From PyPI

pip install pydgq

From source

git clone https://github.com/Technologicat/pydgq.git
cd pydgq
pip install .

Performance builds

The default build uses meson's release optimization (-O2). For numerically intensive workloads, you can enable architecture-specific optimizations:

CFLAGS="-march=native -O2 -msse -msse2 -mfma -mfpmath=sse" pip install --no-build-isolation .

Note: wheels on PyPI are built without -march=native for portability. Build from source if you want maximum performance on your specific hardware.

Development

pdm install                              # creates venv, installs dev deps
pip install --no-build-isolation -e .    # editable install (needs venv activated)
pdm run pytest tests/ -v                 # run tests

The --no-build-isolation flag is required for editable installs with meson-python — the on-import rebuild mechanism needs build dependencies to remain available in the environment.

PATH note: The meson-python editable loader needs meson and ninja on PATH. If you get rebuild errors, ensure the venv's bin/ is on the path:

export PATH="$(pwd)/.venv/bin:$PATH"

Usage summary

The user is expected to provide a custom kernel, which computes the RHS f(u, t) for the specific problem to be solved.

The problem is solved by instantiating this custom kernel, and passing the instance to the ivp() function of the pydgq.solver.odesolve module (along with solver options).

A Cython example kernel is provided in pydgq.examples.example_kernel. A standalone visualization script (Lorenz attractor) is in examples/.

Software architecture

The design of pydgq is based on two main class hierarchies, consisting of Cython extension types (cdef classes):

  • IntegratorBase: interface class for integrator algorithms
    • ExplicitIntegrator: base class for explicit methods, which are implemented in pydgq.solver.explicit:
      • RK4: fourth-order Runge-Kutta
      • RK3: Kutta's third-order method
      • RK2: parametric second-order Runge-Kutta
      • FE: forward Euler (explicit Euler)
      • SE: symplectic Euler, for 2nd-order systems reduced to a twice larger 1st-order system
    • ImplicitIntegrator: base class for implicit methods, which are implemented in pydgq.solver.implicit:
      • IMR: implicit midpoint rule
      • BE: backward Euler (implicit Euler)
      • GalerkinIntegrator: base class for Galerkin methods using a Lobatto basis, which are implemented in pydgq.solver.galerkin:
        • DG: discontinuous Galerkin
        • CG: continuous Galerkin
  • KernelBase: interface class for RHS kernels
    • CythonKernel: base class for kernels implemented in Cython, see pydgq.solver.builtin_kernels for examples:
      • Linear1stOrderKernel: w' = M w
      • Linear1stOrderKernelWithMassMatrix: A w' = M w
      • Linear2ndOrderKernel: u'' = M0 u + M1 u'
        • solved as a twice larger 1st-order system, by defining v := u', thus obtaining u' = v and v' = M0 u + M1 v
        • the DOF vector is defined as w := (u1, v1, u2, v2, ..., um, vm), where m is the number of DOFs of the original 2nd-order system.
      • Linear2ndOrderKernelWithMassMatrix: M2 u'' = M0 u + M1 u'
        • solved as u' = v and M2 v' = M0 u + M1 v similarly as above
      • CythonKernel acts as a base class for your own Cython-based kernels
    • PythonKernel: base class for kernels implemented in Python
      • PythonKernel acts as a base class for your own Python-based kernels

The ivp() function of pydgq.solver.odesolve understands the IntegratorBase and KernelBase interfaces, and acts as the driver routine.

Aliases to primitive data types (to allow precision switching at compile time) are defined in pydgq.solver.types: Python (import), Cython (cimport). The Python-accessible names point to the appropriate NumPy symbols. RTYPE is real, ZTYPE is complex, and DTYPE is an alias representing the problem data type. The corresponding Cython-accessible datatypes have the _t suffix (RTYPE_t, ZTYPE_t, DTYPE_t).

Currently, DTYPE is real, but it is kept conceptually separate from RTYPE so that complex-valued problems can be later supported, if necessary (this requires some changes in the code, especially any calls to dgesv).

Linear and nonlinear problems

The built-in kernels concentrate on linear problems, because for this specific class of problems, it is possible to provide generic pre-built kernels. The provided set of four kernels attempts to cover the most common use cases, especially the case of small-amplitude vibration problems in mechanics, which are of the second order in time, and typically have all three matrices M0, M1 and M2.

The main focus of the library, however, is on solving arbitrary nonlinear problems, and thus no algorithms specific to linear problems have been used. This makes the solver severely suboptimal for linear problems, but significantly increases flexibility.

Be aware that due to this choice of approach, the usual stability results for integrators for linear problems do not apply. For example, BE is no longer stable at any timestep size, because for large enough dt, contractivity in the Banach/Picard iteration is lost. (The standard results are based on classical von Neumann stability analysis; without modifications, these arguments are not applicable to the algorithm based on Banach/Picard iteration.)

Lobatto basis functions / precalculation

The numerical evaluation of the Lobatto basis functions is numerically highly sensitive to catastrophic cancellation (see the user manual); IEEE-754 double precision is insufficient to compute the intermediate results. To work around this issue, the basis functions are pre-evaluated once, by the module pydgq.utils.precalc, using higher precision in software (via mpmath).

The precalculation can be run again by running the module as the main program, e.g. python -m pydgq.utils.precalc. The module has some command-line options; use the standard --help option to see them.

The precalc module stores the values of the basis functions (at quadrature points and at visualization points, both on the reference element [-1,1]) into pydgq_data.npz, a compressed NumPy archive.

A data file with default precalc settings (q = 10, nx = 101) is included in the package. It is architecture-independent.

When running the solver, to use Galerkin methods, pydgq.solver.galerkin.init() must be called before calling pydgq.solver.odesolve.ivp().

Data file location

During pydgq.solver.galerkin.init(), the solver attempts to load pydgq_data.npz from these locations, in this order:

  1. ./pydgq_data.npz (local override),
  2. ~/.config/pydgq/pydgq_data.npz (user override),
  3. Installed package data, via importlib.resources.

If all three steps fail, an error is raised.

Dependencies

Runtime: NumPy, PyLU

Build: Cython (≥ 3.0), meson-python

Precalculation only: mpmath (extended-precision arithmetic for Lobatto basis evaluation)

Examples: Matplotlib (for the Lorenz visualization script in examples/)

License

BSD. Copyright 2016-2026 Juha Jeronen and University of Jyväskylä / JAMK University of Applied Sciences.

Acknowledgement

This work was financially supported by the Jenny and Antti Wihuri Foundation.

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

pydgq-1.0.0.tar.gz (847.2 kB view details)

Uploaded Source

Built Distributions

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

pydgq-1.0.0-cp314-cp314-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.14Windows x86-64

pydgq-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pydgq-1.0.0-cp314-cp314-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pydgq-1.0.0-cp313-cp313-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13Windows x86-64

pydgq-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pydgq-1.0.0-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pydgq-1.0.0-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12Windows x86-64

pydgq-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pydgq-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pydgq-1.0.0-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11Windows x86-64

pydgq-1.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pydgq-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file pydgq-1.0.0.tar.gz.

File metadata

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

File hashes

Hashes for pydgq-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b93f00e5f29c52d332d72fb83f4a98fe097ccacbdfc274eadd9049ae683098ff
MD5 44bdb72836df3c1fa254ee409485f1e9
BLAKE2b-256 8e7d1f6fc70737436250da8eec75c92087dbbe643903bd69c4d3a428c7eb514e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0.tar.gz:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pydgq-1.0.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydgq-1.0.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 caad20700d17afc5c8d0520a86d271a8c2f1681a3acc9c78de9a57e9dbad2c61
MD5 7739ea3afe9aa907e911e6d3c243bf47
BLAKE2b-256 c20421d3f629495bfec865bfa4e3dfc56375e424f736609a5a73877af783497b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp314-cp314-win_amd64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pydgq-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 51c04bba9d37dba0f90b9cc3c51ecadfc567f75a0b05afe9dcc397cdd35ad4ef
MD5 f07cb040627a115473611574cdeecc0a
BLAKE2b-256 69660538dc7a18ed57a494dd308d6faebd61c768f4cde5f06279d16eaa009ff4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pydgq-1.0.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b18ee574037c8ab302786662e864dafdd6b6b750eedc61095a8f25d7c6ba6a77
MD5 294ed765240dbf4a63ee5e08b8e1de70
BLAKE2b-256 2f5e2fc7acebbf8b9cc6bc40328a1fe66a75afcb8aace5f8c601fb460af9c097

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pydgq-1.0.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydgq-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 26469102df6b78eb0e78942a8605b1f397d1ffabdaef95fe0b700079d85ec0b5
MD5 d56c03438beda6c88fe477040ae4495a
BLAKE2b-256 7baf6f02df0ff56b121e1f82f276a81c2367939433b4c20de3cd9006dbd1286e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp313-cp313-win_amd64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pydgq-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 061acad20c91a9b892c43325e0228a16c68ae6404b6e76693b3e6848f120fcde
MD5 7120602f425b0c458f9d989a2842d472
BLAKE2b-256 12aa60cb77cfc046d35a4657e54e801a703ef6325a712a0146ff4e045a548a0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pydgq-1.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ed945b81f4814b60cfd5e9466222309b10cd868b3af30110678c29862812420
MD5 2fadbf31cd8220c19e44e6479f7f3f71
BLAKE2b-256 6fe509c2ef399adc14b6c93d85ba7c5d3ce6584035f07b2c127c7cb999df061d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pydgq-1.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydgq-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0752128e930f02b18650b8180cee21b76591de62bfc10d7141ee166e87db6614
MD5 39e95a214734a74411fb42439e386a98
BLAKE2b-256 a649f88ceea2daa6c6a1b0df53b443de924eea20cc4416fa22ec0c3c4f4f043f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp312-cp312-win_amd64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pydgq-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4157406aed7dacc66e8216a9cc27bf1beb9fa70fa26e92c9d13f406b3f0d5256
MD5 87eeab529c9b2f80724a4f5b9e37fdd9
BLAKE2b-256 c560bd160fded4549fd16ab9bee4d0107327528d2e1f0f85fc70038df8090534

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pydgq-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5361b66ff16d04a280b836dda58eec665a5e7acde7d41c125fb06d54475d661
MD5 3b7a55688a0e1c163294eb6033d8e1bb
BLAKE2b-256 1c5b1fb4aa358d0779f6dc8eec8c49ba13655a0aa9571bf84b3464e1e988c59e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pydgq-1.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydgq-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6240d5c122f624df2476ace95527da4aa1dc69c6f87d112d15e083f8d77128b2
MD5 dc34b017aa59adc94f7911465aeb1bf1
BLAKE2b-256 14b84bb87dc40022b9180eb12c2d7ea08af9744c083b682678a18558549ffa8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp311-cp311-win_amd64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pydgq-1.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1fa5e2c9eb7338aa2d273dd23f2038d543c19526385cbe8df64e6ff9ef10cd4e
MD5 28b097eb4de5bdf02a24782596b4f333
BLAKE2b-256 a97562290356fa24ff773bbe9766bc5a1324ef6b7f1b6e46c3e2142f3e77d578

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on Technologicat/pydgq

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

File details

Details for the file pydgq-1.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pydgq-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d93a6a3aad81c75915fca4811e63108b53a92b8aff99eb422f646e6cb8311a4
MD5 878be4f58cc2395fd606bbd85f8e9694
BLAKE2b-256 b158afa2fe60193a1698f9e7b772046c17194e2f65a93ae89a830f79bccc2d36

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydgq-1.0.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: ci.yml on Technologicat/pydgq

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