Table of Contents

Class TransformAction<TObs, TWAct, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Applies a function to every action before the env steps with it, as Gymnasium's TransformAction does. Give it the space of the actions it takes when they differ from the env's.

public class TransformAction<TObs, TWAct, TAct> : ActionWrapper<TObs, TWAct, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs

Type Parameters

TObs

The observation type, passed through.

TWAct

The action type the wrapper takes.

TAct

The env's action type.

Inheritance
Env<TObs, TWAct>
Wrapper<TObs, TWAct, TObs, TAct>
ActionWrapper<TObs, TWAct, TAct>
TransformAction<TObs, TWAct, TAct>
Implements
Derived
Inherited Members
Extension Methods

Remarks

Without an action space the wrapper forwards the env's, which only works when TWAct is the env's action type: reading it otherwise raises TypeError. The base of Gymnasium's action wrappers, which set Func and SavedKwargs in their own constructors.

Reference: gymnasium/wrappers/transform_action.py.

Constructors

TransformAction(Env<TObs, TAct>)

Wraps env for a subclass that computes its function and space in its own constructor and assigns Func, ActionSpace and SavedKwargs there.

protected TransformAction(Env<TObs, TAct> env)

Parameters

env Env<TObs, TAct>

The env.

Exceptions

TypeError

Thrown when env is null.

TransformAction(Env<TObs, TAct>, TransformActionOptions<TWAct, TAct>)

Builds the instance from its options record: the properties set, the constructor's defaults for the rest.

public TransformAction(Env<TObs, TAct> env, TransformActionOptions<TWAct, TAct> options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options TransformActionOptions<TWAct, TAct>

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

TypeError

Thrown when a required argument is unset, with Python's missing-argument message.

TransformAction(Env<TObs, TAct>, Func<TWAct, TAct>, Space<TWAct>?)

Wraps env.

public TransformAction(Env<TObs, TAct> env, Func<TWAct, TAct> func, Space<TWAct>? actionSpace)

Parameters

env Env<TObs, TAct>

The env.

func Func<TWAct, TAct>

The transformation; null fails at the first step, as Python's None does when called.

actionSpace Space<TWAct>

The wrapper's action space, owned by the wrapper from now on; null forwards the env's.

Exceptions

TypeError

Thrown when env is null.

Properties

Func

The transformation (func).

[PyName("func")]
public Func<TWAct, TAct> Func { get; protected set; }

Property Value

Func<TWAct, TAct>

SavedKwargs

The recorded constructor arguments (Python's _saved_kwargs): a subclass's own, as Python records the first call's.

[PyName("_saved_kwargs")]
public Info SavedKwargs { get; protected set; }

Property Value

Info

Methods

Action(TWAct)

Applies Func (action(action)).

public override TAct Action(TWAct action)

Parameters

action TWAct

The wrapper's action.

Returns

TAct

The env's action.

Exceptions

TypeError

Thrown when the function is null: 'NoneType' object is not callable.