Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
085fc2c
Add test to validate examples in the main PALS repository
EZoni Dec 17, 2025
4e722cc
Merge branch 'main' into run_examples_from_pals
EZoni Feb 9, 2026
22c0f45
Use BeamLine.from_file to read from file
EZoni Feb 9, 2026
82a2486
Start draft of new Lattice class
EZoni Feb 10, 2026
89a5e53
Reexport, rebuild new Lattice class
EZoni Feb 10, 2026
d45ba9d
Replace `line` with `branches`, list of `BeamLine`s only
EZoni Feb 13, 2026
3e0d72a
Simplify For Now
ax3l Feb 17, 2026
11db528
Revert changes to Lattice class
EZoni Feb 18, 2026
10d54f3
Merge branch 'main' into run_examples_from_pals
EZoni Feb 18, 2026
b39c90e
Merge branch 'main' into run_examples_from_pals
EZoni Feb 19, 2026
cfe45e8
Update test
EZoni Feb 19, 2026
69e73ff
Workaround for 'use' syntax
EZoni Feb 19, 2026
0a9732d
Split CI workflow into three separate workflows
EZoni Feb 19, 2026
0e9b38d
Fix upstream examples workflow
EZoni Feb 19, 2026
5960c67
Rename internal examples as local examples
EZoni Feb 19, 2026
d9fe6f3
CI Updates
ax3l Feb 20, 2026
5707a69
Rename test_upstream_examples.py to avoid confusion with pytest
EZoni Feb 20, 2026
ed6f59c
Improve upstream example validation
EZoni Feb 20, 2026
7d77edb
Improve comment on new 'use' syntax
EZoni Feb 20, 2026
926399b
Merge branch 'main' into run_examples_from_pals
EZoni Feb 24, 2026
f066a5b
Do not test with Python 3.10
EZoni Feb 24, 2026
b1c76b7
Add instructions to validation script
EZoni Feb 24, 2026
8ebee3d
Add inline comments before ad-hoc validation
EZoni Feb 24, 2026
127796e
Adopt new naming convention
EZoni Feb 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ jobs:
- name: Test
run: |
pytest tests -v
- name: Examples
- name: Examples (internal)
run: |
python examples/fodo.py
- name: Examples (external)
run: |
# Copy examples directory from the main PALS repository
cd examples
git clone --no-checkout https://github.com/pals-project/pals.git pals_temp
Comment thread
EZoni marked this conversation as resolved.
Outdated
cd pals_temp
git sparse-checkout init
git sparse-checkout set examples/
git checkout main
Comment thread
EZoni marked this conversation as resolved.
Outdated
# Test all external examples
cd -
for file in pals_temp/examples/*.pals.yaml; do
python test_external_examples.py --path "${file}"
done
21 changes: 21 additions & 0 deletions examples/test_external_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import argparse

from pals import Lattice


def main():
# Parse command-line arguments
parser = argparse.ArgumentParser()
parser.add_argument(
"--path",
required=True,
help="Path to the example file",
)
args = parser.parse_args()
example_file = args.path
# Parse and validate YAML data from file
Lattice.from_file(example_file)


if __name__ == "__main__":
main()
12 changes: 0 additions & 12 deletions src/pals/kinds/BeamLine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from .all_elements import get_all_elements_as_annotation
from .mixin import BaseElement
from ..functions import load_file_to_dict, store_dict_to_file


class BeamLine(BaseElement):
Expand All @@ -26,14 +25,3 @@ def model_dump(self, *args, **kwargs):
from pals.kinds.mixin.all_element_mixin import dump_element_list

return dump_element_list(self, "line", *args, **kwargs)

@staticmethod
def from_file(filename: str) -> "BeamLine":
"""Load a BeamLine from a text file"""
pals_dict = load_file_to_dict(filename)
return BeamLine(**pals_dict)

def to_file(self, filename: str):
"""Save a BeamLine to a text file"""
pals_dict = self.model_dump()
store_dict_to_file(filename, pals_dict)
39 changes: 39 additions & 0 deletions src/pals/kinds/Lattice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from pydantic import model_validator
from typing import List, Literal

from .all_elements import get_all_elements_as_annotation
from .mixin import BaseElement
from ..functions import load_file_to_dict, store_dict_to_file


class Lattice(BaseElement):
"""A line of elements and/or other lines"""

kind: Literal["Lattice"] = "Lattice"

line: List[get_all_elements_as_annotation()]
Comment thread
EZoni marked this conversation as resolved.
Outdated

@model_validator(mode="before")
@classmethod
def unpack_json_structure(cls, data):
"""Deserialize the JSON/YAML/...-like dict for Lattice elements"""
from pals.kinds.mixin.all_element_mixin import unpack_element_list_structure

return unpack_element_list_structure(data, "line", "line")

def model_dump(self, *args, **kwargs):
"""Custom model dump for Lattice to handle element list formatting"""
from pals.kinds.mixin.all_element_mixin import dump_element_list

return dump_element_list(self, "line", *args, **kwargs)

@staticmethod
def from_file(filename: str) -> "Lattice":
"""Load a Lattice from a text file"""
pals_dict = load_file_to_dict(filename)
return Lattice(**pals_dict)

def to_file(self, filename: str):
"""Save a Lattice to a text file"""
pals_dict = self.model_dump()
store_dict_to_file(filename, pals_dict)
2 changes: 2 additions & 0 deletions src/pals/kinds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .ACKicker import ACKicker # noqa: F401
from .BeamBeam import BeamBeam # noqa: F401
from .BeamLine import BeamLine # noqa: F401
from .Lattice import Lattice # noqa: F401
from .BeginningEle import BeginningEle # noqa: F401
from .Converter import Converter # noqa: F401
from .CrabCavity import CrabCavity # noqa: F401
Expand Down Expand Up @@ -39,3 +40,4 @@
# Rebuild pydantic models that depend on other classes
UnionEle.model_rebuild()
BeamLine.model_rebuild()
Lattice.model_rebuild()
1 change: 1 addition & 0 deletions src/pals/kinds/all_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
def get_all_element_types(extra_types: tuple = None):
"""Return a tuple of all element types that can be used in BeamLine or UnionEle."""
element_types = (
"Lattice", # Forward reference to handle circular import
"BeamLine", # Forward reference to handle circular import
"UnionEle", # Forward reference to handle circular import
ACKicker,
Expand Down
Loading