Skip to content

Implement experimental PALS converter interfacing with the pals-python project - #644

Draft
cr-xu wants to merge 2 commits into
masterfrom
521-add-pals-support
Draft

Implement experimental PALS converter interfacing with the pals-python project#644
cr-xu wants to merge 2 commits into
masterfrom
521-add-pals-support

Conversation

@cr-xu

@cr-xu cr-xu commented Jun 16, 2026

Copy link
Copy Markdown
Member

Adds PALS lattice conversion support for Cheetah interfacing with the pals-python project.

Essentially it builds a two-directional mapping between pals-python objects and Cheetah objects.

Description

  • Adds cheetah.converters.pals with conversion to/from PALS objects and lattice files.
  • Supports drift, marker, quadrupole, dipole, aperture, RF cavity, horizontal/vertical/combined correctors, and solenoid.
  • Adds Segment convenience methods:
    • Segment.from_pals(...)
    • segment.to_pals(...)
    • Segment.from_pals_file(...)
    • segment.to_pals_file(...)

This is still an experimental implementation as the PALS and pals-python are both evolving.

To handle the extra fields:
PALS fields that Cheetah does not model directly are preserved in element.pals_extras.

  • _extract_extras(...) stores unconsumed PALS fields/groups during PALS -> Cheetah conversion.
  • _merge_group(...) and _split_pals_extras(...) re-emit preserved data during Cheetah -> PALS conversion, so that the round-trip is possible.
  • Unknown PALS element kinds become cheetah.Marker with the full PALS payload stored in pals_extras, plus an UnknownElementWarning.
  • Unsupported Cheetah elements or lossy conversions raise NotImplementedError.

Tests

Added PALS conversion tests for:

  • In-memory round trips
  • File round trips
  • Extra PALS parameter preservation
  • Unknown PALS element fallback
  • Unsupported Cheetah element rejection
  • New Segment PALS helper methods

Verified with:

  • pytest tests/test_pals_conversion.py
  • pytest tests/test_pals_conversion.py tests/test_lattice_json.py tests/test_bmad_conversion.py
  • pytest --ignore=tests/test_3d_visualization.py

Motivation and Context

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist

  • I have updated the changelog accordingly (required).
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.
  • I have reformatted the code and checked that formatting passes (required).
  • I have have fixed all issues found by flake8 (required).
  • I have ensured that all pytest tests pass (required).
  • I have run pytest on a machine with a CUDA GPU and made sure all tests pass (required).
  • I have checked that the documentation builds (required).

Note: We are using a maximum length of 88 characters per line.

@cr-xu cr-xu linked an issue Jun 16, 2026 that may be closed by this pull request
@cr-xu cr-xu changed the title Add initial attempt for the pals converter Implement experimental PALS converter interfacing with the pals-python project Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PALS support

1 participant