Skip to content

Material handoff from upstream frameworks, checked against every required calculation - #75

Open
alhermann wants to merge 3 commits into
mainfrom
feat/scale-bridging
Open

alhermann wants to merge 3 commits into
mainfrom
feat/scale-bridging

Conversation

@alhermann

Copy link
Copy Markdown
Collaborator

openPASO accepts material constants from another framework and hands them to a continuum model only when every calculation a check requires has actually run. The first producer is GENIUS, which writes and test-runs Quantum ESPRESSO inputs. A missing calculation counts as a failed check, not a skipped one: a check that only compares the calculations it finds cannot see one that never ran.

What is added.

  • src/scale_bridge:
    • the handoff card: values plus every calculation behind them;
    • the obligation ledger: accept, reject or incomplete, with a plan of the missing calculations, their settings and estimated cost;
    • continuum stiffness, rotated about z, plane stress;
    • a provider interface (entry point group openpaso.material_providers; the GENIUS adapter lives with GENIUS).
  • One rule, for cubic elastic constants from plane-wave DFT stress-strain calculations:
    • cutoff ×1.25 and k-mesh ×1.3;
    • with smearing, half the smearing and k-mesh ×1.5;
    • C′ and C44 within 2 %, pressure within 0.1 GPa;
    • reported values within 1 % of the stresses.
  • MCP tool material_handoff, with the actions schema, check, plan, continuum (refused unless the check accepts), providers, produce and complete.
  • Docs: how-it-works/scale-bridging.md, tools/material_handoff.md, the tools index and the menu.

Which failures it catches. The rule rejects or holds back a card when:

  • a required convergence calculation is missing, was stopped, or failed;
  • a repeat's settings are looser, or differ in anything besides the tightened ones;
  • an unsmeared reference is repeated with smearing;
  • a repeat applies a different strain than the calculation it claims to repeat;
  • the reference is strained or lacks a cutoff or k-mesh;
  • a strain is mixed or asymmetric;
  • any tensor entry is not finite;
  • the values are not in GPa;
  • C′, C44 or the pressure moves beyond its limit;
  • the values on the card do not follow from the stresses.

The normal pair may lie along any cube axis and the shear pair in any plane; in a cubic crystal they are equivalent. A provider's labels cannot place a saved card outside its folder.

How it was checked.

  • tests/test_scale_bridge.py: 31 cases. They include:

    • every failure listed above;
    • relabelled cube axes;
    • the tool flow with a fake provider;
    • path-traversing labels.

    The cases added after Copilot's review on the fork fail on the code before them.

  • A copper card built from real Quantum ESPRESSO outputs written by GENIUS is accepted (tests/data/cu_elastic_card.json; C11 177.25, C12 123.42, C44 79.17 GPa). An agent then used these constants in the web interface for a perforated copper sheet in NGSolve, and openPASO verified that result.

  • pytest tests: 130 passed, 15 skipped (Windows, before the last round of rule tests; test_scale_bridge.py passes after it).

Not run: the suite on Linux.

…checks

Material data from another framework (for example elastic constants from
Quantum ESPRESSO) is passed to a continuum model only when every calculation a
check requires has run. The required calculations are derived from the
producer's own settings, so a missing one counts as failed instead of being
skipped; a check that only compares the calculations it finds cannot see one
that never ran.

- src/scale_bridge: handoff card (values plus every calculation behind them),
  obligation ledger (accept / reject / incomplete, plan of the missing
  calculations with their settings and estimated cost), rule for cubic elastic
  constants from plane-wave DFT stress-strain calculations (cutoff x1.25 and
  k-mesh x1.3; half smearing and k-mesh x1.5 when smearing is used; C' and C44
  within 2 %, pressure within 0.1 GPa; reported values within 1 % of the
  stresses), continuum stiffness (rotated about z, plane stress), provider
  interface (entry point group openpaso.material_providers; GENIUS is the
  intended first provider, its adapter lives with GENIUS)
- tool material_handoff: schema, check, plan, continuum (refused unless the
  check accepts), providers, produce, complete
- docs: how-it-works/scale-bridging.md, tools/material_handoff.md, tools index,
  menu, _gen_reference TOOL_GROUPS

