pub struct DqnRunner<E, Enc, Act, B>where
E: Environment,
B: AutodiffBackend,{ /* private fields */ }Expand description
The imperative training runner.
Drives the interaction between an environment and a DQN agent,
exposing it as an iterator that yields StepMetrics after every step.
§Usage
ⓘ
let mut runner = DqnRunner::new(env, agent, seed);
for step in runner.steps().take(50_000) {
if step.episode_done {
println!("Episode {} reward: {}", step.episode, step.episode_reward);
}
}§Why an iterator?
- You control the loop: add early stopping, custom logging, checkpointing
- bevy-gym can drive the same runner one step per ECS tick
- No callbacks, no closures, no inversion of control
Implementations§
Source§impl<E, Enc, Act, B> DqnRunner<E, Enc, Act, B>where
E: Environment,
E::Observation: Clone + Send + Sync + 'static,
E::Action: Clone + Send + Sync + 'static,
Enc: ObservationEncoder<E::Observation, B> + ObservationEncoder<E::Observation, B::InnerBackend>,
Act: DiscreteActionMapper<E::Action>,
B: AutodiffBackend,
impl<E, Enc, Act, B> DqnRunner<E, Enc, Act, B>where
E: Environment,
E::Observation: Clone + Send + Sync + 'static,
E::Action: Clone + Send + Sync + 'static,
Enc: ObservationEncoder<E::Observation, B> + ObservationEncoder<E::Observation, B::InnerBackend>,
Act: DiscreteActionMapper<E::Action>,
B: AutodiffBackend,
pub fn new(env: E, agent: DqnAgent<E, Enc, Act, B>, seed: u64) -> Self
Sourcepub fn steps(&mut self) -> StepIter<'_, E, Enc, Act, B> ⓘ
pub fn steps(&mut self) -> StepIter<'_, E, Enc, Act, B> ⓘ
Returns an iterator that yields StepMetrics after each environment step.
Auto Trait Implementations§
impl<E, Enc, Act, B> Freeze for DqnRunner<E, Enc, Act, B>where
E: Freeze,
Enc: Freeze,
Act: Freeze,
<B as Backend>::Device: Freeze,
<E as Environment>::Observation: Freeze,
impl<E, Enc, Act, B> !RefUnwindSafe for DqnRunner<E, Enc, Act, B>
impl<E, Enc, Act, B> Send for DqnRunner<E, Enc, Act, B>
impl<E, Enc, Act, B> !Sync for DqnRunner<E, Enc, Act, B>
impl<E, Enc, Act, B> Unpin for DqnRunner<E, Enc, Act, B>where
E: Unpin,
Enc: Unpin,
Act: Unpin,
<B as Backend>::Device: Unpin,
<E as Environment>::Observation: Unpin,
<E as Environment>::Action: Unpin,
<B as Backend>::FloatTensorPrimitive: Unpin,
<B as Backend>::QuantizedTensorPrimitive: Unpin,
<<B as AutodiffBackend>::InnerBackend as Backend>::FloatTensorPrimitive: Unpin,
<<B as AutodiffBackend>::InnerBackend as Backend>::QuantizedTensorPrimitive: Unpin,
impl<E, Enc, Act, B> UnsafeUnpin for DqnRunner<E, Enc, Act, B>where
E: UnsafeUnpin,
Enc: UnsafeUnpin,
Act: UnsafeUnpin,
<B as Backend>::Device: UnsafeUnpin,
<E as Environment>::Observation: UnsafeUnpin,
impl<E, Enc, Act, B> !UnwindSafe for DqnRunner<E, Enc, Act, B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more