Skip to content

fix: enricher molar_mass + pymarkdown MD031 + ADR infrastructure - #14

Merged
gerchowl merged 4 commits into
devfrom
chore/enricher-pymarkdown-molar-mass
Apr 15, 2026
Merged

gerchowl merged 4 commits into
devfrom
chore/enricher-pymarkdown-molar-mass

Conversation

@gerchowl

Copy link
Copy Markdown
Contributor

Summary

Resolves two of the three pre-existing-debt issues from last session and establishes ADR infrastructure on the way.

Issue #11 (Python pin / cadquery-ocp + vtk wheel gap) is deliberately not included — it deserves its own PR because it restructures CI into a matrix.

Commits

  1. fix(pymarkdown): rewrite RELEASE_PROCESS + TEMPERATURE_UNITS to satisfy MD031
  2. docs(adr): add ADR infrastructure + ADR-0001 on derived chemistry
  3. fix(enricher): Material.molar_mass computed property + correct enricher docs

#9 — enricher fix + Material.molar_mass

Diagnosis: periodictable.formula(compound).density is always None — the library only has density data for pure elements. A compound's density depends on crystal packing and cannot be derived from the formula alone. The three xfail(strict=True) tests in test_enrichers.py were asking a question with no answer at that layer.

Fix: enrich_from_periodictable's docstring is rewritten to say exactly what it does (composition extraction, element density) and doesn't. Its actual behavior is unchanged — the density-setting path was already a no-op for compounds because formula.density was None. The three latent tests are rewritten to check what actually works (composition + derivable molar mass).

In parallel, Material gains molar_mass + molar_mass_qty as computed @property accessors. They parse self.formula using a local ATOMIC_WEIGHT table in src/pymat/elements.py — a line-for-line mirror of mat-rs/src/elements.rs so the Python and Rust crates give identical numbers to Monte Carlo consumers using both. The new parser handles fractional stoichiometry (Lu1.8Y0.2SiO5) and strips dopant suffixes (LYSO:Ce).

Why as a @property on Material and not in a property group? → See docs/decisions/0001-derived-chemistry-properties-live-on-material.md. Short version: molar mass is definitionally derived from the formula, storing it invites drift, the Rust crate already does it this way, and adding a one-field ChemicalProperties group is YAGNI. The ADR documents the upgrade trigger (≥2 non-derivable chemistry properties needing a home).

#10 — pymarkdown MD031

Diagnosis: pymarkdown's MD031 fixer (not scanner) has a bug with fenced code blocks nested in list items. It tries to add blank lines around the fence but also strips the 3-space indent, un-nesting the block from its list item. On the container CI runner it crashes with BadPluginError; on newer local versions it "succeeds" with destructive output (e.g. pulling git tag -f -a latest out of its numbered step).

Fix: preemptively apply the correct form in both files — blank line before the fence, fence still at 3-space indent — so the fixer has nothing to do. Also clean up MD022/MD026/MD032/MD034 on TEMPERATURE_UNITS_IMPLEMENTATION.md (bare URLs wrapped in angle brackets, trailing colons removed from headings, blank lines around lists). Both files are now idempotent under pymarkdown fix + scan.

The pre-commit exclusion list in .pre-commit-config.yaml drops back to the original three files (README.md, CONTRIBUTE.md, TESTING.md). The underlying pymarkdown fixer bug should still be filed upstream as a follow-up.

Test plan

  • Lint & Format passes (pymarkdown now clean on all files)
  • Tests — 125 passed, 11 skipped locally (up from 122 passed + 3 xfailed)
  • Rust (mat-rs) — no changes in this PR, should pass
  • Security Scan, Dependency Review, CodeQL — no changes, should pass

Related

🤖 Generated with Claude Code

gerchowl and others added 4 commits April 15, 2026 12:47
…fy MD031

Fixes #10.

Root cause: pymarkdown's MD031 fixer has a bug with fenced code blocks
nested inside list items. It tries to add blank lines around the fence
but also strips the 3-space indent, which un-nests the block from its
list item. On the container runner it crashes outright
(BadPluginError); on newer local versions it "succeeds" but produces
corrupted markdown (e.g. replacing "git tag -f -a latest" with no
indent, pulling it out of the numbered step).

Workaround: preemptively apply the correct form — blank line before
the fence, fence still at 3-space indent — so the fixer has nothing
to do. Also clean up MD022 (missing blanks around headings), MD026
(trailing colons), MD032 (missing blanks around lists), and MD034
(bare URLs in TEMPERATURE_UNITS_IMPLEMENTATION.md).

With both files now idempotent under pymarkdown fix + scan, the
pre-commit exclusion list drops back to the original 3 files.

The underlying pymarkdown fixer bug should be reported upstream.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Introduces docs/decisions/ with a MADR-ish template (status, context,
decision, consequences, alternatives, upgrade trigger) and the first
ADR documenting why derived chemistry quantities like molar mass live
as computed @Property accessors on Material rather than in a new
ChemicalProperties group.

Rationale (short version): molar mass is definitionally a function of
formula; storing it invites drift. Rust crate rs-materials already
exposes it as a computed function — Python parity matters for Monte
Carlo consumers that use both. YAGNI rules out a 1-field property
group. Upgrade trigger: when ≥2 non-definitionally-derived chemistry
properties (heat of formation, oxidation state, etc.) need a home,
introduce the group and keep Material.molar_mass as a shortcut
property reading from it.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…er docs

Fixes #9.

enrich_from_periodictable no longer promises to set density for
compounds — periodictable only has density data for pure elements,
and a compound's density depends on crystal packing (not derivable
from formula). The docstring now explicitly says so and points users
at enrich_from_matproj for compound density. The density-setting
code path is unchanged (it was already a no-op for compounds because
formula.density is None); the fix is removing the false promise and
removing the three latently-broken tests that expected it to work.

In its place, Material gains a computed molar_mass @Property (and
molar_mass_qty for pint). Molar mass is parsed from self.formula
using a local ATOMIC_WEIGHT table in pymat/elements.py — mirror of
mat-rs/src/elements.rs to keep Python and Rust APIs symmetric for
Monte Carlo consumers using both. The new parser handles fractional
stoichiometry (Lu1.8Y0.2SiO5) and strips dopant notation (LYSO:Ce).

See ADR-0001 for why this lives on Material rather than in a
ChemicalProperties group.

Tests:
- Three previously xfailed tests in test_enrichers.py rewritten to
  check composition extraction + molar_mass (what actually works),
  no longer xfail.
- New TestMolarMass class in test_core.py with 8 tests: pure
  element, simple compound, fractional stoichiometry, dopant
  stripping, missing formula, unknown element, pint integration.
- 125 passed, 11 skipped (up from 122 passed, 3 xfailed).

Also: enricher uses logger.warning instead of print for invalid
formula warnings, and properly chains ImportError via `from e`.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.

1 participant