moplayground.utils¶
The config reader, Pareto-front statistics, progress callbacks and plots, and rotation utilities.
moplayground.utils.config
¶
Single access point between YAML config files and the moplayground package.
Classes:
| Name | Description |
|---|---|
MOConfig |
|
Functions:
| Name | Description |
|---|---|
check_same_env |
Raise |
MOConfig
¶
Bases: Config
Attributes:
| Name | Type | Description |
|---|---|---|
default_scalarization |
ndarray
|
Objective weights used to scalarize the reward when |
gaitlib_path |
Gait library directory ( |
|
sampling_params |
dict
|
Sampling settings: |
ppo_network_params |
dict
|
Network settings for PPO. |
morlax_network_params |
dict
|
Network settings for MORLAX (hypernetwork + target MLP shapes). |
amor_network_params |
dict
|
Network settings for AMOR. |
objectives |
list
|
Reward keys per objective, one list per reward dimension. |
num_objectives |
int
|
Number of objectives (length of the reward vector). |
objective_labels |
Display names for the objectives, or |
Source code in src/moplayground/utils/config.py
check_same_env
¶
Raise ValueError unless every config deploys the same environment.
Compares env and the full env_config section. Use this before
evaluating several runs together (e.g. eval.pareto.get_morlax_fronts
with a list of run directories).
Source code in src/moplayground/utils/config.py
moplayground.utils.pareto
¶
Functions:
| Name | Description |
|---|---|
project_to_simplex |
Euclidean projection of |
closest_points |
Index into |
corner_tradeoffs |
Indices of the tradeoffs nearest each one-hot corner of the simplex. |
get_nondominated |
|
hypervolume_from_nondominated |
Compute the hypervolume of a non-dominated front in minimization space. |
sparsity_from_normalized_nondominated |
|
get_pareto_statistics |
Compute hypervolume and sparsity for a set of objective vectors. |
project_to_simplex
¶
Euclidean projection of v onto the probability simplex.
Source code in src/moplayground/utils/pareto.py
closest_points
¶
Index into points of the nearest (Euclidean) neighbor of each target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
|
required | |
targets
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in src/moplayground/utils/pareto.py
corner_tradeoffs
¶
Indices of the tradeoffs nearest each one-hot corner of the simplex.
get_nondominated
¶
hypervolume_from_nondominated
¶
Compute the hypervolume of a non-dominated front in minimization space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F_min
|
|
required | |
ref_point
|
|
None
|
Returns:
| Type | Description |
|---|---|
|
Hypervolume as a float, computed by |
Source code in src/moplayground/utils/pareto.py
sparsity_from_normalized_nondominated
¶
get_pareto_statistics
¶
Compute hypervolume and sparsity for a set of objective vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
|
required | |
ref_point
|
|
None
|
Returns:
| Type | Description |
|---|---|
|
Tuple |
Source code in src/moplayground/utils/pareto.py
moplayground.utils.plotting
¶
Classes:
| Name | Description |
|---|---|
MOTrainingPlottingInfo |
|
MOProgress |
Multi-objective progress callback for |
Functions:
| Name | Description |
|---|---|
default_coloring |
|
plot_pareto |
Plot a pareto frontier. |
plot_sequential_paretos |
|
plot_sequential_hypervolume |
|
MOTrainingPlottingInfo
dataclass
¶
Methods:
| Name | Description |
|---|---|
save |
|
Attributes:
| Name | Type | Description |
|---|---|---|
start_time |
float
|
|
times |
list
|
|
iterations |
list
|
|
paretos |
list
|
|
tradeoffs |
list
|
|
labels |
list
|
|
hypervolumes |
list
|
|
sparsities |
list
|
|
Source code in src/moplayground/utils/plotting.py
save
¶
Source code in src/moplayground/utils/plotting.py
MOProgress
¶
Bases: Progress
Multi-objective progress callback for mm.train(progress_cls=...).
Records the eval Pareto front each epoch, writes hypervolume/sparsity to
save_dir/progress.csv, and plots the fronts when there are 2 objectives.
labels names the objectives on the plot axes; pass it with
functools.partial(MOProgress, labels=...) since mm.train builds the
callback itself.
Methods:
| Name | Description |
|---|---|
load |
|
plot_progress |
|
Attributes:
| Name | Type | Description |
|---|---|---|
training_data |
|
|
times |
|
Source code in src/moplayground/utils/plotting.py
training_data
instance-attribute
¶
training_data = MOTrainingPlottingInfo(start_time=time.time(), labels=list(labels) if labels is not None else [])
load
¶
plot_progress
¶
Source code in src/moplayground/utils/plotting.py
default_coloring
¶
Source code in src/moplayground/utils/plotting.py
plot_pareto
¶
plot_pareto(ax: Axes, pareto: ndarray, colors: str | ndarray = None, objective: list[str] = None, connect: bool = False, show_dominated: bool = True, nondominated_alpha: float = 1.0, dominated_alpha: float = 1.0, nondominated_s: int = 20, dominated_s: int = 8, outline_nondominated: float = 0.0, label: str = None, set_lims: bool = True, label_fontsize: int = 16, special_idxs: ndarray = None, special_marker: str = '*', connect_line_color: str | ndarray = 'black', **plot_kwargs)
Plot a pareto frontier.
colors is a single matplotlib color or per-point color. RGB(A)
label names the front in the legend;
set_lims zooms to the nondominated front.
Source code in src/moplayground/utils/plotting.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
plot_sequential_paretos
¶
plot_sequential_paretos(ax_titles: list[str], paretos: ndarray, tradeoffs: ndarray = None, objectives: list[str] = None)
Source code in src/moplayground/utils/plotting.py
plot_sequential_hypervolume
¶
Source code in src/moplayground/utils/plotting.py
moplayground.utils.geometry
¶
Functions:
| Name | Description |
|---|---|
euler2quat |
Convert euler angles (roll, pitch, yaw) to a quaternion (w, x, y, z). |
quat2euler |
Convert a quaternion (w, x, y, z) to euler angles (roll, pitch, yaw). |
rotx |
Rotation matrix around x axis |
roty |
Rotation matrix around y axis |
rotz |
Rotation matrix around z axis |
rotmat |
Rotation matrix from euler angles (roll, pitch, yaw), same convention as |
quat_mul |
Multiplies two quaternions. |
angle2quat |
Provides a quaternion that describes rotating around axis by angle. |
quat_conjugate |
Returns the conjugate of a quaternion. |
extract_yaw |
Extracts the yaw angle from a quaternion. |
solve_transform |
Solves the transformation, T, between two qpos for the form |
apply_transform |
Applies the offset transform to the qpos |
quat_rotate_vector |
Rotate vector v by quaternion q. |
inv_transform |
Computes the inverse of the offset transform to the qpos |
quat_dist |
|
quat_rotate |
Rotate vector v (3,) using unit quaternion q (w,x,y,z). |
decide_quat |
|
Attributes:
| Name | Type | Description |
|---|---|---|
FREE3D_POS |
|
|
FREE3D_VEL |
|
euler2quat
¶
Convert euler angles (roll, pitch, yaw) to a quaternion (w, x, y, z).
Intrinsic x-y-z convention: the rotation is Rx(roll) @ Ry(pitch) @ Rz(yaw),
matching rotmat and inverted by quat2euler.
Source code in src/moplayground/utils/geometry.py
quat2euler
¶
Convert a quaternion (w, x, y, z) to euler angles (roll, pitch, yaw).
Inverse of euler2quat (intrinsic x-y-z, Rx @ Ry @ Rz).
Source code in src/moplayground/utils/geometry.py
rotx
¶
roty
¶
rotz
¶
rotmat
¶
Rotation matrix from euler angles (roll, pitch, yaw), same convention as euler2quat.
quat_mul
¶
Multiplies two quaternions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
(4,) quaternion (w,x,y,z) |
required | |
v
|
(4,) quaternion (w,x,y,z) |
required |
Returns:
| Type | Description |
|---|---|
|
A quaternion u * v. |
Source code in src/moplayground/utils/geometry.py
angle2quat
¶
Provides a quaternion that describes rotating around axis by angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
(3,) axis (x,y,z) |
required | |
angle
|
() float angle to rotate by |
required |
Returns:
| Type | Description |
|---|---|
|
A quaternion that rotates around axis by angle |
Source code in src/moplayground/utils/geometry.py
quat_conjugate
¶
Returns the conjugate of a quaternion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
(4,) quaternion (w,x,y,z) |
required |
Returns:
| Type | Description |
|---|---|
|
A quaternion that is the conjugate of q. |
Source code in src/moplayground/utils/geometry.py
extract_yaw
¶
Extracts the yaw angle from a quaternion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quat
|
(4,) quaternion (w,x,y,z) |
required |
Returns:
| Type | Description |
|---|---|
|
The yaw angle in radians. |
Source code in src/moplayground/utils/geometry.py
solve_transform
¶
Solves the transformation, T, between two qpos for the form qpos_des = qpos_act @ T
Source code in src/moplayground/utils/geometry.py
apply_transform
¶
Applies the offset transform to the qpos
Source code in src/moplayground/utils/geometry.py
quat_rotate_vector
¶
Rotate vector v by quaternion q. q: array-like, shape (4,) [w, x, y, z] v: array-like, shape (3,) Returns rotated vector as np.ndarray, shape (3,)
Source code in src/moplayground/utils/geometry.py
inv_transform
¶
Computes the inverse of the offset transform to the qpos
Source code in src/moplayground/utils/geometry.py
quat_dist
¶
quat_rotate
¶
Rotate vector v (3,) using unit quaternion q (w,x,y,z).