Skip to content

Commit 921b7b9

Browse files
Nush395Torax team
authored andcommitted
Backwards compatibility fix.
Old config files are saved with the `nx` field which upon reloading now throws an error. Add a before validator so that old file inputs are sanitised before construction. PiperOrigin-RevId: 861228611
1 parent ed6b853 commit 921b7b9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

torax/_src/torax_pydantic/interpolated_param_2d.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ class Grid1D(model_base.BaseModelFrozen):
5151
"""
5252
face_centers: pydantic_types.NumpyArray1DSorted
5353

54+
@pydantic.model_validator(mode='before')
55+
@classmethod
56+
def _conform_data(cls, data: Any) -> Any:
57+
if 'nx' in data:
58+
nx = data['nx']
59+
face_centers = get_face_centers(nx)
60+
data['face_centers'] = face_centers
61+
return data
62+
5463
@pydantic.field_validator('face_centers')
5564
@classmethod
5665
def _validate_face_centers(cls, v: np.ndarray) -> np.ndarray:

0 commit comments

Comments
 (0)