mbodied.types package

Subpackages

Submodules

mbodied.types.geometry module

class mbodied.types.geometry.AbsolutePose(datum=None, *, x: float = 0, y: float = 0, z: float = 0, roll: float = 0, pitch: float = 0, yaw: float = 0)[source]

Bases: Pose

Absolute pose of the robot in 3D space.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ConfigDict = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'from_attributes': True, 'use_enum_values': False, 'validate_assignment': False}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'pitch': FieldInfo(annotation=float, required=False, default=0, description='Absolute pitch about the Y-axis in radians. Positive pitch is down. Motion type: ABSOLUTE', json_schema_extra={'bounds': None, 'motion_type': 'ABSOLUTE', 'shape': None}), 'roll': FieldInfo(annotation=float, required=False, default=0, description='Absolute roll about the X-axis in radians. Positive roll is clockwise. Motion type: ABSOLUTE', json_schema_extra={'bounds': None, 'motion_type': 'ABSOLUTE', 'shape': None}), 'x': FieldInfo(annotation=float, required=False, default=0, description='Absolute X position in 3D space. +x is forward; -x is backward. Motion type: ABSOLUTE', json_schema_extra={'bounds': None, 'motion_type': 'ABSOLUTE', 'shape': None}), 'y': FieldInfo(annotation=float, required=False, default=0, description='Absolute Y position in 3D space. +y is left; -y is right. Motion type: ABSOLUTE', json_schema_extra={'bounds': None, 'motion_type': 'ABSOLUTE', 'shape': None}), 'yaw': FieldInfo(annotation=float, required=False, default=0, description='Absolute yaw about the Z-axis in radians. Positive yaw is left. Motion type: ABSOLUTE', json_schema_extra={'bounds': None, 'motion_type': 'ABSOLUTE', 'shape': None}), 'z': FieldInfo(annotation=float, required=False, default=0, description='Absolute Z position in 3D space. +z is up; -z is down. Motion type: ABSOLUTE', json_schema_extra={'bounds': None, 'motion_type': 'ABSOLUTE', 'shape': None})}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

pitch: float
roll: float
x: float
y: float
yaw: float
z: float
class mbodied.types.geometry.LocationAngle(datum=None, *, x: float = 0.0, y: float = 0.0, theta: float = None)[source]

Bases: Pose3D

