Skip to main content

Python implementation for the Particle Accelerator Lattice Standard (PALS)

Project description

Meet Your Python PALS

This is a Python implementation for the Particle Accelerator Lattice Standard (PALS).

To define the PALS schema, Pydantic is used to map to Python objects, perform automatic validation, and serialize/deserialize data classes to/from many modern file formats. Various modern file formats (e.g., YAML, JSON, TOML, XML, etc.) are supported, which makes the implementation of the schema-following files in any modern programming language easy (e.g., Python, Julia, C++, LUA, Javascript, etc.). Here, we do Python.

Status

This project is a work-in-progress and evolves alongside the Particle Accelerator Lattice Standard (PALS).

Approach

This project implements the PALS schema in a file-agnostic way, mirrored in data objects. The corresponding serialized files (and optionally, also the corresponding Python objects) can be human-written, human-read, and automatically validated.

PALS files follow a schema and readers can error out on issues. Not every PALS implementation needs to be as detailed as the reference implementation in Python. This implementation can be used to convert between different file formats or to validate a file before reading it with your favorite YAML/JSON/TOML/XML/... library in your programming language of choice.

This will enable us to:

  • exchange lattices between codes;
  • use common GUIs for defining lattices;
  • use common lattice visualization tools (2D, 3D, etc.).

FAQ

Why use Pydantic for this implementation?
Implementing directly against a specific file format is possible, but cumbersome. By using a widely-used schema engine, such as Pydantic, we can get serialization/deserialization to/from various file formats, conversion, and validation "for free".

Roadmap

Preliminary roadmap:

  1. Define the PALS schema, using Pydantic.
  2. Document the API.
  3. Develop a reference implementation in Python. Attract additional reference implementations in other languages.
  4. Add supporting helpers, which can import existing MAD-X, Elegant, SXF files. Be as feature complete as possible in these importers.
  5. Reuse the reference implementations and implement readers in community codes for beamline modeling (e.g., the BLAST codes).

For users

You can install this Python implementation of PALS via pip install pals-schema. Package releases can be found here.

Once installed, you can run the examples available in the examples directory to verify that the package was installed correctly.

If you wish to run the unit tests available in the tests directory, please install the package via pip install pals-schema[test] to make sure that all additional dependencies (e.g., pytest) are installed correctly.

For developers

In order to develop and test this Python implementation locally, please follow these steps:

  1. Create a conda environment from the environment.yml file:
    conda env create -f environment.yml
    
  2. Activate the conda environment:
    conda activate pals-python
    
    (This is the environment name in the environment.yml file.)
  3. Install Python PALS in development (editable) mode:
    pip install -e ".[test]"
    

Once you have created the environment with all the required dependencies, you can run the examples available in the examples directory.

You can also run the unit tests available in the tests directory via

pytest tests -v

Here, the command line option -v increases the verbosity of the output. You can also use the command line option -s to display any test output directly in the console (useful for debugging). Please refer to pytest's documentation for further details on the available command line options and/or run pytest --help.

Copyright Notice and License Agreement

PALS Python Copyright (c) 2025, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.

If you have questions about your rights to use or distribute this software, please contact Berkeley Lab's Intellectual Property Office at IPO@lbl.gov.

Please find the full copyright notice in NOTICE.txt and the full license agreement in LICENSE.txt.

The SPDX license identifier is BSD-3-Clause-LBNL.

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

pals_schema-0.3.0.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

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

pals_schema-0.3.0-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

File details

Details for the file pals_schema-0.3.0.tar.gz.

File metadata

  • Download URL: pals_schema-0.3.0.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for pals_schema-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b3f358381c88dcc9fdf31aefa0a9ebba8219eef9265f7473498344589237bd40
MD5 a80522994da2037b4fa948fecfdc12b9
BLAKE2b-256 959b04aec011f225e4125a7bcf4cb092d906832890b2b26e8123ad99d80e583d

See more details on using hashes here.

File details

Details for the file pals_schema-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pals_schema-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 36.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for pals_schema-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22b025f0349dbd84728fafdf7e9038c97f1c4851286cb960b42b03e45d71d425
MD5 cf6c4f9a074b9caba7fda6d67d435344
BLAKE2b-256 b357830f65c378473dc2978f2c3f915e33eeba550eb7dd47086bb0767523f412

See more details on using hashes here.

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