Checked: tests/test_scale_bridge.py, 12 cases (complete evidence accepted;
missing and stopped calculations incomplete and planned; failed calculation,
missing opposite strain pair, non-finite stress, limit exceeded and
unsupported reported values rejected; looser or different settings do not
count; rotation; tool flow with a fake provider). pytest tests: 102 passed,
20 skipped (test_web_search_reports_a_block.py needs langchain, not installed
here).
The rule read the normal pair from e_xx and the shear pair from e_yz only, so a card whose producer sheared in xy (as the GENIUS copper calculations do) was reported as lacking a shear pair. In a cubic crystal every axis and every shear plane give the same constants, so the rule now finds the pair in whichever single component it is applied. Two tests relabel the cube axes of a complete card and expect the same decision and constants.
Answers to Copilot's review of the material handoff.
- Every entry of a strain or stress tensor must be a finite number; a NaN in an entry no rule reads went through.
- A strain counts as normal or shear only if it is pure and symmetric; mixed and asymmetric strains passed as one component.
- The reference must be unstrained, and must state a positive plane-wave cutoff, a valid ecutrho and a three-number k-mesh; without a cutoff the cutoff comparison silently became a k-mesh comparison.
- Values must be in GPa: the rule compares them with stresses in GPa.
- A repeat counts only with the same role and strain as the calculation it repeats, no smearing when the reference has none, and every other setting identical in both directions.
- A completed retry counts over an earlier stopped attempt; a failed one still rejects.
- A stopped base calculation leaves the card incomplete instead of rejecting it on NaN differences; derived values are empty for a structurally invalid card instead of raising.
- A provider's material or kind label can no longer place the saved card outside its folder.
Each case has a test that fails on the previous code (16 cases). A copper card built from real Quantum ESPRESSO outputs written by GENIUS is accepted (tests/data/cu_elastic_card.json).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical issues can hide failed calculations and combine repeats with inconsistent settings, allowing invalid or unconverged elastic constants to pass.

5 open issues
What changed in this PR

Adds a material-data handoff layer between upstream frameworks and openPASO’s continuum solvers, requiring complete convergence evidence before exporting stiffness data.

Changes:

  • Introduces material cards, an obligation ledger, and cubic elastic-constant validation rules.
  • Adds provider integration and the material_handoff tool for checking, completing, and converting material data.
  • Adds regression tests, a GENIUS-produced copper fixture, and user documentation.
File Description
tests/​test_scale_bridge.py Tests validation, provider completion, stiffness conversion, and safe filenames.
tests/​data/​cu_elastic_card.json Supplies copper evidence from Quantum ESPRESSO calculations.
src/​tools/​scale_bridge.py Exposes the material handoff workflow as an MCP tool.
src/​server.py Registers the new tool.
src/​scale_bridge/​rules/​pw_dft_elastic.py Defines cubic elasticity evidence and convergence checks.
src/​scale_bridge/​rules/​__init__.py Dispatches checks and plans to registered rules.
src/​scale_bridge/​providers.py Defines and discovers upstream material providers.
src/​scale_bridge/​obligations.py Tracks required calculations, decisions, and estimated costs.
src/​scale_bridge/​continuum.py Produces rotated stiffness and plane-stress matrices.
src/​scale_bridge/​card.py Defines material cards and structural validation.
src/​scale_bridge/​__init__.py Documents and exports the handoff API.
mkdocs.yml Adds navigation for the new documentation.
docs/​tools/​material_handoff.md Documents tool parameters and actions.
docs/​tools/​index.md Adds the tool and updates the tool count.
docs/​how-it-works/​scale-bridging.md Explains evidence checks, providers, and limitations.
docs/​_gen_reference.py Adds the tool to generated reference documentation.

Review effort: Balanced

same = [c for c in hits if c.role == base.role and _same_strain(c, base)]
fit = [c for c in same if satisfies(c.settings, need)]
# a completed retry counts over an earlier stopped attempt; a failed one still rejects
fit.sort(key=lambda c: {"complete": 0, "failed": 1, "stopped": 2}[c.status])
Comment on lines +224 to +225
if base_done and all(o.status == COMPLETE for o in cmp.obligations):
qb, qv = quantities(*chosen), quantities(*repeats)
"""(reference, normal+, normal-, shear+, shear-) at the reference settings, or (None, reason)."""
if card.units != "GPa":
return None, f"the values are in '{card.units}'; this rule compares them with stresses in GPa"
own = [c for c in card.evidence if not c.variant_of]
{k: REPORTED_LIMIT for k in ("C11", "C12", "C44")}, [])
for c in chosen:
st, reason = _status(c)
reported.obligations.append(Obligation(c.name, c.settings, 0.0, st, reason, c.name if st == COMPLETE else ""))
Comment on lines +199 to +200
reported.differences = {k: abs(card.values[k] / q[k] - 1) if k in card.values and q[k] else float("nan")
for k in reported.limits}

This branch has not been deployed

No deployments
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.

2 participants