Alias for Pose3D. A 2D+1 space representing x, y, and theta.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ConfigDict = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'from_attributes': True, 'use_enum_values': False, 'validate_assignment': False}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'theta': FieldInfo(annotation=float, required=False, default_factory=<lambda>, description='Rotation (radians) about the z axis. Positive is counter-clockwise. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'x': FieldInfo(annotation=float, required=False, default=0.0, description='X position in 2D space. +x is forward; -x is backward. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'y': FieldInfo(annotation=float, required=False, default=0.0, description='Y position in 2D space. +y is left; -y is right. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None})}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class mbodied.types.geometry.Pose(datum=None, *, x: float = 0, y: float = 0, z: float = 0, roll: float = 0, pitch: float = 0, yaw: float = 0)[source]

Bases: Pose6D

Alias for Pose6D. A movement for a 6D space representing x, y, z, roll, pitch, and yaw.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ConfigDict = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'from_attributes': True, 'use_enum_values': False, 'validate_assignment': False}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'pitch': FieldInfo(annotation=float, required=False, default=0, description='Pitch about the Y-axis in radians. Positive pitch is down. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'roll': FieldInfo(annotation=float, required=False, default=0, description='Roll about the X-axis in radians. Positive roll is clockwise. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'x': FieldInfo(annotation=float, required=False, default=0, description='X position in 3D space. +x is forward; -x is backward. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'y': FieldInfo(annotation=float, required=False, default=0, description='Y position in 3D space. +y is left; -y is right. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'yaw': FieldInfo(annotation=float, required=False, default=0, description='Yaw about the Z-axis in radians. Positive yaw is left. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'z': FieldInfo(annotation=float, required=False, default=0, description='Z position in 3D space. +z is up; -z is down. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None})}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class mbodied.types.geometry.Pose3D(datum=None, *, x: float = 0.0, y: float = 0.0, theta: float = None)[source]

Bases: Motion

Action for a 2D+1 space representing x, y, and theta.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ConfigDict = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'from_attributes': True, 'use_enum_values': False, 'validate_assignment': False}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'theta': FieldInfo(annotation=float, required=False, default_factory=<lambda>, description='Rotation (radians) about the z axis. Positive is counter-clockwise. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'x': FieldInfo(annotation=float, required=False, default=0.0, description='X position in 2D space. +x is forward; -x is backward. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'y': FieldInfo(annotation=float, required=False, default=0.0, description='Y position in 2D space. +y is left; -y is right. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None})}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

theta: float
x: float
y: float
class mbodied.types.geometry.Pose6D(datum=None, *, x: float = 0, y: float = 0, z: float = 0, roll: float = 0, pitch: float = 0, yaw: float = 0)[source]

Bases: Motion

Movement for a 6D space representing x, y, z, roll, pitch, and yaw.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ConfigDict = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'from_attributes': True, 'use_enum_values': False, 'validate_assignment': False}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'pitch': FieldInfo(annotation=float, required=False, default=0, description='Pitch about the Y-axis in radians. Positive pitch is down. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'roll': FieldInfo(annotation=float, required=False, default=0, description='Roll about the X-axis in radians. Positive roll is clockwise. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'x': FieldInfo(annotation=float, required=False, default=0, description='X position in 3D space. +x is forward; -x is backward. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'y': FieldInfo(annotation=float, required=False, default=0, description='Y position in 3D space. +y is left; -y is right. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'yaw': FieldInfo(annotation=float, required=False, default=0, description='Yaw about the Z-axis in radians. Positive yaw is left. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None}), 'z': FieldInfo(annotation=float, required=False, default=0, description='Z position in 3D space. +z is up; -z is down. Motion type: UNSPECIFIED', json_schema_extra={'bounds': None, 'motion_type': 'UNSPECIFIED', 'shape': None})}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

pitch: float
roll: float
x: float
y: float
yaw: float
z: float
class mbodied.types.geometry.RelativePose(datum=None, *, x: float = 0, y: float = 0, z: float = 0, roll: float = 0, pitch: float = 0, yaw: float = 0)[source]

Bases: Pose

Relative pose of the robot in 3D space.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ConfigDict = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'from_attributes': True, 'use_enum_values': False, 'validate_assignment': False}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'pitch': FieldInfo(annotation=float, required=False, default=0, description='Relative pitch about the Y-axis in radians. Positive pitch is down. Motion type: RELATIVE', json_schema_extra={'bounds': None, 'motion_type': 'RELATIVE', 'shape': None}), 'roll': FieldInfo(annotation=float, required=False, default=0, description='Relative roll about the X-axis in radians. Positive roll is clockwise. Motion type: RELATIVE', json_schema_extra={'bounds': None, 'motion_type': 'RELATIVE', 'shape': None}), 'x': FieldInfo(annotation=float, required=False, default=0, description='Relative X position in 3D space. +x is forward; -x is backward. Motion type: RELATIVE', json_schema_extra={'bounds': None, 'motion_type': 'RELATIVE', 'shape': None}), 'y': FieldInfo(annotation=float, required=False, default=0, description='Relative Y position in 3D space. +y is left; -y is right. Motion type: RELATIVE', json_schema_extra={'bounds': None, 'motion_type': 'RELATIVE', 'shape': None}), 'yaw': FieldInfo(annotation=float, required=False, default=0, description='Relative yaw about the Z-axis in radians. Positive yaw is left. Motion type: RELATIVE', json_schema_extra={'bounds': None, 'motion_type': 'RELATIVE', 'shape': None}), 'z': FieldInfo(annotation=float, required=False, default=0, description='Relative Z position in 3D space. +z is up; -z is down. Motion type: RELATIVE', json_schema_extra={'bounds': None, 'motion_type': 'RELATIVE', 'shape': None})}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

pitch: float
roll: float
x: float
y: float
yaw: float
z: float

mbodied.types.message module

class mbodied.types.message.Message(content: Any | None = None, role: Literal['user', 'assistant', 'system'] = 'user')[source]

Bases: Sample

Single completion sample space.

Message can be text, image, list of text/images, Sample, or other modality.

role

The role of the message sender (user, assistant, or system).

Type:

Literal[‘user’, ‘assistant’, ‘system’]

content

The content of the message, which can be of various types.

Type:

Any | None

content: Any | None
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ConfigDict = {'arbitrary_types_allowed': True, 'extra': 'allow', 'from_attributes': True, 'use_enum_values': False, 'validate_assignment': False}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'content': FieldInfo(annotation=Union[Any, NoneType], required=False, default_factory=list), 'role': FieldInfo(annotation=Literal['user', 'assistant', 'system'], required=False, default='user')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

role: Literal['user', 'assistant', 'system']
classmethod supports(arg: Any) bool[source]

Checks if the argument type is supported by the Message class.

Parameters:

arg – The argument to be checked.

Returns:

True if the argument type is supported, False otherwise.

mbodied.types.ndarray module

mbodied.types.sample module

class mbodied.types.sample.Sample(datum=None, **data)[source]

Bases: BaseModel

A base model class for serializing, recording, and manipulating arbitray data.

classmethod default_sample(output_type='Sample') Sample | Dict[str, Any][source]

Generate a default Sample instance from its class attributes. Useful for padding.

This is the “no-op” instance and should be overriden as needed.

classmethod default_space() Dict[source]

Return the Gym space for the Sample class based on its class attributes.

classmethod default_value() Sample[source]

Get the default value for the Sample instance.

Returns:

The default value for the Sample instance.

Return type:

Sample

dict(exclude_none=True, exclude: set[str] = None) Dict[str, Any][source]

Return the Sample object as a dictionary with None values excluded.

Parameters:
  • exclude_none (bool, optional) – Whether to exclude None values. Defaults to True.

  • exclude (set[str], optional) – Set of attribute names to exclude. Defaults to None.

Returns:

Dictionary representation of the Sample object.

Return type:

Dict[str, Any]

flatten(output_type: Literal['dict', 'np', 'pt', 'list'] = 'dict', non_numerical: Literal['ignore', 'forbid', 'allow'] = 'allow') Dict[str, Any] | ndarray | Tensor | List[source]
classmethod from_flat_dict(flat_dict: Dict[str, Any], schema: Dict = None) Sample[source]

Initialize a Sample instance from a flattened dictionary.

classmethod from_space(space: Space) Sample[source]

Generate a Sample instance from a Gym space.

classmethod init_from(d: Any, pack=False) Sample[source]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ConfigDict = {'arbitrary_types_allowed': True, 'extra': 'allow', 'from_attributes': True, 'use_enum_values': False, 'validate_assignment': False}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_field_info(key: str) FieldInfo[source]

Get the FieldInfo for a given attribute key.

model_fields: ClassVar[dict[str, FieldInfo]] = {}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

static obj_to_schema(value: Any) Dict[source]

Generates a simplified JSON schema from a dictionary.

Parameters:

value (Any) – An object to generate a schema for.

Returns:

A simplified JSON schema representing the structure of the dictionary.

Return type:

dict

classmethod pack_from(samples: List[Sample | Dict]) Sample[source]

Pack a list of samples into a single sample with lists for attributes.

Parameters:

samples (List[Union[Sample, Dict]]) – List of samples or dictionaries.

Returns:

Packed sample with lists for attributes.

Return type:

Sample

random_sample() Sample[source]

Generate a random Sample instance based on its instance attributes. Omits None values.

Override this method in subclasses to customize the sample generation.

classmethod read(data: Any) Sample[source]

Read a Sample instance from a JSON string or dictionary or path.

Parameters:

data (Any) – The JSON string or dictionary to read.

Returns:

The read Sample instance.

Return type:

Sample

schema(resolve_refs: bool = True, include_descriptions=False) Dict[source]

Returns a simplified json schema.

Removing additionalProperties, selecting the first type in anyOf, and converting numpy schema to the desired type. Optionally resolves references.

Parameters:
  • schema (dict) – A dictionary representing the JSON schema.

  • resolve_refs (bool) – Whether to resolve references in the schema. Defaults to True.

  • include_descriptions (bool) – Whether to include descriptions in the schema. Defaults to False.

Returns:

A simplified JSON schema.

Return type:

dict

space() Dict[source]

Return the corresponding Gym space for the Sample instance based on its instance attributes. Omits None values.

Override this method in subclasses to customize the space generation.

classmethod space_for(value: Any, max_text_length: int = 1000, info: Annotated = None) Space[source]

Default Gym space generation for a given value.

Only used for subclasses that do not override the space method.

to(container: Any) Any[source]

Convert the Sample instance to a different container type.

Parameters:
  • container (Any) – The container type to convert to. Supported types are

  • 'dict' (pytorch), 'space' (gym.space)

  • 'list' (pytorch), 'space' (gym.space)

  • 'np' (pytorch), 'space' (gym.space)

  • 'pt' (pytorch), 'space' (gym.space)

  • 'schema' (datasets.Dataset)

  • 'json' (datasets.Dataset)

  • 'hf' (datasets.Dataset)

Returns:

The converted container.

Return type:

Any

classmethod unflatten(one_d_array_or_dict, schema=None) Sample[source]

Unflatten a one-dimensional array or dictionary into a Sample instance.

If a dictionary is provided, its keys are ignored.

Parameters:
  • one_d_array_or_dict – A one-dimensional array or dictionary to unflatten.

  • schema – A dictionary representing the JSON schema. Defaults to using the class’s schema.

Returns:

The unflattened Sample instance.

Return type:

Sample

Examples

>>> sample = Sample(x=1, y=2, z={"a": 3, "b": 4}, extra_field=5)
>>> flat_list = sample.flatten()
>>> print(flat_list)
[1, 2, 3, 4, 5]
>>> Sample.unflatten(flat_list, sample.schema())
Sample(x=1, y=2, z={'a': 3, 'b': 4}, extra_field=5)
unpack(to_dicts=False) List[Sample | Dict][source]

Unpack the packed Sample object into a list of Sample objects or dictionaries.

Module contents