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.
Files changed (150) hide show
  1. supermodel/__init__.py +3 -0
  2. supermodel/backtest.py +111 -0
  3. supermodel/cli.py +621 -0
  4. supermodel/config.py +274 -0
  5. supermodel/deps.py +66 -0
  6. supermodel/eda.py +283 -0
  7. supermodel/experiments.py +86 -0
  8. supermodel/guards.py +416 -0
  9. supermodel/hooks/guard_bash.py +13 -0
  10. supermodel/hooks/guard_write.py +13 -0
  11. supermodel/hooks/session_end.py +13 -0
  12. supermodel/hooks/session_start.py +13 -0
  13. supermodel/install.py +162 -0
  14. supermodel/integrity.py +184 -0
  15. supermodel/kinds/__init__.py +31 -0
  16. supermodel/kinds/base.py +99 -0
  17. supermodel/kinds/custom/__init__.py +71 -0
  18. supermodel/kinds/custom/backtest.py +52 -0
  19. supermodel/kinds/custom/config.py +22 -0
  20. supermodel/kinds/custom/kind.py +515 -0
  21. supermodel/kinds/custom/template/.claude/commands/eda.md +13 -0
  22. supermodel/kinds/custom/template/.claude/commands/new-experiment.md +13 -0
  23. supermodel/kinds/custom/template/CLAUDE.md +37 -0
  24. supermodel/kinds/custom/template/eda/CLAUDE.md +5 -0
  25. supermodel/kinds/custom/template/eval/CLAUDE.md +5 -0
  26. supermodel/kinds/custom/template/eval/evaluate.py +39 -0
  27. supermodel/kinds/custom/template/eval/helpers.py +17 -0
  28. supermodel/kinds/custom/template/experiments/CLAUDE.md +6 -0
  29. supermodel/kinds/custom/template/modeling/CLAUDE.md +6 -0
  30. supermodel/kinds/custom/template/modeling/__init__.py +0 -0
  31. supermodel/kinds/custom/template/modeling/base.py +17 -0
  32. supermodel/kinds/custom/template/modeling/methods/__init__.py +1 -0
  33. supermodel/kinds/custom/template/modeling/registry.py +45 -0
  34. supermodel/kinds/custom/template/runner/CLAUDE.md +3 -0
  35. supermodel/kinds/custom/template/runner/kind.py +191 -0
  36. supermodel/kinds/supervised/__init__.py +67 -0
  37. supermodel/kinds/supervised/backtest.py +114 -0
  38. supermodel/kinds/supervised/config.py +269 -0
  39. supermodel/kinds/supervised/kind.py +549 -0
  40. supermodel/kinds/supervised/template/CLAUDE.md +43 -0
  41. supermodel/kinds/supervised/template/eda/CLAUDE.md +5 -0
  42. supermodel/kinds/supervised/template/eval/CLAUDE.md +3 -0
  43. supermodel/kinds/supervised/template/eval/build_splits.py +911 -0
  44. supermodel/kinds/supervised/template/eval/evaluate.py +240 -0
  45. supermodel/kinds/supervised/template/eval/metrics.py +230 -0
  46. supermodel/kinds/supervised/template/experiments/CLAUDE.md +6 -0
  47. supermodel/kinds/supervised/template/modeling/CLAUDE.md +16 -0
  48. supermodel/kinds/supervised/template/modeling/__init__.py +1 -0
  49. supermodel/kinds/supervised/template/modeling/base.py +371 -0
  50. supermodel/kinds/supervised/template/modeling/estimators/__init__.py +0 -0
  51. supermodel/kinds/supervised/template/modeling/estimators/baselines.py +107 -0
  52. supermodel/kinds/supervised/template/modeling/estimators/gbm.py +110 -0
  53. supermodel/kinds/supervised/template/modeling/model_classes/__init__.py +0 -0
  54. supermodel/kinds/supervised/template/modeling/model_classes/tabular.py +13 -0
  55. supermodel/kinds/supervised/template/modeling/registry.py +123 -0
  56. supermodel/kinds/supervised/template/modeling/steps/__init__.py +0 -0
  57. supermodel/kinds/supervised/template/modeling/steps/features.py +32 -0
  58. supermodel/kinds/supervised/template/modeling/steps/preprocess.py +149 -0
  59. supermodel/kinds/supervised/template/modeling/tests/__init__.py +0 -0
  60. supermodel/kinds/supervised/template/modeling/tests/test_contract.py +32 -0
  61. supermodel/kinds/supervised/template/runner/CLAUDE.md +6 -0
  62. supermodel/kinds/supervised/template/runner/data.py +125 -0
  63. supermodel/kinds/supervised/template/runner/folds.py +82 -0
  64. supermodel/kinds/supervised/template/runner/kind.py +121 -0
  65. supermodel/kinds/supervised/template/runner/predict.py +149 -0
  66. supermodel/kinds/supervised/template/runner/train.py +100 -0
  67. supermodel/memory.py +279 -0
  68. supermodel/modeler.py +645 -0
  69. supermodel/paths.py +98 -0
  70. supermodel/profile.py +137 -0
  71. supermodel/project_imports.py +24 -0
  72. supermodel/reports.py +92 -0
  73. supermodel/review.py +306 -0
  74. supermodel/scaffold.py +367 -0
  75. supermodel/splits.py +248 -0
  76. supermodel/template/.claude/commands/backtest.md +12 -0
  77. supermodel/template/.claude/commands/brief.md +10 -0
  78. supermodel/template/.claude/commands/eda.md +13 -0
  79. supermodel/template/.claude/commands/new-experiment.md +13 -0
  80. supermodel/template/.claude/commands/setup.md +34 -0
  81. supermodel/template/.claude/commands/status.md +4 -0
  82. supermodel/template/.claude/commands/wrap-up.md +7 -0
  83. supermodel/template/.claude/settings.json +17 -0
  84. supermodel/template/AGENTS.md +27 -0
  85. supermodel/template/CLAUDE.md +18 -0
  86. supermodel/template/DATA_ACCESS.md +6 -0
  87. supermodel/template/champion/CLAUDE.md +2 -0
  88. supermodel/template/data/CLAUDE.md +2 -0
  89. supermodel/template/docs/CLAUDE.md +8 -0
  90. supermodel/template/eda/CLAUDE.md +6 -0
  91. supermodel/template/eval/CLAUDE.md +2 -0
  92. supermodel/template/eval/__init__.py +0 -0
  93. supermodel/template/experiments/CLAUDE.md +2 -0
  94. supermodel/template/memory/CLAUDE.md +4 -0
  95. supermodel/template/modeling/CLAUDE.md +2 -0
  96. supermodel/template/runner/CLAUDE.md +2 -0
  97. supermodel/template/runner/__init__.py +0 -0
  98. supermodel/template/runner/ledger.py +73 -0
  99. supermodel/template/runner/run.py +341 -0
  100. supermodel/template/utils/CLAUDE.md +5 -0
  101. supermodel/template/utils/__init__.py +1 -0
  102. supermodel/testing/__init__.py +2 -0
  103. supermodel/testing/contract.py +293 -0
  104. supermodel/testing/custom_project.py +91 -0
  105. supermodel/testing/data.py +133 -0
  106. supermodel/testing/fakes.py +296 -0
  107. supermodel/testing/project.py +296 -0
  108. supermodel/testing/revenue.py +143 -0
  109. supermodel/tests/conftest.py +88 -0
  110. supermodel/tests/fixtures/old_runner_data.py +105 -0
  111. supermodel/tests/snapshots/synth_classification.tsv +16 -0
  112. supermodel/tests/snapshots/synth_forecasting.tsv +15 -0
  113. supermodel/tests/snapshots/synth_ranking.tsv +15 -0
  114. supermodel/tests/snapshots/synth_regression.tsv +15 -0
  115. supermodel/tests/test_ablation_workflow.py +108 -0
  116. supermodel/tests/test_backtest.py +55 -0
  117. supermodel/tests/test_config.py +138 -0
  118. supermodel/tests/test_custom_e2e.py +56 -0
  119. supermodel/tests/test_custom_engine.py +692 -0
  120. supermodel/tests/test_custom_runner.py +142 -0
  121. supermodel/tests/test_docs.py +30 -0
  122. supermodel/tests/test_e2e.py +240 -0
  123. supermodel/tests/test_eda.py +59 -0
  124. supermodel/tests/test_enforcement.py +442 -0
  125. supermodel/tests/test_evaluate.py +183 -0
  126. supermodel/tests/test_flexible_splits.py +313 -0
  127. supermodel/tests/test_fold_integrity.py +217 -0
  128. supermodel/tests/test_freeze_flow.py +154 -0
  129. supermodel/tests/test_kind_contract.py +330 -0
  130. supermodel/tests/test_kinds_config.py +91 -0
  131. supermodel/tests/test_ledger.py +54 -0
  132. supermodel/tests/test_metrics.py +92 -0
  133. supermodel/tests/test_modeling.py +266 -0
  134. supermodel/tests/test_project_imports.py +59 -0
  135. supermodel/tests/test_review.py +137 -0
  136. supermodel/tests/test_rolling_origin.py +145 -0
  137. supermodel/tests/test_runner_seam.py +28 -0
  138. supermodel/tests/test_scaffold_and_pin.py +210 -0
  139. supermodel/tests/test_shadowing.py +108 -0
  140. supermodel/tests/test_splits.py +211 -0
  141. supermodel/tests/test_trust_standard.py +101 -0
  142. supermodel/tests/test_venv.py +87 -0
  143. supermodel/user_commands/init-project.md +15 -0
  144. supermodel/util.py +72 -0
  145. supermodel/venv.py +149 -0
  146. supermodel_ml-0.1.0.dist-info/METADATA +330 -0
  147. supermodel_ml-0.1.0.dist-info/RECORD +150 -0
  148. supermodel_ml-0.1.0.dist-info/WHEEL +5 -0
  149. supermodel_ml-0.1.0.dist-info/entry_points.txt +2 -0
  150. supermodel_ml-0.1.0.dist-info/top_level.txt +1 -0
supermodel/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """Supermodel: a repo scaffold + engine for trustworthy, conversational ML experimentation."""
2
+
3
+ __version__ = "0.1.0"
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="")