Repository navigation
fix: enricher molar_mass + pymarkdown MD031 + ADR infrastructure - #14
Merged
Merged
Conversation
…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]>
This was referenced Apr 15, 2026
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
Resolves two of the three pre-existing-debt issues from last session and establishes ADR infrastructure on the way.
enrich_from_periodictablecompound densityRELEASE_PROCESS.mddocs/decisions/+ first ADRIssue #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
fix(pymarkdown): rewrite RELEASE_PROCESS + TEMPERATURE_UNITS to satisfy MD031docs(adr): add ADR infrastructure + ADR-0001 on derived chemistryfix(enricher): Material.molar_mass computed property + correct enricher docs#9 — enricher fix +
Material.molar_massDiagnosis:
periodictable.formula(compound).densityis alwaysNone— 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 threexfail(strict=True)tests intest_enrichers.pywere 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 becauseformula.densitywas None. The three latent tests are rewritten to check what actually works (composition + derivable molar mass).In parallel,
Materialgainsmolar_mass+molar_mass_qtyas computed@propertyaccessors. They parseself.formulausing a localATOMIC_WEIGHTtable insrc/pymat/elements.py— a line-for-line mirror ofmat-rs/src/elements.rsso 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
@propertyonMaterialand not in a property group? → Seedocs/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-fieldChemicalPropertiesgroup 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. pullinggit tag -f -a latestout 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 underpymarkdown fix+scan.The pre-commit exclusion list in
.pre-commit-config.yamldrops 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
Related
🤖 Generated with Claude Code