Skip to main content

pyffag

DA-based FFAG accelerator tracking using differential algebra.

Built on daceypy for arbitrary-order transfer map computation through FFAG sector magnets via integration of the exact midplane Hamiltonian.

Installation

pip install pyffag

Quick start

import numpy as np
from daceypy import DA
from pyffag import sector_map, compose_sequence, compose_n, tune, twiss
from pyffag.constants import kinetic_to_brho, M_PROTON

# 250 MeV proton FFAG ring: 8 FD doublet cells
DA.init(5, 2)  # DA order 5, 2 variables (x, px)
Brho = kinetic_to_brho(250.0, M_PROTON)

# F magnet: horizontally focusing sector, 25 degrees
F = sector_map([0.9, 2.0], Brho, angle=np.radians(25.0))

# D magnet: horizontally defocusing sector, 20 degrees
D = sector_map([0.9, -3.0], Brho, angle=np.radians(20.0))

cell = compose_sequence([F, D])
ring = compose_n(cell, 8)

print(f"Cell tune: {twiss(cell)['tune']:.4f}")
print(f"Ring tune: {tune(ring):.4f}")

Features

  • Sector tracking — exact curvilinear Hamiltonian integration through sector magnets with polynomial midplane field By(x) = Σ B_k x^k. Midplane 2-DOF (sector_map) and 4-DOF (sector_map_4d, Maxwell-consistent off-midplane expansion).
  • Element maps — exact drift, thin quadrupole / sextupole / octupole, edge kicks.
  • Ring operations — map composition, N-fold composition, closed-orbit finding (Newton with DA Jacobian; see below).
  • Optics — transfer matrix, tune, Twiss (β, α, γ), stability check, symplecticity error.
  • Shared lattice format — JSON schema that defines a sequence of elements and drives pyffag.build_map(). Portable across pyffag versions and, when paired with external cross-validation harnesses, across codes.

Lattice format (JSON)

{
  "name": "fd_doublet",
  "brho": 2.0,
  "elements": [
    {"type": "sector", "B": [1.0, 2.0], "angle_deg": 15.0},
    {"type": "drift",  "length": 0.3},
    {"type": "sector", "B": [1.0, -1.0], "angle_deg": 15.0},
    {"type": "thin_sext", "kL": 0.05}
  ]
}
import pyffag
from daceypy import DA

lattice = pyffag.load("fd_doublet.json")
DA.init(5, 2)
ring = pyffag.build_map(lattice)
print(pyffag.tune(ring), pyffag.twiss(ring))

Element types: sector, drift, drift_paraxial, thin_quad, thin_sext, thin_oct, edge_kick. See pyffag.lattice for the full schema.

Closed-orbit finding

from daceypy import DA
from pyffag import sector_map, find_closed_orbit

DA.init(5, 2)
x_co, px_co, converged = find_closed_orbit(
    lambda: sector_map([1.0, 2.0], 2.0, angle=0.4363),
    x_guess=0.0, px_guess=0.0,
)

The solver expands the DA map internally about the current guess and uses the DA Jacobian for a Newton step. Converges in one iteration for linear maps; quadratic convergence for nonlinear.

Physics

sector_map() integrates the midplane equations of motion in Frenet-Serret (curvilinear) coordinates with arc length as the independent variable. Sector magnets have radial edge faces (no edge focusing); non-radial edges are modelled explicitly via edge_kick.

Integration with danf

For nonlinear normal-form analysis (detuning, chromaticity, complex-basis NF) use danf:

from danf import NormalForm, chromaticity_1d

nf = NormalForm(ring)
nf.compute()
print(nf.tunes, nf.detuning)

License

MIT

Release files for pyffag 0.3.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 pyffag 0.3.0
File Size Uploaded
pyffag-0.3.0.tar.gz 20.3 kB Details

Built distribution (wheel)

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

Total release size: 34.8 kB

Release files / pyffag-0.3.0.tar.gz

Download URL pyffag-0.3.0.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c8e4e1f1f7642bb29e4534e8a695a05e6dcf192bdb5272ceb589e228a27c3440
BLAKE2b-256 checksum
How to use checksums
528ace06f30a37c1900a72bfdad8f8d567403413ba56a9f9a754c2b76f7e5698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / pyffag-0.3.0-py3-none-any.whl

Download URL pyffag-0.3.0-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a01f054359d4b2b747c13a5a870b3c453a83d35283e2e75720e2516640395c7
BLAKE2b-256 checksum
How to use checksums
62a7491373c15befa57ab253d0161aa95a38f53cfe826dd56188f85a367b686b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release 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