EnvPool

Struct EnvPool 

Source
pub struct EnvPool {
    pub envs: Vec<GameEnv>,
    pub action_space: usize,
    pub error_policy: ErrorPolicy,
    /* private fields */
}
Expand description

Pool of independent environments stepped in parallel.

§Examples

use std::sync::Arc;
use weiss_core::{
    BatchOutMinimalBuffers, CardDb, CurriculumConfig, DebugConfig, EnvConfig, EnvPool,
};

let mut pool = EnvPool::new_rl_train(
    8,
    Arc::new(db),
    config,
    CurriculumConfig::default(),
    0,
    None,
    DebugConfig::default(),
)?;
let mut buffers = BatchOutMinimalBuffers::new(pool.envs.len());
let mut out = buffers.view_mut();
pool.reset_into(&mut out)?;

let actions = vec![weiss_core::encode::PASS_ACTION_ID as u32; pool.envs.len()];
pool.step_into(&actions, &mut out)?;

Fields§

§envs: Vec<GameEnv>

Backing environments (one per slot).

§action_space: usize

Fixed action space size used by all envs.

§error_policy: ErrorPolicy

Error policy applied during stepping.

Implementations§

Source§

impl EnvPool

Source

pub fn new_rl_train( num_envs: usize, db: Arc<CardDb>, config: EnvConfig, curriculum: CurriculumConfig, seed: u64, num_threads: Option<usize>, debug: DebugConfig, ) -> Result<Self>

Create a pool configured for RL training (public visibility + lenient errors).

Source

pub fn new_rl_eval( num_envs: usize, db: Arc<CardDb>, config: EnvConfig, curriculum: CurriculumConfig, seed: u64, num_threads: Option<usize>, debug: DebugConfig, ) -> Result<Self>

Create a pool configured for RL evaluation (public visibility).

Source

pub fn new_debug( num_envs: usize, db: Arc<CardDb>, config: EnvConfig, curriculum: CurriculumConfig, seed: u64, num_threads: Option<usize>, debug: DebugConfig, ) -> Result<Self>

Create a pool with explicit config and curriculum.

Source

pub fn set_debug_config(&mut self, debug: DebugConfig)

Update debug settings for all envs in the pool.

Source

pub fn engine_error_reset_count(&self) -> u64

Count of auto-resets triggered by engine errors.

Source

pub fn effective_num_threads(&self) -> usize

Effective thread count used by this pool (1 when running serially).

Source

pub fn set_curriculum(&mut self, curriculum: CurriculumConfig)

Replace curriculum settings for all envs in the pool.

Source

pub fn set_error_policy(&mut self, error_policy: ErrorPolicy)

Update error policy for all envs in the pool.

Source

pub fn set_output_mask_enabled(&mut self, enabled: bool)

Enable or disable output action masks for all envs.

Source

pub fn set_output_mask_bits_enabled(&mut self, enabled: bool)

Enable or disable output action mask bits for all envs.

Source

pub fn set_i16_clamp_enabled(&mut self, enabled: bool)

Enable or disable i16 clamping for i16 output buffers.

Source

pub fn set_i16_overflow_counter_enabled(&self, enabled: bool)

Enable or disable counting of i16 overflows.

Source

pub fn i16_overflow_count(&self) -> u64

Total count of i16 clamp overflows since last reset.

Source

pub fn config_hash(&self) -> u64

Stable hash of the pool’s config and curriculum.

Source

pub fn max_card_id(&self) -> u32

Maximum card id available in the underlying database.

Source

pub fn episode_seed_batch(&self) -> Vec<u64>

Episode seeds for each env in the pool.

Source

pub fn episode_index_batch(&self) -> Vec<u32>

Episode indices for each env in the pool.

Source

pub fn env_index_batch(&self) -> Vec<u32>

Environment indices for each env in the pool.

Source

pub fn starting_player_batch(&self) -> Vec<u8>

Starting player for each env in the pool.

Source

pub fn decision_count_batch(&self) -> Vec<u32>

Decision counts for each env in the pool.

Source

pub fn tick_count_batch(&self) -> Vec<u32>

Tick counts for each env in the pool.

Source

pub fn enable_replay_sampling(&mut self, config: ReplayConfig) -> Result<()>

Enable replay sampling for all envs in the pool.

Source§

impl EnvPool

Source

pub fn state_fingerprint_batch(&self) -> Vec<u64>

Compute state fingerprints for each env.

Source

pub fn events_fingerprint_batch(&self) -> Vec<u64>

Compute event-stream fingerprints for each env.

Source

pub fn obs_fingerprint_batch(&self) -> Vec<u64>

Compute observation fingerprints for each env.

Source§

impl EnvPool

Sample a legal action id uniformly per env.

Sample a legal action id uniformly per env into a buffer.

Write the first legal action id per env into a buffer.

Source

pub fn legal_action_ids_and_sample_uniform_into( &mut self, ids: &mut [u16], offsets: &mut [u32], seeds: &[u64], sampled: &mut [u32], ) -> Result<usize>

