Skip to content

Optimization

Typed objective and constraint configs, contributions, and solver configuration.

ObjectiveConfig

Bases: BaseModel

Base class for objective configs keyed by an extensible enum member.

Methods:

Name Description
with_weight

Return a copy with a different objective weight.

Attributes:

Name Type Description
model_config
kind ObjectiveKind
weight float

Attributes

model_config class-attribute instance-attribute

model_config = ConfigDict(extra='forbid', arbitrary_types_allowed=True)

kind class-attribute

kind: ObjectiveKind

weight class-attribute instance-attribute

weight: float = 1.0

Functions

with_weight

with_weight(weight: float) -> Self

Return a copy with a different objective weight.

LaplacianObjectiveConfig

Bases: ObjectiveConfig

Interaction-mesh Laplacian deformation objective.

Attributes:

Name Type Description
kind

Attributes

kind class-attribute instance-attribute

kind = LAPLACIAN

LinkTrackingObjectiveConfig

Bases: ObjectiveConfig

Track robot links to a typed target plan.

Attributes:

Name Type Description
kind
weight_scale float

Attributes

kind class-attribute instance-attribute

kind = LINK_TRACKING

weight_scale class-attribute instance-attribute

weight_scale: float = 1.0

SmoothnessObjectiveConfig

Bases: ObjectiveConfig

Penalize changes from the previous frame.

Attributes:

Name Type Description
kind

Attributes

kind class-attribute instance-attribute

kind = SMOOTHNESS

NominalTrackingObjectiveConfig

Bases: ObjectiveConfig

Track a nominal posture for typed robot joints or explicit qpos coordinates.

Attributes:

Name Type Description
kind
weight float
joints tuple[RobotJoint, ...]
qpos_indices tuple[int, ...]
fallback NominalFallback

Attributes

kind class-attribute instance-attribute

kind = NOMINAL_TRACKING

weight class-attribute instance-attribute

weight: float = 5.0

joints class-attribute instance-attribute

joints: tuple[RobotJoint, ...] = ()

qpos_indices class-attribute instance-attribute

qpos_indices: tuple[int, ...] = ()

fallback class-attribute instance-attribute

fallback: NominalFallback = ZERO

ConstraintConfig

Bases: BaseModel

Base class for constraint configs keyed by an extensible enum member.

Methods:

Name Description
with_enabled

Return a copy with a different enabled state.

disabled

Return a disabled copy.

Attributes:

Name Type Description
model_config
kind ConstraintKind
enabled bool

Attributes

model_config class-attribute instance-attribute

model_config = ConfigDict(extra='forbid', arbitrary_types_allowed=True)

kind class-attribute

kind: ConstraintKind

enabled class-attribute instance-attribute

enabled: bool = True

Functions

with_enabled

with_enabled(enabled: bool = True) -> Self

Return a copy with a different enabled state.

disabled

disabled() -> Self

Return a disabled copy.

JointLimitsConstraintConfig

Bases: ConstraintConfig

Box limits on actuated joints.

Attributes:

Name Type Description
kind

Attributes

kind class-attribute instance-attribute

kind = JOINT_LIMITS

TrustRegionConstraintConfig

Bases: ConstraintConfig

Cap the Euclidean norm of each SQP update.

Attributes:

Name Type Description
kind
radius float | None

Attributes

kind class-attribute instance-attribute

kind = TRUST_REGION

radius class-attribute instance-attribute

radius: float | None = None

FootStickingConstraintConfig

Bases: ConstraintConfig

Constrain active support links near their previous tangent-plane position.

Attributes:

Name Type Description
kind
tolerance float

Attributes

kind class-attribute instance-attribute

kind = FOOT_STICKING

tolerance class-attribute instance-attribute

tolerance: float = 0.001

FootLockConstraintConfig

Bases: ConstraintConfig

Pin exact typed support links or subjects during configured windows.

Attributes:

Name Type Description
kind
windows tuple[FootLockWindow, ...]
z_floor float
tolerance float

Attributes

kind class-attribute instance-attribute

