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
12 changes: 12 additions & 0 deletions pyaml/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class ConfigModel(BaseModel):
Data folder
arrays : list[ArrayConfig], optional
Element family
description : str , optional
Acceleration description
devices : list[Element]
Element list
"""
Expand All @@ -52,6 +54,7 @@ class ConfigModel(BaseModel):
controls: list[ControlSystem] = None
simulators: list[Simulator] = None
data_folder: str
description: str | None = None
arrays: list[ArrayConfig] = None
devices: list[Element]

Expand Down Expand Up @@ -115,6 +118,12 @@ def post_init(self):
for c in self._cfg.controls:
c.post_init()

def get_description(self) -> str:
"""
Returns the description of the accelerator
"""
return self._cfg.description

@property
def live(self) -> ControlSystem:
return self.__live
Expand All @@ -123,6 +132,9 @@ def live(self) -> ControlSystem:
def design(self) -> Simulator:
return self.__design

def __repr__(self):
return repr(self._cfg).replace("ConfigModel", self.__class__.__name__)

@staticmethod
def from_dict(config_dict: dict, ignore_external=False) -> "Accelerator":
"""
Expand Down
9 changes: 9 additions & 0 deletions pyaml/common/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class ElementConfigModel(BaseModel):
----------
name : str
The name of the PyAML element.
description : str, optional
Description of the element.
lattice_names : str or None, optional
The name(s) of the associated element(s) in the lattice. By default,
the PyAML element name is used. lattice_name accept the following
Expand All @@ -51,6 +53,7 @@ class ElementConfigModel(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True, extra="forbid")

name: str
description: str | None = None
lattice_names: str | None = None


Expand Down Expand Up @@ -82,6 +85,12 @@ def get_lattice_names(self) -> str:
else:
return self._cfg.lattice_names

def get_description(self) -> str:
"""
Returns the description of the element
"""
return self._cfg.description

def set_energy(self, E: float):
"""
Set the instrument energy on this element
Expand Down
9 changes: 9 additions & 0 deletions pyaml/lattice/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class ConfigModel(BaseModel):
AT lattice ring name
linker : LatticeElementsLinker, optional
The linker configuration model
description : str , optional
Simulator description
"""

model_config = ConfigDict(arbitrary_types_allowed=True, extra="forbid")
Expand All @@ -75,6 +77,7 @@ class ConfigModel(BaseModel):
lattice: str
mat_key: str = None
linker: LatticeElementsLinker = None
description: str | None = None


class Simulator(ElementHolder):
Expand Down Expand Up @@ -109,6 +112,12 @@ def name(self) -> str:
def get_lattice(self) -> at.Lattice:
return self.ring

def get_description(self) -> str:
"""
Returns the description of the accelerator
"""
return self._cfg.description

def set_energy(self, E: float):
self.ring.energy = E
# Needed by energy dependant element (i.e. magnet coil current calculation)
Expand Down
3 changes: 3 additions & 0 deletions tests/config/EBSTune.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ type: pyaml.accelerator
facility: ESRF
machine: sr
energy: 6e9
description: "Accelerator configuration for EBS storage ring"
simulators:
- type: pyaml.lattice.simulator
description: "EBS lattice"
lattice: sr/lattices/ebs.mat
name: design
controls:
Expand Down Expand Up @@ -141,6 +143,7 @@ arrays:
- QF1A-C03
devices:
- type: pyaml.magnet.quadrupole
description: "QF1E-C04 quadrupole"
name: QF1E-C04
model:
type: pyaml.magnet.linear_model
Expand Down
9 changes: 8 additions & 1 deletion tests/test_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@


def test_tune():
sr: Accelerator = Accelerator.load("tests/config/EBSTune.yaml", ignore_external=True)
sr: Accelerator = Accelerator.load(
"tests/config/EBSTune.yaml", ignore_external=True
)

assert sr.get_description() == "Accelerator configuration for EBS storage ring"
assert sr.design.get_magnet("QF1E-C04").get_description() == "QF1E-C04 quadrupole"
assert sr.design.get_description() == "EBS lattice"

sr.design.get_lattice().disable_6d()

quadForTuneDesign = sr.design.get_magnets("QForTune")
Expand Down
Loading