Skip to content

Commit 4b4b015

Browse files
committed
[Vibe] Update Elements
Based on the prompt > We defined a meta-data schema for particle accelerator lattice lements in pals. > You will find in pals/source the description of elements and their meta-data, the pals/examples has an example. > Ignore the inheritance feature for now. > I want you to find and read the element definitions. > I want you to find and read the implementation of existing PALS Python elements in pals-python/. Follow their structure and style. > Then, do this workflow: > 1. read and understand one element at a time > 2. go to pals-python/schema and add a new element, one at a time, following the existing implementation > 3. go to pals-python/tests/test_schema.py and define a compact test per new element > Repeat this until all elements defined in PALS are implemented in pals-python. And ~20 follow-up prompts.
1 parent 5b727e5 commit 4b4b015

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1714
-15
lines changed

src/pals/kinds/ACKicker.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import Literal
2+
3+
from .ThickElement import ThickElement
4+
from ._warnings import under_construction
5+
6+
7+
@under_construction("ACKicker")
8+
class ACKicker(ThickElement):
9+
"""Time varying kicker element"""
10+
11+
# Discriminator field
12+
kind: Literal["ACKicker"] = "ACKicker"
13+
14+
# Note: ACKickerP parameter group not yet implemented

src/pals/kinds/BaseElement.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
from pydantic import BaseModel, ConfigDict
2-
from typing import Literal
2+
from typing import Literal, Optional
3+
4+
from ..parameters import (
5+
ApertureParameters,
6+
BodyShiftParameters,
7+
FloorParameters,
8+
MetaParameters,
9+
ReferenceParameters,
10+
ReferenceChangeParameters,
11+
TrackingParameters,
12+
)
313

414

515
class BaseElement(BaseModel):
@@ -15,8 +25,19 @@ class BaseElement(BaseModel):
1525
# element name
1626
name: str
1727

28+
# Common parameter groups (optional for all elements)
29+
ApertureP: Optional[ApertureParameters] = None
30+
BodyShiftP: Optional[BodyShiftParameters] = None
31+
FloorP: Optional[FloorParameters] = None
32+
MetaP: Optional[MetaParameters] = None
33+
ReferenceP: Optional[ReferenceParameters] = None
34+
ReferenceChangeP: Optional[ReferenceChangeParameters] = None
35+
TrackingP: Optional[TrackingParameters] = None
36+
1837
def model_dump(self, *args, **kwargs):
1938
"""This makes sure the element name property is moved out and up to a one-key dictionary"""
39+
# Exclude None values from serialization
40+
kwargs.setdefault("exclude_none", True)
2041
elem_dict = super().model_dump(*args, **kwargs)
2142
name = elem_dict.pop("name", None)
2243
if name is None:

src/pals/kinds/BeamBeam.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import Literal, Optional
2+
3+
from .BaseElement import BaseElement
4+
from ..parameters import BeamBeamParameters
5+
from ._warnings import under_construction
6+
7+
8+
@under_construction("BeamBeam")
9+
class BeamBeam(BaseElement):
10+
"""Element for simulating colliding beams"""
11+
12+
# Discriminator field
13+
kind: Literal["BeamBeam"] = "BeamBeam"
14+
15+
# Beam-beam-specific parameters
16+
BeamBeamP: Optional[BeamBeamParameters] = None

src/pals/kinds/BeamLine.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@
66
from .Drift import Drift
77
from .Quadrupole import Quadrupole
88

9+
# Import schema elements
10+
from .Marker import Marker
11+
from .Sextupole import Sextupole
12+
from .Octupole import Octupole
13+
from .Multipole import Multipole
14+
from .RBend import RBend
15+
from .SBend import SBend
16+
from .Solenoid import Solenoid
17+
from .RFCavity import RFCavity
18+
from .Patch import Patch
19+
from .FloorShift import FloorShift
20+
from .Fork import Fork
21+
from .BeamBeam import BeamBeam
22+
from .BeginningEle import BeginningEle
23+
from .Fiducial import Fiducial
24+
from .NullEle import NullEle
25+
from .Kicker import Kicker
26+
from .ACKicker import ACKicker
27+
from .CrabCavity import CrabCavity
28+
from .EGun import EGun
29+
from .Feedback import Feedback
30+
from .Girder import Girder
31+
from .Instrument import Instrument
32+
from .Mask import Mask
33+
from .Match import Match
34+
from .Taylor import Taylor
35+
from .Wiggler import Wiggler
36+
from .Converter import Converter
37+
from .Foil import Foil
38+
from .UnionEle import UnionEle
39+
940

