Repository navigation
feat(schema): _stddev sibling sugar + ufloat boundary helper (#149) - #183
Merged
Merged
Conversation
Per ADR-0003, `_stddev` is loader sugar — not a parallel set of
dataclass fields. The existing in-value `{nominal, stddev}` form
remains canonical (now also routed through `_parse_value` for
property scalars, not just compositions). Sibling sugar exists
for hand-edited TOML ergonomics.
Loader (src/pymat/loader.py):
- Two-pass `update_properties`: collect `<base>_stddev` siblings,
then route each value through `_parse_value` and fold sibling
stddev into a ufloat at assignment time.
- Hard error on double-specification (in-value `{nominal, stddev}`
AND sibling `_stddev`) — silent precedence is worse than failure.
- Hard error on orphan stddev (`density_stddev` with no base value).
Boundary helpers (per ADR-0003 #6):
- `Material.density_g_mm3` coerces ufloat → nominal float for
build123d (which can't accept ufloats in mass calculations).
- pymat-mcp `_nominal()` helper applied at JSON boundaries
(`_props_dict`, `_brief`, `compute_mass`) so agents never see
a ufloat that `json.dumps` can't serialize.
Tests:
- `tests/test_stddev_sugar.py` (11 tests): sibling sugar + value form
+ double-spec + orphan + zero stddev + multiple fields per group +
density_g_mm3 boundary + mass_from_volume_mm3 boundary.
- `clients/python/pymat-mcp/tests/test_tools.py::TestComputeMass::
test_ufloat_density_returns_plain_floats`: end-to-end JSON round-trip
with a ufloat density.
Full suite: 499 passed, 11 skipped, no regressions.
Closes #149
6 tasks
3 tasks done
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Per ADR-0003,
_stddevlands as loader sugar, not as parallel dataclass fields. The existing in-value{nominal, stddev}form is now also routed through_parse_valuefor property scalars (it already worked for compositions). Sibling sugar exists for hand-edited TOML ergonomics. Both forms work; double-specification is a hard error.Loader changes (
src/pymat/loader.py)Two-pass
update_properties:<base>_stddevsiblings into{base_key: stddev}._parse_value(so dict forms work for scalars too), then fold sibling stddev into a ufloat at assignment.Hard errors:
ValueError_stddev(no matching base value) →ValueErrorBoundary helpers (per ADR-0003 §6)
Once contributors actually populate uncertainties, downstream callers crossing JSON or build123d boundaries will see
ufloatwhere they expectfloat:Material.density_g_mm3_props_dict_nominal()helper applied after the existing Pint-magnitude unwrap_briefcompute_massdensity_g_per_cm3andmass_gboth become plain floatsTest plan
tests/test_stddev_sugar.py(11 tests): sibling sugar + value form + double-spec + orphan + zero stddev + multiple fields +density_g_mm3boundary +mass_from_volume_mm3boundaryclients/python/pymat-mcp/tests/test_tools.py::TestComputeMass::test_ufloat_density_returns_plain_floats: end-to-end JSON round-trip with a ufloat densityruff checkcleanruff formatno diffRisks / regressions considered
{nominal, stddev}for property scalars — there are none in the corpus today (the form only worked for compositions until now). New routing is purely additive for them.<prop>_stddev-named legacy fields that aren't intended as siblings — none exist; verified by full suite +test_toml_integritypassing.uncertaintiesimport on cold path — already imported by loader for_parse_value; no new dependency surface.*_qtyproperties when value is ufloat — Pint+ufloat interop is intact (Pint accepts ufloat as magnitude);density_qty.to('kg/m^3')works,.magnitudeis a ufloat. Lossy coercion only at JSON/build123d boundaries.Closes #149
Part of the schema foundation series: #150 (merged) → #149 → #148 → #174.