Trainer
Trainer(context: RuntimeContext[DQNExperimentConfiguration], actor_model: DQNModel, learner_model: ThreadSafeModel, replay_buffer: ReplayBuffer, replay_writer: ReplayWriter, reward_shaping: RewardShapingPipeline | None = None, env_factory: Callable[[], OakEmuMultiEnv] | None = None) -> NoneTrainer component responsible for interacting with the environment and collecting transitions.
Initialize the Trainer.
Parameters:
context(RuntimeContext[DQNExperimentConfiguration]) – The shared runtime context.actor_model(DQNModel) – The local DQN model for action selection.learner_model(ThreadSafeModel) – The learner model container (for weight sync).replay_buffer(ReplayBuffer) – The experience replay buffer.replay_writer(ReplayWriter) – Dedicated replay-writer runtime for replay inserts.reward_shaping(RewardShapingPipeline | None) – Optional actor-owned reward-shaping pipeline.env_factory(Callable[[], OakEmuMultiEnv] | None) – Optional multi-environment factory; seeAgent.
Properties
replay_buffer
replay_buffer: ReplayBufferGet the replay buffer.
Returns:
ReplayBuffer– The ReplayBuffer instance.
replay_queue_depth
replay_queue_depth: intGet the number of replay batches waiting to be inserted.
Returns:
int– The replay queue depth.
staged_transition_count
staged_transition_count: intGet the number of transitions currently staged on the actor.
Returns:
int– The number of locally buffered transitions.
steps
steps: intGet the total number of environment steps.
Returns:
int– The total step count.
trajectory_runtime
trajectory_runtime: TrajectoryEpisodeCoordinatorGet the shared trajectory runtime coordinator.
Returns:
TrajectoryEpisodeCoordinator– The trainer's trajectory runtime coordinator.
Methods
freeze_replay_pipeline
freeze_replay_pipeline() -> AbstractContextManager[None]Freeze replay submission, flush actor-side staging, and drain the replay writer.
Returns:
AbstractContextManager[None]– A context manager that keeps replay submission frozen for the duration of the block.
replace_replay_buffer
replace_replay_buffer(replay_buffer: ReplayBuffer) -> NoneReplace the replay buffer and reconnect the replay writer.
Parameters:
replay_buffer(ReplayBuffer) – The new replay buffer.
restore_runtime_state
restore_runtime_state(state: ActorRuntimeState) -> NoneRestore checkpointed trainer counters and trajectory runtime state.
Not named restore_state (unlike Agent.restore_state): the trainer restores a strictly wider payload than the base episode-totals state, so this is a distinct method rather than an incompatibly-typed override.
Parameters:
state(ActorRuntimeState) – The trainer runtime state to restore.
run
run() -> NoneMain loop for the Trainer, interacting with the environment and adding data to the replay buffer.