Class AsyncVectorEnv
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
Reference: gymnasium/vector/async_vector_env.py.
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
envFnsIEnumerable<Func<IEnv>>One function per sub-env, each called by its worker; the first also once by the constructor.
sharedMemoryboolWhether the workers write their observations into one shared buffer.
copyboolWhether every returned observation batch is a deep copy.
observationModeobject"same"(null),"different", or the pair of batched and single spaces.autoresetModeobjectAn AutoresetMode or its value; null is
NEXT_STEP.maxConcurrencyobjectHow many sub-envs may run
resetorstepat once, or null.executionModeAsyncExecutionModeWhere the calls run (DR-22).
threadCountint?The number of threads of DedicatedThreads.
contextstringGymnasium's start method: accepted and kept, with nothing to choose.
daemonboolWhether the dedicated threads are background threads (the default).
workerAsyncVectorWorkerA 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
envFnsis null.- ValueError
Thrown for an unknown mode, a bad
max_concurrencyor 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/Sequencespace 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
indexintThe sub-env's index.
envFnFunc<IEnv>Builds the sub-env, which this worker owns.
pipePipeConnectionThe worker's end of the pipe.
parentPipePipeConnectionThe worker's handle on the parent's end, closed first, as Gymnasium's worker does.
sharedMemoryobjectThe shared observation buffer to write into, or null to send observations through the pipe.
errorQueueConcurrentQueue<AsyncWorkerError>Where a failure is reported before the
(null, false)answer.autoresetModeAutoresetModeWhen an ended sub-env resets.
semaphoreSemaphoreSlimThe concurrency permits held around
resetandstep, or null.
Remarks
Reference: gymnasium/vector/async_vector_env.py.
Exceptions
- Exception
What
envFnthrows, 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.