Summary
Convert DiffusionConfig (L84) and GridGeometry (L76) in matrix_ops.py from frozen dataclasses to Pydantic BaseModel.
Motivation
DiffusionConfig — bc field accepts any string but only "neumann" and "absorbing" are valid. Validation currently happens downstream in build_laplacian_tridiag(). Pydantic Literal["neumann", "absorbing"] catches invalid values at construction.
GridGeometry — n and dx have implicit constraints (n > 0, dx > 0) that are never checked. Pydantic Field(gt=0) adds guardrails.
coeff in DiffusionConfig should likely be ge=0 (non-negative diffusion coefficient).
Scope
- Convert 2 dataclasses → Pydantic
BaseModel with frozen=True
- Add field constraints and
bc as Literal type
- Remove downstream
bc validation in build_laplacian_tridiag()
- Update tests
Constraints
- Must pass
ruff check --preview and mypy --strict
Related
Summary
Convert
DiffusionConfig(L84) andGridGeometry(L76) inmatrix_ops.pyfrom frozen dataclasses to PydanticBaseModel.Motivation
DiffusionConfig—bcfield accepts any string but only"neumann"and"absorbing"are valid. Validation currently happens downstream inbuild_laplacian_tridiag(). PydanticLiteral["neumann", "absorbing"]catches invalid values at construction.GridGeometry—nanddxhave implicit constraints (n > 0,dx > 0) that are never checked. PydanticField(gt=0)adds guardrails.coeffinDiffusionConfigshould likely bege=0(non-negative diffusion coefficient).Scope
BaseModelwithfrozen=TruebcasLiteraltypebcvalidation inbuild_laplacian_tridiag()Constraints
ruff check --previewandmypy --strictRelated
RunConfigand nested config dataclasses #52 (Pydantic-ify RunConfig)