Type System

MJINX uses Python’s type annotations throughout the codebase to enhance code clarity, enable better IDE support, and catch potential errors. This module provides the type definitions and aliases used across the library.

This module contains type definitions and aliases used throughout the mjinx library.

ArrayLike

Type alias for an array-like object, either a numpy array or a JAX array-like object.

alias of _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | Array | ndarray | bool | number

ArrayOrFloat: TypeAlias = numpy.ndarray | jax.Array | float

Type alias for an array or a float value.

ClassKFunctions

Type alias for Class K functions, which are scalar functions that take and return ndarrays.

CollisionBody: TypeAlias = int | str

Type alias for collision body representation, either as an integer ID or a string name.

CollisionPair

Type alias for a pair of collision body IDs.

class PositionLimitType(value)

Bases: Enum

Type which describes possible position limits.

The position limit could be only minimal, only maximal, or minimal and maximal.

BOTH = 2
MAX = 1
MIN = 0
static from_str(type)

Generates position limit type from string.

Parameters:

type (str) – position limit type.

Raises:

ValueError – limit name is not ‘min’, ‘max’, or ‘both’.

Return type:

mjinx.typing.PositionLimitType

Returns:

corresponding enum type.

static includes_max(type)

Either given limit includes maximum limit or not.

Returns true, if limit is either MIN or BOTH, and false otherwise.

Parameters:

type (mjinx.typing.PositionLimitType) – limit to be processes.

Return type:

bool

Returns:

True, if limit includes maximum limit, False otherwise.

static includes_min(type)

Either given limit includes minimum limit or not.

Returns true, if limit is either MIN or BOTH, and false otherwise.

Parameters:

type (mjinx.typing.PositionLimitType) – limit to be processes.

Return type:

bool

Returns:

True, if limit includes minimum limit, False otherwise.

class SimplifiedContact(geom, dist, pos, frame)

Bases: PyTreeNode

dist: Array
frame: Array
geom: Array
pos: Array
replace(**changes)

Return a new object replacing specified fields with new values.

This is especially useful for frozen classes. Example usage:

@dataclass(frozen=True) class C:

x: int y: int

c = C(1, 2) c1 = replace(c, x=3) assert c1.x == 3 and c1.y == 2

ndarray: TypeAlias = numpy.ndarray | jax.Array

Type alias for numpy or JAX numpy arrays.

Type Aliases

The following type aliases are defined for common data structures and function signatures:

ndarray

Type alias for numpy or JAX numpy arrays.

Annotation:

= np.ndarray | jnp.ndarray

ArrayOrFloat

Type alias for an array or a scalar float value.

Annotation:

= ndarray | float

ClassKFunctions

Type alias for Class K functions, which are scalar functions that take and return ndarrays.

Annotation:

= Callable[[ndarray], ndarray]

CollisionBody

Type alias for collision body representation, either as an integer ID or a string name.

Annotation:

= int | str

CollisionPair

Type alias for a pair of collision body IDs.

Annotation:

= tuple[int, int]

Enumerations

class PositionLimitType(value)

Bases: Enum

Type which describes possible position limits.

The position limit could be only minimal, only maximal, or minimal and maximal.

Enumeration of possible position limit types.

MIN = 0

Minimum position limit.

MAX = 1

Maximum position limit.

BOTH = 2

Both minimum and maximum position limits.

BOTH = 2
MAX = 1
MIN = 0
static from_str(type)

Generates position limit type from string.

Parameters:

type (str) – position limit type.

Raises:

ValueError – limit name is not ‘min’, ‘max’, or ‘both’.

Return type:

mjinx.typing.PositionLimitType

Returns:

corresponding enum type.

static includes_max(type)

Either given limit includes maximum limit or not.

Returns true, if limit is either MIN or BOTH, and false otherwise.

Parameters:

type (mjinx.typing.PositionLimitType) – limit to be processes.

Return type:

bool

Returns:

True, if limit includes maximum limit, False otherwise.

static includes_min(type)

Either given limit includes minimum limit or not.

Returns true, if limit is either MIN or BOTH, and false otherwise.

Parameters:

type (mjinx.typing.PositionLimitType) – limit to be processes.

Return type:

bool

Returns:

True, if limit includes minimum limit, False otherwise.