Table of Contents

Class PyCopy

Namespace
Gym.Utils
Assembly
Gym.dll

Python's copy.deepcopy for the values Gymnasium deep-copies: specs (deepcopy(env.spec) before a wrapper edits it) and recorded constructor arguments (RecordConstructorArgs). The copy shares nothing mutable with the original, so editing one never shows through the other.

public static class PyCopy
Inheritance
PyCopy
Inherited Members

Remarks

Copied: Info (and Metadata), EnvSpec, WrapperSpec, NDArray (a new buffer), .NET arrays, and any IList or IDictionary with a public parameterless constructor (List<T>, Dictionary<TKey, TValue>), element by element. Shared: immutable values (strings, numbers, enums, null) and every other object, which Python would copy through its __deepcopy__/pickle protocol and .NET has no general way to; a mutable object of another type inside a spec's kwargs is therefore shared by the copy.

Python's memo, which copies an object reachable twice only once and survives cycles, is not reproduced: a value reachable twice is copied twice, and a cycle recurses without end.

Methods

DeepCopy(object?)

Deep-copies a value as the class remarks describe.

public static object? DeepCopy(object? value)

Parameters

value object

The value.

Returns

object

The copy, or value itself when it is immutable or of a type that is shared.

Exceptions

TargetInvocationException

Thrown when the parameterless constructor of a copied collection type throws (the copy is created through it).