-
Notifications
You must be signed in to change notification settings - Fork 21
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
Convert magnet to use pydantic model #104
Convert magnet to use pydantic model #104
Conversation
…ng. Can extract by area
…automatic_yaml_generation
…tKing06/lcls-tools into 92_automatic_yaml_generation
…ctional changes to tests
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.
Looks great, thanks!
frozen=True, | ||
) | ||
... | ||
|
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.
Three dots here?
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.
Comment here on the ...
) | ||
with open(location, "r") as device_file: | ||
config_data = yaml.safe_load(device_file) | ||
if name: |
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.
Add comments here on default behavior and naming issue.
metadata: | ||
b_tolerance : 0.002 # in Tesla? | ||
length : 0.135 # in meters? |
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.
Move comments to doc strings.
def test_set_bdes_with_args(self, mock_trim, mock_bdes_put): | ||
bdes_settings = { | ||
"SOL1B": 0.1, | ||
} |
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.
What happens if someone passes a dict with SOL1B not as a string/in quotes?
self.assertIsNone(create_magnet(self.bad_config, "SOL1B")) | ||
self.assertIsNone(create_magnet(area="GUNB", name="BAD-MAGNET-NAME")) | ||
|
||
@patch( |
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.
Some comments around here?
* magnets and screen conversion from csv to dictionary structures working. Can extract by area * add functionality for extracting multiple areas at once * add PVs to yaml magnets extraction * removing unneeded file * working on adding image pvs to yaml files * working on image device code * flake8 and black formatting * make construction function self, add error handling for MEME timeout * formatting * make area a list in screens * add pv_info to screen construction * restrict wildcard search in meme * added models for magnet and associated fields * start to move magnet functions over to pydantic model * magnet pydantic model working with reader now * updated yaml test files to reflect new yaml for devices * magnet and reader tests up to date with pydantic changes, minimal functional changes to tests * make MagnetPVSet have frozen attributes.# * make MagnetPVSet have frozen attributes. * frozen for controls_information base class * missed return for area property! * add setter for bdes * working on being able to set bdes values for several mags * find file by area in reader * use area over location for scope * change yaml path. * remove path * first attempt at function to scan mags * magnet and device now using pydantic model * tests reflect model changes, need to check coverage * add check for function in scan * remove custom exception, pydantic handles mandatory information now * coverage up to 100% for each new class now * formatting * add pydantic to requirements * remove superceeded yaml * add comments for units in tolerance/length * add comment explaining adding name for device here --------- Co-authored-by: Neveu <[email protected]> Co-authored-by: Neveu <[email protected]> Co-authored-by: matt <[email protected]>
Summary of Changes
Device and Magnet classes were originally constructed via dictionary loaded from yaml files. The majority of initialisation code was associated with type-checking, and ensuring that the correct information was defined inside the dictionary passed to the constructor.
It was found that Pydantic models can achieve the same effect and do better at type-enforcement/field-enforcement as well as simplifying the code that defines the class architecture for our devices.
Tests
The user-facing side of these changes now allow us to write code for interfacing with devices like below:
closes #100