Skip to main content

madng-tpsa - GTPSA (truncated power series) for Python

This repository exposes the features of MAD-NG's GTPSA (Generalised Truncated Power Series Algebra) through a Python interface. The package builds libmadng_tpsa.so on Linux or libmadng_tpsa.dylib on macOS, and uses CFFI ABI mode to access the native functionality.

import numpy as np
import scipy

from madng_tpsa import Descriptor

d = Descriptor(variables=['x', 'y'], order=3)
x, y = d.vars()
f = x * x + 2.0 * y

# Inspect!
f  # => Tpsa({(0, 1): 2.0, (2, 0): 1.0})
f.format()  # => '2 * y + x**2'
f.format('table')  # => a Rich table showing all coefficients

# Basic operations
c = d.constant(42)
c.const_part  # => 42
f.const_part  # => 0

f.monomial_coeffs()  # => {(0, 1): 2.0, (2, 0): 1.0}
f.derivative('y')  # => Tpsa({(0, 0): 2.0})
f.grad()  # => [0, 2]

# Compatible with Numpy protocol
np.sin(f)  # => Tpsa({(0, 1): 2.0, (2, 0): 1.0, (0, 3): -1.3333333333333333})
scipy.special.wofz(f)  # => Tpsa({(0, 0): 1.0, (0, 2): -4.0, (2, 1): -4.0})

Through the xobjects entry point declared in pyproject.toml, the MAD-NG TPSA C API is automatically made available to Xobjects, so projects built on Xobjects can reuse it without much extra wiring, relying on madng-tpsa abstractions in the Python-side API.

Build

The project uses scikit-build-core and CMake:

git submodule update --init --recursive
pip install .
pip install -e .
python -m build

pip install -e . runs CMake and copies the generated shared library into src/madng_tpsa/lib/, matching the installed wheel layout. MAD-NG headers copied into src/madng_tpsa/include/ and platform shared libraries in src/madng_tpsa/lib/ are generated artefacts and ignored by Git.

By default, CMake builds from the bundled madng/src checkout. To use another MAD-NG source tree:

pip install . --config-settings=cmake.define.MADNG_SRC=/path/to/madng/src

Requirements: a C compiler, CMake, BLAS/LAPACK on Linux, and Accelerate on macOS.

Development

Install the package together with the development tools:

python -m pip install --group dev -e .

Enable the pre-commit hooks:

pre-commit install

The hooks run Ruff formatting/linting and Ty type checking. To run the same checks manually:

pre-commit run --all-files

Tests

pytest tests/

The tests exercise the standalone engine bindings; xtrack is not imported.

Download files

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

Source Distribution

madng_tpsa-0.1.0.tar.gz (97.1 MB view details)

Uploaded Source

Built Distributions

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

madng_tpsa-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl (12.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

madng_tpsa-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (367.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

madng_tpsa-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (12.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

madng_tpsa-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (367.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

madng_tpsa-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (12.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

madng_tpsa-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (367.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file madng_tpsa-0.1.0.tar.gz.

File metadata

  • Download URL: madng_tpsa-0.1.0.tar.gz
  • Upload date:
  • Size: 97.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for madng_tpsa-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b8b64c94a73bc6ed02180dbd6960233d029a889df12acbaf9a26dcf8bf172e6d
MD5 ee783244e7f9d3eb0e5281b771924d68
BLAKE2b-256 62771697b044905d5eadcc080fb3ef39d64e10257a6ff5330548eaaf2a6d0176

See more details on using hashes here.

Provenance

The following attestation bundles were made for madng_tpsa-0.1.0.tar.gz:

Publisher: release.yaml on babreufig/madng-tpsa

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

File details

Details for the file madng_tpsa-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for madng_tpsa-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5c1df93c70c84417d73259579e6b8f98f1c9cddcef361666ccc2939bd6b615b2
MD5 7f524cfcda5ca7fdd6f126565e0d7cb6
BLAKE2b-256 9902a5d70fe0f9c7ceb7d8068b9b0570997dda358cda9cc4bed329e562090fa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for madng_tpsa-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: release.yaml on babreufig/madng-tpsa

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

File details

Details for the file madng_tpsa-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for madng_tpsa-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b75da7f3e7692d0c7ae2c6045dfdcb2a0d46d2a93b0d9915544b100113db5d1f
MD5 2c7ef45a4d691a1bc21c6797fb8bc19b
BLAKE2b-256 3daba16063bb6179c1eb8d10381d6b05b0b50251e72e8d3d47879b084462e01c

See more details on using hashes here.

Provenance

The following attestation bundles were made for madng_tpsa-0.1.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yaml on babreufig/madng-tpsa

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

File details

Details for the file madng_tpsa-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for madng_tpsa-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7a3b88baf3de8ccc47d4f2fbc88b87286afe3331683f74d8bd892aea80630bf7
MD5 632eaff5099347ba246f6e9f670190f3
BLAKE2b-256 798a0304592a135c3a4737dc4a79e8d7ccc692d08ac55a2a1c04e75aebb1bda8

See more details on using hashes here.

Provenance

The following attestation bundles were made for madng_tpsa-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: release.yaml on babreufig/madng-tpsa

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

File details

Details for the file madng_tpsa-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for madng_tpsa-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b6d6b0ae910a718db477db2f786165cb4176e0cf46e24aa4d8eac76a62cdfd9f
MD5 084dc8e11f78faf4984e5c6a465e0f3d
BLAKE2b-256 82ec991d100124d7aee7322fa876cf41733c0d307145e31c55abb19d6d224270

See more details on using hashes here.

Provenance

The following attestation bundles were made for madng_tpsa-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yaml on babreufig/madng-tpsa

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

File details

Details for the file madng_tpsa-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for madng_tpsa-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 25fcaf7faf4e99cca37751a536682674bf4fda54124d0fbb65769cd5e7be0e3e
MD5 c7268a426113673d634bf8bbf671df25
BLAKE2b-256 aa4dfcc713f22dc812da408dcb894c9c7c7b1664967931cd8953b904069dd2f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for madng_tpsa-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: release.yaml on babreufig/madng-tpsa

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

File details

Details for the file madng_tpsa-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for madng_tpsa-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6d81f1cd5f32ed6e3ba4d8d9188687bad71a619b4be68a2980b0b7a5bb9f6a3f
MD5 3182588a7630ef27a57bb0d2042fc3d6
BLAKE2b-256 aeaef64b4a91cc551ae9fcb9be616e7df0496a1b93cba09aa6d3cab37efe7cd8

See more details on using hashes here.

Provenance

The following attestation bundles were made for madng_tpsa-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yaml on babreufig/madng-tpsa

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

Release history Release notifications | RSS feed

0.3.0

9 files

0.2.0

9 files

0.1.1

9 files

This release

0.1.0 This release

7 files

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