feat: built-in default QRF k-point model with HuggingFace resolution#38
Merged
Conversation
refactor(core): introduce staged pipeline
test: establish baseline coverage
Implement `source="huggingface"` in `load_model`: parse the location as `"<repo_id>::<filename>"`, download via `hf_hub_download` (honoring `revision`), and joblib-load the artifact. First step toward a built-in default ModelSpec resolved from the Hub. Tests mock the download (no network). Part of #31 Written by an agent on behalf of Junwen Yin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add the model-agnostic half of the default k-point advisor: - DEFAULT_KPOINTS_MODEL: built-in ModelSpec for the STFC QRF95 on HuggingFace. - predict_kspacing_quantiles: QRF output (lower, median, upper) k-spacing with the calibrated interval correction. - kspacing_to_selection: median spacing -> mesh via k_distance_to_mesh, with source="model" provenance carrying the interval and confidence level. Feature extraction (heavy deps) and advisor wiring come next. Part of #31 Written by an agent on behalf of Junwen Yin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Name the k-index advisor for what it is (predicts a k-index into a mesh table), pairing it with the new kspacing_advisor (predicts k-spacing). Renames the module and its test; updates import paths. Public function names are unchanged. Part of #31 Written by an agent on behalf of Junwen Yin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Align the QRF advisor with the existing kmesh terminology (`k_distance_to_mesh`, `k_distance`): rename the module, functions (`predict_kdistance_quantiles`, `kdistance_to_selection`), and its test. The `CalculationHints.k_spacing` contract field is unchanged. Part of #31 Written by an agent on behalf of Junwen Yin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reproduce the non-metallicity half of the QRF k-distance feature vector: composition (matminer ElementProperty/Stoichiometry/ValenceOrbital), structure (GlobalSymmetry/Density), SOAP (dscribe), and lattice/symmetry values, in the trained order. Single-structure API `extract_structure_features` -> 419-dim block; the CGCNN metallicity block (64) is appended separately to reach 483. Part of #31 Written by an agent on behalf of Junwen Yin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Port the CGCNN model (PyG), radius graph builder, and atom embedding lookup needed to compute the "metal" block of the QRF k-distance feature vector: - cgcnn.py: CGCNN_PyG with extract_crystal_repr (64-dim pooled representation) - cgcnn_graph.py: radius-based PyG graph builder - atom_features.py: per-atom embedding lookup from atom_init JSON - metallicity.py: load the pretrained CGCNN checkpoint + metal_features() Verified against the recovered checkpoint: 419 (struct) + 64 (metal) = 483, matching the trained QRF input. Committed tests use small/fake models (no checkpoint, no network). Part of #31 Written by an agent on behalf of Junwen Yin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- extract_qrf_features: concat struct(419) + CGCNN metal(64) -> 483-dim vector. - qrf_kdistance_advisor: Kmesh backend loading the QRF + metallicity model once, predicting k-distance and resolving a mesh; explicit k-grid/k-spacing hints bypass the model. Verified end-to-end (QRF from HF + CGCNN from recovered checkpoint): diamond Si -> 10x10x10 at 0.217 Å⁻¹, source="model", confidence 0.95. Committed tests mock the models (no network/checkpoint). Part of #31 Written by an agent on behalf of Junwen Yin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ailable The default k-point advisor must never make the tool require network or hard- fail. Guard both failure points: model/dependency load (torch/PyG/matminer missing, HF download fails, bad checkpoint) and per-structure inference. On failure, degrade to the heuristic k-point advice from the Advise stage. The fallback mesh keeps its advice-derived provenance source (default/analysis, never "model") — the result is a genuine heuristic recommendation, not a placeholder — and appends a warning naming the reason the model was skipped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… box Add default_kmesh_advisor() (QRF + heuristic fallback, metallicity checkpoint env-overridable) and default_pipeline() wiring it into the Kmesh stage. The CLI now runs the default QRF model when neither --model nor an explicit k-point hint is given; an explicit hint resolves from advice without loading any model, and --model still selects the local CSLR k-index backend. The bare Pipeline() default stays the spacing heuristic so library callers never trigger GB-scale model loads implicitly. Until the CGCNN metallicity checkpoint is published to Hugging Face (#36), production environments without it fall back to heuristic advice with a provenance warning. Verified end-to-end via the CLI: with the checkpoint present, Si resolves to source="model" (kpoints-goldilocks-QRF, confidence 0.95); with it missing, the run degrades to source="default" and records the reason. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Decision on #32: the default QRF k-point model is a core capability, so its ML stack ships in the base install rather than an optional extra. Add dscribe, huggingface_hub, pandas, sklearn-quantile, torch, and torch-geometric to core dependencies so `goldilocks-core recommend` predicts k-points out of the box with no extra install step, at the cost of a GB-scale base install (accepted trade-off). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…#36) The QRF k-distance features need a CGCNN metallicity checkpoint + atom-embedding table. Now published at JunwenYin/metallicity-goldilocks-CGCNN, so the default advisor resolves both from the Hub (cached) instead of a local path. Explicit local paths still win, and GOLDILOCKS_METALLICITY_{CHECKPOINT,ATOM_INIT,REPO} override for offline development. Resolution runs inside the guarded load, so a download failure degrades to heuristic advice like any other load error. With this, the default pipeline predicts k-points out of the box on a clean machine with no local_data. Verified live: Si resolves QRF + metallicity from HF and returns source="model" (confidence 0.95). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
|
(Marking as draft so its clear this branch is still WIP) |
Collaborator
|
Also are those |
Collaborator
Author
Yes you are correct I will fix it. |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
50df872 to
40b2e5c
Compare
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Part of #31 (and gates #30). Ships the functional core of a built-in default ML k-point model that resolves from Hugging Face, so ML k-point prediction works without the caller supplying a model.
What this delivers
ml/models.load_modelnow supportssource="huggingface"(location"<repo_id>::<filename>", download + local cache viahuggingface_hub). Previously local-only.DEFAULT_KPOINTS_MODEL= STFC QRF95 (STFC-SCD/kpoints-goldilocks-QRF::QRF95.pkl),target="k_distance", pinned + reproducible.predict_kdistance_quantiles(3 quantiles → median + calibrated interval),kdistance_to_selection(median → mesh, interval + confidence →Provenance,source="model").main— the 483-dim vector the QRF was trained on:ml/kdistance_features.py— matminer composition/structure + dscribe SOAP + lattice/symmetry (419-dim)ml/cgcnn.py,ml/cgcnn_graph.py,ml/atom_features.py,ml/metallicity.py— CGCNN metallicity crystal representation (64-dim)qrf_kdistance_advisorloads QRF + CGCNN once; an explicitk_grid/k_spacinghint bypasses the model.Verification
End-to-end validated: diamond Si → 10×10×10 mesh at 0.217 Å⁻¹,
source="model", confidence 0.95 (QRF from HF + CGCNN metallicity). 93 tests pass; committed tests mock the models (no network / no checkpoint in CI).Naming
Renamed
kmesh_advisor → kindex_advisorandkspacing → kdistancefor consistency with the aiida-quantumespresso "k-distance" term (contract rename tracked separately).Deferred (follow-ups, not in this PR)
Pipelineto use this advisor by default.source="fallback"provenance when model/deps unavailable.pyproject— gated on Decide: k-points ML stack as core deps vs optional extra (torch/matminer/dscribe) #32 (core vs optional extra).local_data/; production resolution blocked on Upload CGCNN metallicity model to HuggingFace (needed by QRF k-points #31 and Analyze metallicity #34) #36 (HF upload).🤖 Generated with Claude Code