Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions examples/fodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../src/")))

from pals_schema.MagneticMultipoleParameters import MagneticMultipoleParameters
from pals_schema.DriftElement import DriftElement
from pals_schema.QuadrupoleElement import QuadrupoleElement
from pals_schema.Drift import Drift
from pals_schema.Quadrupole import Quadrupole
Comment on lines +10 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you!

In a follow-up PR, can you please check if we want to write simply

from pals import Drift, Quadrupole, Beamline

If empty/specific __init__.py files are missing we can add them.

from pals_schema.BeamLine import BeamLine


def main():
drift1 = DriftElement(
drift1 = Drift(
name="drift1",
length=0.25,
)
quad1 = QuadrupoleElement(
quad1 = Quadrupole(
name="quad1",
length=1.0,
MagneticMultipoleP=MagneticMultipoleParameters(
Bn1=1.0,
),
)
drift2 = DriftElement(
drift2 = Drift(
name="drift2",
length=0.5,
)
quad2 = QuadrupoleElement(
quad2 = Quadrupole(
name="quad2",
length=1.0,
MagneticMultipoleP=MagneticMultipoleParameters(
Bn1=-1.0,
),
)
drift3 = DriftElement(
drift3 = Drift(
name="drift3",
length=0.5,
)
Expand Down
8 changes: 4 additions & 4 deletions src/pals_schema/BeamLine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from pals_schema.BaseElement import BaseElement
from pals_schema.ThickElement import ThickElement
Comment on lines 4 to 5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ax3l

I kept the Element suffix for the base element class and the thick element class, because naming them simply Base and Thick sounds a bit odd to me, but let me know if you want to rename those as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that is perfect for the mixin/base classes 👍

from pals_schema.DriftElement import DriftElement
from pals_schema.QuadrupoleElement import QuadrupoleElement
from pals_schema.Drift import Drift
from pals_schema.Quadrupole import Quadrupole


class BeamLine(BaseElement):
Expand All @@ -21,8 +21,8 @@ class BeamLine(BaseElement):
Union[
BaseElement,
ThickElement,
DriftElement,
QuadrupoleElement,
Drift,
Quadrupole,
"BeamLine",
],
Field(discriminator="kind"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .ThickElement import ThickElement


class DriftElement(ThickElement):
class Drift(ThickElement):
"""A field free region"""

# Discriminator field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .MagneticMultipoleParameters import MagneticMultipoleParameters


class QuadrupoleElement(ThickElement):
class Quadrupole(ThickElement):
"""A quadrupole element"""

# Discriminator field
Expand Down
14 changes: 7 additions & 7 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from pals_schema.MagneticMultipoleParameters import MagneticMultipoleParameters
from pals_schema.BaseElement import BaseElement
from pals_schema.ThickElement import ThickElement
from pals_schema.DriftElement import DriftElement
from pals_schema.QuadrupoleElement import QuadrupoleElement
from pals_schema.Drift import Drift
from pals_schema.Quadrupole import Quadrupole
from pals_schema.BeamLine import BeamLine


Expand Down Expand Up @@ -45,11 +45,11 @@ def test_ThickElement():
assert not passed


def test_DriftElement():
def test_Drift():
# Create one drift element with custom name and length
element_name = "drift_element"
element_length = 1.0
element = DriftElement(
element = Drift(
name=element_name,
length=element_length,
)
Expand All @@ -67,7 +67,7 @@ def test_DriftElement():
assert not passed


def test_QuadrupoleElement():
def test_Quadrupole():
# Create one drift element with custom name and length
element_name = "quadrupole_element"
element_length = 1.0
Expand All @@ -85,7 +85,7 @@ def test_QuadrupoleElement():
Bs2=element_magnetic_multipole_Bs2,
tilt2=element_magnetic_multipole_tilt2,
)
element = QuadrupoleElement(
element = Quadrupole(
name=element_name,
length=element_length,
MagneticMultipoleP=element_magnetic_multipole,
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_BeamLine():
line1.line.extend([element2])
assert line1.line == [element1, element2]
# Create second line with one drift element
element3 = DriftElement(name="element3", length=3.0)
element3 = Drift(name="element3", length=3.0)
line2 = BeamLine(name="line2", line=[element3])
# Extend first line with second line
line1.line.extend(line2.line)
Expand Down