Coverage for examples/aether_quant_lab.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 12:55 +0000

1"""The model lab from the library: a lab folder, a dataset in the production layout, a linear model trained as counted trials, 

2then judged out of sample (a cost-aware book at the lab's N), compared with a momentum baseline, explained and exported to the 

3`aq models` format. No torch, no network: the bundled sample and the `linear` template. `aq lab` runs the same steps as commands 

4(docs/guide/model-lab.md); with torch, `--template multitask` trains the project's own network the same way. 

5 

6 python examples/aether_quant_lab.py 

7""" 

8 

9from __future__ import annotations 

10 

11import sys 

12import tempfile 

13import zipfile 

14from pathlib import Path 

15 

16sys.path.insert(0, str(Path(__file__).resolve().parents[1])) 

17 

18from aether_quant import lab, samples 

19 

20 

21def main() -> None: 

22 with tempfile.TemporaryDirectory() as tmp: 

23 folder = Path(tmp) / "mylab" 

24 lab.init_lab(folder) 

25 dataset = lab.build_dataset(samples.load_sample_prices(), features="core", targets=(5, 20)) 

26 dataset.to_csv(folder / "data" / "dataset.csv", index=False) 

27 print("dataset rows by split: " + ", ".join(f"{split} {count}" for split, count in dataset.groupby("split").size().items())) 

28 lab.new_model(folder, "ridge", "linear") 

29 record = lab.train_run(folder, "ridge", seeds=[1, 2], log=lambda line: None) 

30 print(f"run {record['id']}: out-of-sample IC {record['metrics']['oof_ic_mean']:.4f}, N {record['trials_n']}") 

31 run = lab.find_run(folder, "latest") 

32 report = lab.evaluate_run(run, lab_dir=folder, book=True) 

33 print(lab.render_eval(report)) 

34 print(lab.render_compare(lab.compare_runs([run], baseline="momentum_20"))) 

35 result = lab.export_run(run, folder / "ridge.zip", card=lab.model_card(run, report)) 

36 print("exported " + ", ".join(sorted(zipfile.ZipFile(result["zip"]).namelist()))) 

37 

38 

39if __name__ == "__main__": 

40 main()