Optional hyperparameter search¶
When to use¶
After a baseline workflow-run (or legacy methyl-validation path) is understood, use a controlled outer loop to compare candidate settings—typically Tier A knobs in profile actionConfig.validation (e.g. stability_dmp_freq, n_iterations as budget, stability_min_balanced_accuracy). Tuning detector and model backends (Tier B/C) is a separate, often nested exercise; see the theory chapter on multi-stage search tradeoffs in docs/theory/chapters/15-model-creation-and-validation.md (Optional pipeline hyperparameter search).
Assay procedure first, then HPO
Assay procedure packs (pipelineProcedure) and hyperparameter search are complementary, not alternatives.
| Layer | Role | In the HPO grid? |
|---|---|---|
pipelineProcedure |
Fixed assay recipe (library protocol, SamplePrep/lifecycle, informME/deconv on/off, gene FeatureCuts axis, covariate paths) | No — choose once on the instance/context base |
pipelineProfile |
SaMD rung / research profile (samd_research, …) |
Fixed per search request |
| HPO overlay / grid axes | Tier-A actionConfig knobs (mostly validation.*) |
Yes |
Operator order:
- Pick analyte +
pipelineProcedure(see ch.24). - Run a baseline with that procedure +
samd_research. - Sweep Tier-A knobs with
scenario-start/hyperparam-grid-start(or legacymethyl-hyperparam-search) on the same procedure base. - Operator-gated promote the winning overlay (
portal.sp_promote_hyperparam_winnerdeep-merges dotted trial keys such asvalidation.stability_dmp_freqinto the existing studyactionConfig; it does not replace the whole overlay); freeze / model-MC with covariates after stability search.
Do not put pipelineProcedure, aligner, or library protocol in grid axes. Changing procedure is a different study setup, not a trial. Typical axes for gene-FeatureCuts procedures (buffy_wgbs_*_gene_fc, cfdna_wgbs_plasma): validation.stability_gene_featurecuts_max_dmps / _max_genes, stability_target_balanced_accuracy / gene_featurecuts_target_ba, stability_gene_freq, n_iterations (budget).
Production paths: scenario vs grid
The methyl-hyperparam-search subprocess loop described below is the legacy driver.
Scenario (assumption check): methyl-study-start scenario-start with a HyperparamScenarioRequest overlay — one workflow instance + executionScopeId, no Cartesian axes. Use this to confirm personal assumptions or evaluate a stability target (BA gates, FeatureCuts caps, frequencies). JSON null clears a site/profile knob. Ensure the instance context (or study start base) already carries pipelineProcedure.
Grid search: methyl-study-start hyperparam-grid-start expands axes into N instances (cfg.hyperparameter_search_run + trials). Score with hyperparam-grid-score.
Workers never run the outer loop. See Portal remote control and config propagation — methylation.
What it is¶
- A read-only scalar objective (J) is computed from artifacts under
monte_carlo_runs/. Metric sources (first match wins): metrics_summary.jsonat the MC root (or a singlemodel_mc/*/metrics_summary.json)- Else aggregate
run_*/gene_stability/gene_featurecuts_metrics.jsoninto a synthetic summary (balanced_accuracymean/median) — so stability-only Tier-A grids can score gene FeatureCuts BA without freeze/model-MC - Optional
stability/stability_summary.jsonfor panel-size terms / min-stable constraints - The
methyl-hyperparam-searchentry point is a small grid driver: for each grid point it writeswork_dir/trial_NNNN/mc_config.jsonwith a mergedMonteCarloConfigand a distinctoutput_base, runsmethyl-validation(e.g. with--stability), then scores the run. - It does not use
sklearn.model_selectionCV: each evaluation is a subprocess and file read. - This is worker-package capability on a promoted release. Experiment knobs live as JSON under
/work(grids, weights, base MC config). It does not changewf/cfgschemas.
Formula and weights: packages/methylvalidation/docs/HYPERPARAMETER_SEARCH.md (full (J), ObjectiveWeights, constraint semantics).
Environments¶
The search is deliberately separated across three environments. Keeping them distinct is what lets you experiment against a promoted release without editing platform code.
| Environment | Where | Role for hyperparameter search |
|---|---|---|
| Development | Repo checkout + .venv |
Author and unit-test the driver (methyl-hyperparam-search), objective, and mapper/gene-select fixes. Run --dry-run and small smoke grids only. This is the source of package fixes, not the place for long experiments. |
| Experimentation | Promoted release worker venv (/work/goliath/current) + JSON under /work |
Run the outer loop. All tunable knobs live as JSON (base_mc_config.json, grid_*.json, weights_*.json); the driver scores gene-FeatureCuts BA from stability-only runs. No wf/cfg schema changes. |
| Production | DB-backed gateway workflows | Consumes the winning locked configuration via resolvedConfig; profiles/programs come from the runtime-bundle. The search driver itself is not part of the production task path — only its result is promoted. |
Package fixes that the experimentation environment depends on (gene-FeatureCuts BA objective fallback, nullable gene-select caps, mapper discovery-CSV default) must be in the promoted release before you rely on them there; until then, run from a repo checkout that has them.
Command example¶
Use a dedicated MC config and a work directory on shared storage if many trials. Prefer the release worker venv (/work/goliath/current/env/worker.env), not a git checkout:
set -a && source /work/goliath/current/env/worker.env && set +a
# The worker venv is on each node's local disk, never on /work.
export PATH=/opt/goliath/venv-aarch64/bin:$PATH
methyl-hyperparam-search \
--config /work/experiments/my_mc_config.json \
--work-dir /work/experiments/hp_run1 \
--grid '{"stability_dmp_freq": [0.6, 0.7], "stability_min_balanced_accuracy": [null, 0.5]}' \
--weights-json /work/experiments/weights_ba.json \
-- \
--stability
- Extra
methyl-validationflags follow the search options and are forwarded verbatim. The leading--separator is optional (... --stabilityand... -- --stabilityare equivalent). - JSON
nullin--gridomits that field so the base config value is kept (it does not mean “uncap”). To raise a site cap, put an explicit integer in the grid or base config. - Results:
work-dir/search_summary.json(per-trial rows and best feasible trial, if any). --weights-jsoncan point to a file forObjectiveWeights(e.g. BA-dominant:w_balanced_accuracy=1,stat=mean).--baseline-summary /path/to/metrics_summary.jsonenforces rollout-style feasibility vs a baseline (same idea asmethyl-validation --rollout-compare); seepackages/methylvalidation/docs/ROLLOUT.mdandpackages/methylvalidation/docs/HYPERPARAMETER_SEARCH.md.--dry-runonly writes trial configs and paths; no pipeline subprocesses.
Resuming after a failure¶
--stability --resume N --skip-centroidreuses existing centroids and continues detector → mapper → gene-select fromrun_000N. Use this to resume trials that failed mid-pipeline (e.g. a mapper error) without recomputing centroids.--skip-detectiononly recomputes stability frequency from existing detector outputs; it does not re-run mapper or gene-select. It cannot recover a trial whose mapper/gene-select step failed — a full--stability(optionally with--skip-centroid) is required there.
Pitfalls¶
- Discovery vs calibration: settings that optimize stability panel size may not optimize NLL, Brier, or ECE; prefer a two-stage strategy or tight constraints, not a single ad hoc weight mix.
n_iterations: treat primarily as compute budget to stabilize medians, not a dimension to grid-search widely without cost awareness.
See also¶
- Methylation application packs —
pipelineProcedurerecipes (fixed base under HPO) packages/methylvalidation/docs/HYPERPARAMETER_SEARCH.mdpackages/methylvalidation/docs/ROLLOUT.md(promotion / dual-run thinking)docs/theory/chapters/15-model-creation-and-validation.md(Optional pipeline hyperparameter search)- Distributed MethylValidation on shared storage (Chapter 13; parallel execution of a single config’s iterations)
- Buffy gene Tier-A cross-VM — worked gene-FeatureCuts grid on a buffy procedure base