1041
class BeamLine(BaseElement):
1142
"""A line of elements and/or other lines"""
@@ -19,11 +50,43 @@ class BeamLine(BaseElement):
1950
line: List[
2051
Annotated[
2152
Union[
53+
# Base classes (for testing compatibility)
2254
BaseElement,
2355
ThickElement,
56+
# Original elements
2457
Drift,
2558
Quadrupole,
2659
"BeamLine",
60+
# New schema elements
61+
Marker,
62+
Sextupole,
63+
Octupole,
64+
Multipole,
65+
RBend,
66+
SBend,
67+
Solenoid,
68+
RFCavity,
69+
Patch,
70+
FloorShift,
71+
Fork,
72+
BeamBeam,
73+
BeginningEle,
74+
Fiducial,
75+
NullEle,
76+
Kicker,
77+
ACKicker,
78+
CrabCavity,
79+
EGun,
80+
Feedback,
81+
Girder,
82+
Instrument,
83+
Mask,
84+
Match,
85+
Taylor,
86+
Wiggler,
87+
Converter,
88+
Foil,
89+
UnionEle,
2790
],
2891
Field(discriminator="kind"),
2992
]

src/pals/kinds/BeginningEle.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import Literal
2+
3+
from .BaseElement import BaseElement
4+
from ._warnings import under_construction
5+
6+
7+
@under_construction("BeginningEle")
8+
class BeginningEle(BaseElement):
9+
"""Initial element at start of a branch"""
10+
11+
# Discriminator field
12+
kind: Literal["BeginningEle"] = "BeginningEle"

src/pals/kinds/Converter.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import Literal, Optional
2+
3+
from .BaseElement import BaseElement
4+
from ..parameters import ElectricMultipoleParameters
5+
from ..parameters import MagneticMultipoleParameters
6+
from ._warnings import under_construction
7+
8+
9+
@under_construction("Converter")
10+
class Converter(BaseElement):
11+
"""Target to produce new species. EG: Positron converter"""
12+
13+
# Discriminator field
14+
kind: Literal["Converter"] = "Converter"
15+
16+
# Converter-specific parameters (in addition to inherited ones)
17+
ElectricMultipoleP: Optional[ElectricMultipoleParameters] = None
18+
MagneticMultipoleP: Optional[MagneticMultipoleParameters] = None

src/pals/kinds/CrabCavity.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import Literal, Optional
2+
3+
from .ThickElement import ThickElement
4+
from ..parameters import ElectricMultipoleParameters
5+
from ..parameters import MagneticMultipoleParameters
6+
from ._warnings import under_construction
7+
8+
9+
@under_construction("CrabCavity")
10+
class CrabCavity(ThickElement):
11+
"""RF crab cavity"""
12+
13+
# Discriminator field
14+
kind: Literal["CrabCavity"] = "CrabCavity"
15+
16+
# CrabCavity-specific parameters (in addition to inherited ones)
17+
ElectricMultipoleP: Optional[ElectricMultipoleParameters] = None
18+
MagneticMultipoleP: Optional[MagneticMultipoleParameters] = None

src/pals/kinds/Drift.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from typing import Literal
22

33
from .ThickElement import ThickElement
4+
from ._warnings import under_construction
45

56

7+
@under_construction("Drift")
68
class Drift(ThickElement):
7-
"""A field free region"""
9+
"""Field free region"""
810

911
# Discriminator field
1012
kind: Literal["Drift"] = "Drift"

src/pals/kinds/EGun.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import Literal, Optional
2+
3+
from .ThickElement import ThickElement
4+
from ..parameters import ElectricMultipoleParameters
5+
from ..parameters import MagneticMultipoleParameters
6+
from ._warnings import under_construction
7+
8+
9+
@under_construction("EGun")
10+
class EGun(ThickElement):
11+
"""Electron gun"""
12+
13+
# Discriminator field
14+
kind: Literal["EGun"] = "EGun"
15+
16+
# EGun-specific parameters (in addition to inherited ones)
17+
ElectricMultipoleP: Optional[ElectricMultipoleParameters] = None
18+
MagneticMultipoleP: Optional[MagneticMultipoleParameters] = None

src/pals/kinds/Feedback.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import Literal
2+
3+
from .BaseElement import BaseElement
4+
from ._warnings import under_construction
5+
6+
7+
@under_construction("Feedback")
8+
class Feedback(BaseElement):
9+
"""Element used to simulate a feedback circuit"""
10+
11+
# Discriminator field
12+
kind: Literal["Feedback"] = "Feedback"

0 commit comments

Comments
 (0)