Coverage for src/romfarmer/farmhand/optimizer/__init__.py: 0%

11 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-09-04 16:33 -0700

1"""Budget optimizer — iterative LangGraph loop for fitting ROM builds to a storage target. 

2 

3The optimizer accepts a superset pool manifest (all games passing DAT/region/language 

4filters) and a storage target with headroom tolerance. It runs a tight 

5evaluator-optimizer loop — using an LLM critic to adjust per-generation rating 

6thresholds — until the estimated build size sits inside the window 

7``[target_total - target_free - tolerance, target_total - target_free + tolerance]``. 

8 

9All iteration work is pure in-memory estimation against the pool manifest 

10(zero disk I/O). Only the final converged thresholds are handed to the 

11full orchestrator to produce the actual staged build. 

12 

13Typical usage:: 

14 

15 from romfarmer.farmhand.optimizer import run_optimizer, collect_pool 

16 

17 # 1. (once) collect pool manifest from an existing superset build output 

18 collect_pool(build_name="nointro-1g1r-eng", output_base=Path("output")) 

19 

20 # 2. run the optimizer loop 

21 result = run_optimizer( 

22 build_name="nointro-1g1r-eng", 

23 target_total_bytes=2_000_000_000_000, # 1.9 TB 

24 target_free_bytes=30 * 1024**3, 

25 tolerance_bytes=5 * 1024**3, 

26 max_iterations=8, 

27 ) 

28 print(result.verdict, result.final_thresholds) 

29""" 

30 

31from __future__ import annotations 

32 

33import datetime as _dt 

34 

35from .graph import build_optimizer_graph, run_optimizer 

36from .merge import MergeResult, merge_pools, merge_pools_from_builds 

37from .pool import collect_pool, estimate_build_size, load_pool 

38from .state import BudgetState, BuildReport, CriticDecision, IterationLog, OptimizerResult 

39from .thresholds import ( 

40 ApplyResult, 

41 apply_thresholds_to_build, 

42 apply_thresholds_to_builds, 

43 load_thresholds_from_optimizer_log, 

44) 

45 

46# Retirement condition (intent brief follow-up, 2026-09-03): this package is 

47# superseded by romfarmer.intent. It is removed when the psx pilot completes 

48# on the intent loop OR on this date, whichever comes first. A test fails 

49# once the date passes so the removal cannot be forgotten. 

50LEGACY_RETIRE_AFTER = _dt.date(2026, 12, 31) 

51 

52 

53def legacy_optimizer_status(today: _dt.date | None = None) -> str: 

54 """``"deprecated"`` until ``LEGACY_RETIRE_AFTER``, then ``"retired"``.""" 

55 return "retired" if (today or _dt.date.today()) > LEGACY_RETIRE_AFTER else "deprecated" 

56 

57 

58__all__ = [ 

59 "LEGACY_RETIRE_AFTER", 

60 "legacy_optimizer_status", 

61 "collect_pool", 

62 "load_pool", 

63 "estimate_build_size", 

64 "BudgetState", 

65 "IterationLog", 

66 "CriticDecision", 

67 "BuildReport", 

68 "OptimizerResult", 

69 "build_optimizer_graph", 

70 "run_optimizer", 

71 "merge_pools", 

72 "merge_pools_from_builds", 

73 "MergeResult", 

74 "apply_thresholds_to_build", 

75 "apply_thresholds_to_builds", 

76 "load_thresholds_from_optimizer_log", 

77 "ApplyResult", 

78]