OakEmuMultiEnv
OakEmuMultiEnv(number_of_environments: int, number_of_runners: int, game_configuration: GameConfiguration, model_configuration: ModelConfiguration, training_configuration: TrainingConfiguration | None, observation_shape_order: Literal['hwf', 'fhw'], training_mode: TrainingMode = TrainingMode.TRAINING, dump_directory: str | PathLike | None = None) -> NoneManages multiple OakEmu environments running in parallel.
Initialize the OakEmuMultiEnv.
Parameters:
number_of_environments(int) – Total number of parallel environments.number_of_runners(int) – Number of threads used to update the environments.game_configuration(GameConfiguration) – The game configuration.model_configuration(ModelConfiguration) – The model configuration.training_configuration(TrainingConfiguration | None) – The training configuration.observation_shape_order(Literal['hwf', 'fhw']) – Dimension order for observations.training_mode(TrainingMode) – The training mode.dump_directory(str | PathLike | None) – Optional directory for environment dumps.
Properties
action_shape
action_shape: intGet the action shape.
Returns:
int– The size of the discrete action space.
action_space
action_space: DiscreteGet the action space.
Returns:
Discrete– The Discrete action space.
number_of_environments
number_of_environments: intGet the number of environments.
Returns:
int– The total number of parallel environments.
number_of_runners
number_of_runners: intGet the number of runners.
Returns:
int– The number of runner threads.
observation_shape
observation_shape: tuple[int, int, int]Get the observation shape.
Returns:
tuple[int, int, int]– The shape of the observations.
observation_space
observation_space: BoxGet the observation space.
Returns:
Box– The Box observation space.
result_queue_depth
result_queue_depth: intGet the current number of results waiting to be dequeued.
Returns:
int– The current result queue depth.
training_mode
training_mode: TrainingModeGet the training mode.
Returns:
TrainingMode– The training mode.
Methods
dispose
dispose() -> NoneRelease the underlying C# environment's native resources (it is IDisposable).
run
run() -> MultiEnvRunReturns a context manager that starts the environment and stops it when exiting the context.
Returns:
MultiEnvRun– A MultiEnvRun instance.
start
start() -> NoneStart all parallel environments.
stop
stop() -> NoneStop all parallel environments.
unsafe_dequeue_results
unsafe_dequeue_results(max_results: int) -> list[MultiEnvResult]Dequeue up to max_results available results without blocking, via a single pointer-based interop call.
No pythonnet objects are marshalled per result: OakEmu writes scalars, observation pointers and any trajectory block bytes into one reused buffer and returns its address, and everything is parsed in Python with ctypes/struct/numpy. Observations and trajectories are copied out eagerly, so the returned results remain valid after the environments move on. Trajectories are returned as mrkwatkins.oakemu_rl.gymnasium.TrajectoryData.TrajectoryData, numeric StepResult.Data entries cross inline (falling back to trajectory end values for completed episodes), and failed results raise RuntimeError carrying the environment exception text.
Parameters:
max_results(int) – The maximum number of results to dequeue.
Returns:
list[MultiEnvResult]– The parsed results; empty if no results were queued.
unsafe_dequeue_results_blocking
unsafe_dequeue_results_blocking(max_results: int, timeout_milliseconds: int) -> list[MultiEnvResult]As unsafe_dequeue_results, but block until at least one result is queued, the channel completes, or timeout_milliseconds elapses, before draining ; a consumer can wait on the next result without spinning. OakEmu releases the GIL while waiting, so other Python threads run. The wait triggers on any result, so a slow replay/random environment never holds the batch up behind faster single steps. Returns an empty list when the timeout elapses with nothing queued.
Parameters:
max_results(int) – The maximum number of results to dequeue.timeout_milliseconds(int) – The maximum time to wait for the first result before returning empty.
Returns:
list[MultiEnvResult]– The parsed results; empty if none arrived before the timeout.
unsafe_enqueue_random
unsafe_enqueue_random(environment_id: int, *, action_indices: Sequence[int | np.integer] | bytes | bytearray | None = None, initial_state: bytes | None = None, reset_parameters: dict[str, int] | None = None) -> NoneEnqueue one full random exploration episode via the pointer-based interop call.
Parameters:
environment_id(int) – The target environment ID.action_indices(Sequence[int | integer] | bytes | bytearray | None) – Optional subset of action indices to sample from.initial_state(bytes | None) – Optional serialised emulator state.reset_parameters(dict[str, int] | None) – Optional reset-parameter overrides (for example{"start_cavern": 1}), applied on the fast path. Requires an OakEmu build that exposesResetParameterNames.
unsafe_enqueue_replay
unsafe_enqueue_replay(environment_id: int, *, initial_state: bytes, action_indices: Sequence[int | np.integer] | bytes | bytearray, trajectory_recording_mode: ReplayTrajectoryRecordingMode = ReplayTrajectoryRecordingMode.FULL) -> NoneEnqueue one full replay execution via the pointer-based interop call.
The initial state and action indices cross to OakEmu as pointers and are copied there, avoiding per-element pythonnet marshalling.
Parameters:
environment_id(int) – The target environment ID.initial_state(bytes) – Serialised emulator state to replay from.action_indices(Sequence[int | integer] | bytes | bytearray) – Action indices to replay.trajectory_recording_mode(ReplayTrajectoryRecordingMode) – Whether OakEmu should keep replay trajectory recording enabled.
unsafe_enqueue_reset
unsafe_enqueue_reset(environment_id: int, initial_state: bytes | None = None, reset_parameters: dict[str, int] | None = None, initial_frames: bytes | None = None) -> NoneEnqueue a reset action via the pointer-based interop call.
Parameters:
environment_id(int) – The target environment ID.initial_state(bytes | None) – Optional serialised emulator state to reset from.reset_parameters(dict[str, int] | None) – Optional reset-parameter overrides (for example{"start_cavern": 1}), applied on the fast path. Requires an OakEmu build that exposesResetParameterNames.initial_frames(bytes | None) – Optional seed for the observation frame stack, as the raw stacked-observation bytes in the configured layout. A snapshot is an emulator state, not a rendered-frame history, so without this the environment fills the stack by repeating the restored frame -- which at a midpoint restart shows the policy a world where nothing is moving. Only meaningful alongsideinitial_state.
unsafe_enqueue_reset_all
unsafe_enqueue_reset_all() -> NoneEnqueue a reset action for every environment in one pointer-based interop call.
unsafe_enqueue_steps
unsafe_enqueue_steps(steps: Sequence[tuple[int, int]]) -> NoneEnqueue step actions for several environments in one pointer-based interop call.
No pythonnet action objects are created or marshalled: the actions are packed into one buffer that OakEmu reads directly.
Parameters:
steps(Sequence[tuple[int, int]]) –(environment_id, action_index)pairs.
Values
metadata
metadata = {'observation_shape_orders': ['hwf', 'fhw']}