diff --git a/examples/ESRF_ORM_example/correct_orbit.py b/examples/ESRF_ORM_example/correct_orbit.py index 0a856681..f29b2a47 100644 --- a/examples/ESRF_ORM_example/correct_orbit.py +++ b/examples/ESRF_ORM_example/correct_orbit.py @@ -29,22 +29,15 @@ np.random.seed(1) # mangle orbit -hcorr.strengths.set( - hcorr.strengths.get() + std_kick * np.random.normal(size=len(hcorr)) -) -vcorr.strengths.set( - vcorr.strengths.get() + std_kick * np.random.normal(size=len(vcorr)) -) +hcorr.strengths.set(hcorr.strengths.get() + std_kick * np.random.normal(size=len(hcorr))) +vcorr.strengths.set(vcorr.strengths.get() + std_kick * np.random.normal(size=len(vcorr))) h0 = hcorr.strengths.get() v0 = vcorr.strengths.get() positions_bc = bpms.positions.get() std_bc = np.std(positions_bc, axis=0) -print( - "R.m.s. orbit before correction " - f"H: {1e6 * std_bc[0]: .1f} µm, V: {1e6 * std_bc[1]: .1f} µm." -) +print(f"R.m.s. orbit before correction H: {1e6 * std_bc[0]: .1f} µm, V: {1e6 * std_bc[1]: .1f} µm.") ######################################################## ebs.orbit.set_virtual_weight(1000) @@ -57,10 +50,7 @@ ## inspect orbit correction positions_ac = bpms.positions.get() std_ac = np.std(positions_ac, axis=0) -print( - "R.m.s. orbit after correction H: " - f"{1e6 * std_ac[0]: .1f} µm, V: {1e6 * std_ac[1]: .1f} µm," -) +print(f"R.m.s. orbit after correction H: {1e6 * std_ac[0]: .1f} µm, V: {1e6 * std_ac[1]: .1f} µm,") fig = plt.figure() ax1 = fig.add_subplot(311) diff --git a/examples/ESRF_ORM_example/correct_orbit_disp.py b/examples/ESRF_ORM_example/correct_orbit_disp.py index 360caec1..ec366d38 100644 --- a/examples/ESRF_ORM_example/correct_orbit_disp.py +++ b/examples/ESRF_ORM_example/correct_orbit_disp.py @@ -32,19 +32,12 @@ bpms = ebs.get_bpms("BPM") # mangle orbit -hcorr.strengths.set( - hcorr.strengths.get() + std_kick * np.random.normal(size=len(hcorr)) -) -vcorr.strengths.set( - vcorr.strengths.get() + std_kick * np.random.normal(size=len(vcorr)) -) +hcorr.strengths.set(hcorr.strengths.get() + std_kick * np.random.normal(size=len(hcorr))) +vcorr.strengths.set(vcorr.strengths.get() + std_kick * np.random.normal(size=len(vcorr))) positions_bc = bpms.positions.get() std_bc = np.std(positions_bc, axis=0) -print( - "R.m.s. orbit before correction " - f"H: {1e6 * std_bc[0]: .1f} µm, V: {1e6 * std_bc[1]: .1f} µm." -) +print(f"R.m.s. orbit before correction H: {1e6 * std_bc[0]: .1f} µm, V: {1e6 * std_bc[1]: .1f} µm.") ######################################################## ## Correct the orbit @@ -58,10 +51,7 @@ ## inspect orbit correction positions_ac = bpms.positions.get() std_ac = np.std(positions_ac, axis=0) -print( - "R.m.s. orbit after correction H: " - f"{1e6 * std_ac[0]: .1f} µm, V: {1e6 * std_ac[1]: .1f} µm," -) +print(f"R.m.s. orbit after correction H: {1e6 * std_ac[0]: .1f} µm, V: {1e6 * std_ac[1]: .1f} µm,") fig = plt.figure() ax1 = fig.add_subplot(311) diff --git a/examples/ESRF_ORM_example/measure_dispersion.py b/examples/ESRF_ORM_example/measure_dispersion.py index 2e1960ac..90a3111e 100644 --- a/examples/ESRF_ORM_example/measure_dispersion.py +++ b/examples/ESRF_ORM_example/measure_dispersion.py @@ -8,9 +8,7 @@ from pyaml.tuning_tools.dispersion import Dispersion parent_folder = Path(__file__).parent -config_path = parent_folder.parent.parent.joinpath( - "tests", "config", "EBSOrbit.yaml" -).resolve() +config_path = parent_folder.parent.parent.joinpath("tests", "config", "EBSOrbit.yaml").resolve() sr = Accelerator.load(config_path) ebs = sr.design diff --git a/examples/ESRF_ORM_example/measure_reduced_ORM.py b/examples/ESRF_ORM_example/measure_reduced_ORM.py index 97159fff..ad7bc1bb 100644 --- a/examples/ESRF_ORM_example/measure_reduced_ORM.py +++ b/examples/ESRF_ORM_example/measure_reduced_ORM.py @@ -9,14 +9,10 @@ from pyaml.tuning_tools.orbit_response_matrix import OrbitResponseMatrix # disable printing during ORM measurement to illustrate callback. -logger = logging.getLogger("pyaml.tuning_tools.orbit_response_matrix").setLevel( - logging.WARNING -) +logger = logging.getLogger("pyaml.tuning_tools.orbit_response_matrix").setLevel(logging.WARNING) parent_folder = Path(__file__).parent -config_path = parent_folder.parent.parent.joinpath( - "tests", "config", "EBSOrbit.yaml" -).resolve() +config_path = parent_folder.parent.parent.joinpath("tests", "config", "EBSOrbit.yaml").resolve() sr = Accelerator.load(config_path) ebs = sr.design orm = ebs.orm diff --git a/examples/ESRF_tune_example/esrf_tune_example_no_yaml.py b/examples/ESRF_tune_example/esrf_tune_example_no_yaml.py index 4b385bf3..0296b04f 100644 --- a/examples/ESRF_tune_example/esrf_tune_example_no_yaml.py +++ b/examples/ESRF_tune_example/esrf_tune_example_no_yaml.py @@ -97,9 +97,7 @@ names.append(cfg["name"]) -simulator = Simulator( - SimulatorConfigModel(name="design", lattice="config/sr/lattices/ebs.mat") -) +simulator = Simulator(SimulatorConfigModel(name="design", lattice="config/sr/lattices/ebs.mat")) quads = Magnet(MagnetArrayConfigModel(name="quadsForTune", elements=names)) @@ -142,12 +140,8 @@ # we directly connect to th CS qxAtt, qyAtt = control.attach( [ - AttributeReadOnly( - AttributeReadOnlyConfig(attribute="sys/ringsimulator/ebs/Tune_h", unit="") - ), - AttributeReadOnly( - AttributeReadOnlyConfig(attribute="sys/ringsimulator/ebs/Tune_v", unit="") - ), + AttributeReadOnly(AttributeReadOnlyConfig(attribute="sys/ringsimulator/ebs/Tune_h", unit="")), + AttributeReadOnly(AttributeReadOnlyConfig(attribute="sys/ringsimulator/ebs/Tune_v", unit="")), ] ) diff --git a/examples/SOLEIL_examples/01-SOLEIL_II_tune_example.ipynb b/examples/SOLEIL_examples/01-SOLEIL_II_tune_example.ipynb index 8fa8de61..32008104 100644 --- a/examples/SOLEIL_examples/01-SOLEIL_II_tune_example.ipynb +++ b/examples/SOLEIL_examples/01-SOLEIL_II_tune_example.ipynb @@ -725,9 +725,7 @@ "print(f\"Tune after correction {tune_monitor.tune.get()}\")\n", "qcorrectors.strengths.set(old_strength_values)\n", "sleep(3)\n", - "print(\n", - " f\"Tune setting the tune back to original value correction {tune_monitor.tune.get()}\"\n", - ")" + "print(f\"Tune setting the tune back to original value correction {tune_monitor.tune.get()}\")" ] } ], diff --git a/examples/SOLEIL_examples/02-chromaticity_measurement.ipynb b/examples/SOLEIL_examples/02-chromaticity_measurement.ipynb index c5d43d01..8c588537 100644 --- a/examples/SOLEIL_examples/02-chromaticity_measurement.ipynb +++ b/examples/SOLEIL_examples/02-chromaticity_measurement.ipynb @@ -103,9 +103,7 @@ } ], "source": [ - "chromaticity_measurement = control_mode.get_chromaticity_monitor(\n", - " \"DEFAULT_CHROMATICITY_MEASUREMENT\"\n", - ")\n", + "chromaticity_measurement = control_mode.get_chromaticity_monitor(\"DEFAULT_CHROMATICITY_MEASUREMENT\")\n", "chromaticity_measurement" ] }, diff --git a/pyaml/arrays/cfm_magnet_array.py b/pyaml/arrays/cfm_magnet_array.py index 00446f75..539b6de5 100644 --- a/pyaml/arrays/cfm_magnet_array.py +++ b/pyaml/arrays/cfm_magnet_array.py @@ -106,11 +106,7 @@ def __init__( self.__rwhardwares = RWMagnetHardwares(arrayName, magnets) if use_aggregator: - raise ( - PyAMLException( - "Aggregator not implemented for CombinedFunctionMagnetArray" - ) - ) + raise (PyAMLException("Aggregator not implemented for CombinedFunctionMagnetArray")) @property def strengths(self) -> RWMagnetStrengths: diff --git a/pyaml/arrays/element_array.py b/pyaml/arrays/element_array.py index 8a3a4770..8ffae693 100644 --- a/pyaml/arrays/element_array.py +++ b/pyaml/arrays/element_array.py @@ -113,9 +113,7 @@ def __ensure_compatible_operand(self, other: object) -> "ElementArray": if len(self) > 0 and len(other) > 0: if self.get_peer() is not None and other.get_peer() is not None: if self.get_peer() != other.get_peer(): - raise PyAMLException( - f"{self.__class__.__name__}: cannot operate on arrays attached to different peers" - ) + raise PyAMLException(f"{self.__class__.__name__}: cannot operate on arrays attached to different peers") return other def __auto_array(self, elements: list[Element]): diff --git a/pyaml/common/element_holder.py b/pyaml/common/element_holder.py index 4898d11c..0d34d17e 100644 --- a/pyaml/common/element_holder.py +++ b/pyaml/common/element_holder.py @@ -123,17 +123,13 @@ def fill_array( except Exception as err: raise PyAMLException(f"{constructor.__name__} {array_name} : {err} @index {len(a)}") from None if m in a: - raise PyAMLException( - f"{constructor.__name__} {array_name} : duplicate name {name} @index {len(a)}" - ) from None + raise PyAMLException(f"{constructor.__name__} {array_name} : duplicate name {name} @index {len(a)}") from None a.append(m) ARR[array_name] = constructor(array_name, a) def __add(self, array, element: Element): if element.get_name() in self.__ALL: # Ensure name unicity - raise PyAMLException( - f"Duplicate element {element.__class__.__name__} name {{element.get_name()}}" - ) from None + raise PyAMLException(f"Duplicate element {element.__class__.__name__} name {{element.get_name()}}") from None array[element.get_name()] = element self.__ALL[element.get_name()] = element diff --git a/pyaml/configuration/csvcurve.py b/pyaml/configuration/csvcurve.py index fadb0a45..ef8352d3 100644 --- a/pyaml/configuration/csvcurve.py +++ b/pyaml/configuration/csvcurve.py @@ -39,16 +39,11 @@ def __init__(self, cfg: ConfigModel): try: self._curve = np.genfromtxt(path, delimiter=",", dtype=float, loose=False) except ValueError as e: - raise PyAMLException( - f"CSVCurve(file='{cfg.file}',dtype=float): {str(e)}" - ) from None + raise PyAMLException(f"CSVCurve(file='{cfg.file}',dtype=float): {str(e)}") from None _s = np.shape(self._curve) if len(_s) != 2 or _s[1] != 2: - raise PyAMLException( - f"CSVCurve(file='{cfg.file}',dtype=float):" - f"wrong shape (2,2) expected but got {str(_s)}" - ) + raise PyAMLException(f"CSVCurve(file='{cfg.file}',dtype=float):wrong shape (2,2) expected but got {str(_s)}") def get_curve(self) -> np.array: """ diff --git a/pyaml/configuration/csvmatrix.py b/pyaml/configuration/csvmatrix.py index daed97f8..993cec99 100644 --- a/pyaml/configuration/csvmatrix.py +++ b/pyaml/configuration/csvmatrix.py @@ -38,9 +38,7 @@ def __init__(self, cfg: ConfigModel): try: self._mat = np.genfromtxt(path, delimiter=",", dtype=float, loose=False) except ValueError as e: - raise PyAMLException( - f"CSVMatrix(file='{cfg.file}',dtype=float): {str(e)}" - ) from None + raise PyAMLException(f"CSVMatrix(file='{cfg.file}',dtype=float): {str(e)}") from None def get_matrix(self) -> np.array: """ diff --git a/pyaml/configuration/factory.py b/pyaml/configuration/factory.py index 08edf4a7..8078a310 100644 --- a/pyaml/configuration/factory.py +++ b/pyaml/configuration/factory.py @@ -131,9 +131,7 @@ def build_object(self, d: dict, ignore_external: bool = False): obj = elem_cls(cfg) self.register_element(obj) except Exception as e: - raise PyAMLConfigException( - f"{str(e)} when creating '{module.__name__}.{class_str}' {location_str}" - ) from e + raise PyAMLConfigException(f"{str(e)} when creating '{module.__name__}.{class_str}' {location_str}") from e else: # Delayed construction @@ -200,9 +198,7 @@ def depth_first_build(self, d, ignore_external: bool): # We are now on leaf (no nested object), we can construct return self.build_object(d, ignore_external) - raise PyAMLConfigException( - "Unexpected element found. 'dict' or 'list' expected but got '{d.__class__.__name__}'" - ) + raise PyAMLConfigException("Unexpected element found. 'dict' or 'list' expected but got '{d.__class__.__name__}'") def register_element(self, elt): if isinstance(elt, Element): diff --git a/pyaml/configuration/fileloader.py b/pyaml/configuration/fileloader.py index d4a8e81e..9aa652a7 100644 --- a/pyaml/configuration/fileloader.py +++ b/pyaml/configuration/fileloader.py @@ -58,9 +58,7 @@ class PyAMLConfigCyclingException(PyAMLException): def __init__(self, error_filename: str, path_stack: list[Path]): self.error_filename = error_filename parent_file_stack = [parent_path.name for parent_path in path_stack] - super().__init__( - f"Circular file inclusion of {error_filename}. File list before reaching it: {parent_file_stack}" - ) + super().__init__(f"Circular file inclusion of {error_filename}. File list before reaching it: {parent_file_stack}") pass @@ -115,9 +113,7 @@ def expand_dict(self, d: dict): location = field_locations[key] file, line, col = location location_str = f" in {file} at line {line}, column {col}" - raise PyAMLException( - f"Circular file inclusion of {pyaml_ex.error_filename}{location_str}" - ) from pyaml_ex + raise PyAMLException(f"Circular file inclusion of {pyaml_ex.error_filename}{location_str}") from pyaml_ex # Recursively expand a list def expand_list(self, l: list): diff --git a/pyaml/configuration/inline_curve.py b/pyaml/configuration/inline_curve.py index e92071ab..a9de9f99 100644 --- a/pyaml/configuration/inline_curve.py +++ b/pyaml/configuration/inline_curve.py @@ -38,9 +38,7 @@ def __init__(self, cfg: ConfigModel): _s = np.shape(self._curve) if len(_s) != 2 or _s[1] != 2: - raise PyAMLException( - f"InlineCurve(mat='{cfg.mat}',dtype=float): wrong shape (2,2) expected but got {str(_s)}" - ) + raise PyAMLException(f"InlineCurve(mat='{cfg.mat}',dtype=float): wrong shape (2,2) expected but got {str(_s)}") def get_curve(self) -> np.array: """ diff --git a/pyaml/configuration/manager.py b/pyaml/configuration/manager.py index 3ebfee09..1d451113 100644 --- a/pyaml/configuration/manager.py +++ b/pyaml/configuration/manager.py @@ -106,9 +106,7 @@ def root_fields(cls) -> tuple[str, ...]: def __init__(self): self._state: dict[str, Any] = {"type": self.DEFAULT_TYPE} - self._items_by_category: dict[str, dict[str, dict[str, Any]]] = { - category: {} for category in self.NAMED_CATEGORIES - } + self._items_by_category: dict[str, dict[str, dict[str, Any]]] = {category: {} for category in self.NAMED_CATEGORIES} self._sources_by_category: dict[str, dict[str, str]] = {category: {} for category in self.NAMED_CATEGORIES} self._field_sources: dict[str, str] = {} self._build_root: SourceRoot = get_root_folder() @@ -297,11 +295,7 @@ def categories(self) -> list[str]: >>> manager.categories() """ - return [ - category - for category in self.NAMED_CATEGORIES - if self._state.get(category) and len(self._state[category]) > 0 - ] + return [category for category in self.NAMED_CATEGORIES if self._state.get(category) and len(self._state[category]) > 0] def keys(self, category: str | None = None) -> list[str]: r""" @@ -450,9 +444,7 @@ def settings(self) -> dict[str, Any]: extra_fields = [ field for field in self._state.keys() - if field not in self.NAMED_CATEGORIES - and field not in ordered_fields - and field not in _INTERNAL_METADATA_KEYS + if field not in self.NAMED_CATEGORIES and field not in ordered_fields and field not in _INTERNAL_METADATA_KEYS ] for field in ordered_fields + extra_fields: settings[field] = copy.deepcopy(self._state[field]) @@ -553,8 +545,7 @@ def __getattr__(self, name): return self.get(categories[0], name) if len(categories) > 1: raise AttributeError( - f"ConfigurationManager key '{name}' is ambiguous across categories {categories}. " - "Use get(category, name)." + f"ConfigurationManager key '{name}' is ambiguous across categories {categories}. Use get(category, name)." ) raise AttributeError(f"'ConfigurationManager' object has no attribute '{name}'") @@ -810,9 +801,7 @@ def _describe_entry_source(self, entry: dict[str, Any], fallback_source: str) -> def _coerce_path(self, payload) -> str: if isinstance(payload, (str, os.PathLike)): return os.fspath(payload) - raise PyAMLConfigException( - f"Cannot infer configuration source from payload of type '{type(payload).__name__}'." - ) + raise PyAMLConfigException(f"Cannot infer configuration source from payload of type '{type(payload).__name__}'.") def _extend_unique(self, target: list[str], values) -> None: for value in values: diff --git a/pyaml/control/readback_value.py b/pyaml/control/readback_value.py index 004a8ee9..207641c3 100644 --- a/pyaml/control/readback_value.py +++ b/pyaml/control/readback_value.py @@ -69,10 +69,7 @@ def __repr__(self): str Human-readable representation. """ - return ( - f"Value({self.value}, quality='{self.quality}'," - + f"timestamp='{self.timestamp}')" - ) + return f"Value({self.value}, quality='{self.quality}'," + f"timestamp='{self.timestamp}')" def __float__(self): """ diff --git a/pyaml/lattice/attribute_linker.py b/pyaml/lattice/attribute_linker.py index 820b8c97..793726f1 100644 --- a/pyaml/lattice/attribute_linker.py +++ b/pyaml/lattice/attribute_linker.py @@ -79,12 +79,8 @@ def get_element_identifier(self, element: Element) -> LinkerIdentifier: LinkerIdentifier The identifier for linking the element """ - return PyAtAttributeIdentifier( - self.linker_config_model.attribute_name, element.get_name() - ) + return PyAtAttributeIdentifier(self.linker_config_model.attribute_name, element.get_name()) - def _test_at_element( - self, identifier: PyAtAttributeIdentifier, element: at.Element - ) -> bool: + def _test_at_element(self, identifier: PyAtAttributeIdentifier, element: at.Element) -> bool: attr_value = getattr(element, identifier.attribute_name, None) return attr_value == identifier.identifier diff --git a/pyaml/lattice/lattice_elements_linker.py b/pyaml/lattice/lattice_elements_linker.py index 68b40da1..de83cf33 100644 --- a/pyaml/lattice/lattice_elements_linker.py +++ b/pyaml/lattice/lattice_elements_linker.py @@ -75,9 +75,7 @@ def set_lattice(self, lattice: Lattice): self.lattice = lattice @abstractmethod - def _test_at_element( - self, identifier: LinkerIdentifier, element: at.Element - ) -> bool: + def _test_at_element(self, identifier: LinkerIdentifier, element: at.Element) -> bool: pass @abstractmethod @@ -103,9 +101,7 @@ def _iter_matches(self, identifier: LinkerIdentifier) -> Iterable[at.Element]: if self._test_at_element(identifier, elem): yield elem - def get_at_elements( - self, element_id: LinkerIdentifier | list[LinkerIdentifier] - ) -> list[at.Element]: + def get_at_elements(self, element_id: LinkerIdentifier | list[LinkerIdentifier]) -> list[at.Element]: """Return a list of PyAT elements matching the given identifiers. This method should resolve one or multiple PyAML identifiers @@ -138,10 +134,7 @@ def get_at_elements( results.extend(self._iter_matches(ident)) if not results: - raise PyAMLException( - f"No PyAT elements found for identifier(s): " - f"{', '.join(i.__repr__() for i in identifiers)}" - ) + raise PyAMLException(f"No PyAT elements found for identifier(s): {', '.join(i.__repr__() for i in identifiers)}") return results def get_at_element(self, element_id: LinkerIdentifier) -> at.Element: @@ -164,6 +157,4 @@ def get_at_element(self, element_id: LinkerIdentifier) -> at.Element: """ for elem in self._iter_matches(element_id): return elem - raise PyAMLException( - f"No PyAT element found for FamName: {element_id.__repr__()}" - ) + raise PyAMLException(f"No PyAT element found for FamName: {element_id.__repr__()}") diff --git a/pyaml/lattice/simulator.py b/pyaml/lattice/simulator.py index db2f4d13..a877588a 100644 --- a/pyaml/lattice/simulator.py +++ b/pyaml/lattice/simulator.py @@ -145,9 +145,7 @@ def fill_device(self, elements: list[Element]): elif isinstance(e, CombinedFunctionMagnet): currents = RWHardwareArray(self.get_at_elems(e), e.polynoms, e.model) if e.model.has_physics() else None - strengths = ( - RWStrengthArray(self.get_at_elems(e), e.polynoms, e.model) if e.model.has_physics() else None - ) + strengths = RWStrengthArray(self.get_at_elems(e), e.polynoms, e.model) if e.model.has_physics() else None # Create unique refs of each function for this simulator ms = e.attach(self, strengths, currents) self.add_cfm_magnet(ms[0]) @@ -212,9 +210,7 @@ def fill_device(self, elements: list[Element]): # Expect unique name for cavities cav = self.get_at_elems(Element(c)) if len(cav) > 1: - raise PyAMLException( - f"RF transmitter {t.get_name()},multiple cavity definition:{{cav[0]}}" - ) + raise PyAMLException(f"RF transmitter {t.get_name()},multiple cavity definition:{{cav[0]}}") if len(cav) == 0: raise PyAMLException(f"RF transmitter {t.get_name()}, No cavity found") cavsPerTrans.append(cav[0]) diff --git a/pyaml/magnet/cfm_magnet.py b/pyaml/magnet/cfm_magnet.py index 9249a6c8..957c0e19 100644 --- a/pyaml/magnet/cfm_magnet.py +++ b/pyaml/magnet/cfm_magnet.py @@ -53,23 +53,16 @@ def __init__(self, cfg: ConfigModel, peer=None): if peer is None: # Configuration part if self.model is not None and not hasattr(self.model._cfg, "multipoles"): - raise PyAMLException( - f"{cfg.name} model: mutipoles" - "field required for combined function magnet" - ) + raise PyAMLException(f"{cfg.name} model: mutipolesfield required for combined function magnet") idx = 0 self.polynoms = [] for _idx, m in enumerate(cfg.mapping): # Check mapping validity if len(m) != 2: - raise PyAMLException( - "Invalid CombinedFunctionMagnet mapping for {m}" - ) + raise PyAMLException("Invalid CombinedFunctionMagnet mapping for {m}") if m[0] not in _fmap: - raise PyAMLException( - m[0] + " not implemented for combined function magnet" - ) + raise PyAMLException(m[0] + " not implemented for combined function magnet") if m[0] not in self.model._cfg.multipoles: raise PyAMLException(m[0] + " not found in underlying magnet model") self.polynoms.append(_fmap[m[0]].polynom) @@ -127,9 +120,7 @@ def strengths(self) -> abstract.ReadWriteFloatScalar: """ self.check_peer() if self.__strengths is None: - raise PyAMLException( - f"{str(self)} has no model that supports physics units" - ) + raise PyAMLException(f"{str(self)} has no model that supports physics units") return self.__strengths @property @@ -140,9 +131,7 @@ def hardwares(self) -> abstract.ReadWriteFloatScalar: """ self.check_peer() if self.__hardwares is None: - raise PyAMLException( - f"{str(self)} has no model that supports hardware units" - ) + raise PyAMLException(f"{str(self)} has no model that supports hardware units") return self.__hardwares def set_energy(self, E: float): diff --git a/pyaml/magnet/identity_cfm_model.py b/pyaml/magnet/identity_cfm_model.py index 1b4a6bd3..8333b3b1 100644 --- a/pyaml/magnet/identity_cfm_model.py +++ b/pyaml/magnet/identity_cfm_model.py @@ -46,14 +46,10 @@ def __init__(self, cfg: ConfigModel): self.__nbFunction: int = len(cfg.multipoles) if cfg.physics is None and cfg.powerconverters is None: - raise PyAMLException( - "Invalid IdentityCFMagnetModel configuration," - "physics or powerconverters device required" - ) + raise PyAMLException("Invalid IdentityCFMagnetModel configuration,physics or powerconverters device required") if cfg.physics is not None and cfg.powerconverters is not None: raise PyAMLException( - "Invalid IdentityCFMagnetModel configuration," - "physics or powerconverters device required but not both" + "Invalid IdentityCFMagnetModel configuration,physics or powerconverters device required but not both" ) if cfg.physics: self.__devices = cfg.physics @@ -68,8 +64,7 @@ def __check_len(self, obj, name, expected_len): lgth = len(obj) if lgth != expected_len: raise PyAMLException( - f"{name} does not have the expected " - f"number of items ({expected_len} items expected but got {lgth})" + f"{name} does not have the expected number of items ({expected_len} items expected but got {lgth})" ) def compute_hardware_values(self, strengths: np.array) -> np.array: diff --git a/pyaml/magnet/identity_model.py b/pyaml/magnet/identity_model.py index 132fff1f..9692de6d 100644 --- a/pyaml/magnet/identity_model.py +++ b/pyaml/magnet/identity_model.py @@ -40,14 +40,10 @@ def __init__(self, cfg: ConfigModel): self._cfg = cfg self.__unit = cfg.unit if cfg.physics is None and cfg.powerconverter is None: - raise PyAMLException( - "Invalid IdentityMagnetModel configuration," - "physics or powerconverter device required" - ) + raise PyAMLException("Invalid IdentityMagnetModel configuration,physics or powerconverter device required") if cfg.physics is not None and cfg.powerconverter is not None: raise PyAMLException( - "Invalid IdentityMagnetModel configuration," - "physics or powerconverter device required but not both" + "Invalid IdentityMagnetModel configuration,physics or powerconverter device required but not both" ) if cfg.physics: self.__device = cfg.physics diff --git a/pyaml/magnet/linear_cfm_model.py b/pyaml/magnet/linear_cfm_model.py index 6ddc5421..c1795c12 100644 --- a/pyaml/magnet/linear_cfm_model.py +++ b/pyaml/magnet/linear_cfm_model.py @@ -92,12 +92,8 @@ def __init__(self, cfg: ConfigModel): else: self.__po = cfg.pseudo_factors - self.__check_len( - self.__calibration_factors, "calibration_factors", self.__nbFunction - ) - self.__check_len( - self.__calibration_offsets, "calibration_offsets", self.__nbFunction - ) + self.__check_len(self.__calibration_factors, "calibration_factors", self.__nbFunction) + self.__check_len(self.__calibration_offsets, "calibration_offsets", self.__nbFunction) self.__check_len(self.__pf, "pseudo_factors", self.__nbFunction) self.__check_len(self.__po, "pseudo_offsets", self.__nbFunction) self.__check_len(cfg.units, "units", self.__nbFunction) @@ -112,8 +108,7 @@ def __init__(self, cfg: ConfigModel): if len(_s) != 2 or _s[0] != self.__nbFunction or _s[1] != self.__nbPS: raise PyAMLException( - "matrix wrong dimension " - f"({self.__nbFunction}x{self.__nbPS} expected but got {_s[0]}x{_s[1]})" + f"matrix wrong dimension ({self.__nbFunction}x{self.__nbPS} expected but got {_s[0]}x{_s[1]})" ) self.__curves = [] @@ -133,18 +128,13 @@ def __check_len(self, obj, name, expected_len): lgth = len(obj) if lgth != expected_len: raise PyAMLException( - f"{name} does not have the expected " - f"number of items ({expected_len} items expected but got {lgth})" + f"{name} does not have the expected number of items ({expected_len} items expected but got {lgth})" ) def compute_hardware_values(self, strengths: np.array) -> np.array: _pI = np.zeros(self.__nbFunction) for idx, c in enumerate(self.__rcurves): - _pI[idx] = ( - self.__pf[idx] - * np.interp(strengths[idx] * self._brho, c[:, 0], c[:, 1]) - + self.__po[idx] - ) + _pI[idx] = self.__pf[idx] * np.interp(strengths[idx] * self._brho, c[:, 0], c[:, 1]) + self.__po[idx] _currents = np.matmul(self.__inv, _pI) return _currents @@ -152,12 +142,7 @@ def compute_strengths(self, currents: np.array) -> np.array: _strength = np.zeros(self.__nbFunction) _pI = np.matmul(self.__matrix, currents) for idx, c in enumerate(self.__curves): - _strength[idx] = ( - np.interp( - (_pI[idx] - self.__po[idx]) / self.__pf[idx], c[:, 0], c[:, 1] - ) - / self._brho - ) + _strength[idx] = np.interp((_pI[idx] - self.__po[idx]) / self.__pf[idx], c[:, 0], c[:, 1]) / self._brho return _strength def get_strength_units(self) -> list[str]: @@ -173,9 +158,7 @@ def set_magnet_rigidity(self, brho: np.double): self._brho = brho def has_hardware(self) -> bool: - return (self.__nbPS == self.__nbFunction) and np.allclose( - self.__matrix, np.eye(self.__nbFunction) - ) + return (self.__nbPS == self.__nbFunction) and np.allclose(self.__matrix, np.eye(self.__nbFunction)) def __repr__(self): return __pyaml_repr__(self) diff --git a/pyaml/magnet/linear_model.py b/pyaml/magnet/linear_model.py index 44e182bc..ac9b57e0 100644 --- a/pyaml/magnet/linear_model.py +++ b/pyaml/magnet/linear_model.py @@ -52,10 +52,7 @@ def __init__(self, cfg: ConfigModel): self._cfg = cfg if self._cfg.curve: self.__curve = cfg.curve.get_curve() - self.__curve[:, 1] = ( - self.__curve[:, 1] * cfg.calibration_factor * cfg.crosstalk - + cfg.calibration_offset - ) + self.__curve[:, 1] = self.__curve[:, 1] * cfg.calibration_factor * cfg.crosstalk + cfg.calibration_offset self.__rcurve = Curve.inverse(self.__curve) else: self.__curve = None @@ -69,19 +66,14 @@ def __init__(self, cfg: ConfigModel): def compute_hardware_values(self, strengths: np.array) -> np.array: if self.__rcurve is not None: - _current = np.interp( - strengths[0] * self.__brho, self.__rcurve[:, 0], self.__rcurve[:, 1] - ) + _current = np.interp(strengths[0] * self.__brho, self.__rcurve[:, 0], self.__rcurve[:, 1]) else: _current = (strengths[0] * self.__brho) / self.__g + self.__o return np.array([_current]) def compute_strengths(self, currents: np.array) -> np.array: if self.__curve is not None: - _strength = ( - np.interp(currents[0], self.__curve[:, 0], self.__curve[:, 1]) - / self.__brho - ) + _strength = np.interp(currents[0], self.__curve[:, 0], self.__curve[:, 1]) / self.__brho else: _strength = ((currents[0] - self.__o) * self.__g) / self.__brho return np.array([_strength]) diff --git a/pyaml/magnet/linear_serialized_model.py b/pyaml/magnet/linear_serialized_model.py index cfae4bb3..77eef97b 100644 --- a/pyaml/magnet/linear_serialized_model.py +++ b/pyaml/magnet/linear_serialized_model.py @@ -75,8 +75,7 @@ def _check_len(obj, name, expected_length): length = len(obj) if length != expected_length: raise PyAMLException( - f"{name} does not have the expected " - f"number of items ({expected_length} items expected but got {length})" + f"{name} does not have the expected number of items ({expected_length} items expected but got {length})" ) @@ -92,9 +91,7 @@ def __init__(self, cfg: ConfigModel): self.__brho = np.nan # Check config - self.__nbMagnets: int = _get_max_length( - cfg.curves, cfg.calibration_factors, cfg.calibration_offsets, cfg.crosstalk - ) + self.__nbMagnets: int = _get_max_length(cfg.curves, cfg.calibration_factors, cfg.calibration_offsets, cfg.crosstalk) self.__calibration_factors = np.ones(self.__nbMagnets) self.__calibration_offsets = np.ones(self.__nbMagnets) self.__crosstalk = np.ones(self.__nbMagnets) @@ -105,16 +102,12 @@ def __initialize(self): if self._cfg.calibration_factors is None: self.__calibration_factors = np.ones(self.__nbMagnets) else: - self.__calibration_factors = _to_list_of_length( - self._cfg.calibration_factors, self.__nbMagnets - ) + self.__calibration_factors = _to_list_of_length(self._cfg.calibration_factors, self.__nbMagnets) if self._cfg.calibration_offsets is None: self.__calibration_offsets = np.zeros(self.__nbMagnets) else: - self.__calibration_offsets = _to_list_of_length( - self._cfg.calibration_offsets, self.__nbMagnets - ) + self.__calibration_offsets = _to_list_of_length(self._cfg.calibration_offsets, self.__nbMagnets) if self._cfg.crosstalk is None: self.__crosstalk = np.zeros(self.__nbMagnets) @@ -155,18 +148,12 @@ def get_sub_model(self, index: int) -> LinearMagnetModel: def compute_hardware_values(self, strengths: np.array) -> np.array: return np.array( - [ - model.compute_hardware_values([strength]) - for strength, model in zip(strengths, self.__sub_models) - ] + [model.compute_hardware_values([strength]) for strength, model in zip(strengths, self.__sub_models, strict=True)] ) def compute_strengths(self, currents: np.array) -> np.array: return np.array( - [ - model.compute_strengths([current]) - for current, model in zip(currents, self.__sub_models) - ] + [model.compute_strengths([current]) for current, model in zip(currents, self.__sub_models, strict=True)] ) def get_strength_units(self) -> list[str]: diff --git a/pyaml/magnet/model.py b/pyaml/magnet/model.py index cce2bfdc..4b48c546 100644 --- a/pyaml/magnet/model.py +++ b/pyaml/magnet/model.py @@ -13,9 +13,7 @@ class MagnetModel(metaclass=ABCMeta): """ @abstractmethod - def compute_hardware_values( - self, strengths: npt.NDArray[np.float64] - ) -> npt.NDArray[np.float64]: + def compute_hardware_values(self, strengths: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]: """ Compute hardware value(s) from magnet strength(s) @@ -33,9 +31,7 @@ def compute_hardware_values( pass @abstractmethod - def compute_strengths( - self, hardware_values: npt.NDArray[np.float64] - ) -> npt.NDArray[np.float64]: + def compute_strengths(self, hardware_values: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]: """ Compute magnet strength(s) from hardware value(s) diff --git a/pyaml/magnet/spline_model.py b/pyaml/magnet/spline_model.py index 2f589753..bc6d20d3 100644 --- a/pyaml/magnet/spline_model.py +++ b/pyaml/magnet/spline_model.py @@ -54,18 +54,13 @@ class SplineMagnetModel(MagnetModel): def __init__(self, cfg: ConfigModel): self._cfg = cfg self.__curve = cfg.curve.get_curve() - self.__curve[:, 1] = ( - self.__curve[:, 1] * cfg.calibration_factor * cfg.crosstalk - + cfg.calibration_offset - ) + self.__curve[:, 1] = self.__curve[:, 1] * cfg.calibration_factor * cfg.crosstalk + cfg.calibration_offset rcurve = Curve.inverse(self.__curve) self.__strength_unit = cfg.unit self.__hardware_unit = cfg.powerconverter.unit() self.__brho = np.nan self.__ps = cfg.powerconverter - self.__spl = make_smoothing_spline( - self.__curve[:, 0], self.__curve[:, 1], lam=cfg.alpha - ) + self.__spl = make_smoothing_spline(self.__curve[:, 0], self.__curve[:, 1], lam=cfg.alpha) self.__rspl = make_smoothing_spline(rcurve[:, 0], rcurve[:, 1], lam=cfg.alpha) def compute_hardware_values(self, strengths: np.array) -> np.array: diff --git a/pyaml/rf/rf_transmitter.py b/pyaml/rf/rf_transmitter.py index 013dbbf7..9014d72b 100644 --- a/pyaml/rf/rf_transmitter.py +++ b/pyaml/rf/rf_transmitter.py @@ -70,9 +70,7 @@ def voltage(self) -> abstract.ReadWriteFloatScalar: If transmitter is unattached or has no voltage device defined """ if self.__voltage is None: - raise PyAMLException( - f"{str(self)} is unattached or has no voltage device defined" - ) + raise PyAMLException(f"{str(self)} is unattached or has no voltage device defined") return self.__voltage @property @@ -91,9 +89,7 @@ def phase(self) -> abstract.ReadWriteFloatScalar: If transmitter is unattached or has no phase device defined """ if self.__phase is None: - raise PyAMLException( - f"{str(self)} is unattached or has no phase device defined" - ) + raise PyAMLException(f"{str(self)} is unattached or has no phase device defined") return self.__phase def attach( diff --git a/pyaml/tuning_tools/orbit.py b/pyaml/tuning_tools/orbit.py index 2dff6a18..6baa1f88 100644 --- a/pyaml/tuning_tools/orbit.py +++ b/pyaml/tuning_tools/orbit.py @@ -64,8 +64,7 @@ def __init__(self, cfg: ConfigModel): else: if cfg.singular_values_H is not None or cfg.singular_values_V is not None: raise PyAMLException( - "Either `singular_values` or `singular_values_H` and " - "`singular_values_V` must be provided, not both." + "Either `singular_values` or `singular_values_H` and `singular_values_V` must be provided, not both." ) self.singular_values_H = cfg.singular_values self.singular_values_V = cfg.singular_values diff --git a/pyaml/tuning_tools/orbit_response_matrix.py b/pyaml/tuning_tools/orbit_response_matrix.py index 99c8d2fd..26710f1d 100644 --- a/pyaml/tuning_tools/orbit_response_matrix.py +++ b/pyaml/tuning_tools/orbit_response_matrix.py @@ -105,9 +105,7 @@ def measure( interface.set_wait_time = sleep_step if corrector_names is None: - logger.info( - f"Measuring correctors from the default arrays: {self.hcorr_array_name} and {self.vcorr_array_name}." - ) + logger.info(f"Measuring correctors from the default arrays: {self.hcorr_array_name} and {self.vcorr_array_name}.") hcorrector_names = element_holder.get_magnets(self.hcorr_array_name).names() vcorrector_names = element_holder.get_magnets(self.vcorr_array_name).names() corrector_names = hcorrector_names + vcorrector_names diff --git a/pyproject.toml b/pyproject.toml index 4c3ae2b1..470b4804 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,7 +95,7 @@ allow-direct-references = true version-file = "pyaml/_version.py" [tool.ruff] -line-length = 120 +line-length = 127 target-version = "py311" [tool.ruff.lint] diff --git a/tests/conftest.py b/tests/conftest.py index 3dabdb68..030cb61f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -185,8 +185,7 @@ def _installed_test_packages( if package_name in _TEST_PACKAGES } if package_map and all( - _module_matches_test_package(package_name, package_path) - for package_name, package_path in package_map.items() + _module_matches_test_package(package_name, package_path) for package_name, package_path in package_map.items() ): yield return diff --git a/tests/dummy_cs/tango-pyaml/tango/pyaml/attribute_with_tango_powersupply_mocking_behaviour.py b/tests/dummy_cs/tango-pyaml/tango/pyaml/attribute_with_tango_powersupply_mocking_behaviour.py index 9a12dee7..c336b183 100644 --- a/tests/dummy_cs/tango-pyaml/tango/pyaml/attribute_with_tango_powersupply_mocking_behaviour.py +++ b/tests/dummy_cs/tango-pyaml/tango/pyaml/attribute_with_tango_powersupply_mocking_behaviour.py @@ -70,15 +70,11 @@ def __compute_current(self): self._current = self.compute_hardware_values(np.array([self._strength]))[0] def compute_hardware_values(self, strengths: np.array) -> np.array: - _current = np.interp( - strengths[0] * self.__brho, self.__rcurve[:, 0], self.__rcurve[:, 1] - ) + _current = np.interp(strengths[0] * self.__brho, self.__rcurve[:, 0], self.__rcurve[:, 1]) return np.array([_current]) def compute_strengths(self, currents: np.array) -> np.array: - _strength = ( - np.interp(currents[0], self.__curve[:, 0], self.__curve[:, 1]) / self.__brho - ) + _strength = np.interp(currents[0], self.__curve[:, 0], self.__curve[:, 1]) / self.__brho return np.array([_strength]) def set_magnet_model_data( @@ -98,9 +94,7 @@ def set_magnet_model_data( _s = np.shape(self.__curve) if len(_s) != 2 or _s[1] != 2: raise Exception(curve_file + " wrong dimension") - self.__curve[:, 1] = ( - self.__curve[:, 1] * calibration_factor * crosstalk + calibration_offset - ) + self.__curve[:, 1] = self.__curve[:, 1] * calibration_factor * crosstalk + calibration_offset self.__rcurve = Curve.inverse(self.__curve) diff --git a/tests/external/pyaml_external/external_magnet_model.py b/tests/external/pyaml_external/external_magnet_model.py index fdfaaa06..14e83b89 100644 --- a/tests/external/pyaml_external/external_magnet_model.py +++ b/tests/external/pyaml_external/external_magnet_model.py @@ -30,10 +30,7 @@ class ExternalMagnetModel(MagnetModel): """ def __init__(self, cfg: ConfigModel): - print( - "ExternalMagnetModel:\n powersupply:%s\n param:%s" - % (cfg.powersupply.name(), cfg.param) - ) + print("ExternalMagnetModel:\n powersupply:%s\n param:%s" % (cfg.powersupply.name(), cfg.param)) self._cfg = cfg # Implementation of the MagnetModel abstract class diff --git a/tests/lattice_info.py b/tests/lattice_info.py index ef973b34..6fc01d95 100644 --- a/tests/lattice_info.py +++ b/tests/lattice_info.py @@ -8,11 +8,7 @@ def prepare_and_save(): # Add cell number to FamName for e in ring: attrs = e.__dict__ - toremove = [ - k - for k, v in attrs.items() - if k.startswith("Calibration") or k == "SerialNumber" - ] + toremove = [k for k, v in attrs.items() if k.startswith("Calibration") or k == "SerialNumber"] for tr in toremove: delattr(e, tr) if hasattr(e, "Device") and not isinstance(e, at.Monitor): diff --git a/tests/test_arrays_ops.py b/tests/test_arrays_ops.py index 6422a259..7027c761 100644 --- a/tests/test_arrays_ops.py +++ b/tests/test_arrays_ops.py @@ -178,9 +178,7 @@ def test_mask_by_type_returns_correct_boolean_mask( [{"name": "tango-pyaml", "path": "tests/dummy_cs/tango-pyaml"}], indirect=True, ) -def test_filter_by_type_returns_autotyped_array( - install_test_package, accelerator_from_fragments, sr_configuration_fragments -): +def test_filter_by_type_returns_autotyped_array(install_test_package, accelerator_from_fragments, sr_configuration_fragments): sr = accelerator_from_fragments(*sr_configuration_fragments) sr.design.get_lattice().disable_6d() @@ -228,9 +226,7 @@ def test_element_array_or_union_is_unique_stable_and_autotyped( [{"name": "tango-pyaml", "path": "tests/dummy_cs/tango-pyaml"}], indirect=True, ) -def test_element_array_add_is_alias_of_union( - install_test_package, accelerator_from_fragments, sr_configuration_fragments -): +def test_element_array_add_is_alias_of_union(install_test_package, accelerator_from_fragments, sr_configuration_fragments): sr = accelerator_from_fragments(*sr_configuration_fragments) sr.design.get_lattice().disable_6d() diff --git a/tests/test_errors.py b/tests/test_errors.py index 58471afa..e58cc7cb 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -132,9 +132,7 @@ def test_malformed_remote_included_yaml_reports_source_line_and_column(http_conf "data_folder: /data/store\n" "devices: fragments/broken_devices.yaml\n" ), - "/configs/fragments/broken_devices.yaml": ( - "- type: pyaml.bpm.bpm\n name: BPM_BROKEN\n model:\n type: [oops\n" - ), + "/configs/fragments/broken_devices.yaml": ("- type: pyaml.bpm.bpm\n name: BPM_BROKEN\n model:\n type: [oops\n"), } with http_config_server(routes) as base_url: diff --git a/tests/test_linkers.py b/tests/test_linkers.py index 42d2f763..9e8734bb 100644 --- a/tests/test_linkers.py +++ b/tests/test_linkers.py @@ -190,14 +190,10 @@ def test_various_naming_addressing(): assert len(elts) == 3 check_index(ring, elts, [140, 290, 424]) - elts = sr.design.get_magnet( - "QF1E-C04-C05-C06-2" - ).strength._RWStrengthScalar__elements + elts = sr.design.get_magnet("QF1E-C04-C05-C06-2").strength._RWStrengthScalar__elements assert len(elts) == 3 check_index(ring, elts, [140, 290, 424]) - elts = sr.design.get_magnet( - "QF1E-C04-C05-C06-3" - ).strength._RWStrengthScalar__elements + elts = sr.design.get_magnet("QF1E-C04-C05-C06-3").strength._RWStrengthScalar__elements assert len(elts) == 3 check_index(ring, elts, [140, 290, 424]) diff --git a/tests/test_load_quad.py b/tests/test_load_quad.py index 22d9f3c1..ac64605e 100644 --- a/tests/test_load_quad.py +++ b/tests/test_load_quad.py @@ -41,9 +41,7 @@ def test_quad_external_model(install_test_package, config_root_dir): "tango_host": "ebs-simu-3:10000", } ) - hcorr_with_external_model: HCorrector = Factory.depth_first_build( - cfg_hcorr_yaml, False - ) + hcorr_with_external_model: HCorrector = Factory.depth_first_build(cfg_hcorr_yaml, False) dev = cs.attach(hcorr_with_external_model.model.get_devices())[0] strength = RWStrengthScalar(hcorr_with_external_model.model, dev) hardware = RWHardwareScalar(hcorr_with_external_model.model, dev) diff --git a/tests/test_patterns.py b/tests/test_patterns.py index 4fde9c1c..79dbe835 100644 --- a/tests/test_patterns.py +++ b/tests/test_patterns.py @@ -5,9 +5,7 @@ def test_tune(): - sr: Accelerator = Accelerator.load( - "tests/config/EBSTune-patterns.yaml", ignore_external=True - ) + sr: Accelerator = Accelerator.load("tests/config/EBSTune-patterns.yaml", ignore_external=True) sr.design.get_lattice().disable_6d() quadForTune = sr.design.get_magnets("QForTune") @@ -17,9 +15,4 @@ def test_tune(): assert sr.design.get_magnet("QF1E-C06") is not None assert sr.design.get_magnet("QF1E-C05") is not None assert "QF1E-C05" not in quadForTest.names() - assert all( - [ - not (name.startswith("Q") and name.endswith("-C06")) - for name in quadForTest.names() - ] - ) + assert all([not (name.startswith("Q") and name.endswith("-C06")) for name in quadForTest.names()]) diff --git a/tests/test_ranges_cfm_deviceaccess.py b/tests/test_ranges_cfm_deviceaccess.py index 887558e7..d8e09fac 100644 --- a/tests/test_ranges_cfm_deviceaccess.py +++ b/tests/test_ranges_cfm_deviceaccess.py @@ -20,9 +20,7 @@ def _out_of_range(vmin, vmax) -> float: return float(vmax) + 0.1 if vmin is not None: return float(vmin) - 0.1 - raise RuntimeError( - "Unbounded range [None, None], cannot build an out-of-range value." - ) + raise RuntimeError("Unbounded range [None, None], cannot build an out-of-range value.") @pytest.mark.parametrize( @@ -35,9 +33,7 @@ def _out_of_range(vmin, vmax) -> float: ], indirect=["install_test_package"], ) -def test_cfm_ranges_from_yaml_are_propagated_and_enforced( - magnet_file, install_test_package -): +def test_cfm_ranges_from_yaml_are_propagated_and_enforced(magnet_file, install_test_package): sr: Accelerator = Accelerator.load(magnet_file) sr.design.get_lattice().disable_6d() diff --git a/tests/test_tune_hardware.py b/tests/test_tune_hardware.py index d5b9529e..638bc839 100644 --- a/tests/test_tune_hardware.py +++ b/tests/test_tune_hardware.py @@ -5,9 +5,7 @@ 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) sr.design.get_lattice().disable_6d() quadForTuneDesign = sr.design.get_magnets("QForTune") diff --git a/tests/test_tuning_orbit_correction.py b/tests/test_tuning_orbit_correction.py index 62e2668e..447bea50 100644 --- a/tests/test_tuning_orbit_correction.py +++ b/tests/test_tuning_orbit_correction.py @@ -221,13 +221,9 @@ def test_tuning_orbit_correction(): element_holder.orbit.set_rf_weight(rf_weight) # test getters of weights - assert np.isclose( - element_holder.orbit.get_weight("BPM_C04-05", plane="H"), 1, rtol=0, atol=1e-16 - ) + assert np.isclose(element_holder.orbit.get_weight("BPM_C04-05", plane="H"), 1, rtol=0, atol=1e-16) assert np.isclose(element_holder.orbit.get_virtual_weight(), 1, rtol=0, atol=1e-16) - assert np.isclose( - element_holder.orbit.get_rf_weight(), rf_weight, rtol=0, atol=1e-16 - ) + assert np.isclose(element_holder.orbit.get_rf_weight(), rf_weight, rtol=0, atol=1e-16) def test_tuning_orbit_correction_config(): diff --git a/tests/test_values.py b/tests/test_values.py index a5ed3f86..f404d650 100644 --- a/tests/test_values.py +++ b/tests/test_values.py @@ -30,9 +30,7 @@ def test_value_basic(self): assert allez_venez == 6 assert allez_venez == Value(6) - laissez_faire_l_insouciance = Value(allez_venez) / Value( - et_entrez_dans_la_danse - ) + laissez_faire_l_insouciance = Value(allez_venez) / Value(et_entrez_dans_la_danse) assert isinstance(laissez_faire_l_insouciance, float) assert laissez_faire_l_insouciance == 3 diff --git a/tunemat.json b/tunemat.json new file mode 100644 index 00000000..269a38fa --- /dev/null +++ b/tunemat.json @@ -0,0 +1,387 @@ +{ + "type": "pyaml.tuning_tools.response_matrix_data", + "matrix": [ + [ + 0.1785312775665071, + 0.17890918518254084, + 0.17917983711424057, + 0.1784306145899417, + 0.17932054383273943, + 0.17884878472013144, + 0.17868979674900975, + 0.17950221390589105, + 0.17836418103545082, + 0.17902879800274496, + 0.17907228791497198, + 0.1784534376253477, + 0.17936885137875835, + 0.1787317009097067, + 0.17880339380355048, + 0.17934220350290797, + 0.17843576159082275, + 0.17914061857193797, + 0.1789550646144611, + 0.17850485174275565, + 0.15843662941744663, + 0.15753129847057012, + 0.15237976934923125, + 0.15250702233238211, + 0.17830407720298425, + 0.17955648207695907, + 0.17845839986763146, + 0.1788046875300653, + 0.17936621410946652, + 0.17824945151401206, + 0.17941811039923206, + 0.179053720016642, + 0.17841113460537183, + 0.17957284018182973, + 0.17835112510161677, + 0.17897117554260822, + 0.1792322649588063, + 0.1782539868933064, + 0.17950825398710402, + 0.1787657276039467, + 0.17866201317662256, + 0.1795468408175016, + 0.1782791132018402, + 0.17925585255346155, + 0.17897151251833332, + 0.1783004122266063, + 0.17956082326409106, + 0.17873060988743417, + 0.1787168867781186, + 0.1794815161113017, + 0.1557743895247432, + 0.15662709150848775, + 0.17893299550625352, + 0.17847487988637, + 0.1793719829240592, + 0.17881762675503454, + 0.1787402055494769, + 0.1793163846461332, + 0.17843723260024813, + 0.17929549094519714, + 0.17880609438747364, + 0.1785348380697882, + 0.5908202260337947, + 0.591804326284251, + 0.5927433850580477, + 0.5907924113074392, + 0.5938799794077965, + 0.592651350724005, + 0.5920998835132196, + 0.5939144437447363, + 0.5907241307892552, + 0.5921955880411334, + 0.5923465450205501, + 0.5907349727388156, + 0.5939110630959199, + 0.5922519087026012, + 0.5925005553769624, + 0.5939036158975064, + 0.5907588135342645, + 0.5925942683560059, + 0.5919503994561426, + 0.5907780348426983, + 0.5241148481271996, + 0.5216304415095463, + 0.5024833537822793, + 0.5026608620767314, + 0.5911591919940951, + 0.5941944394646792, + 0.5903846474147878, + 0.5912864766008386, + 0.5932346430970181, + 0.5903265313270123, + 0.5943811615927164, + 0.5931317421159488, + 0.5916598821478769, + 0.5944256953097082, + 0.5901869888025324, + 0.5918016339520604, + 0.5927074763678597, + 0.5901599862537243, + 0.594511785559082, + 0.5925782043750272, + 0.5922183702236627, + 0.5945225115591701, + 0.5901240610672875, + 0.5923671162255673, + 0.5921394538524472, + 0.5901314847933659, + 0.5945044466607041, + 0.5920424841798777, + 0.5927530522539803, + 0.5944839213026243, + 0.5146725638374705, + 0.5168174053726826, + 0.5921905507622061, + 0.5907611382385825, + 0.5938737229152502, + 0.5921302946054752, + 0.5926197804212441, + 0.5938597887819586, + 0.5908095538947888, + 0.5927439945174751, + 0.5918047599753895, + 0.5908381917668626 + ], + [ + -1.2605596746839698, + -1.260314688052433, + -1.2598022979387613, + -1.2608315803008807, + -1.2598121601015144, + -1.2616063388576348, + -1.2614323082810186, + -1.2592055195276286, + -1.260011434582875, + -1.2610524334594198, + -1.260264548021417, + -1.261156005468167, + -1.2614583695325088, + -1.2597294629118627, + -1.260355682249359, + -1.2603501653951632, + -1.2597269089392737, + -1.2614586427656116, + -1.261151797385951, + -1.2602699245495286, + -1.2871885888787737, + -1.2858022703771121, + -1.295512068086313, + -1.2959131489942433, + -1.2602345472412235, + -1.2611911834869982, + -1.2611013020891182, + -1.26019174095382, + -1.2607701410655148, + -1.2600777222959714, + -1.259871215381625, + -1.2608570002270447, + -1.2609502039789833, + -1.260754558720656, + -1.2613492090024492, + -1.2596539671116957, + -1.2599698189208475, + -1.2607145508591877, + -1.2597697772198657, + -1.2610818268854462, + -1.260342724002106, + -1.2610777481203428, + -1.2611896741604456, + -1.2592259524440985, + -1.2595995109043745, + -1.2615755059258715, + -1.2607211342624547, + -1.260588792161843, + -1.2619319687812158, + -1.2593928849735647, + -1.2887869934308238, + -1.289137222220127, + -1.2603040800013288, + -1.2611660756733922, + -1.2609224119697338, + -1.2596076084958607, + -1.2599947981356552, + -1.2612842195808271, + -1.260556223423026, + -1.2601243935955742, + -1.2605216638339467, + -1.2609008985969838, + -0.49429912401421916, + -0.4942011848785288, + -0.49402884426397176, + -0.4944403242668205, + -0.49392715312179813, + -0.4946444167769348, + -0.494642475784568, + -0.49384803328222926, + -0.4940031027717007, + -0.49450349263457927, + -0.49410766421620345, + -0.49446404467967664, + -0.4946162529839704, + -0.4939250829982811, + -0.49424031875411334, + -0.49423811306070764, + -0.4939243690971207, + -0.49461666915995295, + -0.49446220468818414, + -0.4941096561139613, + -0.49580432387785756, + -0.49525990132137654, + -0.495847581273301, + -0.4960629050582144, + -0.49405329285656663, + -0.4945045490734046, + -0.4944593030919986, + -0.49409568533387294, + -0.4943868486234626, + -0.4941100382965802, + -0.49400608370830934, + -0.4944961134639714, + -0.49429209945439645, + -0.4942981255562362, + -0.4945974694420263, + -0.4939197575981602, + -0.4940787556634296, + -0.49437648356964736, + -0.4939864595138177, + -0.4945109812737325, + -0.4941389209023317, + -0.49443276362082234, + -0.4945754345897502, + -0.4938861760950264, + -0.4938234754592319, + -0.49469773213683954, + -0.4942676459879225, + -0.4943106724386581, + -0.4947356646151091, + -0.49380505579399436, + -0.49553591837780964, + -0.495742188148518, + -0.4940722391477692, + -0.4944901952558256, + -0.4944531012929243, + -0.4940232475564299, + -0.4939673852005777, + -0.4945672189560213, + -0.49428634374737435, + -0.4942095438964511, + -0.4941586272116938, + -0.49439460739097996 + ] + ], + "variable_names": [ + "QD2E-C04", + "QD2A-C05", + "QD2E-C05", + "QD2A-C06", + "QD2E-C06", + "QD2A-C07", + "QD2E-C07", + "QD2A-C08", + "QD2E-C08", + "QD2A-C09", + "QD2E-C09", + "QD2A-C10", + "QD2E-C10", + "QD2A-C11", + "QD2E-C11", + "QD2A-C12", + "QD2E-C12", + "QD2A-C13", + "QD2E-C13", + "QD2A-C14", + "QD2E-C14", + "QD2A-C15", + "QD2E-C15", + "QD2A-C16", + "QD2E-C16", + "QD2A-C17", + "QD2E-C17", + "QD2A-C18", + "QD2E-C18", + "QD2A-C19", + "QD2E-C19", + "QD2A-C20", + "QD2E-C20", + "QD2A-C21", + "QD2E-C21", + "QD2A-C22", + "QD2E-C22", + "QD2A-C23", + "QD2E-C23", + "QD2A-C24", + "QD2E-C24", + "QD2A-C25", + "QD2E-C25", + "QD2A-C26", + "QD2E-C26", + "QD2A-C27", + "QD2E-C27", + "QD2A-C28", + "QD2E-C28", + "QD2A-C29", + "QD2E-C29", + "QD2A-C30", + "QD2E-C30", + "QD2A-C31", + "QD2E-C31", + "QD2A-C32", + "QD2E-C32", + "QD2A-C01", + "QD2E-C01", + "QD2A-C02", + "QD2E-C02", + "QD2A-C03", + "QF1E-C04", + "QF1A-C05", + "QF1E-C05", + "QF1A-C06", + "QF1E-C06", + "QF1A-C07", + "QF1E-C07", + "QF1A-C08", + "QF1E-C08", + "QF1A-C09", + "QF1E-C09", + "QF1A-C10", + "QF1E-C10", + "QF1A-C11", + "QF1E-C11", + "QF1A-C12", + "QF1E-C12", + "QF1A-C13", + "QF1E-C13", + "QF1A-C14", + "QF1E-C14", + "QF1A-C15", + "QF1E-C15", + "QF1A-C16", + "QF1E-C16", + "QF1A-C17", + "QF1E-C17", + "QF1A-C18", + "QF1E-C18", + "QF1A-C19", + "QF1E-C19", + "QF1A-C20", + "QF1E-C20", + "QF1A-C21", + "QF1E-C21", + "QF1A-C22", + "QF1E-C22", + "QF1A-C23", + "QF1E-C23", + "QF1A-C24", + "QF1E-C24", + "QF1A-C25", + "QF1E-C25", + "QF1A-C26", + "QF1E-C26", + "QF1A-C27", + "QF1E-C27", + "QF1A-C28", + "QF1E-C28", + "QF1A-C29", + "QF1E-C29", + "QF1A-C30", + "QF1E-C30", + "QF1A-C31", + "QF1E-C31", + "QF1A-C32", + "QF1E-C32", + "QF1A-C01", + "QF1E-C01", + "QF1A-C02", + "QF1E-C02", + "QF1A-C03" + ], + "observable_names": [ + "BETATRON_TUNE.x", + "BETATRON_TUNE.y" + ] +}