-
Notifications
You must be signed in to change notification settings - Fork 3
Feature implement bpm device #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ca42f9e
Initial implementation of pyAML BPM interfaces for control system and…
gubaidulinvadim 60c87cd
Merge branch 'main' into feature-implement-bpm-device
gubaidulinvadim 4578931
Fixed import errors. First runnable test (still fails).
gubaidulinvadim 438671f
Changed to only scalar attributes for DeviceAccess (xpos, ypos, etc)
gubaidulinvadim 329f0b0
Corrected configuration of BPM. Configuration passes without errors now.
gubaidulinvadim 44085d6
Passing simplest test for BPM in Simulator
gubaidulinvadim 7abdb74
Separated tests for simulator.
gubaidulinvadim 214e2d5
Merged main branch
gubaidulinvadim 22ce8e9
Identation correction
gubaidulinvadim b7f88ce
Corrections after merge. Simulator tests pass.
gubaidulinvadim 90df829
Merge with main (with RF devices).
gubaidulinvadim b4f375a
Added tests to 'live' mode
gubaidulinvadim b8dd9ed
Added a simple BPM model
gubaidulinvadim 55c7df8
Added SimpleBPM to tests
gubaidulinvadim 0ae537a
Inheriting from BPMSimpleModel
gubaidulinvadim 5f51ce4
Following JLP suggestions. Shorter names for some BPM model functions.
gubaidulinvadim 37a897f
Added tests with nonzero orbit at BPMs (Simulator). Removed __hardwar…
gubaidulinvadim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| from pyaml.lattice.element import Element, ElementConfigModel | ||
| from pyaml.lattice.abstract_impl import RBpmArray, RWBpmOffsetArray, RWBpmTiltScalar | ||
| from ..control.deviceaccess import DeviceAccess | ||
| from ..control import abstract | ||
| from typing import Self | ||
| from pyaml.bpm.bpm_model import BPMModel | ||
|
|
||
| PYAMLCLASS = "BPM" | ||
|
|
||
| class ConfigModel(ElementConfigModel): | ||
|
|
||
| model: BPMModel | None = None | ||
| """Object in charge of BPM modeling""" | ||
|
|
||
|
|
||
|
|
||
| class BPM(Element): | ||
| """ | ||
| Class providing access to one BPM of a physical or simulated lattice | ||
| """ | ||
|
|
||
| def __init__(self, cfg: ConfigModel): | ||
| """ | ||
| Construct a BPM | ||
|
|
||
| Parameters | ||
| ---------- | ||
| name : str | ||
| Element name | ||
| hardware : DeviceAccess | ||
| Direct access to a hardware (bypass the BPM model) | ||
| model : BPMModel | ||
| BPM model in charge of computing beam position | ||
| """ | ||
|
|
||
| super().__init__(cfg.name) | ||
|
|
||
| self.__model = cfg.model if hasattr(cfg, "model") else None | ||
| self._cfg = cfg | ||
| self.__positions = None | ||
| self.__offset = None | ||
| self.__tilt = None | ||
|
|
||
| @property | ||
| def model(self) -> BPMModel: | ||
| return self.__model | ||
|
|
||
| @property | ||
| def positions(self) -> RBpmArray: | ||
| if self.__positions is None: | ||
| raise Exception(f"{str(self)} has no attached positions") | ||
| return self.__positions | ||
|
|
||
| @property | ||
| def offset(self) -> RWBpmOffsetArray: | ||
| if self.__offset is None: | ||
| raise Exception(f"{str(self)} has no attached offset") | ||
| return self.__offset | ||
|
|
||
| @property | ||
| def tilt(self) -> RWBpmTiltScalar: | ||
| if self.__tilt is None: | ||
| raise Exception(f"{str(self)} has no attached tilt") | ||
| return self.__tilt | ||
|
|
||
| def attach(self, positions: RBpmArray , offset: RWBpmOffsetArray, | ||
| tilt: RWBpmTiltScalar) -> Self: | ||
| # Attach positions, offset and tilt attributes and returns a new | ||
| # reference | ||
| obj = self.__class__(self._cfg) | ||
| obj.__model = self.__model | ||
| obj.__positions = positions | ||
| obj.__offset = offset | ||
| obj.__tilt = tilt | ||
| return obj | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from abc import ABCMeta, abstractmethod | ||
| import numpy as np | ||
| from numpy.typing import NDArray | ||
|
|
||
| class BPMModel(metaclass=ABCMeta): | ||
| """ | ||
| Abstract class providing interface to accessing BPM positions, offsets, | ||
| tilts. | ||
| """ | ||
| @abstractmethod | ||
| def read_position(self) -> NDArray[np.float64]: | ||
| """ | ||
| Read horizontal and vertical positions from a BPM. | ||
| Returns | ||
| ------- | ||
| NDArray[np.float64] | ||
| Array of shape (2,) containing the horizontal and vertical | ||
| positions | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def read_tilt(self) -> float: | ||
| """ | ||
| Read the tilt value from a BPM. | ||
| Returns | ||
| ------- | ||
| float | ||
| The tilt value of the BPM | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def read_offset(self) -> NDArray: | ||
| """ | ||
| Read the offset values from a BPM. | ||
| Returns | ||
| ------- | ||
| NDArray[np.float64] | ||
| Array of shape (2,) containing the horizontal and vertical | ||
| offsets | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def set_tilt(self, tilt: float): | ||
| """ | ||
| Set the tilt value of a BPM. | ||
| Parameters | ||
| ---------- | ||
| tilt : float | ||
| The tilt value to set for the BPM | ||
| Returns | ||
| ------- | ||
| None | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def set_offset(self, offset: NDArray[np.float64]): | ||
| """ | ||
| Set the offset values of a BPM | ||
| Parameters | ||
| ---------- | ||
| offset_values : NDArray[np.float64] | ||
| Array of shape (2,) containing the horizontal and vertical | ||
| offsets to set for the BPM | ||
| """ | ||
| pass | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| from pyaml.bpm.bpm_model import BPMModel | ||
| from pydantic import BaseModel,ConfigDict | ||
| import numpy as np | ||
| from ..control.deviceaccess import DeviceAccess | ||
| from numpy.typing import NDArray | ||
| # Define the main class name for this module | ||
| PYAMLCLASS = "BPMSimpleModel" | ||
|
|
||
| class ConfigModel(BaseModel): | ||
|
|
||
| model_config = ConfigDict(arbitrary_types_allowed=True,extra="forbid") | ||
|
|
||
| x_pos: DeviceAccess | ||
| """Horizontal position""" | ||
| y_pos: DeviceAccess | ||
| """Vertical position""" | ||
|
|
||
| class BPMSimpleModel(BPMModel): | ||
| """ | ||
| Concrete implementation of BPMModel that simulates a BPM with tilt and | ||
| offset values. | ||
| """ | ||
| def __init__(self, cfg: ConfigModel): | ||
| self._cfg = cfg | ||
|
|
||
| self.__x_pos = cfg.x_pos | ||
| self.__y_pos = cfg.y_pos | ||
|
|
||
| def read_position(self) -> NDArray: | ||
| """ | ||
| Simulate reading the position values from a BPM. | ||
| Returns | ||
| ------- | ||
| np.ndarray | ||
| Array of shape (2,) containing the horizontal and vertical | ||
| positions | ||
| """ | ||
| return np.array([self.__x_pos.get(), self.__y_pos.get()]) | ||
|
|
||
| def read_tilt(self) -> float: | ||
| """ | ||
| Simulate reading the tilt value from a BPM. | ||
| Returns | ||
| ------- | ||
| float | ||
| The tilt value of the BPM | ||
| """ | ||
| raise NotImplementedError("Tilt reading not implemented in this model.") | ||
|
|
||
| def read_offset(self) -> NDArray: | ||
| """ | ||
| Simulate reading the offset values from a BPM. | ||
| Returns | ||
| ------- | ||
| np.ndarray | ||
| Array of shape (2,) containing the horizontal and vertical | ||
| offsets | ||
| """ | ||
| raise NotImplementedError("Offset reading not implemented in this model.") | ||
| def set_tilt(self, tilt: float): | ||
| """ | ||
| Simulate setting the tilt value of a BPM. | ||
| Parameters | ||
| ---------- | ||
| tilt : float | ||
| The tilt value to set for the BPM | ||
| Returns | ||
| ------- | ||
| None | ||
| """ | ||
| raise NotImplementedError("Tilt setting not implemented in this model.") | ||
|
|
||
| def set_offset(self, offset_values: np.ndarray): | ||
| """ | ||
| Simulate setting the offset values of a BPM | ||
| Parameters | ||
| ---------- | ||
| offset_values : np.ndarray | ||
| Array of shape (2,) containing the horizontal and vertical | ||
| offsets to set for the BPM | ||
| """ | ||
| raise NotImplementedError("Offset setting not implemented in this model.") | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| from pyaml.bpm.bpm_model import BPMModel | ||
| from pyaml.bpm.bpm_simple_model import BPMSimpleModel | ||
| from pydantic import BaseModel,ConfigDict | ||
| import numpy as np | ||
| from ..control.deviceaccess import DeviceAccess | ||
| from numpy.typing import NDArray | ||
| # Define the main class name for this module | ||
| PYAMLCLASS = "BPMTiltOffsetModel" | ||
|
|
||
| class ConfigModel(BaseModel): | ||
|
|
||
| model_config = ConfigDict(arbitrary_types_allowed=True,extra="forbid") | ||
|
|
||
| x_pos: DeviceAccess | ||
| """Horizontal position""" | ||
| y_pos: DeviceAccess | ||
| """Vertical position""" | ||
| x_offset: DeviceAccess | ||
| """Horizontal BPM offset""" | ||
| y_offset: DeviceAccess | ||
| """Vertical BPM offset""" | ||
| tilt: DeviceAccess | ||
| """BPM tilt""" | ||
|
|
||
| class BPMTiltOffsetModel(BPMSimpleModel): | ||
| """ | ||
| Concrete implementation of BPMModel that simulates a BPM with tilt and | ||
| offset values. | ||
| """ | ||
| def __init__(self, cfg: ConfigModel): | ||
| super().__init__(cfg) | ||
| self.__x_pos = cfg.x_pos | ||
| self.__y_pos = cfg.y_pos | ||
| self.__x_offset = cfg.x_offset | ||
| self.__y_offset = cfg.y_offset | ||
| self.__tilt = cfg.tilt | ||
|
|
||
| def read_tilt(self) -> float: | ||
| """ | ||
| Simulate reading the tilt value from a BPM. | ||
| Returns | ||
| ------- | ||
| float | ||
| The tilt value of the BPM | ||
| """ | ||
| return self.__tilt.get() | ||
|
|
||
| def read_offset(self) -> NDArray: | ||
| """ | ||
| Simulate reading the offset values from a BPM. | ||
| Returns | ||
| ------- | ||
| np.ndarray | ||
| Array of shape (2,) containing the horizontal and vertical | ||
| offsets | ||
| """ | ||
| return np.array([self.__x_offset.get(), self.__y_offset.get()]) | ||
|
|
||
| def set_tilt(self, tilt: float): | ||
| """ | ||
| Simulate setting the tilt value of a BPM. | ||
| Parameters | ||
| ---------- | ||
| tilt : float | ||
| The tilt value to set for the BPM | ||
| Returns | ||
| ------- | ||
| None | ||
| """ | ||
| self.__tilt.set(tilt) | ||
|
|
||
| def set_offset(self, offset_values: np.ndarray): | ||
| """ | ||
| Simulate setting the offset values of a BPM | ||
| Parameters | ||
| ---------- | ||
| offset_values : np.ndarray | ||
| Array of shape (2,) containing the horizontal and vertical | ||
| offsets to set for the BPM | ||
| """ | ||
| self.__x_offset.set(offset_values[0]) | ||
| self.__y_offset.set(offset_values[1]) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 things:
__init__()i.e.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will correct. I understood that the hardware part can be skipped only yesterday by looking at your RF device implementation.