You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Overview
With the implementation in the main branch, if we add a `name` attribute
to the `line` object created in the FODO example, the attribute is
ignored and the output is
```yaml
kind: Line
line:
- drift1:
kind: Drift
length: 0.25
- quad1:
MagneticMultipoleP:
Bn1: 1.0
kind: Quadrupole
length: 1.0
- drift2:
kind: Drift
length: 0.5
- quad2:
MagneticMultipoleP:
Bn1: -1.0
kind: Quadrupole
length: 1.0
- drift3:
kind: Drift
length: 0.5
```
This is not consistent with the example in
https://github.com/campa-consortium/pals/blob/main/examples/fodo.pals.yaml.
With the implementation in this branch, if we add a `name` attribute to
the `line` object created in the FODO example, the attribute is stored
and the output is
```yaml
fodo_cell:
kind: BeamLine
line:
- drift1:
kind: Drift
length: 0.25
- quad1:
MagneticMultipoleP:
Bn1: 1.0
kind: Quadrupole
length: 1.0
- drift2:
kind: Drift
length: 0.5
- quad2:
MagneticMultipoleP:
Bn1: -1.0
kind: Quadrupole
length: 1.0
- drift3:
kind: Drift
length: 0.5
```
which is consistent with the example in
https://github.com/campa-consortium/pals/blob/main/examples/fodo.pals.yaml.
This is achieved primarily by deriving the `Line` (`BeamLine` after pals-project#15)
class from the base element class `BaseElement` instead of deriving it
from Pydantic's base model class `BaseModel`.
I also merged the custom field validation of the `line` field with the
custom model validation, since we needed one anyways to fix the
deserialization. I don't see why they should be separate.
I wonder if the right way to do this is using `@model_serializer`
instead of `@model_validator`...
### To do
- [x] Serialization (fixed with
[c391e43](pals-project@c391e43),
very few lines changed)
- [x] Deserialization (fixed with the custom model validator, many more
lines changed)
- [x] Cleaning
0 commit comments