kind = FOOT_LOCK

windows class-attribute instance-attribute

windows: tuple[FootLockWindow, ...] = ()

z_floor class-attribute instance-attribute

z_floor: float = 0.0

tolerance class-attribute instance-attribute

tolerance: float = 0.005

NonPenetrationConstraintConfig

Bases: ConstraintConfig

Separate selected typed robot links from support and explicit geometry.

Attributes:

Name Type Description
kind
links tuple[RobotLink, ...]
subjects tuple[ContactSubject, ...]
sources tuple[NonPenetrationSource, ...]
geometry_pairs tuple[GeometryPair, ...]
tolerance float
floor_z float
scene_clearance float
activation_distance float | None

Attributes

kind class-attribute instance-attribute

kind = NON_PENETRATION
links: tuple[RobotLink, ...] = ()

subjects class-attribute instance-attribute

subjects: tuple[ContactSubject, ...] = ()

sources class-attribute instance-attribute

sources: tuple[NonPenetrationSource, ...] = (SUPPORT, SCENE_POINTS, GEOMETRY)

geometry_pairs class-attribute instance-attribute

geometry_pairs: tuple[GeometryPair, ...] = ()

tolerance class-attribute instance-attribute

tolerance: float = 0.001

floor_z class-attribute instance-attribute

floor_z: float = 0.0

scene_clearance class-attribute instance-attribute

scene_clearance: float = 0.02

activation_distance class-attribute instance-attribute

activation_distance: float | None = None

SelfCollisionConstraintConfig

Bases: ConstraintConfig

Maintain minimum separation between explicit typed robot geometry pairs.

Attributes:

Name Type Description
kind
pairs tuple[GeometryPair, ...]
minimum_distance float
margin float | None
windows tuple[tuple[int, int], ...] | None

Attributes

kind class-attribute instance-attribute

kind = SELF_COLLISION

pairs class-attribute instance-attribute

pairs: tuple[GeometryPair, ...] = ()

minimum_distance class-attribute instance-attribute

minimum_distance: float = 0.02

margin class-attribute instance-attribute

margin: float | None = None

windows class-attribute instance-attribute

windows: tuple[tuple[int, int], ...] | None = None

OptimizationProfile

Bases: BaseModel

Reusable typed objective/constraint composition.

Methods:

Name Description
defaults

Return default robot-only optimization terms.

objective

Return the last objective matching kind.

constraint

Return the last constraint matching kind.

with_objective
without_objective
with_constraint
without_constraint
validate_registry_references

Attributes:

Name Type Description
model_config
name str
objectives tuple[ObjectiveConfig, ...]
constraints tuple[ConstraintConfig, ...]
provenance dict[str, object]
objective_kinds tuple[ObjectiveKind, ...]

Objective kinds in profile order.

constraint_kinds tuple[ConstraintKind, ...]

Constraint kinds in profile order.

Attributes

model_config class-attribute instance-attribute

model_config = ConfigDict(arbitrary_types_allowed=True)

name class-attribute instance-attribute

name: str = 'custom'

objectives class-attribute instance-attribute

objectives: tuple[ObjectiveConfig, ...] = ()

constraints class-attribute instance-attribute

constraints: tuple[ConstraintConfig, ...] = ()

provenance class-attribute instance-attribute

provenance: dict[str, object] = Field(default_factory=dict)

objective_kinds property

objective_kinds: tuple[ObjectiveKind, ...]

Objective kinds in profile order.

constraint_kinds property

constraint_kinds: tuple[ConstraintKind, ...]

Constraint kinds in profile order.

Functions

defaults classmethod

defaults(*, name: str = 'default') -> OptimizationProfile

Return default robot-only optimization terms.

objective

objective(kind: ObjectiveKind) -> ObjectiveConfig | None

Return the last objective matching kind.

constraint

constraint(kind: ConstraintKind) -> ConstraintConfig | None

Return the last constraint matching kind.

with_objective

with_objective(objective: ObjectiveConfig, *, replace: bool = True) -> Self

without_objective

