diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index f9784d21..3a6f856b 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -17,7 +17,7 @@ A clear and concise description of what you want to happen. A clear and concise description of any alternative solutions or features you've considered. An argument for why this solution is not the preferred one. **Example** -Give a concise example of the envisioned featured. +Give a concise example of the envisioned featured. **Additional context** Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md index 3f59e42b..dff92f81 100644 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -22,11 +22,11 @@ Describe the changes that had to be made to an existing functionality (if they w - [ ] ... ## Testing - The following tests (compatible with pytest) were added: + The following tests (compatible with pytest) were added: - [ ] first test - [ ] second test - ... - + ## Verify that your checklist complies with the project - [ ] New and existing unit tests pass locally - [ ] Tests were added to prove that all features/changes are effective diff --git a/.github/workflows/deploy-pypi.yaml b/.github/workflows/deploy-pypi.yaml index ecd56716..738987b2 100644 --- a/.github/workflows/deploy-pypi.yaml +++ b/.github/workflows/deploy-pypi.yaml @@ -8,7 +8,7 @@ on: jobs: deploy: - + runs-on: ubuntu-latest #environment: release @@ -25,7 +25,7 @@ jobs: cache-dependency-path: '**/pyproject.toml' - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip pip install hatch - name: Build package run: hatch build diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 04c11c2b..053ecb44 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -13,14 +13,14 @@ permissions: write-all jobs: documentation: name: ${{ matrix.os }} / ${{ matrix.python-version }} - + runs-on: ${{ matrix.os }} - + strategy: matrix: # only lowest supported Python on latest ubuntu os: [ubuntu-latest] python-version: [3.14] - + permissions: issues: write pull-requests: write @@ -49,7 +49,7 @@ jobs: - name: Install dependencies run: pip install -r ./docs/requirements.txt - + - name: Build documentation run: python -m sphinx -b html docs ./docs/_build -d ./docs/_build @@ -81,6 +81,3 @@ jobs: # with: # github_token: ${{ secrets.GITHUB_TOKEN }} # publish_dir: docs/_build/html - - - \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8192a5e0..616c197e 100644 --- a/.gitignore +++ b/.gitignore @@ -59,7 +59,7 @@ coverage.xml .pytest_cache/ cover/ -# DS +# DS **/.DS_Store # Translations diff --git a/.readthedocs.yaml b/.readthedocs.yaml index c23d12bf..511a6cab 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -30,4 +30,3 @@ sphinx: python: install: - requirements: docs/requirements.txt - diff --git a/README.md b/README.md index a17daaae..b20ecc39 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Documentation Status](https://readthedocs.org/projects/pyaml/badge/?version=latest)](https://pyaml.readthedocs.io/en/latest/?badge=latest) +[![Documentation Status](https://readthedocs.org/projects/pyaml/badge/?version=latest)](https://pyaml.readthedocs.io/en/latest/?badge=latest) ![Current release](https://img.shields.io/github/v/tag/python-accelerator-middle-layer/pyaml) # pyAML: Python Accelerator Middle Layer @@ -10,7 +10,7 @@ Disclaimer: the pyAML software is still under development. 1. Clone the repository 2. Create a virtual environment and activate it 3. Install the package. For editable installation: - + ``` cd pyaml pip install -e . diff --git a/docs/Makefile b/docs/Makefile index 36fdb7b5..c468f816 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -156,4 +156,4 @@ linkcheck: doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ - "results in $(BUILDDIR)/doctest/output.txt." \ No newline at end of file + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/api.rst b/docs/api.rst index b68bd568..9553643a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -5,4 +5,4 @@ API :toctree: generated :recursive: - pyaml \ No newline at end of file + pyaml diff --git a/docs/index.rst b/docs/index.rst index 67e4267a..c66a1a23 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,6 +1,6 @@ pyAML documentation =================== - + Introduction ------------ @@ -14,12 +14,12 @@ With pyAML, it WILL be possible to (the software is at conceptualization stage): - **compute statistical properties for several lattice instances with errors** - **flexible complex unit conversions** - **easy and friendly configuration** -- many more features +- many more features Installation ------------ -pip support will be provided later. -for the time being: +pip support will be provided later. +for the time being: git clone https://github.com/python-accelerator-middle-layer/pyaml.git @@ -57,7 +57,7 @@ Discussion Shared documents ~~~~~~~~~~~~~~~~ -to access the shared documents please ask S.Liuzzo for access rigths. +to access the shared documents please ask S.Liuzzo for access rigths. The pyAML "software requirement specification" document is visible here: https://www.overleaf.com/read/hnrqzhfpbvpp#ef8935 @@ -76,4 +76,3 @@ Indices and tables * :ref:`genindex` * :ref:`modindex` * :ref:`search` - diff --git a/docs/modules/bpm.rst b/docs/modules/bpm.rst index f5ff7867..2dd4b5f2 100644 --- a/docs/modules/bpm.rst +++ b/docs/modules/bpm.rst @@ -11,4 +11,4 @@ BPMS :members: .. automodule:: pyaml.bpm.bpm_simple_model - :members: \ No newline at end of file + :members: diff --git a/docs/modules/configuration.rst b/docs/modules/configuration.rst index dc44a648..68c1b6cf 100644 --- a/docs/modules/configuration.rst +++ b/docs/modules/configuration.rst @@ -6,7 +6,7 @@ Configuration .. automodule:: pyaml.configuration.factory :members: - + .. automodule:: pyaml.configuration.matrix :members: @@ -18,7 +18,7 @@ Configuration .. automodule:: pyaml.configuration.matrix :members: - + .. automodule:: pyaml.configuration.csvmatrix :members: diff --git a/docs/modules/lattice.rst b/docs/modules/lattice.rst index 781c017e..cce3d9aa 100644 --- a/docs/modules/lattice.rst +++ b/docs/modules/lattice.rst @@ -6,7 +6,7 @@ lattice .. automodule:: pyaml.lattice.attribute_linker :members: - + .. automodule:: pyaml.lattice.element_holder :members: @@ -21,5 +21,3 @@ lattice .. automodule:: pyaml.lattice.simulator :members: - - diff --git a/docs/modules/pyaml.rst b/docs/modules/pyaml.rst index fd258108..ce558c7e 100644 --- a/docs/modules/pyaml.rst +++ b/docs/modules/pyaml.rst @@ -21,4 +21,3 @@ pyaml .. toctree:: :maxdepth: 2 :caption: Contents: - diff --git a/docs/modules/rf.rst b/docs/modules/rf.rst index 2d5a3b62..390a6d1e 100644 --- a/docs/modules/rf.rst +++ b/docs/modules/rf.rst @@ -6,4 +6,3 @@ RF .. automodule:: pyaml.rf.rf_transmitter :members: - diff --git a/docs/requirements.txt b/docs/requirements.txt index b624fa8e..bfadd59e 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -12,4 +12,4 @@ accelerator-toolbox==0.7.1 matplotlib==3.10.7 ipykernel==7.1.0 myst-nb==1.3.0 -pydata-sphinx-theme==0.16.1 \ No newline at end of file +pydata-sphinx-theme==0.16.1 diff --git a/pyaml/common/constants.py b/pyaml/common/constants.py new file mode 100644 index 00000000..b6227f5d --- /dev/null +++ b/pyaml/common/constants.py @@ -0,0 +1,5 @@ +""" +PyAML global constants +""" + +HORIZONTAL_KICK_SIGN: float = -1.0 diff --git a/pyaml/lattice/abstract_impl.py b/pyaml/lattice/abstract_impl.py index b8591ef2..6651e18d 100644 --- a/pyaml/lattice/abstract_impl.py +++ b/pyaml/lattice/abstract_impl.py @@ -28,15 +28,16 @@ def __init__( self.__model = model self.__elements = elements self.__poly = elements[0].__getattribute__(poly.attName) + self.__sign = poly.sign self.__polyIdx = poly.index def get(self) -> float: - s = self.__poly[self.__polyIdx] * self.__elements[0].Length + s = self.__poly[self.__polyIdx] * self.__sign * self.__elements[0].Length return self.__model.compute_hardware_values([s])[0] def set(self, value: float): s = self.__model.compute_strengths([value])[0] - self.__poly[self.__polyIdx] = s / self.__elements[0].Length + self.__poly[self.__polyIdx] = s / (self.__elements[0].Length * self.__sign) def set_and_wait(self, value: float): raise NotImplementedError("Not implemented yet.") @@ -59,15 +60,16 @@ def __init__( self.__model = model self.__elements = elements self.__poly = elements[0].__getattribute__(poly.attName) + self.__sign = poly.sign self.__polyIdx = poly.index # Gets the value def get(self) -> float: - return self.__poly[self.__polyIdx] * self.__elements[0].Length + return self.__poly[self.__polyIdx] * self.__sign * self.__elements[0].Length # Sets the value def set(self, value: float): - self.__poly[self.__polyIdx] = value / self.__elements[0].Length + self.__poly[self.__polyIdx] = value / (self.__elements[0].Length * self.__sign) # Sets the value and wait that the read value reach the setpoint def set_and_wait(self, value: float): @@ -93,17 +95,23 @@ def __init__( self.__elements = elements self.__poly = [] self.__polyIdx = [] + self.__sign = [] self.__model = model for p in poly: self.__poly.append(elements[0].__getattribute__(p.attName)) self.__polyIdx.append(p.index) + self.__sign.append(p.sign) # Gets the value def get(self) -> np.array: nbStrength = len(self.__poly) s = np.zeros(nbStrength) for i in range(nbStrength): - s[i] = self.__poly[i][self.__polyIdx[i]] * self.__elements[0].Length + s[i] = ( + self.__poly[i][self.__polyIdx[i]] + * self.__sign[i] + * self.__elements[0].Length + ) return self.__model.compute_hardware_values(s) # Sets the value @@ -111,7 +119,9 @@ def set(self, value: np.array): nbStrength = len(self.__poly) s = self.__model.compute_strengths(value) for i in range(nbStrength): - self.__poly[i][self.__polyIdx[i]] = s[i] / self.__elements[0].Length + self.__poly[i][self.__polyIdx[i]] = s[i] / ( + self.__elements[0].Length * self.__sign[i] + ) # Sets the value and wait that the read value reach the setpoint def set_and_wait(self, value: np.array): @@ -136,17 +146,23 @@ def __init__( self.__elements = elements self.__poly = [] self.__polyIdx = [] + self.__sign = [] self.__model = model for p in poly: self.__poly.append(elements[0].__getattribute__(p.attName)) self.__polyIdx.append(p.index) + self.__sign.append(p.sign) # Gets the value def get(self) -> np.array: nbStrength = len(self.__poly) s = np.zeros(nbStrength) for i in range(nbStrength): - s[i] = self.__poly[i][self.__polyIdx[i]] * self.__elements[0].Length + s[i] = ( + self.__poly[i][self.__polyIdx[i]] + * self.__sign[i] + * self.__elements[0].Length + ) return s # Sets the value @@ -154,7 +170,9 @@ def set(self, value: np.array): nbStrength = len(self.__poly) s = np.zeros(nbStrength) for i in range(nbStrength): - self.__poly[i][self.__polyIdx[i]] = value[i] / self.__elements[0].Length + self.__poly[i][self.__polyIdx[i]] = value[i] / ( + self.__elements[0].Length * self.__sign[i] + ) # Sets the value and wait that the read value reach the setpoint def set_and_wait(self, value: np.array): @@ -173,11 +191,11 @@ class BPMScalarAggregator(ScalarAggregator): BPM simulator aggregator """ - def __init__(self, ring:at.Lattice): + def __init__(self, ring: at.Lattice): self.lattice = ring self.refpts = [] - def add_elem(self,elem:at.Element): + def add_elem(self, elem: at.Element): self.refpts.append(self.lattice.index(elem)) def set(self, value: NDArray[np.float64]): diff --git a/pyaml/lattice/polynom_info.py b/pyaml/lattice/polynom_info.py index 4d4f2aeb..6e03a49d 100644 --- a/pyaml/lattice/polynom_info.py +++ b/pyaml/lattice/polynom_info.py @@ -8,7 +8,7 @@ class PolynomInfo: Polynom information """ - def __init__(self, attName: str, index: int): + def __init__(self, attName: str, index: int, sign: float = 1.0): """ Construct a polynom information object @@ -21,3 +21,4 @@ def __init__(self, attName: str, index: int): """ self.attName = attName self.index = index + self.sign = sign diff --git a/pyaml/magnet/corrector.py b/pyaml/magnet/corrector.py new file mode 100644 index 00000000..606495b6 --- /dev/null +++ b/pyaml/magnet/corrector.py @@ -0,0 +1,30 @@ +import numpy as np + +from ..common import abstract +from .magnet import Magnet + + +class RWCorrectorAngle(abstract.ReadWriteFloatScalar): + """ + Set the angle of a horizontal or vertical corrector. + KickAngle sign convention is defined the a global PyAML constant + (see pyaml.common.constant.HORIZONATL_KICK_SIGN). + To change the convention, you have execute the code below prior to everything: + import pyaml.common.constants + pyaml.common.constants.HORIZONTAL_KICK_SIGN = -1.0 + """ + + def __init__(self, corr: Magnet): + self._mag = corr + + def get(self) -> float: + return np.arctan(self._mag.strength.get()) + + def set(self, value: float): + self._mag.strength.set(np.tan(value)) + + def set_and_wait(self, value: float): + raise NotImplementedError("Not implemented yet.") + + def unit(self) -> str: + return "rad" diff --git a/pyaml/magnet/hcorrector.py b/pyaml/magnet/hcorrector.py index bc2910a8..eb9b670f 100644 --- a/pyaml/magnet/hcorrector.py +++ b/pyaml/magnet/hcorrector.py @@ -1,4 +1,7 @@ +from ..common import abstract +from ..common.constants import HORIZONTAL_KICK_SIGN from ..lattice.polynom_info import PolynomInfo +from .corrector import RWCorrectorAngle from .magnet import Magnet, MagnetConfigModel # Define the main class name for this module @@ -11,7 +14,7 @@ class ConfigModel(MagnetConfigModel): ... class HCorrector(Magnet): """Horizontal Corrector class""" - polynom = PolynomInfo("PolynomB", 0) + polynom = PolynomInfo("PolynomB", 0, HORIZONTAL_KICK_SIGN) def __init__(self, cfg: ConfigModel): super().__init__( @@ -19,3 +22,11 @@ def __init__(self, cfg: ConfigModel): cfg.model if hasattr(cfg, "model") else None, ) self._cfg = cfg + self.__angle = RWCorrectorAngle(self) + + @property + def angle(self) -> abstract.ReadWriteFloatScalar: + """ + Set the kick angle. + """ + return self.__angle diff --git a/pyaml/magnet/vcorrector.py b/pyaml/magnet/vcorrector.py index 2e5334f1..a2f3850e 100644 --- a/pyaml/magnet/vcorrector.py +++ b/pyaml/magnet/vcorrector.py @@ -1,4 +1,6 @@ +from ..common import abstract from ..lattice.polynom_info import PolynomInfo +from .corrector import RWCorrectorAngle from .magnet import Magnet, MagnetConfigModel # Define the main class name for this module @@ -19,3 +21,11 @@ def __init__(self, cfg: ConfigModel): cfg.model if hasattr(cfg, "model") else None, ) self._cfg = cfg + self.__angle = RWCorrectorAngle(self) + + @property + def angle(self) -> abstract.ReadWriteFloatScalar: + """ + Set the kick angle. + """ + return self.__angle diff --git a/tests/config/EBSOrbit.yaml b/tests/config/EBSOrbit.yaml index b5d72a8d..3e406c97 100644 --- a/tests/config/EBSOrbit.yaml +++ b/tests/config/EBSOrbit.yaml @@ -927,7 +927,7 @@ devices: tune_v: type: tango.pyaml.attribute_read_only attribute: sys/ringsimulator/ebs/Tune_v - unit: "" + unit: "" - type: pyaml.rf.rf_plant name: RF masterclock: diff --git a/tests/config/EBSTune.yaml b/tests/config/EBSTune.yaml index 41714113..e2d03d92 100644 --- a/tests/config/EBSTune.yaml +++ b/tests/config/EBSTune.yaml @@ -1885,4 +1885,3 @@ devices: type: tango.pyaml.attribute_read_only attribute: srdiag/tune/tune_v unit: mm - diff --git a/tests/config/EBS_rf.yaml b/tests/config/EBS_rf.yaml index 59aa86a5..67274c18 100644 --- a/tests/config/EBS_rf.yaml +++ b/tests/config/EBS_rf.yaml @@ -8,9 +8,9 @@ simulators: controls: - type: tango.pyaml.controlsystem tango_host: ebs-simu-3:10000 - name: live + name: live data_folder: /data/store -devices: +devices: - type: pyaml.rf.rf_plant name: RF masterclock: diff --git a/tests/config/EBS_rf_multi.yaml b/tests/config/EBS_rf_multi.yaml index e79ca5bc..4a899f02 100644 --- a/tests/config/EBS_rf_multi.yaml +++ b/tests/config/EBS_rf_multi.yaml @@ -10,7 +10,7 @@ controls: tango_host: ebs-simu-3:10000 name: live data_folder: /data/store -devices: +devices: - type: pyaml.rf.rf_plant name: RF masterclock: diff --git a/tests/config/EBS_rf_notrans.yaml b/tests/config/EBS_rf_notrans.yaml index c3a61870..2a62123b 100644 --- a/tests/config/EBS_rf_notrans.yaml +++ b/tests/config/EBS_rf_notrans.yaml @@ -8,12 +8,12 @@ simulators: controls: - type: tango.pyaml.controlsystem tango_host: ebs-simu-3:10000 - name: live + name: live data_folder: /data/store -devices: +devices: - type: pyaml.rf.rf_plant name: RF masterclock: type: tango.pyaml.attribute attribute: sy/ms/1/Frequency - unit: Hz \ No newline at end of file + unit: Hz diff --git a/tests/config/bad_conf_cycles.json b/tests/config/bad_conf_cycles.json index ee420251..587f760b 100644 --- a/tests/config/bad_conf_cycles.json +++ b/tests/config/bad_conf_cycles.json @@ -24,4 +24,4 @@ "sr/correctors/SH1AC01.yaml", "sr/correctors/SH1AC02.yaml" ] -} \ No newline at end of file +} diff --git a/tests/config/bpms.yaml b/tests/config/bpms.yaml index 50e7f168..8cbf4fd5 100644 --- a/tests/config/bpms.yaml +++ b/tests/config/bpms.yaml @@ -62,8 +62,8 @@ devices: - type: pyaml.magnet.cfm_magnet name: SH1A-C01 #Name of the element in the lattice model mapping: - # Multipole mapping for usage in families, in this example SH1-C01A-H is not - # a lattice element present in the model, it is just a name to use in + # Multipole mapping for usage in families, in this example SH1-C01A-H is not + # a lattice element present in the model, it is just a name to use in # PyAML families. When this 'virutal' element is set, it then applies # the corresponding multipole on the parent element. - [B0, SH1A-C01-H] diff --git a/tests/config/sr-attribute-linker.yaml b/tests/config/sr-attribute-linker.yaml index 106122d5..4b465a34 100644 --- a/tests/config/sr-attribute-linker.yaml +++ b/tests/config/sr-attribute-linker.yaml @@ -23,4 +23,4 @@ arrays: devices: - sr/quadrupoles/QF1AC01.yaml - sr/correctors/SH1AC01.yaml - - sr/correctors/SH1AC02.yaml \ No newline at end of file + - sr/correctors/SH1AC02.yaml diff --git a/tests/config/sr-ident-cfm.yaml b/tests/config/sr-ident-cfm.yaml index 4b384950..a3ff078e 100644 --- a/tests/config/sr-ident-cfm.yaml +++ b/tests/config/sr-ident-cfm.yaml @@ -24,4 +24,4 @@ arrays: devices: - sr/quadrupoles/QF1AC01.yaml - sr/correctors/SH1AC01-ident.yaml - - sr/correctors/SH1AC02.yaml \ No newline at end of file + - sr/correctors/SH1AC02.yaml diff --git a/tests/config/sr/correctors/SH1AC01-ident.yaml b/tests/config/sr/correctors/SH1AC01-ident.yaml index 7e9ae2ad..f5f56895 100644 --- a/tests/config/sr/correctors/SH1AC01-ident.yaml +++ b/tests/config/sr/correctors/SH1AC01-ident.yaml @@ -1,8 +1,8 @@ type: pyaml.magnet.cfm_magnet name: SH1A-C01 #Name of the element in the lattice model mapping: - # Multipole mapping for usage in families, in this example SH1-C01A-H is not - # a lattice element present in the model, it is just a name to use in + # Multipole mapping for usage in families, in this example SH1-C01A-H is not + # a lattice element present in the model, it is just a name to use in # PyAML families. When this 'virutal' element is set, it then applies # the corresponding multipole on the parent element. - [B0, SH1A-C01-H] diff --git a/tests/config/sr/correctors/SH1AC01.yaml b/tests/config/sr/correctors/SH1AC01.yaml index cb97c47c..717ad973 100644 --- a/tests/config/sr/correctors/SH1AC01.yaml +++ b/tests/config/sr/correctors/SH1AC01.yaml @@ -1,8 +1,8 @@ type: pyaml.magnet.cfm_magnet name: SH1A-C01 #Name of the element in the lattice model mapping: - # Multipole mapping for usage in families, in this example SH1-C01A-H is not - # a lattice element present in the model, it is just a name to use in + # Multipole mapping for usage in families, in this example SH1-C01A-H is not + # a lattice element present in the model, it is just a name to use in # PyAML families. When this 'virutal' element is set, it then applies # the corresponding multipole on the parent element. - [B0, SH1A-C01-H] diff --git a/tests/config/sr/correctors/SH1AC02.yaml b/tests/config/sr/correctors/SH1AC02.yaml index f7474c52..590d69b9 100644 --- a/tests/config/sr/correctors/SH1AC02.yaml +++ b/tests/config/sr/correctors/SH1AC02.yaml @@ -1,8 +1,8 @@ type: pyaml.magnet.cfm_magnet name: SH1A-C02 #Name of the element in the lattice model mapping: - # Multipole mapping for usage in families, in this example SH1-C01A-H is not - # a lattice element present in the model, it is just a name to use in + # Multipole mapping for usage in families, in this example SH1-C01A-H is not + # a lattice element present in the model, it is just a name to use in # PyAML families. When this 'virutal' element is set, it then applies # the corresponding multipole on the parent element. - [B0, SH1A-C02-H] diff --git a/tests/config/sr/custom_magnets/hidcorr.yaml b/tests/config/sr/custom_magnets/hidcorr.yaml index 178c7efc..8c55999f 100644 --- a/tests/config/sr/custom_magnets/hidcorr.yaml +++ b/tests/config/sr/custom_magnets/hidcorr.yaml @@ -12,4 +12,4 @@ model: type: pyaml.control.device setpoint: sr/id/c01-1/gap readback: sr/id/c01-1/gap - unit: A \ No newline at end of file + unit: A diff --git a/tests/config/sr/magnet_models/QD2_strength.csv b/tests/config/sr/magnet_models/QD2_strength.csv index fb5684ed..f61fae5e 100644 --- a/tests/config/sr/magnet_models/QD2_strength.csv +++ b/tests/config/sr/magnet_models/QD2_strength.csv @@ -98,4 +98,4 @@ 106.969697, -13.54414964 107.979798, -13.58201323 108.989899, -13.61912026 - 110, -13.655849 \ No newline at end of file + 110, -13.655849 diff --git a/tests/config/sr/magnet_models/QF1AC01.yaml b/tests/config/sr/magnet_models/QF1AC01.yaml index 5665f697..3670f2e6 100644 --- a/tests/config/sr/magnet_models/QF1AC01.yaml +++ b/tests/config/sr/magnet_models/QF1AC01.yaml @@ -7,4 +7,4 @@ powerconverter: type: pyaml.control.device setpoint: sr/ps-qf1/c01-a/current readback: sr/ps-qf1/c01-a/current - unit: A \ No newline at end of file + unit: A diff --git a/tests/config/sr/magnet_models/SH1AC01.yaml b/tests/config/sr/magnet_models/SH1AC01.yaml index 51094ab8..d8eb8fa4 100644 --- a/tests/config/sr/magnet_models/SH1AC01.yaml +++ b/tests/config/sr/magnet_models/SH1AC01.yaml @@ -21,4 +21,4 @@ unit: A - type: tango.pyaml.attribute attribute: srmag/ps-corr-sh1/c01-a-ch3/current - unit: A \ No newline at end of file + unit: A diff --git a/tests/config/sr/magnet_models/SH1AC02.yaml b/tests/config/sr/magnet_models/SH1AC02.yaml index a3b50465..5c0664b6 100644 --- a/tests/config/sr/magnet_models/SH1AC02.yaml +++ b/tests/config/sr/magnet_models/SH1AC02.yaml @@ -21,4 +21,4 @@ unit: A - type: tango.pyaml.attribute attribute: srmag/ps-corr-sh1/c02-a-ch3/current - unit: A \ No newline at end of file + unit: A diff --git a/tests/config/sr/magnet_models/quadcurve.yaml b/tests/config/sr/magnet_models/quadcurve.yaml index f86fb476..a536a9f6 100644 --- a/tests/config/sr/magnet_models/quadcurve.yaml +++ b/tests/config/sr/magnet_models/quadcurve.yaml @@ -1,2 +1,2 @@ type: pyaml.configuration.csvcurve -file: sr/magnet_models/QF1_strength.csv \ No newline at end of file +file: sr/magnet_models/QF1_strength.csv diff --git a/tests/config/sr/magnet_models/quadcurve_data.yaml b/tests/config/sr/magnet_models/quadcurve_data.yaml index 4b411b86..020ac047 100644 --- a/tests/config/sr/magnet_models/quadcurve_data.yaml +++ b/tests/config/sr/magnet_models/quadcurve_data.yaml @@ -1,4 +1,4 @@ -#Current , Int.Grad. +#Current , Int.Grad. #[A] , [T] - [ 0, 0] - [20.1010101, 11.70165639] diff --git a/tests/config/sr/quadrupoles/QF1AC01-IDENT-HW.yaml b/tests/config/sr/quadrupoles/QF1AC01-IDENT-HW.yaml index 0532f794..ec4e2bc8 100644 --- a/tests/config/sr/quadrupoles/QF1AC01-IDENT-HW.yaml +++ b/tests/config/sr/quadrupoles/QF1AC01-IDENT-HW.yaml @@ -8,4 +8,3 @@ model: setpoint: sr/ps-qf1/c01-a/strength readback: sr/ps-qf1/c01-a/strength unit: 1/m - diff --git a/tests/config/sr/quadrupoles/QF1C01A_2.yaml b/tests/config/sr/quadrupoles/QF1C01A_2.yaml index 09d762b0..b976a852 100644 --- a/tests/config/sr/quadrupoles/QF1C01A_2.yaml +++ b/tests/config/sr/quadrupoles/QF1C01A_2.yaml @@ -10,4 +10,4 @@ model: type: pyaml.control.device setpoint: sr/ps-qf1/c01-a/current readback: sr/ps-qf1/c01-a/current - unit: A \ No newline at end of file + unit: A diff --git a/tests/external/pyproject.toml b/tests/external/pyproject.toml index 45df2d17..0e6e9f2e 100644 --- a/tests/external/pyproject.toml +++ b/tests/external/pyproject.toml @@ -17,4 +17,4 @@ dependencies = [ "numpy>=1.21.0", "scipy>=1.7.3", "accelerator-toolbox>=0.6.1" -] \ No newline at end of file +] diff --git a/tests/test_arrays.py b/tests/test_arrays.py index 60fd75c6..e26b32a3 100644 --- a/tests/test_arrays.py +++ b/tests/test_arrays.py @@ -26,28 +26,42 @@ def test_arrays(install_test_package): sr.design.get_magnet("SH1A-C01-V").strength.set(0.000015) o, _ = sr.design.get_lattice().find_orbit() - assert np.abs(o[0] + 9.91848416e-05) < 1e-10 - assert np.abs(o[1] + 3.54829761e-07) < 1e-10 - assert np.abs(o[2] + 1.56246320e-06) < 1e-10 - assert np.abs(o[3] + 1.75037311e-05) < 1e-10 + assert np.abs(o[0] - 9.90267693e-05) < 1e-10 + assert np.abs(o[1] - 3.39661431e-07) < 1e-10 + assert np.abs(o[2] + 1.59928207e-06) < 1e-10 + assert np.abs(o[3] + 1.74771216e-05) < 1e-10 sr.design.get_magnet("SH1A-C02-H").strength.set(-0.000008) sr.design.get_magnet("SH1A-C02-V").strength.set(-0.000017) o, _ = sr.design.get_lattice().find_orbit() - assert np.abs(o[0] + 1.60277642e-04) < 1e-10 - assert np.abs(o[1] - 2.36103795e-06) < 1e-10 - assert np.abs(o[2] - 3.62843295e-05) < 1e-10 - assert np.abs(o[3] + 6.06571010e-06) < 1e-10 + assert np.abs(o[0] - 1.60555804e-04) < 1e-10 + assert np.abs(o[1] + 2.37234366e-06) < 1e-10 + assert np.abs(o[2] - 3.62695844e-05) < 1e-10 + assert np.abs(o[3] + 5.97692290e-06) < 1e-10 sr.design.get_magnets("HCORR").strengths.set([0.000010, -0.000008]) sr.design.get_magnets("VCORR").strengths.set([0.000015, -0.000017]) o, _ = sr.design.get_lattice().find_orbit() - assert np.abs(o[0] + 1.60277642e-04) < 1e-10 - assert np.abs(o[1] - 2.36103795e-06) < 1e-10 - assert np.abs(o[2] - 3.62843295e-05) < 1e-10 - assert np.abs(o[3] + 6.06571010e-06) < 1e-10 + assert np.abs(o[0] - 1.60555804e-04) < 1e-10 + assert np.abs(o[1] + 2.37234366e-06) < 1e-10 + assert np.abs(o[2] - 3.62695844e-05) < 1e-10 + assert np.abs(o[3] + 5.97692290e-06) < 1e-10 + + p0 = o[0] + + # Test kick angle (small angle, no change from above) + sr.design.get_magnet("SH1A-C02-H").angle.set(-0.000008) + o, _ = sr.design.get_lattice().find_orbit() + assert np.abs(o[0] - 1.60555804e-04) < 1e-10 + assert np.abs(o[1] + 2.37234366e-06) < 1e-10 + assert np.abs(o[2] - 3.62695844e-05) < 1e-10 + assert np.abs(o[3] + 5.97692290e-06) < 1e-10 + + p1 = o[0] + # Diff between small angle approximation and angle + assert np.abs(p0 - p1) - 1.3504822260479443e-15 < 1e-20 # Test on control system @@ -118,10 +132,10 @@ def test_arrays(install_test_package): # Using aggregator pos = sr.design.get_bpms("BPMS").positions.get() - assert np.abs(pos[0][0] + 7.21154171490481e-05) < 1e-10 - assert np.abs(pos[0][1] - 3.3988843436571406e-05) < 1e-10 - assert np.abs(pos[1][0] - 1.1681211772781844e-04) < 1e-10 - assert np.abs(pos[1][1] - 7.072972488250373e-06) < 1e-10 + assert np.abs(pos[0][0] - 7.22262850488348e-05) < 1e-10 + assert np.abs(pos[0][1] - 3.4291613955705856e-05) < 1e-10 + assert np.abs(pos[1][0] + 1.1696152238807462e-04) < 1e-10 + assert np.abs(pos[1][1] - 7.4265634524358045e-06) < 1e-10 # Using aggregator (h and v) pos_h = sr.design.get_bpms("BPMS").h.get() @@ -136,10 +150,10 @@ def test_arrays(install_test_package): bpms = BPMArray("BPM_noagg", bpms, use_aggregator=False) pos = bpms.positions.get() - assert np.abs(pos[0][0] + 7.21154171490481e-05) < 1e-10 - assert np.abs(pos[0][1] - 3.3988843436571406e-05) < 1e-10 - assert np.abs(pos[1][0] - 1.1681211772781844e-04) < 1e-10 - assert np.abs(pos[1][1] - 7.072972488250373e-06) < 1e-10 + assert np.abs(pos[0][0] - 7.22262850488348e-05) < 1e-10 + assert np.abs(pos[0][1] - 3.4291613955705856e-05) < 1e-10 + assert np.abs(pos[1][0] + 1.1696152238807462e-04) < 1e-10 + assert np.abs(pos[1][1] - 7.4265634524358045e-06) < 1e-10 # Radom array elts = sr.design.get_elemens("ElArray") @@ -182,7 +196,7 @@ def test_arrays(install_test_package): assert np.abs(strHVSQ[4] + 0.000017) < 1e-10 # V assert np.abs(strHVSQ[5] - 1e-6) < 1e-10 # SQ - bpmsLive = BPMArray("",sr.live.get_all_bpms()) + bpmsLive = BPMArray("", sr.live.get_all_bpms()) bpmsLive.positions.get() Factory.clear() diff --git a/tests/test_ident_models.py b/tests/test_ident_models.py index 4281efcb..4b0d9dcc 100644 --- a/tests/test_ident_models.py +++ b/tests/test_ident_models.py @@ -40,9 +40,9 @@ def test_cfm_magnets(magnet_file, install_test_package): magnet_v_design.strength.set(0.000015) o, _ = sr.design.get_lattice().find_orbit() - assert np.abs(o[0] + 9.91848416e-05) < 1e-10 - assert np.abs(o[1] + 3.54829761e-07) < 1e-10 - assert np.abs(o[2] + 1.56246320e-06) < 1e-10 - assert np.abs(o[3] + 1.75037311e-05) < 1e-10 + assert np.abs(o[0] - 9.90267693e-05) < 1e-10 + assert np.abs(o[1] - 3.39661431e-07) < 1e-10 + assert np.abs(o[2] + 1.59928207e-06) < 1e-10 + assert np.abs(o[3] + 1.74771216e-05) < 1e-10 Factory.clear()