Skip to content
Open
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
8 changes: 3 additions & 5 deletions pyaml/arrays/magnet_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,16 @@ def set(self, value: np.array):
nvalue = np.ones(self.__nb) * value if isinstance(value, float) else value
if not self.__aggregator:
# Magnets of a series share one power supply: it is written once, from the strengths of the
# magnets of the series present in the array
# magnets of the series present in the array, the others following the resulting hardware value
series: dict[int, tuple[Magnet, dict[int, float]]] = {}
for idx, m in enumerate(self.__magnets):
if m.model is not None and m.model.shares_power_supply():
series.setdefault(id(m.model), (m, {}))[1][m.strength.index()] = nvalue[idx]
else:
m.strength.set(nvalue[idx])
for m, requested in series.values():
if len(requested) == 1:
m.strength.set(next(iter(requested.values())))
else:
m.hardware.set(m.model.compute_hardware_values_partial(None, requested)[0])
current_hardware = np.array([m.hardware.get()])
m.hardware.set(m.model.compute_hardware_values_partial(current_hardware, requested)[0])
else:
self.__aggregator.set(nvalue)

Expand Down
3 changes: 2 additions & 1 deletion pyaml/control/abstract_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ def add_magnet(self, magnet: Magnet, devs: list[DeviceAccess]):
Hardware devices associated with the magnet model.
"""
# Magnets of a serialized group share the serialized model (one power supply for N strengths):
# the power-supply current is computed by the model from the strengths of the magnets present in the array.
# the power-supply current is computed by the model from the strengths of the magnets present in the array,
# the others following the resulting current.
is_indexed = isinstance(magnet.strength, (abstract.RWMapper, RWSerializedStrengthScalar))
strengthIndex = magnet.strength.index() if is_indexed else 0
if magnet.model not in self.__models:
Expand Down
4 changes: 2 additions & 2 deletions pyaml/lattice/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ def _fill_serialized_magnets(self, magnets: SerializedMagnets) -> None:
strengths = []
for index, magnet in enumerate(magnets.get_magnets()):
current = (
RWHardwareScalar(self.get_at_elems(magnet), magnets.polynom, magnets.model.get_sub_model(index))
RWHardwareScalar(self.get_at_elems(magnet), magnets.polynoms[index], magnets.model.get_sub_model(index))
if magnets.model.has_hardware()
else None
)
strength = (
RWStrengthScalar(self.get_at_elems(magnet), magnets.polynom, magnets.model.get_sub_model(index))
RWStrengthScalar(self.get_at_elems(magnet), magnets.polynoms[index], magnets.model.get_sub_model(index))
if magnets.model.has_physics()
else None
)
Expand Down
254 changes: 226 additions & 28 deletions pyaml/magnet/linear_serialized_model.py

Large diffs are not rendered by default.

Loading
Loading