without_objective(*kinds: ObjectiveKind) -> Self

with_constraint

with_constraint(constraint: ConstraintConfig, *, replace: bool = True) -> Self

without_constraint

without_constraint(*kinds: ConstraintKind) -> Self

validate_registry_references

validate_registry_references(solver: SolverSpec | None = None) -> None

SolverSpec

Bases: BaseModel

Solver selection and common options.

Attributes:

Name Type Description
model_config
backend SolverKind
max_iterations int
first_frame_iterations int | None
trust_radius float
tolerance float
convergence ConvergenceMode
cost_atol float
cost_rtol float
verbose bool

Attributes

model_config class-attribute instance-attribute

model_config = ConfigDict(extra='forbid', arbitrary_types_allowed=True)

backend class-attribute instance-attribute

backend: SolverKind = AUTO

max_iterations class-attribute instance-attribute

max_iterations: int = 10

first_frame_iterations class-attribute instance-attribute

first_frame_iterations: int | None = None

trust_radius class-attribute instance-attribute

trust_radius: float = 0.2

tolerance class-attribute instance-attribute

tolerance: float = 1e-06

convergence class-attribute instance-attribute

convergence: ConvergenceMode = STEP_NORM

cost_atol class-attribute instance-attribute

cost_atol: float = 1e-08

cost_rtol class-attribute instance-attribute

cost_rtol: float = 1e-05

verbose class-attribute instance-attribute

verbose: bool = False

ObjectiveContribution dataclass

ObjectiveContribution(matrix: FloatArray, target: FloatArray)

Least-squares contribution from one objective term.

The contribution is expressed as ||matrix @ dq - target||^2 where dq is the current subproblem's actuated-joint increment.

Attributes:

Name Type Description
matrix FloatArray
target FloatArray

Attributes

matrix instance-attribute

matrix: FloatArray

target instance-attribute

target: FloatArray

ConstraintContribution dataclass

ConstraintContribution(
    lower: FloatArray | None = None,
    upper: FloatArray | None = None,
    trust_radius: float | None = None,
    linear_constraints: tuple[LinearConstraint, ...] = (),
)

Bounds and linear constraints from one constraint term.

Attributes:

Name Type Description
lower FloatArray | None
upper FloatArray | None
trust_radius float | None
linear_constraints tuple[LinearConstraint, ...]

Attributes

lower class-attribute instance-attribute

lower: FloatArray | None = None

upper class-attribute instance-attribute

upper: FloatArray | None = None

trust_radius class-attribute instance-attribute

trust_radius: float | None = None

linear_constraints class-attribute instance-attribute

linear_constraints: tuple[LinearConstraint, ...] = ()

TermContext dataclass

TermContext(
    problem: AnyRetargetingProblem,
    compiled: CompiledRetargetingProblem,
    backend: KinematicsBackend,
    q_current: FloatArray,
    q_previous: FloatArray,
    frame_idx: int,
    contact_frame: CompiledContactFrame | None,
    target_frame: CompiledTargetFrame | None,
    robot_point_names: tuple[str, ...],
    robot_points: FloatArray,
    robot_jacobians: FloatArray,
    environment_points: FloatArray,
    adjacency: tuple[tuple[int, ...], ...],
    target_laplacian: FloatArray,
    laplacian_weighting: LaplacianWeighting,
    laplacian_epsilon: float,
    reference_pose: Pose | None,
    joint_lower: FloatArray,
    joint_upper: FloatArray,
    current_joints: FloatArray,
    variable_indices: NDArray[int64] | None = None,
    current_variables: FloatArray | None = None,
    variable_lower: FloatArray | None = None,
    variable_upper: FloatArray | None = None,
    nominal_qpos_frame: NominalQposFrame | None = None,
)

Per-frame data available to objective and constraint terms.

Terms operate on the actuated-joint increment for the current SQP subproblem. All point arrays and Jacobians are already represented in the local frame relevant to the current task, such as the object frame for dynamic object interaction.

Attributes:

Name Type Description
problem RetargetingProblem

Parent run specification.

