ActionPolicy
ActionPolicy(action_masker: ActionMasker, exploration_strategy: ExplorationStrategy, actor_model: DQNModel, learner_model_container: ThreadSafeModel, num_steps_sampled_before_learning_starts: int, *, queue_for_inference: Callable[[int, np.ndarray], None], record_random_step: Callable[[], None]) -> NoneSelects actions for each actor environment and enqueues them for execution.
During warmup, random-controlled trajectory replay, or epsilon-greedy exploration, an action is sampled and enqueued immediately; otherwise the environment is queued for batched greedy inference, with the resulting action applied once the batch completes.
Initialize the action policy.
Parameters:
action_masker(ActionMasker) – Restricts sampled/greedy actions to the game's training action set.exploration_strategy(ExplorationStrategy) – Decides when to explore and the current exploration value.actor_model(DQNModel) – The local model, for exploration-driven noise resets.learner_model_container(ThreadSafeModel) – The learner model container, for weight sync after inference.num_steps_sampled_before_learning_starts(int) – Steps before learning starts, during which actions are always sampled randomly regardless of the exploration strategy.queue_for_inference(Callable[[int, ndarray], None]) – Queues an environment/observation for batched greedy inference.record_random_step(Callable[[], None]) – Records a random-controlled trajectory-replay step.
Methods
get_exploration_value
get_exploration_value(step: int) -> float | NoneGet the current exploration value (epsilon), for metrics logging.
Parameters:
step(int) – The current environment step.
Returns:
float | None– The exploration value, orNonefor exploration strategies without one (for example noisy nets).
on_inference_complete
on_inference_complete(env_state: EnvironmentState, action: int) -> NoneRecord the greedy action chosen by batched inference.
Parameters:
env_state(EnvironmentState) – The state for the environment that completed inference.action(int) – The selected greedy action.
reset_noise_before_inference
reset_noise_before_inference(step: int, num_environments: int) -> NoneReset the actor model's noise before a batched inference flush, if the exploration strategy calls for it.
Parameters:
step(int) – The current environment step.num_environments(int) – The number of actor environments.
select_and_enqueue_action
select_and_enqueue_action(env: OakEmuMultiEnv, env_id: int, env_state: EnvironmentState, *, step: int) -> NoneSelect an action and either enqueue it immediately or queue for batched inference.
During warmup or exploration, a random action is selected and enqueued immediately. Otherwise the environment is queued for batched greedy inference.
Parameters:
env(OakEmuMultiEnv) – The multi-environment instance.env_id(int) – The environment ID.env_state(EnvironmentState) – The state for this environment.step(int) – The current environment step.
sync_weights_after_inference
sync_weights_after_inference() -> NoneSync weights from the learner model if an update is available, resetting noise afterward if the exploration strategy calls for it.