policy_template.py 627 B

123456789101112131415161718192021
  1. """Minimal closed-loop policy. Change only the first line to switch backends."""
  2. from hth_sdk import HTH
  3. def decide(state):
  4. heat = 25 if (state.max_temperature_c or 0) < 45 else 0
  5. return {"fan": 20, "heater": heat, "door": 0}
  6. def run(hth: HTH, steps: int = 8) -> None:
  7. for state in hth.watch(period=0.05, count=steps):
  8. if not state.ready or not state.fresh:
  9. continue
  10. result = hth.set(**decide(state))
  11. print(state.time, result.ok, state.max_temperature_c)
  12. if __name__ == "__main__":
  13. with HTH.demo(scenario="coupled_4chamber", seed=1, speed=20) as hth:
  14. run(hth)