Skip to main content

lume-bmad

Tools for using Bmad in LUME

Installation

This package expects bmad and pytao to be provided by conda.

conda create -n lume-bmad -c conda-forge python=3.11 bmad pytao
conda activate lume-bmad
pip install -e .

For development dependencies:

pip install -e ".[dev]"

Quick import check:

python -c "import pytao, lume_bmad; print('ok')"

Implementation example

The test fixtures in tests/ provide a minimal Tao setup you can use directly:

  • tests/fodo.init: Tao initialization file.
  • tests/fodo.bmad: lattice file loaded by fodo.init.

Because tests/fodo.init references fodo.bmad with a relative path, keep those two files in the same directory.

from pathlib import Path

from pytao import Tao

from lume_bmad.actions import EleScalarVariable
from lume_bmad.model import LUMEBmadModel

# Reuse the fixture Tao setup from tests/
tao_init = Path("tests") / "fodo.init"
tao = Tao(init_file=str(tao_init), noplot=True)

control_variables = [
    EleScalarVariable(
        name="qf:B1_GRADIENT",
        unit="1/m^2",
        element_name="qf",
        property_name="B1_GRADIENT",
    ),
    EleScalarVariable(
        name="qd:B1_GRADIENT",
        unit="1/m^2",
        element_name="qd",
        property_name="B1_GRADIENT",
    ),
]

model = LUMEBmadModel(
    tao=tao,
    action_variables=control_variables,
    dump_locations=["qf", "qd"],
)

# Read and set model variables
print(model.get(["qf:B1_GRADIENT", "qd:B1_GRADIENT"]))
model.set({"qf:B1_GRADIENT": 0.2})

# Enable beam tracking and read a dumped beam distribution
model.set({"track_type": "beam"})
qf_beam = model.get_value("qf_beam")
print(qf_beam.n_particle)

If you want to run this example from outside the repository, copy both fixture files together and pass the path to that copied fodo.init.

Archiving and restoring

from lume_bmad.archive import read_archive_variables
from lume_bmad.utils import tao_from_archive

model.archive("model.h5")
frame = read_archive_variables("model.h5")
print(frame.attrs["errors"])  # Failed variable names mapped to saved errors.
tao = tao_from_archive("model.h5")

To skip reading and storing current variable values while retaining names and all descriptor metadata (including defaults):

model.archive("model.h5", include_variable_values=False)
# Also supported: archive_model(model, "model.h5", include_variable_values=False)

Metadata

Release files for lume-bmad 0.1.2

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

Source distribution (sdist)

Source distribution for lume-bmad 0.1.2
File Size Uploaded Provenance Actions
lume_bmad-0.1.2.tar.gz 58.1 kB Without provenance Details for lume_bmad-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lume-bmad 0.1.2
File Interpreter ABI Platform Actions
lume_bmad-0.1.2-py3-none-any.whl Python 3 none any Details for lume_bmad-0.1.2-py3-none-any.whl

Total release size: 77.6 kB

Release files / lume_bmad-0.1.2.tar.gz

Download URL lume_bmad-0.1.2.tar.gz
Size 58.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9c75571ca3e84eaad8d94f15b859ccd540f5aefd9735b6cb6dc6c7b1aa8ee5ec
BLAKE2b-256 checksum
How to use checksums
937cd57f0084aa16a7eece0a0c7afb3d3931b116971882d79a3f1fc71a8df4c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / lume_bmad-0.1.2-py3-none-any.whl

Download URL lume_bmad-0.1.2-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d1a16ba81f6850d1aef7e45676d92e0067eb0a444e1316e9000bf4ea7299e31
BLAKE2b-256 checksum
How to use checksums
ba718ac2b52290f2551a69219baf890dda4e55276c5f3db657d840f2eebe53d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for lume-bmad 0.1.2

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