Table of Contents

Class AsyncVectorEnv

Namespace
Gym.Vector
Assembly
Gym.dll

AsyncVectorEnv<TObs, TAct> untyped: observations and actions are objects, whatever the spaces, as Gymnasium's own. The untyped MakeVec(..., vectorizationMode: "async") builds this one.

public class AsyncVectorEnv : AsyncVectorEnv<object?, object?>, IVectorEnv, IDisposable
Inheritance
AsyncVectorEnv
Implements
Inherited Members
Extension Methods

Remarks

Constructors

AsyncVectorEnv(IEnumerable<Func<IEnv>>, bool, bool, object?, object?, object?, AsyncExecutionMode, int?, string?, bool, AsyncVectorWorker?)

Builds the workers and the batched spaces; see AsyncVectorEnv<TObs, TAct>'s constructor.

public AsyncVectorEnv(IEnumerable<Func<IEnv>> envFns, bool sharedMemory = true, bool copy = true, object? observationMode = null, object? autoresetMode = null, object? maxConcurrency = null, AsyncExecutionMode executionMode = AsyncExecutionMode.ThreadPool, int? threadCount = null, string? context = null, bool daemon = true, AsyncVectorWorker? worker = null)

Parameters

envFns IEnumerable<Func<IEnv>>

One function per sub-env, each called by its worker; the first also once by the constructor.

sharedMemory bool

Whether the workers write their observations into one shared buffer.

copy bool

Whether every returned observation batch is a deep copy.

observationMode object

"same" (null), "different", or the pair of batched and single spaces.

autoresetMode object

An AutoresetMode or its value; null is NEXT_STEP.

maxConcurrency object

How many sub-envs may run reset or step at once, or null.

executionMode AsyncExecutionMode

Where the calls run (DR-22).

threadCount int?

The number of threads of DedicatedThreads.

context string

Gymnasium's start method: accepted and kept, with nothing to choose.

daemon bool

Whether the dedicated threads are background threads (the default).

worker AsyncVectorWorker

A custom worker serving each sub-env on a thread of its own (DR-38), or null for the built-in workers.

Exceptions

ArgumentNullException

Thrown when envFns is null.

ValueError

Thrown for an unknown mode, a bad max_concurrency or thread count, or a space with no shared layout.

IndexError

Thrown when there are no sub-envs.

TypeError

Thrown when a pair observation mode holds something else than spaces, or a Graph/Sequence space is shared.

RuntimeError

Thrown when a sub-env's spaces do not fit the batch.

EndOfStreamException

Thrown under a custom worker that ended without answering.

Methods

AsyncWorker(int, Func<IEnv>, PipeConnection, PipeConnection, object?, ConcurrentQueue<AsyncWorkerError>, AutoresetMode, SemaphoreSlim?)

The default worker (Gymnasium's _async_worker, DR-38), public so a custom AsyncVectorWorker can wrap it: builds the sub-env with envFn, closes its handle on parentPipe, then answers each (command, data) received on pipe with (result, success), in order, until a close or a failure; the sub-env is closed and disposed on the way out. The vector env's built-in workers run this same loop body through their executors.

public static void AsyncWorker(int index, Func<IEnv> envFn, PipeConnection pipe, PipeConnection parentPipe, object? sharedMemory, ConcurrentQueue<AsyncWorkerError> errorQueue, AutoresetMode autoresetMode, SemaphoreSlim? semaphore)

Parameters

index int

The sub-env's index.

envFn Func<IEnv>

Builds the sub-env, which this worker owns.

pipe PipeConnection

The worker's end of the pipe.

parentPipe PipeConnection

The worker's handle on the parent's end, closed first, as Gymnasium's worker does.

sharedMemory object

The shared observation buffer to write into, or null to send observations through the pipe.

errorQueue ConcurrentQueue<AsyncWorkerError>

Where a failure is reported before the (null, false) answer.

autoresetMode AutoresetMode

When an ended sub-env resets.

semaphore SemaphoreSlim

The concurrency permits held around reset and step, or null.

Remarks

Exceptions

Exception

What envFn throws, before any answer (as in Gymnasium, where the process then dies and the parent sees the end of the pipe), or what answering through a broken pipe throws.