supermodel-ml 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- supermodel/__init__.py +3 -0
- supermodel/backtest.py +111 -0
- supermodel/cli.py +621 -0
- supermodel/config.py +274 -0
- supermodel/deps.py +66 -0
- supermodel/eda.py +283 -0
- supermodel/experiments.py +86 -0
- supermodel/guards.py +416 -0
- supermodel/hooks/guard_bash.py +13 -0
- supermodel/hooks/guard_write.py +13 -0
- supermodel/hooks/session_end.py +13 -0
- supermodel/hooks/session_start.py +13 -0
- supermodel/install.py +162 -0
- supermodel/integrity.py +184 -0
- supermodel/kinds/__init__.py +31 -0
- supermodel/kinds/base.py +99 -0
- supermodel/kinds/custom/__init__.py +71 -0
- supermodel/kinds/custom/backtest.py +52 -0
- supermodel/kinds/custom/config.py +22 -0
- supermodel/kinds/custom/kind.py +515 -0
- supermodel/kinds/custom/template/.claude/commands/eda.md +13 -0
- supermodel/kinds/custom/template/.claude/commands/new-experiment.md +13 -0
- supermodel/kinds/custom/template/CLAUDE.md +37 -0
- supermodel/kinds/custom/template/eda/CLAUDE.md +5 -0
- supermodel/kinds/custom/template/eval/CLAUDE.md +5 -0
- supermodel/kinds/custom/template/eval/evaluate.py +39 -0
- supermodel/kinds/custom/template/eval/helpers.py +17 -0
- supermodel/kinds/custom/template/experiments/CLAUDE.md +6 -0
- supermodel/kinds/custom/template/modeling/CLAUDE.md +6 -0
- supermodel/kinds/custom/template/modeling/__init__.py +0 -0
- supermodel/kinds/custom/template/modeling/base.py +17 -0
- supermodel/kinds/custom/template/modeling/methods/__init__.py +1 -0
- supermodel/kinds/custom/template/modeling/registry.py +45 -0
- supermodel/kinds/custom/template/runner/CLAUDE.md +3 -0
- supermodel/kinds/custom/template/runner/kind.py +191 -0
- supermodel/kinds/supervised/__init__.py +67 -0
- supermodel/kinds/supervised/backtest.py +114 -0
- supermodel/kinds/supervised/config.py +269 -0
- supermodel/kinds/supervised/kind.py +549 -0
- supermodel/kinds/supervised/template/CLAUDE.md +43 -0
- supermodel/kinds/supervised/template/eda/CLAUDE.md +5 -0
- supermodel/kinds/supervised/template/eval/CLAUDE.md +3 -0
- supermodel/kinds/supervised/template/eval/build_splits.py +911 -0
- supermodel/kinds/supervised/template/eval/evaluate.py +240 -0
- supermodel/kinds/supervised/template/eval/metrics.py +230 -0
- supermodel/kinds/supervised/template/experiments/CLAUDE.md +6 -0
- supermodel/kinds/supervised/template/modeling/CLAUDE.md +16 -0
- supermodel/kinds/supervised/template/modeling/__init__.py +1 -0
- supermodel/kinds/supervised/template/modeling/base.py +371 -0
- supermodel/kinds/supervised/template/modeling/estimators/__init__.py +0 -0
- supermodel/kinds/supervised/template/modeling/estimators/baselines.py +107 -0
- supermodel/kinds/supervised/template/modeling/estimators/gbm.py +110 -0
- supermodel/kinds/supervised/template/modeling/model_classes/__init__.py +0 -0
- supermodel/kinds/supervised/template/modeling/model_classes/tabular.py +13 -0
- supermodel/kinds/supervised/template/modeling/registry.py +123 -0
- supermodel/kinds/supervised/template/modeling/steps/__init__.py +0 -0
- supermodel/kinds/supervised/template/modeling/steps/features.py +32 -0
- supermodel/kinds/supervised/template/modeling/steps/preprocess.py +149 -0
- supermodel/kinds/supervised/template/modeling/tests/__init__.py +0 -0
- supermodel/kinds/supervised/template/modeling/tests/test_contract.py +32 -0
- supermodel/kinds/supervised/template/runner/CLAUDE.md +6 -0
- supermodel/kinds/supervised/template/runner/data.py +125 -0
- supermodel/kinds/supervised/template/runner/folds.py +82 -0
- supermodel/kinds/supervised/template/runner/kind.py +121 -0
- supermodel/kinds/supervised/template/runner/predict.py +149 -0
- supermodel/kinds/supervised/template/runner/train.py +100 -0
- supermodel/memory.py +279 -0
- supermodel/modeler.py +645 -0
- supermodel/paths.py +98 -0
- supermodel/profile.py +137 -0
- supermodel/project_imports.py +24 -0
- supermodel/reports.py +92 -0
- supermodel/review.py +306 -0
- supermodel/scaffold.py +367 -0
- supermodel/splits.py +248 -0
- supermodel/template/.claude/commands/backtest.md +12 -0
- supermodel/template/.claude/commands/brief.md +10 -0
- supermodel/template/.claude/commands/eda.md +13 -0
- supermodel/template/.claude/commands/new-experiment.md +13 -0
- supermodel/template/.claude/commands/setup.md +34 -0
- supermodel/template/.claude/commands/status.md +4 -0
- supermodel/template/.claude/commands/wrap-up.md +7 -0
- supermodel/template/.claude/settings.json +17 -0
- supermodel/template/AGENTS.md +27 -0
- supermodel/template/CLAUDE.md +18 -0
- supermodel/template/DATA_ACCESS.md +6 -0
- supermodel/template/champion/CLAUDE.md +2 -0
- supermodel/template/data/CLAUDE.md +2 -0
- supermodel/template/docs/CLAUDE.md +8 -0
- supermodel/template/eda/CLAUDE.md +6 -0
- supermodel/template/eval/CLAUDE.md +2 -0
- supermodel/template/eval/__init__.py +0 -0
- supermodel/template/experiments/CLAUDE.md +2 -0
- supermodel/template/memory/CLAUDE.md +4 -0
- supermodel/template/modeling/CLAUDE.md +2 -0
- supermodel/template/runner/CLAUDE.md +2 -0
- supermodel/template/runner/__init__.py +0 -0
- supermodel/template/runner/ledger.py +73 -0
- supermodel/template/runner/run.py +341 -0
- supermodel/template/utils/CLAUDE.md +5 -0
- supermodel/template/utils/__init__.py +1 -0
- supermodel/testing/__init__.py +2 -0
- supermodel/testing/contract.py +293 -0
- supermodel/testing/custom_project.py +91 -0
- supermodel/testing/data.py +133 -0
- supermodel/testing/fakes.py +296 -0
- supermodel/testing/project.py +296 -0
- supermodel/testing/revenue.py +143 -0
- supermodel/tests/conftest.py +88 -0
- supermodel/tests/fixtures/old_runner_data.py +105 -0
- supermodel/tests/snapshots/synth_classification.tsv +16 -0
- supermodel/tests/snapshots/synth_forecasting.tsv +15 -0
- supermodel/tests/snapshots/synth_ranking.tsv +15 -0
- supermodel/tests/snapshots/synth_regression.tsv +15 -0
- supermodel/tests/test_ablation_workflow.py +108 -0
- supermodel/tests/test_backtest.py +55 -0
- supermodel/tests/test_config.py +138 -0
- supermodel/tests/test_custom_e2e.py +56 -0
- supermodel/tests/test_custom_engine.py +692 -0
- supermodel/tests/test_custom_runner.py +142 -0
- supermodel/tests/test_docs.py +30 -0
- supermodel/tests/test_e2e.py +240 -0
- supermodel/tests/test_eda.py +59 -0
- supermodel/tests/test_enforcement.py +442 -0
- supermodel/tests/test_evaluate.py +183 -0
- supermodel/tests/test_flexible_splits.py +313 -0
- supermodel/tests/test_fold_integrity.py +217 -0
- supermodel/tests/test_freeze_flow.py +154 -0
- supermodel/tests/test_kind_contract.py +330 -0
- supermodel/tests/test_kinds_config.py +91 -0
- supermodel/tests/test_ledger.py +54 -0
- supermodel/tests/test_metrics.py +92 -0
- supermodel/tests/test_modeling.py +266 -0
- supermodel/tests/test_project_imports.py +59 -0
- supermodel/tests/test_review.py +137 -0
- supermodel/tests/test_rolling_origin.py +145 -0
- supermodel/tests/test_runner_seam.py +28 -0
- supermodel/tests/test_scaffold_and_pin.py +210 -0
- supermodel/tests/test_shadowing.py +108 -0
- supermodel/tests/test_splits.py +211 -0
- supermodel/tests/test_trust_standard.py +101 -0
- supermodel/tests/test_venv.py +87 -0
- supermodel/user_commands/init-project.md +15 -0
- supermodel/util.py +72 -0
- supermodel/venv.py +149 -0
- supermodel_ml-0.1.0.dist-info/METADATA +330 -0
- supermodel_ml-0.1.0.dist-info/RECORD +150 -0
- supermodel_ml-0.1.0.dist-info/WHEEL +5 -0
- supermodel_ml-0.1.0.dist-info/entry_points.txt +2 -0
- supermodel_ml-0.1.0.dist-info/top_level.txt +1 -0
supermodel/__init__.py
ADDED
supermodel/backtest.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Versioned development backtests, independent of the promotion ledger."""
|
|
2
|
+
import hashlib
|
|
3
|
+
import importlib
|
|
4
|
+
import json
|
|
5
|
+
import tempfile
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from uuid import uuid4
|
|
9
|
+
|
|
10
|
+
import yaml
|
|
11
|
+
|
|
12
|
+
from supermodel import config, experiments, integrity, kinds
|
|
13
|
+
from supermodel.project_imports import project_on_path
|
|
14
|
+
from supermodel.util import git_head
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def run(root, args):
|
|
18
|
+
archive = root / "experiments/backtests"
|
|
19
|
+
history = [json.loads(p.read_text()) for p in sorted(archive.glob("*/methodology.json"))]
|
|
20
|
+
if args.history:
|
|
21
|
+
for item in history:
|
|
22
|
+
print(item["run"], item["strategy"], item.get("status", "completed"), item["reason"])
|
|
23
|
+
return
|
|
24
|
+
cfg = config.load(root, complete=False)
|
|
25
|
+
if config.kind_name(cfg) == "unset":
|
|
26
|
+
raise ValueError("Describe the project or data first so setup can infer a runnable evaluation.")
|
|
27
|
+
kinds.for_config(cfg)
|
|
28
|
+
from supermodel import deps
|
|
29
|
+
missing_deps = deps.refusal(cfg)
|
|
30
|
+
if missing_deps:
|
|
31
|
+
raise ValueError(missing_deps)
|
|
32
|
+
name = config.kind_name(cfg)
|
|
33
|
+
engine = importlib.import_module(f"supermodel.kinds.{name}.backtest")
|
|
34
|
+
previous = next((item for item in reversed(history) if item["kind"] == name
|
|
35
|
+
and item.get("status", "completed") == "completed"
|
|
36
|
+
and (not args.strategy or item["strategy"] == args.strategy)), None)
|
|
37
|
+
if args.strategy and not previous:
|
|
38
|
+
raise ValueError(f"Unknown {name} backtest strategy {args.strategy}; see --history.")
|
|
39
|
+
method = previous["method"] if previous else engine.defaults(cfg)
|
|
40
|
+
edits = yaml.safe_load(args.set) if args.set else {}
|
|
41
|
+
if not isinstance(edits, dict) or set(edits) - set(method):
|
|
42
|
+
raise ValueError(f"Methodology settings must be a mapping using: {', '.join(method)}")
|
|
43
|
+
for key, value in edits.items():
|
|
44
|
+
if isinstance(method[key], dict) and not isinstance(value, dict):
|
|
45
|
+
raise ValueError(f"{key} must be a mapping of evaluation settings.")
|
|
46
|
+
method[key] = {**method[key], **value} if isinstance(method[key], dict) and isinstance(value, dict) else value
|
|
47
|
+
project_on_path(root)
|
|
48
|
+
engine.prepare(method, cfg)
|
|
49
|
+
# Fingerprint evaluator code only; case directories can contain private inputs.
|
|
50
|
+
evaluator = {p.name: integrity.sha256_file(p) for p in sorted((root / "eval").glob("*.py"))}
|
|
51
|
+
if args.strategy and previous.get("evaluator_files", evaluator) != evaluator:
|
|
52
|
+
raise ValueError("Evaluator code changed since that strategy. Restore its recorded revision to replay it.")
|
|
53
|
+
strategy = hashlib.sha256(config.canonical([name, method, evaluator]).encode()).hexdigest()[:16]
|
|
54
|
+
ids = experiments.existing_ids(root)
|
|
55
|
+
eid = args.experiment or (f"E{ids[-1]:03d}" if ids else None)
|
|
56
|
+
experiment = experiments.find(root, eid) if eid else experiments.create(
|
|
57
|
+
root, "Establish the configured baseline on development data",
|
|
58
|
+
expected_effect="Measure the baseline score for subsequent comparisons.")
|
|
59
|
+
eid = experiment.name.split("-")[0]
|
|
60
|
+
model = yaml.safe_load((experiment / "config.yaml").read_text())
|
|
61
|
+
run_id = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S%fZ") + "-" + uuid4().hex[:6]
|
|
62
|
+
reason = "Request overrides" if edits else "Reused recorded strategy"
|
|
63
|
+
if not previous and not edits:
|
|
64
|
+
reason = "Inferred from project configuration"
|
|
65
|
+
record = dict(schema_version=1, run=run_id, strategy=strategy, kind=name, method=method,
|
|
66
|
+
previous_strategy=previous["strategy"] if previous else None,
|
|
67
|
+
evaluator_files=evaluator, project_commit=git_head(root), reason=args.reason or reason,
|
|
68
|
+
experiment=eid, hypothesis=model.get("hypothesis"), dataset=cfg.get("data") or {},
|
|
69
|
+
modeling_files={p.relative_to(root).as_posix(): integrity.sha256_file(p)
|
|
70
|
+
for p in sorted((root / "modeling").rglob("*.py"))})
|
|
71
|
+
archive.mkdir(parents=True, exist_ok=True)
|
|
72
|
+
with tempfile.TemporaryDirectory(dir=archive) as tmp:
|
|
73
|
+
scratch = Path(tmp)
|
|
74
|
+
bundle = scratch / "record"
|
|
75
|
+
bundle.mkdir()
|
|
76
|
+
try:
|
|
77
|
+
score, selection = engine.evaluate(root, scratch, cfg, method, model)
|
|
78
|
+
except Exception as exc:
|
|
79
|
+
record["status"] = "failed"
|
|
80
|
+
record["error_type"] = type(exc).__name__
|
|
81
|
+
(bundle / "methodology.json").write_text(json.dumps(record, indent=2) + "\n")
|
|
82
|
+
bundle.rename(archive / run_id)
|
|
83
|
+
raise
|
|
84
|
+
record["status"] = "completed"
|
|
85
|
+
result = dict(schema_version=1, run=run_id, strategy=strategy, experiment=eid,
|
|
86
|
+
commit=git_head(root), model_config=model, selection=selection, scores=score)
|
|
87
|
+
for filename, data in (("methodology.json", record), ("results.json", result)):
|
|
88
|
+
(bundle / filename).write_text(json.dumps(data, indent=2, allow_nan=False) + "\n")
|
|
89
|
+
primary = score["primary"]
|
|
90
|
+
tv = ((score.get("train") or {}).get(primary["name"]) or {}).get("value")
|
|
91
|
+
train_line = "" if tv is None else (f"train {primary['name']}: {tv:.6g} (train - validation gap "
|
|
92
|
+
f"{score.get('overfit_gap', 0):+.6g}; larger means more overfitting)\n\n")
|
|
93
|
+
(bundle / "report.md").write_text(
|
|
94
|
+
f"# Development backtest {run_id}\n\n{primary['name']}: {primary['value']:.6g}\n\n{train_line}"
|
|
95
|
+
f"Strategy `{strategy}`: {record['reason']}.\n\n"
|
|
96
|
+
f"## Evaluation method\n\n```json\n{json.dumps(method, indent=2)}\n```\n\n"
|
|
97
|
+
"[Methodology](methodology.json) · [Scores and selection](results.json)\n")
|
|
98
|
+
bundle.rename(archive / run_id)
|
|
99
|
+
print(f"{primary['name']}: {primary['value']:.6g}" + ("" if tv is None else f" (train {tv:.6g}, gap "
|
|
100
|
+
f"{score.get('overfit_gap', 0):+.6g})") + f" · strategy {strategy}\n{archive / run_id / 'report.md'}")
|
|
101
|
+
links = experiment / "backtests"
|
|
102
|
+
links.mkdir(exist_ok=True)
|
|
103
|
+
(links / f"{run_id}.md").write_text(
|
|
104
|
+
f"[Backtest report](../../backtests/{run_id}/report.md) · "
|
|
105
|
+
f"[Methodology and dataset](../../backtests/{run_id}/methodology.json)\n")
|
|
106
|
+
from supermodel import review
|
|
107
|
+
bundle_rel = (archive / run_id).relative_to(root).as_posix()
|
|
108
|
+
print("\n" + review.for_experiment(root, experiment, extra=[
|
|
109
|
+
(f"{bundle_rel}/report.md", None, "backtest report"),
|
|
110
|
+
(f"{bundle_rel}/methodology.json", None, "evaluation method and dataset"),
|
|
111
|
+
(f"{bundle_rel}/results.json", None, "scores and fold selection")]), end="")
|