Fill legal-id buffers and sample one action per env.

Source

pub fn legal_action_ids_batch_into( &mut self, ids: &mut [u16], offsets: &mut [u32], ) -> Result<usize>

Fill legal-id buffers for all envs.

Source

pub fn legal_actions_batch(&self) -> Vec<Vec<ActionDesc>>

Compute legal action descriptors for all envs.

Source

pub fn get_current_player_batch(&self) -> Vec<i8>

Current decision player per env (-1 if none).

Source§

impl EnvPool

Source

pub fn action_masks_batch(&self) -> Result<Vec<u8>>

Fetch dense action masks for all envs.

Source

pub fn action_masks_batch_into(&self, masks: &mut [u8]) -> Result<()>

Fill a provided buffer with dense action masks.

Source

pub fn action_mask_bits_batch(&self) -> Vec<u64>

Fetch packed action mask bits for all envs.

Source

pub fn action_mask_bits_batch_into(&self, bits: &mut [u64]) -> Result<()>

Fill a provided buffer with packed action mask bits.

Source§

impl EnvPool

Source

pub fn debug_event_ring_capacity(&self) -> usize

Debug event ring capacity configured for the pool.

Source

pub fn render_ansi(&self, env_index: usize, perspective: u8) -> String

Render a single env to an ANSI string for debugging.

Source§

impl EnvPool

Source

pub fn select_actions_from_logits_into( &self, logits: &[f32], out: &mut [u32], ) -> Result<()>

Select the best legal action per env from logits (argmax).

Source

pub fn sample_actions_from_logits_into( &self, logits: &[f32], seeds: &[u64], out: &mut [u32], ) -> Result<()>

Sample a legal action per env from logits using softmax.

Source

