Skip to content

fix(cost,#8955): migrate hmm_alpha cost frontmatter->metadata (malformed frontmatter, one-shot) - #8973

Merged
jsboige merged 1 commit into
mainfrom
feature/8955-hmmalpha-cost
Jul 31, 2026
Merged

jsboige merged 1 commit into
mainfrom
feature/8955-hmmalpha-cost

Conversation

@myia-po-2023

@myia-po-2023 myia-po-2023 commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

Grain: MED/data — lane myia-po-2023:CoursIA — prev: MED/tooling #8972 (CLEAN/MERGEABLE) · MED/qc #8966 (MERGED)

Residual of #8955: the 34th cost-divergent notebook — the only non-QC
one — hmm_alpha_research.ipynb (ML-Training). This is my own flagged
residual
from #8966 (I excluded it rather than risk a regression on
ML-Training turf).

The defect (#8955, firsthand on origin/main 2d0858f1d)

Same regression class as the 23 QC quantbooks fixed by #8966: the metadata.cost
scan-skeleton (dated 2026-07-29) flattened the curated cell#0 frontmatter
cost (dated 2026-07-23, 6 days earlier):

field frontmatter (curated) metadata.cost (skeleton) after this PR
cpu_min 90 (27-cell research notebook) 8 (flat default) 90
reproducibility MEDIUM HIGH (flat) MEDIUM
free_alternative null "self" null
metadata_written 2026-07-23T01:30Z 2026-07-29 2026-07-23T01:30Z

_cost_equivalent flagged [cpu_min, reproducibility].

Why #8966's script skipped it (the malformed frontmatter)

migrate_cost_frontmatter_to_metadata.py returned skip-already-migrated
because parse_frontmatter returned None: the cell#0 frontmatter is
malformed — it opens with --- but is never closed by a --- (a blank
line then the # H1 follow directly). The _FRONTMATTER_RE regex over-matches
into the prose (up to the first section --- divider), yaml.safe_load fails
on the mixed YAML+markdown, and the parser bails. Migrated one-shot
(extending the parser for malformed YAML would be disproportionate for 1
notebook; documented here for recurrence).

The fix

merged = {**metadata_cost, **frontmatter_cost} (frontmatter wins on overlap;
metadata keeps notes, qcc_tokens_est, vram_*, gpu_min), then strip the
malformed frontmatter block (lines 1–14 + trailing blank), leaving the H1 to
start cell#0. metadata.cost carries the curated values; metadata_written
refreshes to the curated timestamp.

Verification (firsthand, all canonical tools post-apply)

  • byte_stable_baseline=True, field_equivalent=True, minimal_diff=True
    (only cell#0 source + metadata.cost differ; the rest is structurally identical).
  • detect_markdown_rendering: 0 violations (frontmatter_rawyaml resolved).
  • check_cost_metadata: 0 findings, cost_source=metadata canonical,
    notes preserved.
  • _cost_equivalent: cell#0 no longer has a frontmatter → no divergence.
  • notebook_tools validate: 0 errors (1 warning PRE-EXISTING on
    origin/main, unchanged by this edit — markdown-only cell#0 + metadata.cost
    touched, no code cell affected).
  • nbformat 4.5, 65 cells unchanged, cell#0 source list format preserved.
  • Diff +4/-19, 1 file; catalogue byte-identical to main.

NOT Closes #8955 (G.9 — would close an issue still open)

Firsthand measure on this branch (_cost_equivalent over all notebooks) finds
10 ML- quantbooks STILL cost-divergent* — ML-Classification,
ML-DeepLearning, ML-EnhancedPairs, ML-Ensemble, ML-FeatureEngineering,
ML-RandomForest, ML-Regression, ML-SVM, ML-TextClassification,
ML-XGBoost (all [cpu_min, reduced_pedagogical, reproducibility]).

These are the turf of #8908 (jsboige, OPEN, CHANGES_REQUESTED) — ai-01 AND
the author himself have already identified the strip-only defect there
(No markdown content loss FAILURE per notebook: stripping the frontmatter
loses the curated cost values, the SAME regression class as my reverted
#8959/#8963 and the subject of issue #8955 itself). The author has designated
#8908 the consolidation vehicle for the 33 QC notebooks. They are reusable
via migrate_cost_frontmatter_to_metadata.py --project ML-* (#8966 script)
should the migration be folded into #8908. This PR resolves hmm_alpha (the 1
non-QC divergent) only
— it does not touch the ML-* (active turf, #8908).

See #8955, #8904, #8056, #8966.

Co-Authored-By: Claude-Code noreply@anthropic.com

…strip

Residual of #8955: the 34th cost-divergent notebook (the only non-QC one),
hmm_alpha_research.ipynb (ML-Training). My #8966 migration script SKIPPED it
(parse_frontmatter returned None) because its cell#0 frontmatter is MALFORMED --
it opens with '---' but is NEVER closed by a '---' (a blank line then the H1
follow directly), so the regex over-matches into the prose and yaml.safe_load
fails. Migrated one-shot (extending the parser for malformed YAML would be
disproportionate for 1 notebook).

Defect (firsthand on origin/main 2d0858f): the curated cell#0 frontmatter
cost (dated 2026-07-23) carried cpu_min=90, reproducibility=MEDIUM,
free_alternative=null -- the real measured values for a 27-cell research
notebook. The metadata.cost scan-skeleton (dated 2026-07-29, 6 days LATER)
flattened them to cpu_min=8, reproducibility=HIGH, free_alternative='self'.
Same regression class as the 23 QC quantbooks fixed by #8966: the skeleton
shadowed the curated values. _cost_equivalent flagged [cpu_min, reproducibility].

Fix: merged = {**metadata_cost, **frontmatter_cost} (frontmatter wins on
overlap; metadata keeps notes + qcc_tokens_est + vram_*), then strip the
malformed frontmatter block (lines 1-14 + trailing blank), leaving the H1 to
start cell#0. metadata_written refreshed to the curated 2026-07-23T01:30Z.

Verification (firsthand, all canonical tools post-apply):
- byte_stable_baseline=True, field_equivalent=True, minimal_diff=True.
- detect_markdown_rendering: 0 violations (frontmatter_rawyaml resolved).
- check_cost_metadata: 0 findings, cost_source=metadata canonical, notes preserved.
- _cost_equivalent: cell#0 no longer has a frontmatter -> no divergence.
- notebook_tools validate: 0 errors (1 warning PRE-EXISTING on origin/main,
  unchanged by this edit -- markdown-only cell#0 + metadata.cost touched).
- nbformat 4.5, 65 cells unchanged, cell#0 source list format preserved.
- Diff +4/-19, 1 file; catalogue byte-identical to main.

NOT Closes #8955 (G.9): firsthand measure on this branch finds 10 ML-*
quantbooks (ML-Classification, ML-DeepLearning, ML-EnhancedPairs, ...) STILL
cost-divergent -- #8908 (po-2026) appears to have stripped frontmatter without
migrating the cost (same regression class as my reverted #8959/#8963). They are
reusable via 'migrate_cost_frontmatter_to_metadata.py --project ML-*' (#8966
script) once the turf is clear. Signaled for the coordinator.

See #8955, #8904, #8056, #8966.

Co-Authored-By: Claude-Code <noreply@anthropic.com>
@github-actions github-actions Bot added the variation-tag-genre-offlist GENRE hors de l'enumeration variation-protocol §1 label Jul 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Golden-Set Execution (H.7 P3)

✅ 8/8 notebooks passed (certified reproducible)

Notebook Status Time
2.1-Workflow-ML.ipynb ✅ SUCCESS 6.2s
2.2-Descente-de-gradient.ipynb ✅ SUCCESS 4.4s
2.3-Regression-lineaire-logistique.ipynb ✅ SUCCESS 4.0s
2.4-Arbres-Forets-Ensembles.ipynb ✅ SUCCESS 5.0s
Search-1-StateSpace.ipynb ✅ SUCCESS 4.0s
SL-1-LogicalLearning.ipynb ✅ SUCCESS 3.0s
rl_4_multi_armed_bandits.ipynb ✅ SUCCESS 27.1s
GameTheory-4c-NashExistence-Python.ipynb ✅ SUCCESS 3.7s

Pinned lockfile: scripts/notebook_tools/golden_set.lock.txt (H.7 P3, axe A #4208)

@github-actions

Copy link
Copy Markdown
Contributor

Notebook PR Validation: PASS

  • Notebooks checked: 1
  • Code cells validated: 27
  • Result: All passed

Checks: H.1 (no errors), H.3 (execution_count), C.1 (no banned patterns)
Non-Python kernels (.NET/Lean): C.1 + errors only (execution_count advisory)
QuantConnect notebooks: C.1 + errors only (require QC Cloud for execution)

@jsboige jsboige left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[Hermes] Metadata migration reviewed: frontmatter values → notebook metadata verified field-by-field. All 11 fields preserve their source values (cpu_min 90, reproducibility MEDIUM, free_alternative null, metadata_written 2026-07-23T01:30Z). No data loss. free_alternative: "self" → null is correct for a zero-cost notebook (redundant self-reference). Golden-set 8/8 passed. LGTM.

@jsboige
jsboige merged commit 2a0e1f1 into main Jul 31, 2026
37 checks passed
jsboige added a commit that referenced this pull request Jul 31, 2026
Resolve conflict with #8973 (cost frontmatter->metadata migration merged on
main after this branch's base). The re-exec in f9e3108 regenerated cell#0
with the old YAML frontmatter that #8973 had stripped; this merge takes main's
stripped cell#0 + enriched metadata.cost (cpu_min 90, reproducibility MEDIUM)
and preserves the §D.5 markdown alignment (md#20 log-likelihood -5447.51,
md#28 Sharpe 0.697 / B&H 0.735 / return 167.7%).

Re-executed end-to-end on the merged base (papermill, kernel python3, hmmlearn,
65/65 cells, exit 0) to confirm determinism on the new base: log-likelihood
-5447.51, Sharpe 0.697, B&H 0.735, return 167.7% -- identical to the prior run
(random_state=42 on every GaussianHMM + np.random.seed(42)), confirming the
markdown is sourced by the deterministic outputs.

C.1/C.2: 27 code cells, 0 execution_count=None, 0 errors, 0 forbidden.
Catalogue byte-identical to main.

Co-Authored-By: Claude-Code <noreply@anthropic.com>
@jsboige
jsboige deleted the feature/8955-hmmalpha-cost branch September 2, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

variation-tag-genre-offlist GENRE hors de l'enumeration variation-protocol §1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants