-
Notifications
You must be signed in to change notification settings - Fork 3
Add Unit Tests, First Elements, Examples #3
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
Conversation
0de8f72 to
b764d2f
Compare
This comment was marked as resolved.
This comment was marked as resolved.
b2ca930 to
3390169
Compare
| @@ -1,4 +1,4 @@ | |||
| name: pals | |||
| name: pals-python | |||
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.
The -python suffixes added here are not really needed.
From the Python viewpoint, this repo is "pals".
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.
I think this original "line" concept might be what PALS calls "lattice branch". What do you think?
cemitch99
left a comment
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.
This looks like a good starting point, thanks a lot. Verified that the tests in test_schema.py work (for me locally). My main comment is that some documentation on installation and running of the tests would be useful for collaborators.
|
Here's an example of how the current draft implementation of the quadrupole element works. The code (extracted from a unit test) # Create one drift element with custom name and length
element_name = "quadrupole_element"
element_length = 1.0
element_magnetic_multipole_Bn1 = 1.1
element_magnetic_multipole_Bn2 = 1.2
element_magnetic_multipole_Bs1 = 2.1
element_magnetic_multipole_Bs2 = 2.2
element_magnetic_multipole_tilt1 = 3.1
element_magnetic_multipole_tilt2 = 3.2
element_magnetic_multipole = MagneticMultipoleParameters(
Bn1=element_magnetic_multipole_Bn1,
Bs1=element_magnetic_multipole_Bs1,
tilt1=element_magnetic_multipole_tilt1,
Bn2=element_magnetic_multipole_Bn2,
Bs2=element_magnetic_multipole_Bs2,
tilt2=element_magnetic_multipole_tilt2,
)
element = QuadrupoleElement(
name=element_name,
Length=element_length,
MagneticMultipoleP=element_magnetic_multipole,
)
# Serialize the Line object to YAML
yaml_data = yaml.dump(element.model_dump(), default_flow_style=False)
print(f"\n{yaml_data}")produces the standard output |
adc0689 to
70d3733
Compare
559cc9e to
aabd7ec
Compare
aabd7ec to
f131afd
Compare
|
I think this PR is ready for review and merge. I would proceed with further changes in follow-up PRs, since this is introducing a lot of prerequired infrastructure as well. |
cemitch99
left a comment
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.
All the tests are working. When I run the fodo.py example, I see that the YAML output is as follows:
kind: Line
line:
- kind: Drift
length: 0.25
name: drift1
- MagneticMultipoleP:
Bn1: 1.0
kind: Quadrupole
length: 1.0
name: quad1
- kind: Drift
length: 0.5
name: drift2
- MagneticMultipoleP:
Bn1: -1.0
kind: Quadrupole
length: 1.0
name: quad2
- kind: Drift
length: 0.5
name: drift3
The syntax is slightly different from the most recently-updated examples in the standard documentation, such as:
line:
- thingB
- Drift:
name: thingC
- Quadrupole:
direction: -1
...
- Beamline:
repetition: 3
...
The main differences are the absence of the kind keyword and the second level of indentation for parameters. It contains the same information, so I'm not sure how important this is at this stage.
|
It is ok with me to isolate further changes to a follow-up. |
|
Thanks, @cemitch99. Yes, that is the kind of things I would like to address separately because I think they are not trivial. This YAML output reflects an object of type That object should be all we need, so if I want to achieve this instead I might need to do something custom/manual, like an extra wrapping class or something along these lines. |
|
Remember that the base documentation does not mandate the syntax of the YAML file. Just the logical structure. |
This PR introduces additional infrastructure to enhance development:
pytestto ensure code reliability.The primary goal is to translate the original demo code into comprehensive unit tests, which will be expanded as development progresses.
During the process, I identified some issues in the original demo, likely due to changes in
pydanticsince the initial implementation. To address these, I am re-implementing the original elements one by one, ensuring each part is thoroughly tested according to the original demo.I have also cleaned the
.gitignorefile to make it as minimal as necessary. Additional entries will be added as needed.To-Do:
Follow-up PRs:
Examples
YAML
Example of YAML formatting:
Underlying (pseudo-)code:
JSON
Example of JSON formatting:
{ "element": "Line", "line": [ { "element": "BaseElement", "name": "element1" }, { "element": "ThickElement", "length": 2.0, "name": "element2" } ] }Underlying (pseudo-)code:
Notes
model_dumpis a method ofpydantic's classBaseModel: https://docs.pydantic.dev/latest/concepts/serialization/