atec2026-task-e-reproducibility / demo /solution_dual_act.py
yayalong's picture
Add files using upload-large-folder tool
1e71a55 verified
Raw
History Blame Contribute Delete
2.54 kB
"""Two-ACT relay experiment for ATEC Task E.
Both policies are stepped on every observation so their temporal histories stay
aligned with the actual rollout. The primary policy controls the reliable
early phase; after the score reaches the configured band, the secondary policy
may take over the late object_1 phase.
"""
from __future__ import annotations
import os
from solution_act import AlgSolution as _ActSolution
class AlgSolution:
def __init__(self):
self._primary_path = os.environ.get("ATEC_DUAL_PRIMARY_POLICY", os.environ.get("ATEC_ACT_POLICY_PATH", ""))
self._secondary_path = os.environ.get("ATEC_DUAL_SECONDARY_POLICY", "")
if not self._secondary_path:
raise RuntimeError("ATEC_DUAL_SECONDARY_POLICY is required for solution_dual_act")
old_policy_path = os.environ.get("ATEC_ACT_POLICY_PATH")
try:
if self._primary_path:
os.environ["ATEC_ACT_POLICY_PATH"] = self._primary_path
self.primary = _ActSolution()
os.environ["ATEC_ACT_POLICY_PATH"] = self._secondary_path
self.secondary = _ActSolution()
finally:
if old_policy_path is None:
os.environ.pop("ATEC_ACT_POLICY_PATH", None)
else:
os.environ["ATEC_ACT_POLICY_PATH"] = old_policy_path
self._switch_score = float(os.environ.get("ATEC_DUAL_SWITCH_SCORE", "12.0"))
self._switch_act_steps = int(os.environ.get("ATEC_DUAL_SWITCH_ACT_STEPS", "900"))
self._mode = "primary"
self._step = 0
def reset_episode(self):
self.primary.reset_episode()
self.secondary.reset_episode()
self._mode = "primary"
self._step = 0
def get_action_spec(self):
return None
def predicts(self, obs, current_score):
self._step += 1
primary_resp = self.primary.predicts(obs, current_score)
secondary_resp = self.secondary.predicts(obs, current_score)
primary_steps = int(getattr(self.primary, "_ts", 0))
if (
self._mode == "primary"
and float(current_score) >= self._switch_score
and primary_steps >= self._switch_act_steps
):
self._mode = "secondary"
print(
f"[DUAL_ACT] switching to secondary score={float(current_score):.2f} "
f"primary_steps={primary_steps}",
flush=True,
)
return secondary_resp if self._mode == "secondary" else primary_resp