Skip to main content

actor_thread

Function actor_thread 

Source
pub fn actor_thread<B2, M, E, F>(
    actor_id: AgentId,
    env: E,
    policy: M,
    channels: ActorChannels,
    device: B2::Device,
    seed: u64,
    throttle: ActorThrottle,
    act_fn: F,
) -> Result<ActorStats>
where B2: Backend, M: Module<B2>, E: Environment<Action = i64>, F: FnMut(&M, &[f32], &mut StdRng) -> (i64, f32, f32),
Expand description

Body of one inference-only actor thread.

Steps env with the local policy copy, sending one crate::multi_agent::Experience per step over channels.experience_tx, until either a crate::multi_agent::ControlMessage::Shutdown arrives or the learner drops the experience receiver. Polls channels.broadcast_rx non-blocking on every iteration and hot-swaps the local policy when a newer crate::multi_agent::PolicyBroadcast is available (keeping only the newest when several are queued).

act_fn(&policy, observation, rng) must return the sampled (action, log_prob, value) for a single observation — the host-side counterpart of one batch-1 policy forward. throttle is the staleness valve described on AsyncActorLearnerConfig::max_lead_steps (ActorThrottle::disabled turns it off).

Most callers should use spawn_actor instead of calling this directly.

§Errors

Returns an error when a policy broadcast fails to decode.