Class VectorWrapper<TWObs, TWAct, TObs, TAct>
Wraps a vector env to change its behaviour, forwarding everything it does not change: the spaces (until the wrapper assigns its own), the metadata, the spec, the generator, NumEnvs, reset, step, render and close. Typed by the wrapper's batched types and the wrapped env's.
public class VectorWrapper<TWObs, TWAct, TObs, TAct> : VectorEnv<TWObs, TWAct>, IVectorEnv, IDisposable
Type Parameters
TWObsThe wrapper's batched observation type.
TWActThe wrapper's batched action type.
TObsThe wrapped env's batched observation type.
TActThe wrapped env's batched action type.
- Inheritance
-
VectorEnv<TWObs, TWAct>VectorWrapper<TWObs, TWAct, TObs, TAct>
- Implements
- Derived
-
VectorActionWrapper<TObs, TWAct, TAct>VectorObservationWrapper<TWObs, TObs, TAct>
- Inherited Members
- Extension Methods
Remarks
Unlike a single-env wrapper, a vector wrapper adds nothing to the spec: Spec is the wrapped env's. When the wrapper's types differ from the env's, override Step(TWAct) and Reset(BigInteger?, IReadOnlyDictionary<string, object?>?) (or derive from VectorObservationWrapper<TWObs, TObs, TAct>, VectorActionWrapper<TObs, TWAct, TAct>): the default forwarding passes values through and throws InvalidCastException for a value of only one type.
Reference: gymnasium/vector/vector_env.py.
Constructors
VectorWrapper(VectorEnv<TObs, TAct>)
Wraps env.
public VectorWrapper(VectorEnv<TObs, TAct> env)
Parameters
envVectorEnv<TObs, TAct>The vector env to wrap, possibly another wrapper.
Exceptions
- TypeError
Thrown when
envis null:Expected env to be a.gymnasium.vector.VectorEnvbut got <class 'NoneType'>
Properties
ActionSpace
The env's batched action space, unless this wrapper was assigned its own (_action_space).
public override Space<TWAct> ActionSpace { get; set; }
Property Value
- Space<TWAct>
Exceptions
- TypeError
Thrown by the getter when the env's space holds another element type and this wrapper has none of its own.
Closed
The env's closed flag; setting it sets the env's (Python's property forwards both ways).
public override bool Closed { get; set; }
Property Value
Env
The wrapped vector env (env).
public VectorEnv<TObs, TAct> Env { get; }
Property Value
- VectorEnv<TObs, TAct>
Metadata
The env's metadata, unless this wrapper was assigned its own (Python's _metadata); assigning null restores forwarding.
public override Metadata Metadata { get; set; }
Property Value
NpRandom
The env's generator; assigning one assigns the env's.
public override Generator NpRandom { get; set; }
Property Value
NpRandomSeed
The env's generator seed.
public override BigInteger NpRandomSeed { get; }
Property Value
NumEnvs
The env's number of sub-envs.
public override int NumEnvs { get; protected set; }
Property Value
Exceptions
- AttributeError
Thrown when assigned, as Python's property has no setter.
ObservationSpace
The env's batched observation space, unless this wrapper was assigned its own (_observation_space).
public override Space<TWObs> ObservationSpace { get; set; }
Property Value
- Space<TWObs>
Exceptions
- TypeError
Thrown by the getter when the env's space holds another element type and this wrapper has none of its own.
RenderMode
The env's render mode; read-only on a wrapper.
public override string? RenderMode { get; protected set; }
Property Value
Exceptions
- AttributeError
Thrown when assigned.
SingleActionSpace
The env's single action space, unless this wrapper was assigned its own (_single_action_space).
public override Space SingleActionSpace { get; set; }
Property Value
SingleObservationSpace
The env's single observation space, unless this wrapper was assigned its own (_single_observation_space).
public override Space SingleObservationSpace { get; set; }
Property Value
Spec
The env's spec: a vector wrapper records nothing in it.
public override EnvSpec? Spec { get; set; }
Property Value
Exceptions
- AttributeError
Thrown when assigned, as Python's property has no setter.
Unwrapped
The innermost vector env.
public override IVectorEnv Unwrapped { get; }
Property Value
WrapperActionSpace
This wrapper's own batched action space, null to forward the env's; owned as WrapperObservationSpace is.
[PyName("_action_space")]
protected Space<TWAct>? WrapperActionSpace { get; set; }
Property Value
- Space<TWAct>
Exceptions
- InvalidOperationException
Thrown by the setter for a space an env outside this stack, not yet disposed, owns.
WrapperMetadata
This wrapper's own metadata, null to forward the env's.
[PyName("_metadata")]
protected Metadata? WrapperMetadata { get; set; }
Property Value
WrapperObservationSpace
This wrapper's own batched observation space, null to forward the env's. The wrapper owns and disposes a space it is given (DR-40), except one a vector env beneath it already owns, which it only references.
[PyName("_observation_space")]
protected Space<TWObs>? WrapperObservationSpace { get; set; }
Property Value
- Space<TWObs>
Exceptions
- InvalidOperationException
Thrown by the setter for a space an env outside this stack, not yet disposed, owns.
WrapperSingleActionSpace
This wrapper's own single action space, null to forward the env's.
[PyName("_single_action_space")]
protected Space? WrapperSingleActionSpace { get; set; }
Property Value
WrapperSingleObservationSpace
This wrapper's own single observation space, null to forward the env's.
[PyName("_single_observation_space")]
protected Space? WrapperSingleObservationSpace { get; set; }
Property Value
Methods
Close()
Closes the env beneath (self.env.close()).
public override void Close()
CloseExtras()
The env's close_extras.
protected override void CloseExtras()
Dispose(bool)
Closes, releases this wrapper's own spaces, and disposes the env beneath: disposing the outermost wrapper disposes the stack.
protected override void Dispose(bool disposing)
Parameters
Render()
Forwards to the env (self.env.render()).
public override IReadOnlyList<RenderResult>? Render()
Returns
- IReadOnlyList<RenderResult>
The env's renders.
Reset(IReadOnlyList<BigInteger?>, IReadOnlyDictionary<string, object?>?)
Forwards a reset with one seed per sub-env to the env.
public override VectorResetResult<TWObs> Reset(IReadOnlyList<BigInteger?> seeds, IReadOnlyDictionary<string, object?>? options = null)
Parameters
seedsIReadOnlyList<BigInteger?>The seeds.
optionsIReadOnlyDictionary<string, object>The options.
Returns
- VectorResetResult<TWObs>
The env's result, its observations passed through.
Exceptions
- InvalidCastException
Thrown when the observation types differ and the observations are not of both.
Reset(BigInteger?, IReadOnlyDictionary<string, object?>?)
Forwards to the env (self.env.reset(seed=seed, options=options)); valid only when the wrapper does not change the observation type.
public override VectorResetResult<TWObs> Reset(BigInteger? seed = null, IReadOnlyDictionary<string, object?>? options = null)
Parameters
seedBigInteger?The seed.
optionsIReadOnlyDictionary<string, object>The options.
Returns
- VectorResetResult<TWObs>
The env's result, its observations passed through.
Exceptions
- InvalidCastException
Thrown when the observation types differ and the observations are not of both.
Step(TWAct)
Forwards to the env (self.env.step(actions)); valid only when the wrapper changes neither type.
public override VectorStepResult<TWObs> Step(TWAct actions)
Parameters
actionsTWActThe actions, passed through.
Returns
- VectorStepResult<TWObs>
The env's result, its observations passed through.
Exceptions
- InvalidCastException
Thrown when the types differ and a value is not of both.
ToString()
Python's repr: <ClipReward, SyncVectorEnv(CartPole-v1, num_envs=3)>.
public override string ToString()
Returns
- string
The text.