pub fn step_select_from_logits_into( &mut self, logits: &[f32], actions: &mut [u32], out: &mut BatchOutMinimal<'_>, ) -> Result<()>

Select from logits and step, filling minimal outputs.

Source

pub fn step_select_from_logits_into_i16( &mut self, logits: &[f32], actions: &mut [u32], out: &mut BatchOutMinimalI16<'_>, ) -> Result<()>

Select from logits and step, filling i16 outputs.

Source

pub fn step_select_from_logits_into_nomask( &mut self, logits: &[f32], actions: &mut [u32], out: &mut BatchOutMinimalNoMask<'_>, ) -> Result<()>

Select from logits and step, filling outputs without masks.

Select from logits and step, filling i16 outputs plus legal-id lists.

Requires output masks to be disabled.

Source

pub fn step_sample_from_logits_into( &mut self, logits: &[f32], seeds: &[u64], actions: &mut [u32], out: &mut BatchOutMinimal<'_>, ) -> Result<()>

Sample from logits and step, filling minimal outputs.

Source

pub fn step_sample_from_logits_into_i16( &mut self, logits: &[f32], seeds: &[u64], actions: &mut [u32], out: &mut BatchOutMinimalI16<'_>, ) -> Result<()>

Sample from logits and step, filling i16 outputs.

Source

pub fn step_sample_from_logits_into_nomask( &mut self, logits: &[f32], seeds: &[u64], actions: &mut [u32], out: &mut BatchOutMinimalNoMask<'_>, ) -> Result<()>

Sample from logits and step, filling outputs without masks.

Sample from logits and step, filling i16 outputs plus legal-id lists.

Requires output masks to be disabled.

Source§

impl EnvPool

Source

pub fn reset_into(&mut self, out: &mut BatchOutMinimal<'_>) -> Result<()>

Reset all envs and fill a minimal output batch (i32 obs + masks).

Source

pub fn reset_into_i16(&mut self, out: &mut BatchOutMinimalI16<'_>) -> Result<()>

Reset all envs and fill a minimal output batch (i16 obs + masks).

Reset all envs and fill i16 outputs plus legal-id lists.

Requires output masks to be disabled.

Source

pub fn reset_into_nomask( &mut self, out: &mut BatchOutMinimalNoMask<'_>, ) -> Result<()>

Reset all envs and fill a minimal output batch without masks.

Source

pub fn reset_indices_into( &mut self, indices: &[usize], out: &mut BatchOutMinimal<'_>, ) -> Result<()>

Reset a subset of envs by index and fill minimal outputs.

Returns Err if any index is out of bounds (>= num_envs).

Source

pub fn reset_indices_into_i16( &mut self, indices: &[usize], out: &mut BatchOutMinimalI16<'_>, ) -> Result<()>

Returns Err if any index is out of bounds (>= num_envs). Reset a subset of envs by index and fill i16 outputs.

Returns Err if any index is out of bounds (>= num_envs). Reset a subset of envs by index and fill i16 outputs plus legal-id lists.

Requires output masks to be disabled.

Source

pub fn reset_indices_into_nomask( &mut self, indices: &[usize], out: &mut BatchOutMinimalNoMask<'_>, ) -> Result<()>

Returns Err if any index is out of bounds (>= num_envs). Reset a subset of envs by index and fill outputs without masks.

Source

pub fn reset_done_into( &mut self, done_mask: &[bool], out: &mut BatchOutMinimal<'_>, ) -> Result<()>

Reset envs where done_mask is true and fill minimal outputs.

Source

pub fn reset_done_into_i16( &mut self, done_mask: &[bool], out: &mut BatchOutMinimalI16<'_>, ) -> Result<()>

Reset envs where done_mask is true and fill i16 outputs.

Reset envs where done_mask is true and fill i16 outputs plus legal-id lists.

Requires output masks to be disabled.

Source

pub fn reset_done_into_nomask( &mut self, done_mask: &[bool], out: &mut BatchOutMinimalNoMask<'_>, ) -> Result<()>

Reset envs where done_mask is true and fill outputs without masks.

Source

pub fn reset_debug_into(&mut self, out: &mut BatchOutDebug<'_>) -> Result<()>

Reset all envs and fill debug outputs.

Source

pub fn reset_indices_debug_into( &mut self, indices: &[usize], out: &mut BatchOutDebug<'_>, ) -> Result<()>

Reset a subset of envs by index and fill debug outputs.

Source

pub fn reset_done_debug_into( &mut self, done_mask: &[bool], out: &mut BatchOutDebug<'_>, ) -> Result<()>

Reset envs where done_mask is true and fill debug outputs.

Source

pub fn reset_engine_error_reset_count(&mut self)

Clear the engine error reset counter.

Source

pub fn auto_reset_on_error_codes_into( &mut self, codes: &[u8], out: &mut BatchOutMinimal<'_>, ) -> Result<usize>

Auto-reset envs with non-zero error codes and fill minimal outputs.

Source

pub fn auto_reset_on_error_codes_into_nomask( &mut self, codes: &[u8], out: &mut BatchOutMinimalNoMask<'_>, ) -> Result<usize>

Auto-reset envs with non-zero error codes and fill outputs without masks.

Source

pub fn reset_i16_overflow_count(&self)

Clear the i16 overflow counter.

Source

pub fn reset_indices_with_episode_seeds_into( &mut self, indices: &[usize], episode_seeds: &[u64], out: &mut BatchOutMinimal<'_>, ) -> Result<()>

Returns Err if any index is out of bounds (>= num_envs). Reset a subset of envs with explicit episode seeds and fill minimal outputs.

Source

pub fn reset_indices_with_episode_seeds_into_i16( &mut self, indices: &[usize], episode_seeds: &[u64], out: &mut BatchOutMinimalI16<'_>, ) -> Result<()>

Returns Err if any index is out of bounds (>= num_envs). Reset a subset of envs with explicit episode seeds and fill i16 outputs.

Returns Err if any index is out of bounds (>= num_envs). Reset a subset of envs with explicit episode seeds and fill i16 outputs plus legal-id lists.

Requires output masks to be disabled.

Source

pub fn reset_indices_with_episode_seeds_into_nomask( &mut self, indices: &[usize], episode_seeds: &[u64], out: &mut BatchOutMinimalNoMask<'_>, ) -> Result<()>

Returns Err if any index is out of bounds (>= num_envs). Reset a subset of envs with explicit episode seeds and fill outputs without masks.

Source§

impl EnvPool

Source

pub fn step_into( &mut self, action_ids: &[u32], out: &mut BatchOutMinimal<'_>, ) -> Result<()>

Step all envs with action ids and fill minimal outputs.

Source

pub fn step_into_i16( &mut self, action_ids: &[u32], out: &mut BatchOutMinimalI16<'_>, ) -> Result<()>

Step all envs with action ids and fill i16 outputs.

Step all envs and fill i16 outputs plus legal-id lists.

Requires output masks to be disabled.

Source

pub fn step_into_nomask( &mut self, action_ids: &[u32], out: &mut BatchOutMinimalNoMask<'_>, ) -> Result<()>

Step all envs and fill outputs without masks.

Step using the first legal action per env (i16 + legal ids).

Step using uniformly sampled legal actions (i16 + legal ids).

Source

pub fn step_debug_into( &mut self, action_ids: &[u32], out: &mut BatchOutDebug<'_>, ) -> Result<()>

Step all envs and fill debug outputs.

Step using the first legal action per env.

Step using the first legal action per env (i16 outputs).

Step using the first legal action per env (no masks).

Step using uniformly sampled legal actions.

Step using uniformly sampled legal actions (i16 outputs).

Step using uniformly sampled legal actions (no masks).

Roll out a trajectory using first legal actions.

Roll out a trajectory using first legal actions (i16 outputs).

Roll out a trajectory using first legal actions (i16 + legal ids).

Requires output masks to be disabled.

Roll out a trajectory using first legal actions (no masks).

Roll out a trajectory using uniformly sampled legal actions.

Roll out a trajectory using uniformly sampled legal actions (i16 outputs).

Roll out a trajectory using uniformly sampled legal actions (i16 + legal ids).

Requires output masks to be disabled.

Roll out a trajectory using uniformly sampled legal actions (no masks).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.