mbodied.types package∞
Subpackages∞
- mbodied.types.language package
- Submodules
- mbodied.types.language.control module
LangControl
LangControl.CLOSE_HAND
LangControl.GO_HOME
LangControl.LOOK_DOWN
LangControl.LOOK_LEFT
LangControl.LOOK_RIGHT
LangControl.LOOK_UP
LangControl.MOVE_BACKWARD
LangControl.MOVE_FORWARD
LangControl.MOVE_HAND_BACKWARD
LangControl.MOVE_HAND_DOWN
LangControl.MOVE_HAND_FORWARD
LangControl.MOVE_HAND_LEFT
LangControl.MOVE_HAND_RIGHT
LangControl.MOVE_HAND_UP
LangControl.OPEN_HAND
LangControl.PAUSE
LangControl.RESTART
LangControl.RESUME
LangControl.SLEEP
LangControl.START
LangControl.STOP
LangControl.TURN_LEFT
LangControl.TURN_RIGHT
MobileSingleArmLangControl
MobileSingleArmLangControl.CLOSE_HAND
MobileSingleArmLangControl.LOOK_DOWN
MobileSingleArmLangControl.LOOK_DOWN_A_LITTLE
MobileSingleArmLangControl.LOOK_DOWN_A_LOT
MobileSingleArmLangControl.LOOK_LEFT
MobileSingleArmLangControl.LOOK_LEFT_A_LITTLE
MobileSingleArmLangControl.LOOK_LEFT_A_LOT
MobileSingleArmLangControl.LOOK_RIGHT
MobileSingleArmLangControl.LOOK_RIGHT_A_LITTLE
MobileSingleArmLangControl.LOOK_RIGHT_A_LOT
MobileSingleArmLangControl.LOOK_UP
MobileSingleArmLangControl.LOOK_UP_A_LITTLE
MobileSingleArmLangControl.LOOK_UP_A_LOT
MobileSingleArmLangControl.MOVE_BACKWARD
MobileSingleArmLangControl.MOVE_BACKWARD_A_LITTLE
MobileSingleArmLangControl.MOVE_BACKWARD_A_LOT
MobileSingleArmLangControl.MOVE_FORWARD
MobileSingleArmLangControl.MOVE_FORWARD_A_LITTLE
MobileSingleArmLangControl.MOVE_FORWARD_A_LOT
MobileSingleArmLangControl.MOVE_HAND_BACKWARD
MobileSingleArmLangControl.MOVE_HAND_BACKWARD_A_LITTLE
MobileSingleArmLangControl.MOVE_HAND_BACKWARD_A_LOT
MobileSingleArmLangControl.MOVE_HAND_DOWN
MobileSingleArmLangControl.MOVE_HAND_DOWN_A_LITTLE
MobileSingleArmLangControl.MOVE_HAND_DOWN_A_LOT
MobileSingleArmLangControl.MOVE_HAND_FORWARD
MobileSingleArmLangControl.MOVE_HAND_FORWARD_A_LITTLE
MobileSingleArmLangControl.MOVE_HAND_FORWARD_A_LOT
MobileSingleArmLangControl.MOVE_HAND_LEFT
MobileSingleArmLangControl.MOVE_HAND_LEFT_A_LITTLE
MobileSingleArmLangControl.MOVE_HAND_LEFT_A_LOT
MobileSingleArmLangControl.MOVE_HAND_RIGHT
MobileSingleArmLangControl.MOVE_HAND_RIGHT_A_LITTLE
MobileSingleArmLangControl.MOVE_HAND_RIGHT_A_LOT
MobileSingleArmLangControl.MOVE_HAND_UP
MobileSingleArmLangControl.MOVE_HAND_UP_A_LITTLE
MobileSingleArmLangControl.MOVE_HAND_UP_A_LOT
MobileSingleArmLangControl.MOVE_HOME
MobileSingleArmLangControl.OPEN_HAND
MobileSingleArmLangControl.PITCH_HAND_DOWN
MobileSingleArmLangControl.PITCH_HAND_DOWN_A_LITTLE
MobileSingleArmLangControl.PITCH_HAND_DOWN_A_LOT
MobileSingleArmLangControl.PITCH_HAND_UP
MobileSingleArmLangControl.PITCH_HAND_UP_A_LITTLE
MobileSingleArmLangControl.PITCH_HAND_UP_A_LOT
MobileSingleArmLangControl.ROLL_HAND_CLOCK_WISE
MobileSingleArmLangControl.ROLL_HAND_CLOCK_WISE_A_LITTLE
MobileSingleArmLangControl.ROLL_HAND_CLOCK_WISE_A_LOT
MobileSingleArmLangControl.ROLL_HAND_COUNTER_CLOCK_WISE
MobileSingleArmLangControl.ROLL_HAND_COUNTER_CLOCK_WISE_A_LITTLE
MobileSingleArmLangControl.ROLL_HAND_COUNTER_CLOCK_WISE_A_LOT
MobileSingleArmLangControl.ROTATE_WAIST_LEFT
MobileSingleArmLangControl.ROTATE_WAIST_LEFT_A_LITTLE
MobileSingleArmLangControl.ROTATE_WAIST_LEFT_A_LOT
MobileSingleArmLangControl.ROTATE_WAIST_RIGHT
MobileSingleArmLangControl.ROTATE_WAIST_RIGHT_A_LITTLE
MobileSingleArmLangControl.ROTATE_WAIST_RIGHT_A_LOT
MobileSingleArmLangControl.SLEEP
MobileSingleArmLangControl.TURN_LEFT
MobileSingleArmLangControl.TURN_LEFT_A_LITTLE
MobileSingleArmLangControl.TURN_LEFT_A_LOT
MobileSingleArmLangControl.TURN_RIGHT
MobileSingleArmLangControl.TURN_RIGHT_A_LITTLE
MobileSingleArmLangControl.TURN_RIGHT_A_LOT
MobileSingleArmLangControl.YAW_HAND_CLOCK_WISE
MobileSingleArmLangControl.YAW_HAND_CLOCK_WISE_A_LITTLE
MobileSingleArmLangControl.YAW_HAND_CLOCK_WISE_A_LOT
MobileSingleArmLangControl.YAW_HAND_COUNTER_CLOCK_WISE
MobileSingleArmLangControl.YAW_HAND_COUNTER_CLOCK_WISE_A_LITTLE
MobileSingleArmLangControl.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
Image
Image.array
Image.base64
Image.path
Image.pil
Image.url
Image.size
Image.encoding
Image.array
Image.base64
Image.bytes_to_data()
Image.dump()
Image.encoding
Image.exclude_pil()
Image.from_base64()
Image.from_bytes()
Image.infer_features_dict()
Image.load_url()
Image.model_computed_fields
Image.model_config
Image.model_fields
Image.open()
Image.path
Image.pil
Image.pil_to_data()
Image.save()
Image.show()
Image.size
Image.space()
Image.supports()
Image.url
Image.validate_kwargs()
- Module contents
Image
Image.array
Image.base64
Image.path
Image.pil
Image.url
Image.size
Image.encoding
Image.array
Image.base64
Image.bytes_to_data()
Image.dump()
Image.encoding
Image.exclude_pil()
Image.from_base64()
Image.from_bytes()
Image.infer_features_dict()
Image.load_url()
Image.model_computed_fields
Image.model_config
Image.model_fields
Image.open()
Image.path
Image.pil
Image.pil_to_data()
Image.save()
Image.show()
Image.size
Image.space()
Image.supports()
Image.url
Image.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:
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']∞
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:
- 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)