backend KinematicsBackend

Kinematics provider for positions and Jacobians.

q_current FloatArray

Full qpos vector for the frame being optimized.

q_previous FloatArray

qpos from the prior frame (warm start for smoothness).

frame_idx int

Zero-based index into the motion sequence.

contact_frame ContactFrame | None

Typed contact view for the current frame, when configured.

target_frame TargetFrame | None

Typed link-target view for the current frame, when configured.

robot_point_names tuple[str, ...]

Link or joint names used for mesh matching.

robot_points FloatArray

Robot match points in the task-local frame, shape (P, 3).

robot_jacobians FloatArray

Position Jacobians w.r.t. active variables, shape (P, 3, dof).

environment_points FloatArray

Scene or object sample points, shape (E, 3).

adjacency tuple[tuple[int, ...], ...]

Mesh neighbor indices per vertex.

target_laplacian FloatArray

Desired Laplacian coordinates for the interaction mesh.

laplacian_weighting LaplacianWeighting

Neighbor weighting used by the current mesh builder.

laplacian_epsilon float

Epsilon used by distance-weighted Laplacians.

reference_pose Pose | None

Object pose for dynamic scenes; None in world frame.

joint_lower FloatArray

Actuated joint lower limits for the current robot.

joint_upper FloatArray

Actuated joint upper limits for the current robot.

current_joints FloatArray

Actuated joint values extracted from q_current.

variable_indices NDArray[int64] | None

Qpos indices for active optimization variables.

current_variables FloatArray | None

Active qpos values extracted from q_current.

variable_lower FloatArray | None

Absolute lower bounds for active qpos variables.

variable_upper FloatArray | None

Absolute upper bounds for active qpos variables.

nominal_qpos_frame NominalQposFrame | None

Optional nominal qpos target view.

Attributes

problem instance-attribute

problem: AnyRetargetingProblem

compiled instance-attribute

compiled: CompiledRetargetingProblem

backend instance-attribute

backend: KinematicsBackend

q_current instance-attribute

q_current: FloatArray

q_previous instance-attribute

q_previous: FloatArray

frame_idx instance-attribute

frame_idx: int

contact_frame instance-attribute

contact_frame: CompiledContactFrame | None

target_frame instance-attribute

target_frame: CompiledTargetFrame | None

robot_point_names instance-attribute

robot_point_names: tuple[str, ...]

robot_points instance-attribute

robot_points: FloatArray

robot_jacobians instance-attribute

robot_jacobians: FloatArray

environment_points instance-attribute

environment_points: FloatArray

adjacency instance-attribute

adjacency: tuple[tuple[int, ...], ...]

target_laplacian instance-attribute

target_laplacian: FloatArray

laplacian_weighting instance-attribute

laplacian_weighting: LaplacianWeighting

laplacian_epsilon instance-attribute

laplacian_epsilon: float

reference_pose instance-attribute

reference_pose: Pose | None

joint_lower instance-attribute

joint_lower: FloatArray

joint_upper instance-attribute

joint_upper: FloatArray

current_joints instance-attribute

current_joints: FloatArray

variable_indices class-attribute instance-attribute

variable_indices: NDArray[int64] | None = None

current_variables class-attribute instance-attribute

current_variables: FloatArray | None = None

variable_lower class-attribute instance-attribute

variable_lower: FloatArray | None = None

variable_upper class-attribute instance-attribute

variable_upper: FloatArray | None = None

nominal_qpos_frame class-attribute instance-attribute

nominal_qpos_frame: NominalQposFrame | None = None

dof property

dof: int

Number of coordinates in the subproblem variable.

active_qpos_indices property

active_qpos_indices: NDArray[int64]

Qpos indices represented by the current subproblem variable.

current_variable_values property

current_variable_values: FloatArray

Current values of active qpos variables.

variable_lower_bounds property

variable_lower_bounds: FloatArray

Absolute lower bounds for active qpos variables.

variable_upper_bounds property

variable_upper_bounds: FloatArray

Absolute upper bounds for active qpos variables.