tbp.monty#
- tbp.monty.conf
- tbp.monty.experiment
- tbp.monty.frameworks
- tbp.monty.frameworks.actions
- tbp.monty.frameworks.actions.action_samplers
- tbp.monty.frameworks.actions.actions
ActionLookDownLookDownActionSamplerLookDownActuatorLookUpLookUpActionSamplerLookUpActuatorMoveForwardMoveForwardActionSamplerMoveForwardActuatorMoveTangentiallyMoveTangentiallyActionSamplerMoveTangentiallyActuatorOrientHorizontalOrientHorizontalActionSamplerOrientHorizontalActuatorOrientVerticalOrientVerticalActionSamplerOrientVerticalActuatorSetAgentPitchSetAgentPitchActionSamplerSetAgentPitchActuatorSetAgentPoseSetAgentPoseActionSamplerSetAgentPoseActuatorSetSensorPitchSetSensorPitchActionSamplerSetSensorPitchActuatorSetSensorPoseSetSensorPoseActionSamplerSetSensorPoseActuatorSetSensorRotationSetSensorRotationActionSamplerSetSensorRotationActuatorSetYawSetYawActionSamplerSetYawActuatorTurnLeftTurnLeftActionSamplerTurnLeftActuatorTurnRightTurnRightActionSamplerTurnRightActuator
- tbp.monty.frameworks.environment_utils
- tbp.monty.frameworks.environments
- tbp.monty.frameworks.experiments
- tbp.monty.frameworks.loggers
- tbp.monty.frameworks.models
- tbp.monty.frameworks.models.evidence_matching
- tbp.monty.frameworks.models.evidence_matching.feature_evidence
- tbp.monty.frameworks.models.evidence_matching.features_for_matching
- tbp.monty.frameworks.models.evidence_matching.burst_sampling
- tbp.monty.frameworks.models.evidence_matching.channels
- tbp.monty.frameworks.models.evidence_matching.evidence_slope_tracker
- tbp.monty.frameworks.models.evidence_matching.graph_memory
- tbp.monty.frameworks.models.evidence_matching.hypotheses
- tbp.monty.frameworks.models.evidence_matching.hypotheses_displacer
- tbp.monty.frameworks.models.evidence_matching.hypotheses_updater
- tbp.monty.frameworks.models.evidence_matching.learning_module
- tbp.monty.frameworks.models.evidence_matching.model
- tbp.monty.frameworks.models.mixins
- tbp.monty.frameworks.models.salience
- tbp.monty.frameworks.models.abstract_monty_classes
- tbp.monty.frameworks.models.buffer
- tbp.monty.frameworks.models.displacement_matching
- tbp.monty.frameworks.models.feature_location_matching
- tbp.monty.frameworks.models.goal_generation
- tbp.monty.frameworks.models.graph_matching
- tbp.monty.frameworks.models.monty_base
- tbp.monty.frameworks.models.motor_policies
- tbp.monty.frameworks.models.motor_policy_selectors
- tbp.monty.frameworks.models.motor_system
- tbp.monty.frameworks.models.motor_system_state
- tbp.monty.frameworks.models.no_reset_evidence_matching
- tbp.monty.frameworks.models.object_model
- tbp.monty.frameworks.models.sensor_modules
- tbp.monty.frameworks.models.two_d_sensor_module
- tbp.monty.frameworks.models.evidence_matching
- tbp.monty.frameworks.utils
- tbp.monty.frameworks.utils.communication_utils
- tbp.monty.frameworks.utils.dataclass_utils
- tbp.monty.frameworks.utils.edge_detection
- tbp.monty.frameworks.utils.graph_matching_utils
add_pose_features_to_tolerances()create_exponential_kernel()detect_new_object_exponential()detect_new_object_k_steps()find_step_on_new_object()get_correct_k_n()get_custom_distances()get_initial_possible_poses()get_relevant_curvature()get_scaled_evidences()get_uniform_initial_possible_poses()get_unique_paths()is_in_ranges()possible_sensed_directions()process_delta_evidence_values()
- tbp.monty.frameworks.utils.live_plotter
- tbp.monty.frameworks.utils.logging_utils
accuracy_stats_for_compositional_objects()add_evidence_lm_episode_stats()add_policy_episode_stats()add_pose_lm_episode_stats()calculate_fpr()calculate_performance()calculate_tpr()check_detection_accuracy_at_step()check_rotation_accuracy()compositional_stats_for_all_lms()compute_pose_error()compute_pose_errors()compute_unsupervised_stats()consistent_child_objects_accuracy()deserialize_json_chunks()format_columns_for_wandb()get_graph_lm_episode_stats()get_object_graph_stats()get_reverse_rotation()get_rgba_frames_single_sm()get_stats_per_lm()get_time_stats()get_unique_euler_poses()lm_stats_to_dataframe()load_models_from_dir()load_stats()matches_to_target_str()maybe_rename_existing_dir()maybe_rename_existing_file()mean_num_steps_for_lm()overall_accuracy()print_overall_stats()print_unsupervised_stats()target_data_to_dict()total_size()
- tbp.monty.frameworks.utils.object_model_utils
- tbp.monty.frameworks.utils.plot_utils
- tbp.monty.frameworks.utils.plot_utils_analysis
- tbp.monty.frameworks.utils.plot_utils_dev
- tbp.monty.frameworks.utils.profile_utils
- tbp.monty.frameworks.utils.sensor_processing
arc_from_projection()arc_length_corrected_displacement()center_neighbors()curvature_at_point()directional_curvature()is_coplanar()is_orthogonal()is_unit_vector()log_sign()pixel_dist_to_center()point_pair_features()principal_curvatures()scale_clip()surface_normal_naive()surface_normal_ordinary_least_squares()surface_normal_total_least_squares()weight_matrix()
- tbp.monty.frameworks.utils.spatial_arithmetics
TangentFramealign_multiple_orthonormal_vectors()align_orthonormal_vectors()apply_rf_transform_to_points()check_orthonormal()euler_to_quats()get_angle()get_angle_beefed_up()get_angle_torch()get_angles_for_all_hypotheses()get_more_directions_in_plane()get_right_hand_angle()get_unique_rotations()is_parallel()non_singular_mat()normalize()pose_is_new()project_onto_tangent_plane()rot_mats_to_quats()rotate_multiple_pose_dependent_features()rotate_pose_dependent_features()rotations_to_quats()
- tbp.monty.frameworks.agents
- tbp.monty.frameworks.run
- tbp.monty.frameworks.run_env
- tbp.monty.frameworks.run_parallel
- tbp.monty.frameworks.sensors
- tbp.monty.frameworks.actions
- tbp.monty.simulators
- tbp.monty.simulators.habitat
- tbp.monty.simulators.mujoco
- tbp.monty.simulators.resources
- tbp.monty.simulators.tacto
tbp.monty.cmp#
- class Goal(location: np.ndarray | None, morphological_features: dict[str, Any] | None, non_morphological_features: dict[str, Any] | None, confidence: float, use_state: bool, sender_id: str, sender_type: str, goal_tolerances: dict[str, Any] | None, info: dict[str, Any] | None = None)[source]#
Bases:
MessageSpecialization of
Messagefor goals with null (None) values allowed.Specialized form of message that still adheres to the cortical messaging protocol, but can have null (None) values associated with the location and morphological features.
Used by goal generators (GSGs) to communicate goals to other GSGs, and to motor actuators.
The message variables generally have the same meaning as for the base
Messageclass, and they represent the target values for the receiving system. Thus if a goal specifies a particular object ID (non-morphological feature) in a particular pose (location and morphological features), then the receiving system should attempt to achieve that state.Note however that for the goal, the confidence corresponds to the conviction with which a GSG believes that the current goal should be acted upon. Float bound in [0.0, 1.0].
- __init__(location: np.ndarray | None, morphological_features: dict[str, Any] | None, non_morphological_features: dict[str, Any] | None, confidence: float, use_state: bool, sender_id: str, sender_type: str, goal_tolerances: dict[str, Any] | None, info: dict[str, Any] | None = None)[source]#
Initialize a goal.
- Parameters:
location (np.ndarray | None) – the location to move to in global/body-centric coordinates, or None if the location is not specified as part of the goal. For example, this may be a point on an object’s surface or a location nearby from which a sensor would have a good view of the target point.
morphological_features (dict[str, Any] | None) – dictionary of morphological features or None. For example, it may include pose vectors, whether the pose is fully defined, etc.
non_morphological_features (dict[str, Any] | None) – a dictionary containing non-morphological features at the target location or None.
confidence (float) – a float between 0 and 1 representing the confidence in the goal.
use_state (bool) – a boolean indicating whether the goal should be used.
sender_id (str) – the ID of the sender of the goal (e.g., “LM_0”).
sender_type (str) – the type of sender of the goal (e.g., “GSG”).
goal_tolerances (dict[str, Any] | None) – Dictionary of tolerances that GSGs use when determining whether the current state of the LM matches the driving goal or None. As such, a GSG can send a goal with more or less strict tolerances if certain elements of the message (e.g. the location of a mug vs its orientation) are more or less important.
info (dict[str, Any] | None) – Optional metadata for logging purposes.
- class Message(location, morphological_features, non_morphological_features, confidence, use_state, sender_id, sender_type)[source]#
Bases:
objectMessage class used as message packages passed in Monty using CMP.
The cortical messaging protocol (CMP) is used to pass messages between Monty components and makes sure we can easily set up arbitrary configurations of them. This class makes it easier to define the CMP in one place and defines the content and structure of messages passed between Monty components. It also contains some helper functions to access and modify the message content.
States are represented in this format but can be interpreted by the receiver in different ways:
Observed states: states output by sensor modules Hypothesized states: states output by learning modules Goals: motor output of learning modules
- location#
3D vector representing the location
- morphological_features#
dictionary of morphological features. Should include pose_vectors of shape (3,3) and pose_fully_defined (bool).
- non_morphological_features#
dictionary of non-morphological features.
- confidence#
message confidence. In range [0,1].
- use_state#
boolean indicating whether the message should be used or not.
- sender_id#
string identifying the sender of the message.
- sender_type#
string identifying the type of sender. Can be “SM” or “LM”.
- __init__(location, morphological_features, non_morphological_features, confidence, use_state, sender_id, sender_type)[source]#
Initialize a message.
- get_curvature_directions()[source]#
Return the curvature direction vectors.
- Raises:
ValueError – If self.sender_type is not SM
- get_nth_pose_vector(pose_vector_index)[source]#
Return the nth pose vector.
When self.sender_type == “SM”, the first pose vector is the surface normal and the second and third are the curvature directions. When self.sender_type == “LM”, the pose vectors correspond to the rotation of the object relative to the model learned of it.
- get_on_object()[source]#
Return whether we think we are on the object or not.
This is currently used in the policy to stay on the object.
- get_surface_normal()[source]#
Return the surface normal vector.
- Raises:
ValueError – If self.sender_type is not SM
tbp.monty.context#
- class RuntimeContext(rng: numpy.random.RandomState, suppress_runtime_errors: bool = False) None[source]#
Bases:
objectMonty’s runtime context.
The RuntimeContext carries runtime-scoped values used throughout Monty.
- rng#
The random number generator.
- suppress_runtime_errors#
Whether to suppress runtime errors. Runtime errors can be raised when goal is None or invalid. When in an experimental mode, we want to raise runtime errors by default. When in a production mode, we want to suppress runtime errors by default. Currently, we run a lot of experiments, so the current default is to raise runtime errors.
- __init__(rng: numpy.random.RandomState, suppress_runtime_errors: bool = False) None#
-
rng:
RandomState#
tbp.monty.geometry#
- class Rotation(scipy_rotation: scipy.spatial.transform.Rotation) None[source]#
Bases:
objectRotation in 3 dimensions.
This class was created to be a (nearly) drop-in replacement for (scipy.spatial.transform.Rotation)[https://docs.scipy.org/doc/scipy-1.10.1/reference/generated/scipy.spatial.transform.Rotation.html]. that better conforms to our conventions. Primarily, we wanted to be consistent about using scalar-first (wxyz) order for quaternions, but scalar-last (xyzw) is scipy’s default mode. Consequently, this class’s from_quat and as_quat implementations assume and return scalar-first quaternion components.
Since Rotation is a thin wrapper around scipy.spatial.transform.Rotation, its API is largely inherited from scipy. The main exceptions are:
from_quat and as_quat assume scalar-first order.
The approx_equal method has been backported from future scipy versions.
For consistency, from_scipy_rotation and as_scipy_rotation methods have been added.
Any missing scipy methods can be added as needed.
- static align_vectors(a: npt.ArrayLike, b: npt.ArrayLike, weights: npt.ArrayLike | None = None, return_sensitivity: bool = False) tuple[Rotation, float] | tuple[Rotation, float, np.ndarray][source]#
Estimate a rotation to optimally align two sets of vectors.
For full details, see (scipy.spatial.transform.Rotation.align_vectors)[https://docs.scipy.org/doc/scipy-1.10.1/reference/generated/scipy.spatial.transform.Rotation.align_vectors.html].
- Parameters:
a (npt.ArrayLike) – Array-like of shape (3,) or (N, 3).
b (npt.ArrayLike) – Array-like of shape (3,) or (N, 3).
weights (npt.ArrayLike | None) – Weights describing the relative importance of the vector observations. If None (default), then all values in weights are assumed to be 1. One and only one weight may be infinity, and weights must be positive.
return_sensitivity (bool) – Whether to return the sensitivity matrix. See Notes for details. Default is False.
- Returns:
Best estimate of the Rotation that transforms b to a. rssd : Square root of the weighted sum of the squared distances between
the given sets of vectors.
- sensitivity_matrixSensitivity matrix of the estimated rotation estimate.
See scipy documentation (link above) for details.
- Return type:
rotation
- apply(vectors: numpy.typing.ArrayLike, inverse: bool = False) numpy.ndarray[source]#
Apply this rotation to a set of vectors.
If the original frame rotates to the final frame by this rotation, then its application to a vector can be seen in two ways:
As a projection of vector components expressed in the final frame to the original frame.
As the physical rotation of a vector being glued to the original frame as it rotates. In this case the vector components are expressed in the original frame before and after the rotation.
- Parameters:
vectors (
ArrayLike) – Array-like of shape (3,) or (N, 3) of xyz coordinates to rotate.inverse (
bool) – If True then apply the inverse of this rotation. Equivalent to rotation.inv().apply(vectors).
- Return type:
- Returns:
An array of shape (3,) or (N, 3) of rotated xyz coordinates.
Examples
>>> # pitch up 180°, then roll counter-clockwise 90° >>> a_rotation = Rotation.from_euler("XZ", [np.pi, np.pi/2]) >>> a_rotation.apply([3, 5, 8]) array([-5., -3., -8.])
>>> vectors = np.array([ ... [3, 5, 8], ... [3, 5, -8], ... [3, -5, -8], ... [-3, -5, -8], ... [-3, -5, 8], ... [-3, 5, 8] ... ], dtype=float) >>> a_rotation.apply(vectors) array([[-5., -3., -8.], [-5., -3., 8.], [ 5., -3., 8.], [ 5., 3., 8.], [ 5., 3., -8.], [-5., 3., -8.]])
- approx_equal(other: Rotation, tol: float = 1e-06) bool | np.ndarray[source]#
Check if this rotation is approximately equal to another rotation.
- Parameters:
other (Rotation) – The other rotation to compare to.
tol (float) – Absolute tolerance, expressed in radians.
- Return type:
bool | np.ndarray
- Returns:
True if the angular delta between a and b is within tolerance. False otherwise. If a and b are non-single, returns an array of booleans.
- as_matrix() numpy.ndarray[source]#
- Return type:
- as_quat() numpy.ndarray[source]#
The (scalar-first) quaternion representation.
This methods differs substantially from scipy.spatial.transform.Rotation.as_quat. Here, we return quaternions in scalar-first (wxyz) order, whereas scipy returns them in scalar-last (xyzw) order. Scalar-last ordering will not be supported.
- Return type:
- Returns:
Array of shape (4,) or (N, 4) in scalar-first (wxyz) order.
- as_rotvec(degrees: bool = False) numpy.ndarray[source]#
- Return type:
- static concatenate(rotations: Iterable[Rotation]) Rotation[source]#
Concatenate a sequence of Rotation objects into a single object.
This is useful if you want to, for example, take the mean of a set of rotations and need to pack them into a single object to do so.
- static from_euler(seq: str, angles: float | npt.ArrayLike, degrees: bool = False) Rotation[source]#
- Return type:
Rotation
- static from_quat(quat: numpy.typing.ArrayLike) Rotation[source]#
Build from (scalar-first) quaternion data.
This methods differs substantially from scipy.spatial.transform.Rotation.from_quat. Here, we expect quaternions in scalar-first (wxyz) order, where SciPy expects them in scalar-last (xyzw) order. Scalar-last ordering will not be supported.
- Parameters:
quat (
ArrayLike) – Array-like of shape (4,) or (N, 4) in scalar-first (wxyz) order.- Return type:
- Returns:
A Rotation instance.
- Raises:
ValueError – If quat does not have shape (4,) or (N, 4).
- static from_rotvec(rotvec: numpy.typing.ArrayLike, degrees: bool = False) Rotation[source]#
- Return type:
- inv() Rotation[source]#
Create a new Rotation that is the inverse of this Rotation.
Composition of a rotation with its inverse is an identity transformation.
- Return type:
- Returns:
The new Rotation object.
Examples
>>> fwd = Rotation.from_euler("y", -np.pi/6) # yaw right 30° >>> inv = fwd.inv() >>> inv.inv().approx_equal(fwd) True
- scipy_rotations_approx_equal(a: ScipyRotation, b: ScipyRotation, tol: float = 1e-06) bool | np.ndarray[source]#
Backport of scipy.spatial.transform.Rotation.approx_equal.
- Parameters:
a (ScipyRotation) – First scipy rotation.
b (ScipyRotation) – Second scipy rotation.
tol (float) – Absolute tolerance, expressed in radians.
- Return type:
bool | np.ndarray
- Returns:
True if the angular delta between a and b is within tolerance. False otherwise. If a and b are non-single, returns an array of booleans.
- to_scalar_first(xyzw: numpy.typing.ArrayLike) numpy.ndarray[source]#
Convert a quaternion from scalar-last (xyzw) to scalar-first (wxyz) order.
This is a helper function for the Rotation class extracted for testing purposes.
- Parameters:
xyzw (
ArrayLike) – Array-like of shape (4,) or (N, 4) in scalar-last (xyzw) order.- Return type:
- Returns:
Array of shape (4,) or (N, 4) in scalar-first (wxyz) order.
- to_scalar_last(wxyz: numpy.typing.ArrayLike) numpy.ndarray[source]#
Convert a quaternion from scalar-first (wxyz) to scalar-last (xyzw) order.
This is a helper function for the Rotation class extracted for testing purposes.
- Parameters:
wxyz (
ArrayLike) – Array-like of shape (4,) or (N, 4) in scalar-first (wxyz) order.- Return type:
- Returns:
Array of shape (4,) or (N, 4) in scalar-last (xyzw) order.
tbp.monty.hydra#
- monty_class_resolver(class_name: str) type[source]#
Returns a class object by fully qualified path.
- Return type:
- TODO: This is an interim solution to retrieve my_class in
the my_class(**my_args) pattern.
- ndarray_resolver(list_or_tuple: list | tuple) np.ndarray[source]#
Returns a numpy array from a list or tuple.
- Return type:
np.ndarray
- ones_resolver(n: int) numpy.ndarray[source]#
Returns a numpy array of ones.
- Return type:
- path_expanduser_resolver(path: str) str[source]#
Returns a path with ~ expanded to the user’s home directory.
- Return type:
- register_resolvers() None[source]#
Register custom OmegaConf resolvers for Monty configs.
Skips resolvers that are already registered rather than raising a ValueError, since multiple entry points (e.g. tests/__init__.py and update_snapshots.py) may call this function in the same process.
- Return type:
tbp.monty.math#
tbp.monty.path#
- monty_data_path(custom_data_path: str | Path | None, default_subpath: str | Path) Path[source]#
Get data path, using custom path if provided, or return the default.
- Parameters:
custom_data_path (str | Path | None) – Custom data path provided by the user, or None to use default_subpath.
default_subpath (str | Path) – Default subpath within MONTY_DATA to use if no custom path.
- Return type:
Path
- Returns:
Full data path.