Skip to content

feat(schema): T-dependent property curves (#148) - #185

Merged
gerchowl merged 2 commits into
mainfrom
feature/148-temp-curves
May 5, 2026
Merged

gerchowl merged 2 commits into
mainfrom
feature/148-temp-curves

Conversation

@gerchowl

@gerchowl gerchowl commented May 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds <prop>_curve = {temps_K = [...], values = [...]} TOML support with linear interpolation for 9 properties: thermal_conductivity, specific_heat, thermal_expansion, youngs_modulus, yield_strength, resistivity, refractive_index, light_yield, decay_time.

[aluminum.al6061.thermal]
thermal_conductivity_value = 167
thermal_conductivity_unit = "W/(m*K)"
thermal_conductivity_curve = { temps_K = [77, 200, 293, 400, 500], values = [105, 150, 167, 180, 192] }
from pymat.units import ureg
mat.properties.thermal.thermal_conductivity_at(77 * ureg.kelvin)  # → 105 W/(m·K) Quantity
mat.properties.optical.light_yield_at(233 * ureg.kelvin)          # LYSO at -40 °C → +15% boost

Changes

File What
src/pymat/curves.py (new) TempCurve frozen dataclass with interpolate(T), validation at construction
src/pymat/properties.py 9 new <prop>_curve sibling fields + 8 new <prop>_at(T) methods + 1 updated (thermal_conductivity_at) + shared _eval_curve_or_scalar helper
src/pymat/loader.py New _curve branch in update_properties — builds TempCurve.from_toml() when key ends in _curve and value is a dict
tests/test_temp_curves.py (new) 24 tests: TempCurve interp + edge cases, loader, evaluators, parametrized 8-property check, regression

Edge cases (per ADR-0003 §2 — pinned)

Case Behavior
T at exact knot Return knot value
T between knots Linear interp
T below min knot Clamp to min (debug log)
T above max knot Clamp to max (debug log)
Curve with 1 point Return that constant for any T
Curve absent Fall back to scalar
Unsorted / mismatched / empty Raise at load time (TempCurve.post_init)
Curve for unknown property Silently ignored (consistent with hasattr-based assignment)

Backwards compatibility

  • thermal_conductivity_at(T) precedence: curve > legacy _ref_temp + _coeff linear > scalar. The legacy _ref_temp / _coeff fields stay; existing TOMLs using them continue to work unchanged (regression test included).
  • Scalar field stays a scalar — never promoted to a callable (would break *_qty Pint properties and JSON serialization).
  • Existing TOMLs without _curve fields: fully backwards-compatible, full corpus loads (regression test included).

Deferred

mat.at(T=...) view (mentioned in ADR-0003 §2) is not in this PR. The issue text only requires "linear interpolation in properties.py"; the per-dataclass _at(T) methods satisfy that. The view adds API surface without unblocking downstream work — split into a follow-up if/when needed.

Test plan

  • pytest tests/test_temp_curves.py — 24 tests pass
  • pytest tests/test_temp_curves.py tests/test_check_licenses.py tests/test_sources.py tests/test_stddev_sugar.py — all 67 foundation tests pass together
  • Full suite: 524 passed, 11 skipped, zero regressions
  • ruff check clean, ruff format no diff

Risks / regressions considered

  1. _curve keys leaking into _value parsing path — handled by explicit _curve branch with continue before the _value branch.
  2. <prop>_curve field-existence check — uses hasattr(prop_obj, curve_field) so a curve for a non-existent prop is silently dropped (matches existing assignment semantics; explicit test).
  3. numpy dependency — implementation uses pure Python (no numpy import). No new transitive deps.
  4. Pint Quantity behavior with curve values — evaluators return value * ureg(unit) exactly as *_qty properties do; no new Quantity-shape surprises.
  5. TempCurve frozen dataclass + list fields — frozen=True prevents reassignment, but lists inside are still mutable; per-call interpolate(T) is read-only so this is safe in practice (and from_toml defensively copies via list(...)).

Closes #148
Schema foundation series complete: #150 (merged) → #149 (merged) → #174 (merged) → #148 (this PR).

gerchowl added 2 commits May 5, 2026 13:31
Adds `<prop>_curve = {temps_K = [...], values = [...]}` TOML support
with linear interpolation for 9 properties: thermal_conductivity,
specific_heat, thermal_expansion, youngs_modulus, yield_strength,
resistivity, refractive_index, light_yield, decay_time.

New module `pymat.curves` defines `TempCurve` (frozen dataclass) with
piecewise-linear interpolation; out-of-range temps CLAMP to nearest knot
(per ADR-0003 §2 — engineering data extrapolated below its measured
range is a lie). Validation at construction: empty/unsorted/mismatched
arrays raise immediately, not at query time.

Properties (src/pymat/properties.py):
- New `<prop>_curve: Optional[TempCurve] = None` sibling fields on the
  9 listed properties across Mechanical/Thermal/Electrical/Optical
  dataclasses.
- New `<prop>_at(T)` evaluators on each dataclass (8 new + 1 updated).
- Shared `_eval_curve_or_scalar()` helper dispatches: curve > scalar.
- Existing `thermal_conductivity_at(T)` updated to consult curve first;
  legacy `_ref_temp + _coeff` linear path kept intact for backwards
  compat (precedence: curve > legacy linear > scalar).

Loader (src/pymat/loader.py):
- New `_curve` branch in `update_properties` — when a key ends in
  `_curve` and value is a dict, build via `TempCurve.from_toml`. Unknown
  curve fields silently ignored (consistent with hasattr-based
  assignment on other props).

Tests: tests/test_temp_curves.py (24 tests):
- TempCurve interpolation: exact knot, between knots, clamp below/above,
  single-point, empty/unsorted/mismatched at construction
- Loader: curve parsing, curve-without-scalar, invalid raises at load,
  unknown-prop curve silently ignored
- Evaluators: curve-first precedence, scalar fallback, legacy
  ref_temp+coeff still works
- 8 new `_at(T)` methods parametrized
- Full corpus loads without curves (regression)

Defers `mat.at(T=...)` view to a follow-up PR — issue text only requires
the per-dataclass `_at(T)` methods, and the view adds API surface
without unblocking downstream work.

Full suite: 524 passed, 11 skipped, no regressions.

Closes #148
@gerchowl
gerchowl merged commit 39d3dc4 into main May 5, 2026
19 checks passed
@gerchowl
gerchowl deleted the feature/148-temp-curves branch May 5, 2026 11:37
@vig-os-release-app vig-os-release-app Bot mentioned this pull request May 5, 2026
6 tasks
gerchowl added a commit that referenced this pull request May 6, 2026
Bundles four schema-foundation feats merged after 3.9.0 plus the Vis
public-API clarification into a single release:

- feat(schema): _sources provenance table (#150 / #182)
- feat(schema): _stddev sibling sugar + ufloat boundary helper
  (#149 / #183)
- feat(policy): data licensing policy + CI license gate (#174 / #184)
- feat(schema): T-dependent property curves (#148 / #185)
- fix(vis): declare Vis as public API (#98 / #186)

Three feats × one fix → minor version bump per semver. The version
3.9.1 originally proposed for the Vis public-API change alone became
inconsistent once the four schema feats had landed on main without
their own release cut, so they're rolled into 3.10.0 honestly rather
than shipped as a misleading patch.

CHANGELOG entry for 3.10.0 covers all five items with PR + issue
links. .release-please-manifest.json synced to 3.10.0 so the open
release-please PR (#80) recomputes correctly going forward.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema: T-dependent property curves

1 participant