mbodied.types package∞
Subpackages∞
- mbodied.types.language package
- Submodules
- mbodied.types.language.control module
LangControlLangControl.CLOSE_HANDLangControl.GO_HOMELangControl.LOOK_DOWNLangControl.LOOK_LEFTLangControl.LOOK_RIGHTLangControl.LOOK_UPLangControl.MOVE_BACKWARDLangControl.MOVE_FORWARDLangControl.MOVE_HAND_BACKWARDLangControl.MOVE_HAND_DOWNLangControl.MOVE_HAND_FORWARDLangControl.MOVE_HAND_LEFTLangControl.MOVE_HAND_RIGHTLangControl.MOVE_HAND_UPLangControl.OPEN_HANDLangControl.PAUSELangControl.RESTARTLangControl.RESUMELangControl.SLEEPLangControl.STARTLangControl.STOPLangControl.TURN_LEFTLangControl.TURN_RIGHT
MobileSingleArmLangControlMobileSingleArmLangControl.CLOSE_HANDMobileSingleArmLangControl.LOOK_DOWNMobileSingleArmLangControl.LOOK_DOWN_A_LITTLEMobileSingleArmLangControl.LOOK_DOWN_A_LOTMobileSingleArmLangControl.LOOK_LEFTMobileSingleArmLangControl.LOOK_LEFT_A_LITTLEMobileSingleArmLangControl.LOOK_LEFT_A_LOTMobileSingleArmLangControl.LOOK_RIGHTMobileSingleArmLangControl.LOOK_RIGHT_A_LITTLEMobileSingleArmLangControl.LOOK_RIGHT_A_LOTMobileSingleArmLangControl.LOOK_UPMobileSingleArmLangControl.LOOK_UP_A_LITTLEMobileSingleArmLangControl.LOOK_UP_A_LOTMobileSingleArmLangControl.MOVE_BACKWARDMobileSingleArmLangControl.MOVE_BACKWARD_A_LITTLEMobileSingleArmLangControl.MOVE_BACKWARD_A_LOTMobileSingleArmLangControl.MOVE_FORWARDMobileSingleArmLangControl.MOVE_FORWARD_A_LITTLEMobileSingleArmLangControl.MOVE_FORWARD_A_LOTMobileSingleArmLangControl.MOVE_HAND_BACKWARDMobileSingleArmLangControl.MOVE_HAND_BACKWARD_A_LITTLEMobileSingleArmLangControl.MOVE_HAND_BACKWARD_A_LOTMobileSingleArmLangControl.MOVE_HAND_DOWNMobileSingleArmLangControl.MOVE_HAND_DOWN_A_LITTLEMobileSingleArmLangControl.MOVE_HAND_DOWN_A_LOTMobileSingleArmLangControl.MOVE_HAND_FORWARDMobileSingleArmLangControl.MOVE_HAND_FORWARD_A_LITTLEMobileSingleArmLangControl.MOVE_HAND_FORWARD_A_LOTMobileSingleArmLangControl.MOVE_HAND_LEFTMobileSingleArmLangControl.MOVE_HAND_LEFT_A_LITTLEMobileSingleArmLangControl.MOVE_HAND_LEFT_A_LOTMobileSingleArmLangControl.MOVE_HAND_RIGHTMobileSingleArmLangControl.MOVE_HAND_RIGHT_A_LITTLEMobileSingleArmLangControl.MOVE_HAND_RIGHT_A_LOTMobileSingleArmLangControl.MOVE_HAND_UPMobileSingleArmLangControl.MOVE_HAND_UP_A_LITTLEMobileSingleArmLangControl.MOVE_HAND_UP_A_LOTMobileSingleArmLangControl.MOVE_HOMEMobileSingleArmLangControl.OPEN_HANDMobileSingleArmLangControl.PITCH_HAND_DOWNMobileSingleArmLangControl.PITCH_HAND_DOWN_A_LITTLEMobileSingleArmLangControl.PITCH_HAND_DOWN_A_LOTMobileSingleArmLangControl.PITCH_HAND_UPMobileSingleArmLangControl.PITCH_HAND_UP_A_LITTLEMobileSingleArmLangControl.PITCH_HAND_UP_A_LOTMobileSingleArmLangControl.ROLL_HAND_CLOCK_WISEMobileSingleArmLangControl.ROLL_HAND_CLOCK_WISE_A_LITTLEMobileSingleArmLangControl.ROLL_HAND_CLOCK_WISE_A_LOTMobileSingleArmLangControl.ROLL_HAND_COUNTER_CLOCK_WISEMobileSingleArmLangControl.ROLL_HAND_COUNTER_CLOCK_WISE_A_LITTLEMobileSingleArmLangControl.ROLL_HAND_COUNTER_CLOCK_WISE_A_LOTMobileSingleArmLangControl.ROTATE_WAIST_LEFTMobileSingleArmLangControl.ROTATE_WAIST_LEFT_A_LITTLEMobileSingleArmLangControl.ROTATE_WAIST_LEFT_A_LOTMobileSingleArmLangControl.ROTATE_WAIST_RIGHTMobileSingleArmLangControl.ROTATE_WAIST_RIGHT_A_LITTLEMobileSingleArmLangControl.ROTATE_WAIST_RIGHT_A_LOTMobileSingleArmLangControl.SLEEPMobileSingleArmLangControl.TURN_LEFTMobileSingleArmLangControl.TURN_LEFT_A_LITTLEMobileSingleArmLangControl.TURN_LEFT_A_LOTMobileSingleArmLangControl.TURN_RIGHTMobileSingleArmLangControl.TURN_RIGHT_A_LITTLEMobileSingleArmLangControl.TURN_RIGHT_A_LOTMobileSingleArmLangControl.YAW_HAND_CLOCK_WISEMobileSingleArmLangControl.YAW_HAND_CLOCK_WISE_A_LITTLEMobileSingleArmLangControl.YAW_HAND_CLOCK_WISE_A_LOTMobileSingleArmLangControl.YAW_HAND_COUNTER_CLOCK_WISEMobileSingleArmLangControl.YAW_HAND_COUNTER_CLOCK_WISE_A_LITTLEMobileSingleArmLangControl.YAW_HAND_COUNTER_CLOCK_WISE_A_LOT
create_enum_from_list()get_command_from_string()language_control_to_list()
- Module contents
- mbodied.types.motion package
- mbodied.types.sense package
- Submodules
- mbodied.types.sense.sensor_reading module
- mbodied.types.sense.vision module
ImageImage.arrayImage.base64Image.pathImage.pilImage.urlImage.sizeImage.encodingImage.arrayImage.base64Image.bytes_to_data()Image.dump()Image.encodingImage.exclude_pil()Image.from_base64()Image.from_bytes()Image.infer_features_dict()Image.load_url()Image.model_computed_fieldsImage.model_configImage.model_fieldsImage.open()Image.pathImage.pilImage.pil_to_data()Image.save()Image.show()Image.sizeImage.space()Image.supports()Image.urlImage.validate_kwargs()
- Module contents
ImageImage.arrayImage.base64Image.pathImage.pilImage.urlImage.sizeImage.encodingImage.arrayImage.base64Image.bytes_to_data()Image.dump()Image.encodingImage.exclude_pil()Image.from_base64()Image.from_bytes()Image.infer_features_dict()Image.load_url()Image.model_computed_fieldsImage.model_configImage.model_fieldsImage.open()Image.pathImage.pilImage.pil_to_data()Image.save()Image.show()Image.sizeImage.space()Image.supports()Image.urlImage.validate_kwargs()
- mbodied.types.utils package
- Submodules
- mbodied.types.utils.bboxer module
- mbodied.types.utils.estimate_intrinsics module
- mbodied.types.utils.geometry module
compute_view_params()depth_image_to_pointcloud()downsample_pointcloud()get_rotation_matrix_from_two_points()interpolate_constant_velocity_trajectory()is_line_connectable()is_point_feasible()is_point_in_polygon()leveraged_squared_exponential_kernel()passthrough_filter()pose_to_transformation_matrix()quintic_trajectory()remove_duplicates()remove_duplicates_with_reference()rodrigues_rotation()rotation_matrix()rotation_matrix_to_angular_velocity()rotation_matrix_to_quaternion()rotation_matrix_to_rpy()rotation_to_transformation_matrix()rpy_to_rotation_matrix()sample_points_in_3d()skew_symmetric_matrix()soft_squash()soft_squash_multidim()squared_exponential_kernel()transformation_matrix_to_pose()transformation_matrix_to_position()transformation_matrix_to_rotation()trim_scale()unit_vector()
- Module contents
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:
PoseAbsolute 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:
Pose3DAlias 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:
Pose6DAlias 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:
MotionAction 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:
MotionMovement 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:
PoseRelative 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:
SampleSingle 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']∞
mbodied.types.ndarray module∞
mbodied.types.sample module∞
- class mbodied.types.sample.Sample(datum=None, **data)[source]∞
Bases:
BaseModelA 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:
- 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.
- 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]] = {}∞
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.
- 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:
- 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:
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)