Reference/API

Terms

robokit.terms.Task
Bases: abc.ABC

Base of every cost term: names its variable (var_key) and cost row (cost_name).

Members
attribute[source]
Task.SUPPORTS_CUDA_GRAPH: bool = True
attribute[source]
Task.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attribute[source]
Task.var_key: Enum = VarKey.ROBOT
attribute[source]
Task.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

attribute[source]
Task.robot: Any = None

The robot a built task reads; None on a template.

attribute[source]
Task.weight: Any = 1.0
property[source]
Task.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

property[source]
Task.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

method[source]
Task.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap each Context placeholder, alone or in a tuple, for its value; subclasses then build for the variable.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> task = Step(dt=(Inputs.STEP, 2.0))
>>> task.resolve(None, {Inputs.STEP: 0.5})  # the base swaps placeholders only
>>> task.dt
(0.5, 2.0)
Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
Task.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
method[source]
Task.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
property[source]
Task.cost_name: str

Return the snake-case task name used in cost reports.

property[source]
Task.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

method[source]
Task.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
method[source]
Task.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
robokit.terms.ResidualTask
Bases: Task

Term consumed as a weighted residual and optional Jacobian.

Members
attributeinherited from Task[source]
ResidualTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
ResidualTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
ResidualTask.var_key: Enum = VarKey.ROBOT
attributeinherited from Task[source]
ResidualTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

attributeinherited from Task[source]
ResidualTask.robot: Any = None

The robot a built task reads; None on a template.

attributeinherited from Task[source]
ResidualTask.weight: Any = 1.0
propertyinherited from Task[source]
ResidualTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
ResidualTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
ResidualTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap each Context placeholder, alone or in a tuple, for its value; subclasses then build for the variable.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> task = Step(dt=(Inputs.STEP, 2.0))
>>> task.resolve(None, {Inputs.STEP: 0.5})  # the base swaps placeholders only
>>> task.dt
(0.5, 2.0)
Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
ResidualTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
ResidualTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
ResidualTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
ResidualTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
ResidualTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
ResidualTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attribute[source]
ResidualTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
attribute[source]
ResidualTask.device: Any = None

Device of the task's Warp buffers; None before init_buffers.

method[source]
ResidualTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
property[source]
ResidualTask.residual_dim: int

Dimension of the residual vector.

method[source]
ResidualTask.compute_weighted_residual(
var_values: VarValues,
args: Any = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
method[source]
ResidualTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
method[source]
ResidualTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
method[source]
ResidualTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

robokit.terms.GradientTask
Bases: Task

Per-batch scalar cost and gradient, used by GDOptimizer/LBFGSOptimizer in analytic-gradient mode.

Members
attributeinherited from Task[source]
GradientTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
GradientTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
GradientTask.var_key: Enum = VarKey.ROBOT
attributeinherited from Task[source]
GradientTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

attributeinherited from Task[source]
GradientTask.robot: Any = None

The robot a built task reads; None on a template.

attributeinherited from Task[source]
GradientTask.weight: Any = 1.0
propertyinherited from Task[source]
GradientTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
GradientTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
GradientTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap each Context placeholder, alone or in a tuple, for its value; subclasses then build for the variable.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> task = Step(dt=(Inputs.STEP, 2.0))
>>> task.resolve(None, {Inputs.STEP: 0.5})  # the base swaps placeholders only
>>> task.dt
(0.5, 2.0)
Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
GradientTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
GradientTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
GradientTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
GradientTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
GradientTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
GradientTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
method[source]
GradientTask.compute_weighted_cost_and_gradient(
var_values: VarValues,
args: Any = (),
out_cost: wp.array,
out_gradient: Optional[wp.array] = None,
kwargs: Any = {}
)

Accumulate this term's weighted cost and optional direct gradient.

Parameters
var_valuesVarValuesrequired

Optimization variables.

argsAny= ()
out_costwp.arrayrequired

Shared per-batch cost buffer.

out_gradientOptional[wp.array]= None

Optional shared gradient buffer. If omitted, only cost is accumulated.

kwargsAny= {}
robokit.terms.SparseTask
Bases: ResidualTask

Residual task with an explicitly stored sparse Jacobian.

Members
attributeinherited from Task[source]
SparseTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
SparseTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
SparseTask.var_key: Enum = VarKey.ROBOT
attributeinherited from Task[source]
SparseTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

attributeinherited from Task[source]
SparseTask.robot: Any = None

The robot a built task reads; None on a template.

attributeinherited from Task[source]
SparseTask.weight: Any = 1.0
propertyinherited from Task[source]
SparseTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
SparseTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
SparseTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap each Context placeholder, alone or in a tuple, for its value; subclasses then build for the variable.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> task = Step(dt=(Inputs.STEP, 2.0))
>>> task.resolve(None, {Inputs.STEP: 0.5})  # the base swaps placeholders only
>>> task.dt
(0.5, 2.0)
Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
SparseTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
SparseTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
SparseTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
SparseTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
SparseTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
SparseTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
SparseTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
attributeinherited from ResidualTask[source]
SparseTask.device: Any = None

Device of the task's Warp buffers; None before init_buffers.

methodinherited from ResidualTask[source]
SparseTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
propertyinherited from ResidualTask[source]
SparseTask.residual_dim: int

Dimension of the residual vector.

methodinherited from ResidualTask[source]
SparseTask.compute_weighted_residual(
var_values: VarValues,
args: Any = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
SparseTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
SparseTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
attribute[source]
SparseTask.use_mask: bool = False
attribute[source]
SparseTask.frame_mask: Optional[wp.array] = None
method[source]
SparseTask.compute_sparse_jacobian_pattern(
var_values: VarValues,
args: Any = (),
offset: int = 0,
kwargs: Any = {}
) -> SparsityPattern

Sparsity pattern of the Jacobian matrix.

Parameters
var_valuesVarValuesrequired
argsAny= ()
offsetint= 0
kwargsAny= {}
Returns
SparsityPattern
method[source]
SparseTask.compute_weighted_sparse_jacobian_values(
var_values: VarValues,
args: Any = (),
out_jacobian_values: Optional[wp.array] = None,
offset: int = 0,
kwargs: Any = {}
) -> wp.array

Compute the non-zero values of the weighted Jacobian matrix according to the sparsity pattern.

Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobian_valuesOptional[wp.array]= None
offsetint= 0
kwargsAny= {}
Returns
wp.array
method[source]
SparseTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate normal equations directly from existing sparse rows.

Parameters
var_valuesVarValuesrequired
costswp.arrayrequired
JtJOptional[wp.array]= None
JtrOptional[wp.array]= None
method[source]
SparseTask.fill_residual_and_jacobian(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

Write residuals and optional sparse Jacobian values into shared buffers.

Parameters
var_valuesVarValuesrequired

Optimization variables.

out_residualwp.arrayrequired

Shared residual buffer.

row_offsetintrequired

First residual row for this task.

out_jacobianOptional[wp.array]= None

Optional shared sparse-value buffer.

nnz_offsetint= 0

First sparse entry for this task.

method[source]
SparseTask.set_valid_lengths(
lengths: Union[np.ndarray, wp.array]
)

Set the valid trajectory length for each batch element.

Parameters
lengthsUnion[np.ndarray, wp.array]required

Per-batch valid frame counts.

robokit.terms.EagerTask
Bases: ResidualTask

Task with per-iteration work outside a captured CUDA graph.

Members
attributeinherited from Task[source]
EagerTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
EagerTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
EagerTask.var_key: Enum = VarKey.ROBOT
attributeinherited from Task[source]
EagerTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

attributeinherited from Task[source]
EagerTask.robot: Any = None

The robot a built task reads; None on a template.

attributeinherited from Task[source]
EagerTask.weight: Any = 1.0
propertyinherited from Task[source]
EagerTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
EagerTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
EagerTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap each Context placeholder, alone or in a tuple, for its value; subclasses then build for the variable.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> task = Step(dt=(Inputs.STEP, 2.0))
>>> task.resolve(None, {Inputs.STEP: 0.5})  # the base swaps placeholders only
>>> task.dt
(0.5, 2.0)
Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
EagerTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
EagerTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
EagerTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
EagerTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
EagerTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
EagerTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
EagerTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
attributeinherited from ResidualTask[source]
EagerTask.device: Any = None

Device of the task's Warp buffers; None before init_buffers.

methodinherited from ResidualTask[source]
EagerTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
propertyinherited from ResidualTask[source]
EagerTask.residual_dim: int

Dimension of the residual vector.

methodinherited from ResidualTask[source]
EagerTask.compute_weighted_residual(
var_values: VarValues,
args: Any = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
EagerTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
EagerTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
EagerTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

method[source]
EagerTask.prepare(
var_values: VarValues,
proposed: bool,
iter_idx: int
)

Prepare eager state before a Warp reduction.

Parameters
var_valuesVarValuesrequired

Current or proposed optimization variables.

proposedboolrequired

Whether this is a line-search proposal.

iter_idxintrequired

Solver iteration.

method[source]
EagerTask.on_step(
accept_mask: wp.array,
iter_idx: int,
costs: wp.array
) -> bool

Update eager state after accepting or rejecting a step.

Parameters
accept_maskwp.arrayrequired

Per-batch accepted-step mask.

iter_idxintrequired

Solver iteration.

costswp.arrayrequired

Per-batch costs.

Returns
bool

Whether the solver should stop early.

robokit.terms.RobotTask
Bases: Task

Serial preparation shared by terms that consume a robot state.

Members
attributeinherited from Task[source]
RobotTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
RobotTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
RobotTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

attributeinherited from Task[source]
RobotTask.weight: Any = 1.0
propertyinherited from Task[source]
RobotTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
RobotTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
RobotTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
RobotTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
RobotTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
RobotTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
RobotTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attribute[source]
RobotTask.robot: Optional[Robot]
attribute[source]
RobotTask.var_key: Enum
attribute[source]
RobotTask.precompute_collision_geometry: str = ''
method[source]
RobotTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap placeholders, then take the robot of the state this task reads.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
RobotTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
method[source]
RobotTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
robokit.terms.TrajectoryTask(
dense_task: ResidualTask,
num_frames: Optional[int] = None,
frame_indices: Optional[Union[Sequence[int], Context]] = None,
name: str = ''
)
Bases: RobotTask, SparseTask, GradientTask

Apply independent per-pose tasks to trajectory frames, with one dense tangent block per selected frame.

Parameters
dense_taskResidualTaskrequired

Per-pose residual task.

num_framesOptional[int]= None

Number of trajectory frames, or omitted so the trajectory optimizer sets it.

frame_indicesOptional[Union[Sequence[int], Context]]= None

Frames to include. Defaults to all frames.

namestr= ''

Optional planner input name (start, goal, target, path_goal, or path_target).

Members
attributeinherited from Task[source]
TrajectoryTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
TrajectoryTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
TrajectoryTask.weight: Any = 1.0
propertyinherited from Task[source]
TrajectoryTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
TrajectoryTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
TrajectoryTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
TrajectoryTask.cost_name: str

Return the snake-case task name used in cost reports.

methodinherited from RobotTask[source]
TrajectoryTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
TrajectoryTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
TrajectoryTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
TrajectoryTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
TrajectoryTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from SparseTask[source]
TrajectoryTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate normal equations directly from existing sparse rows.

Parameters
var_valuesVarValuesrequired
costswp.arrayrequired
JtJOptional[wp.array]= None
JtrOptional[wp.array]= None
attributeinherited from SparseTask[source]
TrajectoryTask.use_mask: bool = False
attributeinherited from SparseTask[source]
TrajectoryTask.frame_mask: Optional[wp.array] = None
methodinherited from SparseTask[source]
TrajectoryTask.set_valid_lengths(
lengths: Union[np.ndarray, wp.array]
)

Set the valid trajectory length for each batch element.

Parameters
lengthsUnion[np.ndarray, wp.array]required

Per-batch valid frame counts.

methodinherited from RobotTask[source]
TrajectoryTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
property[source]
TrajectoryTask.dense_task: ResidualTask
attribute[source]
TrajectoryTask.device: Optional[wp_device_type]
property[source]
TrajectoryTask.active: bool
method[source]
TrajectoryTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build for the trajectory in var_values; a built per-pose task keeps its identity and live targets.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
TrajectoryTask.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
property[source]
TrajectoryTask.residual_dim: int
method[source]
TrajectoryTask.fill_residual_and_jacobian(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

A terminal cost whose dense task writes the trajectory layout itself (fill_terminal) takes one launch.

Parameters
var_valuesVarValuesrequired
out_residualwp.arrayrequired
row_offsetintrequired
out_jacobianOptional[wp.array]= None
nnz_offsetint= 0
method[source]
TrajectoryTask.compute_weighted_residual(
var_values: VarValues,
args: Any = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
method[source]
TrajectoryTask.compute_sparse_jacobian_pattern(
var_values: VarValues,
args: Any = (),
offset: int = 0,
out_row_indices: Optional[wp.array] = None,
out_col_indices: Optional[wp.array] = None,
nnz_offset: int = 0,
kwargs: Any = {}
) -> SparsityPattern
Parameters
var_valuesVarValuesrequired
argsAny= ()
offsetint= 0
out_row_indicesOptional[wp.array]= None
out_col_indicesOptional[wp.array]= None
nnz_offsetint= 0
kwargsAny= {}
Returns
SparsityPattern
method[source]
TrajectoryTask.compute_weighted_sparse_jacobian_values(
var_values: VarValues,
args: Any = (),
out_jacobian_values: Optional[wp.array] = None,
offset: int = 0,
nnz_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobian_valuesOptional[wp.array]= None
offsetint= 0
nnz_offsetint= 0
kwargsAny= {}
Returns
wp.array
robokit.terms.FrameTask(
robot: Optional[Robot] = None,
frame_index: Optional[Union[int, Sequence[int], Context]] = None,
T_world_target: Optional[Union[wp.array, np.ndarray, Sequence[wp.array], Context]] = None,
position_weight: Union[float, Sequence[float], np.ndarray, Mapping[str, float]] = 1.0,
orientation_weight: Union[float, Sequence[float], np.ndarray, Mapping[str, float]] = 1.0,
residual_mode: Literal['log', 'distance'] = 'log',
trajectory_frames: int = 1,
name: str = ''
)
Bases: RobotTask, ResidualTask

Match world-frame link targets; "distance" scores translation/angle thresholds, while "log" uses log residuals.

Example

python
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> from robokit.opt.var_values import VarKey, VarValues
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("ur10_description"))
>>> target_link_index = robot.spec.link_names.index("ee_link")
>>> state = robot.state(q=robot.spec.zero_q)
>>> target_link_pose = robot.forward_kinematics(state).get_T_world_link(target_link_index)
>>> frame_task = FrameTask(robot, target_link_index, target_link_pose, position_weight=1.0, orientation_weight=1.0)
>>> random_q = wp.from_numpy(np.array([[-0.5, 0.3, -0.2, 0.4, -0.1, 0.25]], dtype=np.float32), dtype=wp.float32, device="cpu")
>>> state = robot.state(q=random_q)
>>> robot.forward_kinematics(state)
>>> robot.compute_motion_subspace(state)
>>> weighted_residual = frame_task.compute_weighted_residual(VarValues({VarKey.ROBOT: state}))
>>> weighted_jacobian = frame_task.compute_weighted_jacobian(VarValues({VarKey.ROBOT: state}))
>>> assert np.allclose(weighted_residual.numpy()[0, :3], np.array([0.5839, -0.0795, -0.1784], dtype=np.float32), atol=1e-3)
>>> assert np.allclose(weighted_jacobian.numpy()[0, :, 0], np.array([-1.1628, 0.1626, -0.167, -0.0765, 0.3698, 0.9521], dtype=np.float32), atol=1e-3)
Parameters
robotOptional[Robot]= None
frame_indexOptional[Union[int, Sequence[int], Context]]= None
T_world_targetOptional[Union[wp.array, np.ndarray, Sequence[wp.array], Context]]= None
position_weightUnion[float, Sequence[float], np.ndarray, Mapping[str, float]]= 1.0
orientation_weightUnion[float, Sequence[float], np.ndarray, Mapping[str, float]]= 1.0
residual_modeLiteral['log', 'distance']= 'log'
trajectory_framesint= 1
namestr= ''
Members
attributeinherited from Task[source]
FrameTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
FrameTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
FrameTask.var_key: Enum
attributeinherited from Task[source]
FrameTask.weight: Any = 1.0
propertyinherited from Task[source]
FrameTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
FrameTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
FrameTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
FrameTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
FrameTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
FrameTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
FrameTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
methodinherited from ResidualTask[source]
FrameTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
FrameTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
FrameTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
FrameTask.precompute_collision_geometry: str = ''
methodinherited from RobotTask[source]
FrameTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
attribute[source]
FrameTask.residual_mode: Literal['log', 'distance']
attribute[source]
FrameTask.robot: Optional[Robot]
method[source]
FrameTask.set_target(
target: Union[wp.array, np.ndarray, Sequence[wp.array]]
)

Update target poses in-place. Batch size must match the original.

Parameters
targetUnion[wp.array, np.ndarray, Sequence[wp.array]]required
property[source]
FrameTask.active: bool
method[source]
FrameTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Complete a stub with the helper's links and target buffer (not copied); named weights pick those links.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
FrameTask.weights_for(
frame_names: Sequence[str]
) -> Tuple[np.ndarray, np.ndarray]

Resolve scalar, ordered, or named template weights for the selected frames.

python
>>> task = FrameTask(position_weight={"tool": 2.0}, orientation_weight=3.0)
>>> task.weights_for(["tool"])[0].tolist()
[2.0]
Parameters
frame_namesSequence[str]required
Returns
Tuple[np.ndarray, np.ndarray]
method[source]
FrameTask.set_frames(
robot: Robot,
frame_index: Union[int, Sequence[int]],
T_world_target: Union[wp.array, np.ndarray, Sequence[wp.array]]
)

Give a config-time stub its robot, link indices, and targets, keeping the configured weights.

Parameters
robotRobotrequired
frame_indexUnion[int, Sequence[int]]required
T_world_targetUnion[wp.array, np.ndarray, Sequence[wp.array]]required
property[source]
FrameTask.residual_dim: int
method[source]
FrameTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
FrameTask.fill_terminal(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

Write terminal pose residuals and optional sparse Jacobian values in one launch.

Layouts:

  • var_values: flattened poses, trajectory_frames per trajectory.
  • Jacobian: TrajectoryTask's single-frame, row-major values, one per actuated joint.
Parameters
var_valuesVarValuesrequired
out_residualwp.arrayrequired
row_offsetintrequired
out_jacobianOptional[wp.array]= None
nnz_offsetint= 0
method[source]
FrameTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.PositionTask(
robot: Optional[Robot] = None,
frame_index: Optional[Union[int, Sequence[int], Context]] = None,
T_world_target: Optional[Union[wp.array, np.ndarray, Context]] = None,
weight: Union[float, Sequence[float]] = 20.0,
fixed_target: bool = False,
name: str = ''
)
Bases: RobotTask, ResidualTask

Match the world positions of one or more link frames.

Example

python
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> from robokit.opt.var_values import VarKey, VarValues
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("ur10_description"))
>>> target_link_index = robot.link_names.index("ee_link")
>>> state = robot.state(q=robot.zero_q)
>>> target_link_pose = robot.forward_kinematics(state).get_T_world_link(target_link_index).reshape((1, 1))
>>> position_task = PositionTask(robot, target_link_index, target_link_pose, weight=1.0)
>>> random_q = wp.from_numpy(np.array([[-0.5, 0.3, -0.2, 0.4, -0.1, 0.25]], dtype=np.float32), dtype=wp.float32)
>>> state = robot.state(q=random_q)
>>> robot.forward_kinematics(state)
>>> robot.compute_motion_subspace(state)
>>> weighted_residual = position_task.compute_weighted_residual(VarValues({VarKey.ROBOT: state}))
>>> weighted_jacobian = position_task.compute_weighted_jacobian(VarValues({VarKey.ROBOT: state}))
>>> weighted_residual.numpy().shape[1] == 3
True
>>> weighted_jacobian.numpy().shape[1] == 3
True
Parameters
robotOptional[Robot]= None
frame_indexOptional[Union[int, Sequence[int], Context]]= None
T_world_targetOptional[Union[wp.array, np.ndarray, Context]]= None
weightUnion[float, Sequence[float]]= 20.0
fixed_targetbool= False
namestr= ''
Members
attributeinherited from Task[source]
PositionTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
PositionTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
PositionTask.var_key: Enum
propertyinherited from Task[source]
PositionTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
PositionTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
PositionTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
PositionTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
PositionTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
PositionTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
PositionTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
PositionTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
methodinherited from ResidualTask[source]
PositionTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
PositionTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
PositionTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
PositionTask.precompute_collision_geometry: str = ''
attribute[source]
PositionTask.robot: Optional[Robot]
method[source]
PositionTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
method[source]
PositionTask.set_weight(
weight: Union[float, Sequence[float]]
)

Update residual weights in-place. Accepts scalar or per-frame sequence.

Parameters
weightUnion[float, Sequence[float]]required
method[source]
PositionTask.set_frames(
robot: Robot,
frame_index: Union[int, Sequence[int]],
T_world_target: Union[wp.array, np.ndarray]
)

Give a config-time stub its robot, link indices, and targets, keeping the configured weights.

Parameters
robotRobotrequired
frame_indexUnion[int, Sequence[int]]required
T_world_targetUnion[wp.array, np.ndarray]required
method[source]
PositionTask.set_target(
T_world_target: Union[wp.array, np.ndarray]
)

Update target poses in-place. Batch size must match the original.

Parameters
T_world_targetUnion[wp.array, np.ndarray]required
method[source]
PositionTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Complete a stub with the helper's links and target buffer, which it reads directly.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
property[source]
PositionTask.residual_dim: int
method[source]
PositionTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
PositionTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.RotationTask(
robot: Optional[Robot] = None,
frame_index: Optional[Union[int, Sequence[int], Context]] = None,
T_world_target: Optional[Union[wp.array, np.ndarray, Context]] = None,
weight: Union[float, Sequence[float], np.ndarray, Mapping[str, float]] = 10.0,
fixed_target: bool = False,
name: str = ''
)
Bases: RobotTask, ResidualTask

Match the world rotations of one or more link frames.

Example

python
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> from robokit.opt.var_values import VarKey, VarValues
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("ur10_description"))
>>> target_link_index = robot.link_names.index("ee_link")
>>> state = robot.state(q=robot.zero_q)
>>> target_link_pose = robot.forward_kinematics(state).get_T_world_link(target_link_index).reshape((1, 1))
>>> rotation_task = RotationTask(robot, target_link_index, target_link_pose, weight=1.0)
>>> random_q = wp.from_numpy(np.array([[-0.5, 0.3, -0.2, 0.4, -0.1, 0.25]], dtype=np.float32), dtype=wp.float32)
>>> state = robot.state(q=random_q)
>>> robot.forward_kinematics(state)
>>> robot.compute_motion_subspace(state)
>>> weighted_residual = rotation_task.compute_weighted_residual(VarValues({VarKey.ROBOT: state}))
>>> weighted_jacobian = rotation_task.compute_weighted_jacobian(VarValues({VarKey.ROBOT: state}))
>>> weighted_residual.numpy().shape[1] == 3
True
>>> weighted_jacobian.numpy().shape[1] == 3
True
Parameters
robotOptional[Robot]= None
frame_indexOptional[Union[int, Sequence[int], Context]]= None
T_world_targetOptional[Union[wp.array, np.ndarray, Context]]= None
weightUnion[float, Sequence[float], np.ndarray, Mapping[str, float]]= 10.0
fixed_targetbool= False
namestr= ''
Members
attributeinherited from Task[source]
RotationTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
RotationTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
RotationTask.var_key: Enum
propertyinherited from Task[source]
RotationTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
RotationTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
RotationTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
RotationTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
RotationTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
RotationTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
RotationTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
RotationTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
methodinherited from ResidualTask[source]
RotationTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
RotationTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
RotationTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
RotationTask.precompute_collision_geometry: str = ''
attribute[source]
RotationTask.robot: Optional[Robot]
method[source]
RotationTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
method[source]
RotationTask.set_weight(
weight: Union[float, Sequence[float]]
)

Update residual weights in-place. Accepts scalar or per-frame sequence.

Parameters
weightUnion[float, Sequence[float]]required
method[source]
RotationTask.set_frames(
robot: Robot,
frame_index: Union[int, Sequence[int]],
T_world_target: Union[wp.array, np.ndarray]
)

Give a config-time stub its robot, link indices, and targets, keeping the configured weights.

Parameters
robotRobotrequired
frame_indexUnion[int, Sequence[int]]required
T_world_targetUnion[wp.array, np.ndarray]required
method[source]
RotationTask.set_target(
T_world_target: Union[wp.array, np.ndarray]
)

Update target poses in-place. Batch size must match the original.

Parameters
T_world_targetUnion[wp.array, np.ndarray]required
method[source]
RotationTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Complete a stub with the helper's links and target buffer (not copied); named weights zero unlisted links.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
property[source]
RotationTask.residual_dim: int
method[source]
RotationTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
RotationTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.FrameVectorTask(
robot: Optional[Robot] = None,
origin_link_indices: Optional[Union[Sequence[int], Context]] = None,
task_link_indices: Optional[Union[Sequence[int], Context]] = None,
targets: Optional[Union[np.ndarray, wp.array, Context]] = None,
weight: Union[float, Sequence[float], np.ndarray, Mapping[Any, float]] = 1.0,
target_indices: Optional[Sequence[int]] = None,
scale: Union[float, Sequence[float], np.ndarray] = 1.0,
huber_delta: Optional[float] = None,
huber_on_norm: bool = False,
direction_only: bool = False,
soft_gate_start_distance: Optional[float] = None,
soft_gate_full_distance: Optional[float] = None,
soft_gate_pair_mask: Optional[List[bool]] = None,
direction_metric: Literal['length_scaled', 'cosine'] = 'length_scaled',
name: str = '',
weight_mode: Literal['residual', 'cost', 'normalized'] = 'residual',
target_names: Optional[Union[Sequence[str], Context]] = None,
target_links: Optional[Union[Mapping[str, str], Context]] = None,
soft_gate_targets: Optional[Union[Sequence[int], Context]] = None
)
Bases: RobotTask, ResidualTask

Drive point-pair deltas to target vectors; weight_mode "cost" takes sqrt, "normalized" divides by sqrt(rows).

Direction metrics:

  • Default: robot-length-scaled vector error.
  • `direction_only=True with direction_metric="cosine": 1 - dot(normalized_robot, normalized_target)`.

Named weights pick their rows when the task is built:

  • A target name tracks that target's row of targets, ordered by target_names, from the world origin to its link in target_links.
  • (origin link, task link, origin target, task target) reads the pair row origin * len(target_names) + task of a pair buffer.
Parameters
robotOptional[Robot]= None
origin_link_indicesOptional[Union[Sequence[int], Context]]= None
task_link_indicesOptional[Union[Sequence[int], Context]]= None
targetsOptional[Union[np.ndarray, wp.array, Context]]= None
weightUnion[float, Sequence[float], np.ndarray, Mapping[Any, float]]= 1.0
target_indicesOptional[Sequence[int]]= None
scaleUnion[float, Sequence[float], np.ndarray]= 1.0
huber_deltaOptional[float]= None
huber_on_normbool= False
direction_onlybool= False
soft_gate_start_distanceOptional[float]= None
soft_gate_full_distanceOptional[float]= None
soft_gate_pair_maskOptional[List[bool]]= None
direction_metricLiteral['length_scaled', 'cosine']= 'length_scaled'
namestr= ''
weight_modeLiteral['residual', 'cost', 'normalized']= 'residual'
target_namesOptional[Union[Sequence[str], Context]]= None
target_linksOptional[Union[Mapping[str, str], Context]]= None
soft_gate_targetsOptional[Union[Sequence[int], Context]]= None
Members
attributeinherited from Task[source]
FrameVectorTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
FrameVectorTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
FrameVectorTask.var_key: Enum
propertyinherited from Task[source]
FrameVectorTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
FrameVectorTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
FrameVectorTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
FrameVectorTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
FrameVectorTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
FrameVectorTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
FrameVectorTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
FrameVectorTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
FrameVectorTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
FrameVectorTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
FrameVectorTask.precompute_collision_geometry: str = ''
attribute[source]
FrameVectorTask.robot: Optional[Robot]
attribute[source]
FrameVectorTask.device: Optional[wp_device_type]
attribute[source]
FrameVectorTask.targets_wp: Optional[wp.array]
attribute[source]
FrameVectorTask.weights_wp: Optional[wp.array]
method[source]
FrameVectorTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
property[source]
FrameVectorTask.active: bool
method[source]
FrameVectorTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Attach the robot and helper links/targets, reading Warp buffers in place; named weights pick the rows.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
property[source]
FrameVectorTask.residual_dim: int
method[source]
FrameVectorTask.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
method[source]
FrameVectorTask.set_targets(
targets: Union[np.ndarray, wp.array],
weight: Optional[np.ndarray] = None
)

Update targets (and optionally weights) in place; shapes must match the built buffers.

Parameters
targetsUnion[np.ndarray, wp.array]required
weightOptional[np.ndarray]= None
method[source]
FrameVectorTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
FrameVectorTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
col_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
col_offsetint= 0
Returns
wp.array
robokit.terms.ComPositionTask(
robot: Optional[Robot] = None,
target_com_position: Optional[np.ndarray] = None,
weight: Union[float, Sequence[float]] = 1.0
)
Bases: RobotTask, ResidualTask

Penalize world-frame CoM target error using mass-weighted link CoM positions and their analytic Jacobians.

Example

python
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("g1_description"))
>>> task = ComPositionTask(robot=robot, target_com_position=np.zeros(3), weight=1.0)
>>> task.residual_dim
3
Parameters
robotOptional[Robot]= None
target_com_positionOptional[np.ndarray]= None
weightUnion[float, Sequence[float]]= 1.0
Members
attributeinherited from Task[source]
ComPositionTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
ComPositionTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
ComPositionTask.var_key: Enum
attributeinherited from Task[source]
ComPositionTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

attributeinherited from Task[source]
ComPositionTask.weight: Any = 1.0
propertyinherited from Task[source]
ComPositionTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
ComPositionTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from RobotTask[source]
ComPositionTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap placeholders, then take the robot of the state this task reads.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
ComPositionTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
ComPositionTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
ComPositionTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
ComPositionTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
ComPositionTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
ComPositionTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
ComPositionTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
ComPositionTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
ComPositionTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
ComPositionTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
ComPositionTask.precompute_collision_geometry: str = ''
attribute[source]
ComPositionTask.robot: Optional[Robot]
method[source]
ComPositionTask.set_target(
target: np.ndarray
)

Update CoM targets while retaining allocated buffers and captured graphs.

Example

python
>>> task = ComPositionTask(target_com_position=np.zeros(3))
>>> task.set_target(np.array([0.1, 0.0, 0.8]))
>>> task.target_com_position.shape
(3,)
Parameters
targetnp.ndarrayrequired
method[source]
ComPositionTask.set_weight(
weight: Union[float, Sequence[float]]
)

Update the three CoM residual weights in place.

Example

python
>>> task = ComPositionTask(target_com_position=np.zeros(3))
>>> task.set_weight([1.0, 1.0, 0.0])
>>> task.weight
[1.0, 1.0, 0.0]
Parameters
weightUnion[float, Sequence[float]]required
method[source]
ComPositionTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
property[source]
ComPositionTask.residual_dim: int
method[source]
ComPositionTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
ComPositionTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.PositionLimit(
robot: Optional[Robot] = None,
weight: Optional[Union[float, Sequence[float]]] = None,
residual_mode: Literal['abs', 'sqrt_abs', 'exp_barrier'] = 'abs',
residual_eps: float = 1e-06,
mask: Optional[Union[np.ndarray, Mapping[str, float]]] = None,
base_axis: Optional[int] = None,
base_bounds: Tuple[float, float] = (0.3, 0.76),
base_weight: float = 50.0,
include_joints: bool = True,
joint_limits: Optional[Union[np.ndarray, Context]] = None,
warmup_frames: int = 0,
activation: float = 0.0,
name: str = '',
frame: Optional[Union[wp.array, Context]] = None
)
Bases: RobotTask, ResidualTask, GradientTask

Penalize joint and optional floating-base translation limit violations.

Example

python
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> from robokit.opt.var_values import VarKey, VarValues
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("ur10_description"))
>>> joint_var = robot.spec.actuated_joint_limits[:, 0] - 0.1
>>> state = robot.state(q=wp.from_numpy(joint_var[None].astype(np.float32), dtype=wp.float32))
>>> position_limit = PositionLimit(robot=robot)
>>> weighted_residual = position_limit.compute_weighted_residual(VarValues({VarKey.ROBOT: state}))
>>> np.allclose(weighted_residual.numpy()[0], np.array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1], dtype=np.float32))
True
>>> weighted_jacobian = position_limit.compute_weighted_jacobian(VarValues({VarKey.ROBOT: state}))
>>> np.allclose(np.diag(weighted_jacobian.numpy()[0]), np.array([-1.0, -1.0, -1.0, -1.0, -1.0, -1.0], dtype=np.float32))
True
Parameters
robotOptional[Robot]= None
weightOptional[Union[float, Sequence[float]]]= None
residual_modeLiteral['abs', 'sqrt_abs', 'exp_barrier']= 'abs'
residual_epsfloat= 1e-06
maskOptional[Union[np.ndarray, Mapping[str, float]]]= None
base_axisOptional[int]= None
base_boundsTuple[float, float]= (0.3, 0.76)
base_weightfloat= 50.0
include_jointsbool= True
joint_limitsOptional[Union[np.ndarray, Context]]= None
warmup_framesint= 0
activationfloat= 0.0
namestr= ''
frameOptional[Union[wp.array, Context]]= None
Members
attributeinherited from Task[source]
PositionLimit.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
PositionLimit.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
PositionLimit.var_key: Enum
propertyinherited from Task[source]
PositionLimit.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
PositionLimit.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
PositionLimit.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
PositionLimit.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
PositionLimit.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
PositionLimit.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
PositionLimit.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
PositionLimit.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
PositionLimit.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
PositionLimit.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
PositionLimit.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
PositionLimit.precompute_collision_geometry: str = ''
attribute[source]
PositionLimit.robot: Optional[Robot]
attribute[source]
PositionLimit.dof_mask: Optional[wp.array]
method[source]
PositionLimit.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build from the robot; a base bound needs a floating base, e.g. IK with enable_T_world_base=True.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
PositionLimit.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
method[source]
PositionLimit.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
method[source]
PositionLimit.set_weight(
weight: Union[float, Sequence[float]]
)

Update residual weights in-place. Accepts a scalar or per-joint sequence.

Parameters
weightUnion[float, Sequence[float]]required
property[source]
PositionLimit.residual_dim: int
method[source]
PositionLimit.compute_weighted_residual(
var_values: VarValues,
out_residual: wp.array = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualwp.array= None
row_offsetint= 0
Returns
wp.array
method[source]
PositionLimit.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: wp.array = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianwp.array= None
row_offsetint= 0
Returns
wp.array
method[source]
PositionLimit.compute_weighted_cost_and_gradient(
var_values: VarValues,
out_cost: wp.array,
out_gradient: Optional[wp.array] = None
)
Parameters
var_valuesVarValuesrequired
out_costwp.arrayrequired
out_gradientOptional[wp.array]= None
robokit.terms.AxisLimitTask(
robot: Optional[Robot] = None,
frame_index: Optional[int] = None,
local_axis: Tuple[float, float, float] = (0.0, 0.0, 1.0),
world_axis: Tuple[float, float, float] = (0.0, 0.0, 1.0),
min_angle: Optional[float] = None,
max_angle: Optional[float] = None,
weight: float = 1.0
)
Bases: RobotTask, ResidualTask

Limit the angle between a frame-local axis and a world-frame axis.

Parameters
robotOptional[Robot]= None
frame_indexOptional[int]= None
local_axisTuple[float, float, float]= (0.0, 0.0, 1.0)
world_axisTuple[float, float, float]= (0.0, 0.0, 1.0)
min_angleOptional[float]= None
max_angleOptional[float]= None
weightfloat= 1.0
Members
attributeinherited from Task[source]
AxisLimitTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
AxisLimitTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
AxisLimitTask.var_key: Enum
attributeinherited from Task[source]
AxisLimitTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

propertyinherited from Task[source]
AxisLimitTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
AxisLimitTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from RobotTask[source]
AxisLimitTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap placeholders, then take the robot of the state this task reads.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
AxisLimitTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
AxisLimitTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
AxisLimitTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
AxisLimitTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
AxisLimitTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
AxisLimitTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
AxisLimitTask.device: Any = None

Device of the task's Warp buffers; None before init_buffers.

methodinherited from ResidualTask[source]
AxisLimitTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
AxisLimitTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
AxisLimitTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
AxisLimitTask.precompute_collision_geometry: str = ''
method[source]
AxisLimitTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
method[source]
AxisLimitTask.set_weight(
weight: float
)
Parameters
weightfloatrequired
property[source]
AxisLimitTask.residual_dim: int
method[source]
AxisLimitTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
AxisLimitTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.VelocityLimitTask(
robot: Optional[Robot] = None,
dt: Union[float, Context] = 1.0,
prev_state_var: Optional[Union[RobotState, Context]] = None,
velocity_limits: Optional[Union[np.ndarray, Context]] = None,
weight: Optional[Union[float, Sequence[float]]] = None,
name: str = ''
)
Bases: ResidualTask

Penalize joint velocity limit violations relative to a previous state.

Example

python
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("panda_description"))
>>> state_prev = robot.state(q=robot.spec.zero_q)
>>> state_curr = robot.state(q=robot.spec.zero_q + 0.5)
>>> vel_task = VelocityLimitTask(robot=robot, dt=0.1, weight=1.0)
>>> # Residual should be positive if velocity exceeds limits
Parameters
robotOptional[Robot]= None
dtUnion[float, Context]= 1.0
prev_state_varOptional[Union[RobotState, Context]]= None
velocity_limitsOptional[Union[np.ndarray, Context]]= None
weightOptional[Union[float, Sequence[float]]]= None
namestr= ''
Members
attributeinherited from Task[source]
VelocityLimitTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
VelocityLimitTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
VelocityLimitTask.var_key: Enum = VarKey.ROBOT
propertyinherited from Task[source]
VelocityLimitTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
VelocityLimitTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
VelocityLimitTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
VelocityLimitTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
VelocityLimitTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
VelocityLimitTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
VelocityLimitTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
VelocityLimitTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
methodinherited from ResidualTask[source]
VelocityLimitTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
VelocityLimitTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attribute[source]
VelocityLimitTask.robot: Optional[Robot]
method[source]
VelocityLimitTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build from the robot; a previous state from the helper is its buffer, read directly.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
VelocityLimitTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
method[source]
VelocityLimitTask.set_weight(
weight: Union[float, Sequence[float]]
)

Update residual weights in-place. Accepts a scalar or per-joint sequence.

Parameters
weightUnion[float, Sequence[float]]required
method[source]
VelocityLimitTask.set_prev_state(
prev_state: RobotState
)
Parameters
prev_stateRobotStaterequired
method[source]
VelocityLimitTask.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
property[source]
VelocityLimitTask.residual_dim: int
method[source]
VelocityLimitTask.compute_weighted_residual(
var_values: VarValues,
prev_state_var: Optional[Union[RobotState, Context]] = None,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
prev_state_varOptional[Union[RobotState, Context]]= None
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
VelocityLimitTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
prev_state_var: Optional[Union[RobotState, Context]] = None,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
prev_state_varOptional[Union[RobotState, Context]]= None
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.SceneCollisionTask(
robot: Optional[Robot] = None,
scene: Optional[Union[WarpScene, Context]] = None,
geometry: Optional[BaseGeom] = None,
scene_indices: Optional[Union[wp.array, Context]] = None,
use_link_bounding_sphere_filter: bool = False,
weight: Union[float, Sequence[float]] = 1.0,
margin: Optional[float] = 0.02,
sphere_indices: Optional[Sequence[int]] = None,
residual_mode: Literal['abs', 'sqrt_abs'] = 'abs',
residual_eps: float = 1e-06,
penalty: Literal['smooth', 'plain', 'surface_distance'] = 'smooth',
skip_trajectory_endpoints: bool = True,
movable_only: bool = False,
name: str = ''
)
Bases: RobotTask, ResidualTask, GradientTask

Penalize robot collision spheres that approach scene geometry.

Parameters
robotOptional[Robot]= None
sceneOptional[Union[WarpScene, Context]]= None
geometryOptional[BaseGeom]= None
scene_indicesOptional[Union[wp.array, Context]]= None
use_link_bounding_sphere_filterbool= False
weightUnion[float, Sequence[float]]= 1.0
marginOptional[float]= 0.02
sphere_indicesOptional[Sequence[int]]= None
residual_modeLiteral['abs', 'sqrt_abs']= 'abs'
residual_epsfloat= 1e-06
penaltyLiteral['smooth', 'plain', 'surface_distance']= 'smooth'
skip_trajectory_endpointsbool= True
movable_onlybool= False
namestr= ''
Members
attributeinherited from Task[source]
SceneCollisionTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
SceneCollisionTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
SceneCollisionTask.var_key: Enum
propertyinherited from Task[source]
SceneCollisionTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from RobotTask[source]
SceneCollisionTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap placeholders, then take the robot of the state this task reads.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
SceneCollisionTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
SceneCollisionTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
SceneCollisionTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
SceneCollisionTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
SceneCollisionTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
SceneCollisionTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
SceneCollisionTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
attributeinherited from ResidualTask[source]
SceneCollisionTask.device: Any = None

Device of the task's Warp buffers; None before init_buffers.

methodinherited from ResidualTask[source]
SceneCollisionTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
SceneCollisionTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
SceneCollisionTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

property[source]
SceneCollisionTask.active: bool

Whether the term adds cost: nonzero weight and a scene with geometry, or a helper's scene to come.

method[source]
SceneCollisionTask.set_robot(
robot: Robot
)

Build a config-time stub, with fresh query buffers.

Parameters
robotRobotrequired
method[source]
SceneCollisionTask.set_scene_indices(
scene_indices: wp.array
)

Copy a per-query device scene mapping into stable query buffers.

Parameters
scene_indiceswp.arrayrequired
property[source]
SceneCollisionTask.residual_dim: int
method[source]
SceneCollisionTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
SceneCollisionTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
SceneCollisionTask.compute_weighted_cost_and_gradient(
var_values: VarValues,
out_cost: wp.array,
out_gradient: Optional[wp.array] = None,
cost_form: Literal['squared_sum', 'sum_squared'] = 'squared_sum'
)

Compute collision cost and optional direct gradient.

Lifecycle

  1. Prepare trajectory-shaped collision buffers and kinematics.
  2. Query the scene SDF for every selected sphere.
  3. Accumulate the selected cost form and optional gradient.
Parameters
var_valuesVarValuesrequired
out_costwp.arrayrequired
out_gradientOptional[wp.array]= None
cost_formLiteral['squared_sum', 'sum_squared']= 'squared_sum'
robokit.terms.SceneDistanceTask(
robot: Optional[Robot] = None,
warp_meshes: Optional[WarpScene] = None,
num_contact_points: int = 0,
weight: Optional[Union[float, Sequence[float]]] = None,
residual_mode: Literal['abs', 'sqrt_abs'] = 'abs',
residual_eps: float = 1e-06,
points_var_key: Optional[Enum] = None,
local_contact_points: Optional[wp.array] = None,
contact_points_link_indices: Optional[wp.array] = None
)
Bases: RobotTask, ResidualTask, GradientTask

Minimize hand contact-point distance to a scene surface.

Parameters
robotOptional[Robot]= None
warp_meshesOptional[WarpScene]= None
num_contact_pointsint= 0
weightOptional[Union[float, Sequence[float]]]= None
residual_modeLiteral['abs', 'sqrt_abs']= 'abs'
residual_epsfloat= 1e-06
points_var_keyOptional[Enum]= None
local_contact_pointsOptional[wp.array]= None
contact_points_link_indicesOptional[wp.array]= None
Members
attributeinherited from Task[source]
SceneDistanceTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
SceneDistanceTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
SceneDistanceTask.var_key: Enum
attributeinherited from Task[source]
SceneDistanceTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

propertyinherited from Task[source]
SceneDistanceTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
SceneDistanceTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from RobotTask[source]
SceneDistanceTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap placeholders, then take the robot of the state this task reads.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
SceneDistanceTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
SceneDistanceTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
SceneDistanceTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
SceneDistanceTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
SceneDistanceTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
SceneDistanceTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
SceneDistanceTask.device: Any = None

Device of the task's Warp buffers; None before init_buffers.

methodinherited from ResidualTask[source]
SceneDistanceTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
SceneDistanceTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
SceneDistanceTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
SceneDistanceTask.precompute_collision_geometry: str = ''
attribute[source]
SceneDistanceTask.residual_weight: Optional[wp.array]
attribute[source]
SceneDistanceTask.last_query: Optional[tuple]
method[source]
SceneDistanceTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
property[source]
SceneDistanceTask.residual_dim: int
method[source]
SceneDistanceTask.compute_weighted_residual(
var_values: VarValues,
local_contact_points: Optional[wp.array] = None,
contact_points_link_indices: Optional[wp.array] = None,
scene_offsets: Optional[wp.array] = None,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
local_contact_pointsOptional[wp.array]= None
contact_points_link_indicesOptional[wp.array]= None
scene_offsetsOptional[wp.array]= None
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
SceneDistanceTask.compute_weighted_cost_and_gradient(
var_values: VarValues,
out_cost: wp.array,
out_gradient: Optional[wp.array] = None,
local_contact_points: Optional[wp.array] = None,
contact_points_link_indices: Optional[wp.array] = None,
scene_offsets: Optional[wp.array] = None,
precomputed_contact_points_world: Optional[wp.array] = None,
precomputed_signed_dists: Optional[wp.array] = None,
precomputed_closest_points: Optional[wp.array] = None,
precomputed_normals: Optional[wp.array] = None
)

Compute cost and optional gradient.

Lifecycle

  1. Transform local contact points or reuse supplied world points.
  2. Query or reuse closest points, signed distances, and normals.
  3. Compute residuals and accumulate cost and Jᵀr.
Parameters
var_valuesVarValuesrequired
out_costwp.arrayrequired
out_gradientOptional[wp.array]= None
local_contact_pointsOptional[wp.array]= None
contact_points_link_indicesOptional[wp.array]= None
scene_offsetsOptional[wp.array]= None
precomputed_contact_points_worldOptional[wp.array]= None
precomputed_signed_distsOptional[wp.array]= None
precomputed_closest_pointsOptional[wp.array]= None
precomputed_normalsOptional[wp.array]= None
method[source]
SceneDistanceTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
local_contact_points: Optional[wp.array] = None,
contact_points_link_indices: Optional[wp.array] = None,
scene_offsets: Optional[wp.array] = None,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
local_contact_pointsOptional[wp.array]= None
contact_points_link_indicesOptional[wp.array]= None
scene_offsetsOptional[wp.array]= None
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.SelfCollisionTask(
robot: Optional[Robot] = None,
weight: float = 1.0,
margin: float = 0.02,
representation: Literal['sphere', 'capsule', 'link_sphere'] = 'sphere',
link_sphere_radius: Union[float, Literal['auto']] = 'auto',
link_sphere_center: Literal['bounding', 'origin'] = 'bounding',
residual_mode: Literal['abs', 'sqrt_abs'] = 'abs',
residual_eps: float = 1e-06,
filter_adjacent_links: bool = True,
max_active_pairs: int = 50,
name: str = ''
)
Bases: RobotTask, ResidualTask, GradientTask

Penalize the most active robot self-collision pairs.

Parameters
robotOptional[Robot]= None
weightfloat= 1.0
marginfloat= 0.02
representationLiteral['sphere', 'capsule', 'link_sphere']= 'sphere'
link_sphere_radiusUnion[float, Literal['auto']]= 'auto'
link_sphere_centerLiteral['bounding', 'origin']= 'bounding'
residual_modeLiteral['abs', 'sqrt_abs']= 'abs'
residual_epsfloat= 1e-06
filter_adjacent_linksbool= True
max_active_pairsint= 50
namestr= ''
Members
attributeinherited from Task[source]
SelfCollisionTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from RobotTask[source]
SelfCollisionTask.var_key: Enum
propertyinherited from Task[source]
SelfCollisionTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
SelfCollisionTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from RobotTask[source]
SelfCollisionTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap placeholders, then take the robot of the state this task reads.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
SelfCollisionTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
SelfCollisionTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
SelfCollisionTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
SelfCollisionTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
SelfCollisionTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
SelfCollisionTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
SelfCollisionTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
attributeinherited from ResidualTask[source]
SelfCollisionTask.device: Any = None

Device of the task's Warp buffers; None before init_buffers.

methodinherited from ResidualTask[source]
SelfCollisionTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
SelfCollisionTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
SelfCollisionTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

method[source]
SelfCollisionTask.set_robot(
robot: Robot
)

Build a config-time stub's collision pairs with the configured settings.

Parameters
robotRobotrequired
property[source]
SelfCollisionTask.residual_dim: int
method[source]
SelfCollisionTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array

Compute self-collision residuals.

Lifecycle

  1. Prepare world collision geometry.
  2. Select the most active broad-phase link pairs.
  3. Evaluate the closest sphere or capsule pair for each slot.
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
SelfCollisionTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array

Compute the analytic self-collision Jacobian.

Lifecycle

  1. Prepare kinematics and motion subspaces.
  2. Reuse the residual's active-pair selection when available.
  3. Differentiate the selected sphere or capsule distances.
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
SelfCollisionTask.compute_weighted_cost_and_gradient(
var_values: VarValues,
out_cost: wp.array,
out_gradient: Optional[wp.array] = None
)

Compute fused link-sphere cost and optional gradient.

Lifecycle

  1. Prepare link spheres and motion subspaces.
  2. Allocate a scratch gradient for cost-only evaluations.
  3. Accumulate every active link-pair contribution.
Parameters
var_valuesVarValuesrequired
out_costwp.arrayrequired
out_gradientOptional[wp.array]= None
robokit.terms.SmoothnessTask(
robot: Optional[Robot] = None,
prev_var: Optional[Union[RobotState, Context]] = None,
weight: Union[float, Sequence[float]] = 1.0,
base_weight: Optional[Union[float, Sequence[float]]] = None,
name: str = '',
warmup_frames: int = 0,
frame: Optional[Union[wp.array, Context]] = None
)
Bases: ResidualTask, GradientTask

Penalize change from a previous joint and optional base state.

Example

python
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> from robokit.opt.var_values import VarKey
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("panda_description"))
>>> state_prev = robot.state(q=robot.spec.zero_q)
>>> state_curr = robot.state(q=robot.spec.zero_q + 0.1)
>>> smooth_task = SmoothnessTask(robot=robot, weight=0.5)
>>> values = VarValues({VarKey.ROBOT: state_curr})
>>> cost = wp.zeros(1, device=state_curr.q.device)
>>> gradient = wp.zeros((1, state_curr.tangent_dim), device=state_curr.q.device)
>>> smooth_task.compute_weighted_cost_and_gradient(values, state_prev, out_cost=cost, out_gradient=gradient)
>>> np.allclose(gradient.numpy(), 0.025)
True
Parameters
robotOptional[Robot]= None
prev_varOptional[Union[RobotState, Context]]= None
weightUnion[float, Sequence[float]]= 1.0
base_weightOptional[Union[float, Sequence[float]]]= None
namestr= ''
warmup_framesint= 0
frameOptional[Union[wp.array, Context]]= None
Members
attributeinherited from Task[source]
SmoothnessTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
SmoothnessTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
SmoothnessTask.var_key: Enum = VarKey.ROBOT
propertyinherited from Task[source]
SmoothnessTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
SmoothnessTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
SmoothnessTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
SmoothnessTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
SmoothnessTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
SmoothnessTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
SmoothnessTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
methodinherited from ResidualTask[source]
SmoothnessTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
SmoothnessTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attribute[source]
SmoothnessTask.robot: Optional[Robot]
property[source]
SmoothnessTask.active: bool
method[source]
SmoothnessTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build from the robot; a previous state from the helper is its buffer, read directly.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
SmoothnessTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
method[source]
SmoothnessTask.set_weight(
weight: Union[float, Sequence[float]]
)

Update joint-block residual weights in-place. Base-block weights are preserved.

Parameters
weightUnion[float, Sequence[float]]required
method[source]
SmoothnessTask.set_prev_state(
prev_state: RobotState
)
Parameters
prev_stateRobotStaterequired
method[source]
SmoothnessTask.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
property[source]
SmoothnessTask.residual_dim: int
method[source]
SmoothnessTask.compute_weighted_cost_and_gradient(
var_values: VarValues,
prev_var: Optional[RobotState] = None,
out_cost: wp.array,
out_gradient: Optional[wp.array] = None
)

Accumulate half the squared residual norm and its direct gradient.

Parameters
var_valuesVarValuesrequired
prev_varOptional[RobotState]= None
out_costwp.arrayrequired
out_gradientOptional[wp.array]= None
method[source]
SmoothnessTask.compute_weighted_residual(
var_values: VarValues,
prev_var: Optional[RobotState] = None,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
prev_varOptional[RobotState]= None
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
SmoothnessTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
prev_var: Optional[RobotState] = None,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
prev_varOptional[RobotState]= None
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.ConfigurationTask(
robot: Optional[Robot] = None,
rest_q: Optional[Union[np.ndarray, wp.array, Literal['midrange'], Context]] = None,
T_world_base_rest: Optional[Union[wp.array, np.ndarray, Context]] = None,
weight: Union[float, Sequence[float], np.ndarray] = 1.0,
base_weight: Optional[Union[float, Sequence[float], np.ndarray]] = None,
include_joints: bool = True,
var_key: Enum = VarKey.ROBOT,
name: str = '',
mask: Optional[Union[np.ndarray, Context]] = None
)
Bases: ResidualTask

Bias joints/base toward rest; `rest_q="midrange"` uses joint-limit midpoints as the rest state.

Supported variables:

  • RobotState: joints and optional floating base.
  • VectorVar: joint-only block, sized by rest_q with no robot.
  • SE3Var: pose-only block, including model-offset regularization.

Example

python
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> from robokit.opt.var_values import VarKey, VarValues
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("panda_description"))
>>> rest_q = robot.spec.midrange_q
>>> configuration_task = ConfigurationTask(robot=robot, rest_q=rest_q, weight=0.1)
>>> q_init = wp.from_numpy(rest_q + 0.1, dtype=wp.float32)
>>> state = robot.state(q=q_init)
>>> residual = configuration_task.compute_weighted_residual(VarValues({VarKey.ROBOT: state}))
>>> # Residual should be ~0.1 * weight
Parameters
robotOptional[Robot]= None
rest_qOptional[Union[np.ndarray, wp.array, Literal['midrange'], Context]]= None
T_world_base_restOptional[Union[wp.array, np.ndarray, Context]]= None
weightUnion[float, Sequence[float], np.ndarray]= 1.0
base_weightOptional[Union[float, Sequence[float], np.ndarray]]= None
include_jointsbool= True
var_keyEnum= VarKey.ROBOT
namestr= ''
maskOptional[Union[np.ndarray, Context]]= None
Members
attributeinherited from Task[source]
ConfigurationTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
ConfigurationTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

propertyinherited from Task[source]
ConfigurationTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
ConfigurationTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
ConfigurationTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
ConfigurationTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
ConfigurationTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
ConfigurationTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
ConfigurationTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
methodinherited from ResidualTask[source]
ConfigurationTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
ConfigurationTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attribute[source]
ConfigurationTask.rest_q_arg: Optional[Union[np.ndarray, wp.array, Literal['midrange'], Context]]
attribute[source]
ConfigurationTask.T_world_base_rest: Optional[wp.array]
attribute[source]
ConfigurationTask.robot: Optional[Robot]
property[source]
ConfigurationTask.active: bool
method[source]
ConfigurationTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build from the robot; Warp rest values from the helper are its buffers, read directly.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
ConfigurationTask.set_robot(
robot: Optional[Robot] = None
)
Parameters
robotOptional[Robot]= None
method[source]
ConfigurationTask.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
method[source]
ConfigurationTask.set_weight(
weight: Union[float, Sequence[float]]
)

Update joint-block residual weights in-place. Base-block weights are preserved.

Parameters
weightUnion[float, Sequence[float]]required
method[source]
ConfigurationTask.set_target(
rest_q: Optional[Union[wp.array, np.ndarray]] = None,
T_world_base_rest: Optional[Union[wp.array, np.ndarray]] = None
)

Update the rest references; a config-time stub keeps NumPy references until its buffers are built.

Parameters
rest_qOptional[Union[wp.array, np.ndarray]]= None
T_world_base_restOptional[Union[wp.array, np.ndarray]]= None
property[source]
ConfigurationTask.residual_dim: int
method[source]
ConfigurationTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
ConfigurationTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.ManipulabilityTask(
robot: Optional[Robot] = None,
frame_index: Optional[Union[int, Context]] = None,
weight: float = 0.01,
epsilon: float = 1e-06
)
Bases: RobotTask, ResidualTask

Maximize Yoshikawa sqrt(det(J @ J.T)) at frame_index, using the end-effector translational Jacobian.

Analytic derivative columns:

  • Fixed-base joints: computed normally.
  • Floating base: left zero.

Example

python
>>> import numpy as np
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> from robokit.opt.var_values import VarKey, VarValues
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("ur10_description"))
>>> frame_index = robot.spec.link_names.index("ee_link")
>>> random_q = wp.from_numpy(
...     np.array([[-0.5, 0.3, -0.2, 0.4, -0.1, 0.25]], dtype=np.float32), dtype=wp.float32
... )
>>> state = robot.state(q=random_q)
>>> task = ManipulabilityTask(robot, frame_index, weight=0.01)
>>> task.compute_weighted_residual(VarValues({VarKey.ROBOT: state})).numpy().shape[1] == 1
True
>>> task.compute_weighted_jacobian(VarValues({VarKey.ROBOT: state})).numpy().shape[1] == 1
True
Parameters
robotOptional[Robot]= None
frame_indexOptional[Union[int, Context]]= None
weightfloat= 0.01
epsilonfloat= 1e-06
Members
attributeinherited from Task[source]
ManipulabilityTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
ManipulabilityTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
ManipulabilityTask.var_key: Enum
attributeinherited from Task[source]
ManipulabilityTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

propertyinherited from Task[source]
ManipulabilityTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
ManipulabilityTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from RobotTask[source]
ManipulabilityTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap placeholders, then take the robot of the state this task reads.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
ManipulabilityTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
ManipulabilityTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
ManipulabilityTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
ManipulabilityTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
ManipulabilityTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
ManipulabilityTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
ManipulabilityTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
ManipulabilityTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
ManipulabilityTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
ManipulabilityTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
ManipulabilityTask.precompute_collision_geometry: str = ''
methodinherited from RobotTask[source]
ManipulabilityTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
attribute[source]
ManipulabilityTask.robot: Optional[Robot]
attribute[source]
ManipulabilityTask.weight_wp: Optional[wp.array]
method[source]
ManipulabilityTask.set_weight(
weight: float
)

Update the manipulability weight in-place (live-tunable, CUDA-graph safe).

Parameters
weightfloatrequired
property[source]
ManipulabilityTask.residual_dim: int
method[source]
ManipulabilityTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
ManipulabilityTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.ForceClosureTask(
robot: Optional[Robot] = None,
num_contact_points: int = 0,
warp_meshes: Optional[WarpScene] = None,
weight: Optional[Union[float, Sequence[float]]] = None,
contact_force_weights: Optional[Sequence[float]] = None,
local_contact_points: Optional[wp.array] = None,
contact_points_link_indices: Optional[wp.array] = None,
points_var_key: Optional[Enum] = None,
distance_task: Optional[SceneDistanceTask] = None,
_device: Optional[wp_device_type] = None,
_cached_batch_size: int = 0,
_residual_weight_np: Optional[np.ndarray] = None,
residual_weight: Optional[wp.array] = None,
contact_force_weights_wp: Optional[wp.array] = None,
_signed_dists: Optional[wp.array] = None,
_sdf_query_normals: Optional[wp.array] = None,
_sdf_normals: Optional[wp.array] = None,
_sdf_closest_points: Optional[wp.array] = None,
_normal_jacobians: Optional[wp.array] = None,
_contact_points_world: Optional[wp.array] = None,
_direct_residual_buf: Optional[wp.array] = None
)
Bases: RobotTask, ResidualTask, GradientTask

Force closure task: contacts from var.contact_point_centers_world, normals from the SDF of warp_meshes.

Parameters
robotOptional[Robot]= None
num_contact_pointsint= 0
warp_meshesOptional[WarpScene]= None
weightOptional[Union[float, Sequence[float]]]= None
contact_force_weightsOptional[Sequence[float]]= None
local_contact_pointsOptional[wp.array]= None
contact_points_link_indicesOptional[wp.array]= None
points_var_keyOptional[Enum]= None
distance_taskOptional[SceneDistanceTask]= None
_deviceOptional[wp_device_type]= None
_cached_batch_sizeint= 0
_residual_weight_npOptional[np.ndarray]= None
residual_weightOptional[wp.array]= None
contact_force_weights_wpOptional[wp.array]= None
_signed_distsOptional[wp.array]= None
_sdf_query_normalsOptional[wp.array]= None
_sdf_normalsOptional[wp.array]= None
_sdf_closest_pointsOptional[wp.array]= None
_normal_jacobiansOptional[wp.array]= None
_contact_points_worldOptional[wp.array]= None
_direct_residual_bufOptional[wp.array]= None
Members
attributeinherited from Task[source]
ForceClosureTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
ForceClosureTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
ForceClosureTask.var_key: Enum
attributeinherited from Task[source]
ForceClosureTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

propertyinherited from Task[source]
ForceClosureTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

methodinherited from RobotTask[source]
ForceClosureTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Swap placeholders, then take the robot of the state this task reads.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
methodinherited from Task[source]
ForceClosureTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
ForceClosureTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
ForceClosureTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
ForceClosureTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
ForceClosureTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
ForceClosureTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
ForceClosureTask.device: Any = None

Device of the task's Warp buffers; None before init_buffers.

methodinherited from ResidualTask[source]
ForceClosureTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
ForceClosureTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
ForceClosureTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
ForceClosureTask.precompute_collision_geometry: str = ''
attribute[source]
ForceClosureTask.robot: Optional[Robot] = None
attribute[source]
ForceClosureTask.num_contact_points: int = 0
attribute[source]
ForceClosureTask.warp_meshes: Optional[WarpScene] = None
attribute[source]
ForceClosureTask.weight: Optional[Union[float, Sequence[float]]] = None
attribute[source]
ForceClosureTask.contact_force_weights: Optional[Sequence[float]] = None
attribute[source]
ForceClosureTask.local_contact_points: Optional[wp.array] = None
attribute[source]
ForceClosureTask.points_var_key: Optional[Enum] = None

Read the contact points from this variable instead of the stored array.

attribute[source]
ForceClosureTask.distance_task: Optional[SceneDistanceTask] = None

A SceneDistanceTask on the same contacts, listed before this term: its scene query serves both.

attribute[source]
ForceClosureTask.residual_weight: Optional[wp.array] = None
attribute[source]
ForceClosureTask.contact_force_weights_wp: Optional[wp.array] = None
property[source]
ForceClosureTask.parallel_safe: bool
method[source]
ForceClosureTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
property[source]
ForceClosureTask.residual_dim: int
method[source]
ForceClosureTask.compute_weighted_residual(
var_values: VarValues,
local_contact_points: Optional[wp.array] = None,
contact_points_link_indices: Optional[wp.array] = None,
scene_offsets: Optional[wp.array] = None,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
local_contact_pointsOptional[wp.array]= None
contact_points_link_indicesOptional[wp.array]= None
scene_offsetsOptional[wp.array]= None
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
ForceClosureTask.compute_weighted_cost_and_gradient(
var_values: VarValues,
out_cost: wp.array,
out_gradient: Optional[wp.array] = None,
local_contact_points: Optional[wp.array] = None,
contact_points_link_indices: Optional[wp.array] = None,
scene_offsets: Optional[wp.array] = None
)
Parameters
var_valuesVarValuesrequired
out_costwp.arrayrequired
out_gradientOptional[wp.array]= None
local_contact_pointsOptional[wp.array]= None
contact_points_link_indicesOptional[wp.array]= None
scene_offsetsOptional[wp.array]= None
method[source]
ForceClosureTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
local_contact_points: Optional[wp.array] = None,
contact_points_link_indices: Optional[wp.array] = None,
scene_offsets: Optional[wp.array] = None,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
local_contact_pointsOptional[wp.array]= None
contact_points_link_indicesOptional[wp.array]= None
scene_offsetsOptional[wp.array]= None
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.InteractionMeshTask(
robot: Optional[Robot] = None,
robot_link_indices: Optional[Union[np.ndarray, Context]] = None,
weight: float = 1.0,
name: str = ''
)
Bases: RobotTask, ResidualTask

Preserve interaction-mesh Laplacian coordinates from human to robot.

Example

python
>>> from robot_descriptions.loaders.yourdfpy import load_robot_description
>>> import numpy as np
>>> from robokit.helpers.humanoid_retargeting import build_interaction_mesh_frame
>>> from robokit.robo.robot import Robot
>>> robot = Robot.load(load_robot_description("panda_description"))
>>> state = robot.state(q=robot.zero_q)
>>> robot.forward_kinematics(state)
>>> links = [robot.link_names.index(n) for n in robot.link_names[1:5]]
>>> P = state.T_world_link.numpy()[0][links, :3]
>>> pts = np.vstack([P, P.mean(0) + np.array([[0.2, 0, 0], [0, 0.2, 0], [0, 0, 0.2]], np.float32)])
>>> task = InteractionMeshTask(robot, np.array(links, dtype=np.int32))
>>> T_world_object = np.array([0, 0, 0, 1, 0, 0, 0], np.float32)
>>> task.set_frame(*build_interaction_mesh_frame(P, pts[len(P):], T_world_object))
>>> task.residual_dim
21
Parameters
robotOptional[Robot]= None

Robot model. May be assigned later by the solver.

robot_link_indicesOptional[Union[np.ndarray, Context]]= None

Robot link for each dynamic vertex.

weightfloat= 1.0

Residual multiplier.

namestr= ''
Members
attributeinherited from Task[source]
InteractionMeshTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
InteractionMeshTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
InteractionMeshTask.var_key: Enum
propertyinherited from Task[source]
InteractionMeshTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
InteractionMeshTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
InteractionMeshTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
InteractionMeshTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
InteractionMeshTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
InteractionMeshTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
InteractionMeshTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
InteractionMeshTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
InteractionMeshTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
InteractionMeshTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
InteractionMeshTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attributeinherited from RobotTask[source]
InteractionMeshTask.precompute_collision_geometry: str = ''
attribute[source]
InteractionMeshTask.robot: Optional[Robot]
attribute[source]
InteractionMeshTask.device: Optional[wp_device_type]
method[source]
InteractionMeshTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
method[source]
InteractionMeshTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build from the robot and the helper's links, the first vertices of every frame.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
property[source]
InteractionMeshTask.residual_dim: int
method[source]
InteractionMeshTask.set_frame(
neighbor_offsets: np.ndarray,
neighbor_indices: np.ndarray,
neighbor_weights: np.ndarray,
reference_vertex_positions: np.ndarray,
target_laplacian: np.ndarray
)

Set adjacency, reference vertices, and target Laplacian for one frame.

Parameters
neighbor_offsetsnp.ndarrayrequired
neighbor_indicesnp.ndarrayrequired
neighbor_weightsnp.ndarrayrequired
reference_vertex_positionsnp.ndarrayrequired
target_laplaciannp.ndarrayrequired
method[source]
InteractionMeshTask.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
method[source]
InteractionMeshTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
method[source]
InteractionMeshTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_jacobianOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.CompositeTask(
tasks: Sequence[ResidualTask],
thresholds: Optional[Sequence[Optional[Union[float, Sequence[float]]]]] = None,
num_candidates: Union[int, Context] = 1
)
Bases: ResidualTask

Concatenate weighted residuals, with optional threshold-based selection scoring.

Modes:

  • Without thresholds: ordinary residual concatenation for optimization.
  • With thresholds: bounded children are constraints; children with None thresholds are scores.

Selection sequence:

  1. Require each constraint's absolute residuals to satisfy scalar, per-row or repeating bounds.
  2. Return score norm for valid rows and infinity otherwise, preserving ordinary squared costs on valid rows.
  3. Count valid rows per num_candidates group in valid_count; use stable selection to preserve ties.

Example

python
>>> from robokit.terms.dense.configuration_task import ConfigurationTask
>>> task = CompositeTask([ConfigurationTask()], thresholds=[None])
>>> task.residual_dim
1
Parameters
tasksSequence[ResidualTask]required
thresholdsOptional[Sequence[Optional[Union[float, Sequence[float]]]]]= None
num_candidatesUnion[int, Context]= 1
Members
attributeinherited from Task[source]
CompositeTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
CompositeTask.var_key: Enum = VarKey.ROBOT
attributeinherited from Task[source]
CompositeTask.name: str = ''

Label a config gave this term, so config.task(name) finds it again.

attributeinherited from Task[source]
CompositeTask.robot: Any = None

The robot a built task reads; None on a template.

attributeinherited from Task[source]
CompositeTask.weight: Any = 1.0
propertyinherited from Task[source]
CompositeTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
CompositeTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
CompositeTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
CompositeTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
CompositeTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
CompositeTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
CompositeTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
CompositeTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
attributeinherited from ResidualTask[source]
CompositeTask.device: Any = None

Device of the task's Warp buffers; None before init_buffers.

methodinherited from ResidualTask[source]
CompositeTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
CompositeTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
CompositeTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
CompositeTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate this term into shared normal-equation buffers.

Lifecycle

  1. Prepare term state and reusable buffers.
  2. Evaluate residuals and, for a build step, the Jacobian.
  3. Reduce into cost, JᵀJ, and Jᵀr.
Parameters
var_valuesVarValuesrequired

Optimization variables.

costswp.arrayrequired

Shared per-batch cost buffer.

JtJOptional[wp.array]= None

Optional shared normal matrix. Omit for a cost-only step.

JtrOptional[wp.array]= None

Optional shared normal-vector buffer. Omit for a cost-only step.

attribute[source]
CompositeTask.valid_count: Optional[wp.array]
method[source]
CompositeTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build a copy of each unbuilt child, dropping one the context empties, and take the candidate count.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
property[source]
CompositeTask.residual_dim: int
method[source]
CompositeTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare every child task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
method[source]
CompositeTask.compute_weighted_residual(
var_values: VarValues,
out_residual: Optional[wp.array] = None,
row_offset: int = 0
) -> wp.array
Parameters
var_valuesVarValuesrequired
out_residualOptional[wp.array]= None
row_offsetint= 0
Returns
wp.array
robokit.terms.TrajectoryPositionTask(
robot: Optional[Robot] = None,
frame_index: Optional[Union[int, Sequence[int], Context]] = None,
target_positions: Optional[Union[np.ndarray, wp.array, Context]] = None,
weight: Union[float, Sequence[float], np.ndarray, Mapping[str, float]] = 1.0,
target_point_indices: Optional[Union[Sequence[int], Context]] = None,
name: str = ''
)
Bases: RobotTask, SparseTask

Align robot-link positions to optionally indexed world-frame points.

Parameters
robotOptional[Robot]= None
frame_indexOptional[Union[int, Sequence[int], Context]]= None
target_positionsOptional[Union[np.ndarray, wp.array, Context]]= None
weightUnion[float, Sequence[float], np.ndarray, Mapping[str, float]]= 1.0
target_point_indicesOptional[Union[Sequence[int], Context]]= None
namestr= ''
Members
attributeinherited from Task[source]
TrajectoryPositionTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
TrajectoryPositionTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
TrajectoryPositionTask.var_key: Enum
propertyinherited from Task[source]
TrajectoryPositionTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
TrajectoryPositionTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
TrajectoryPositionTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
TrajectoryPositionTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
TrajectoryPositionTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
TrajectoryPositionTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
TrajectoryPositionTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
TrajectoryPositionTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
TrajectoryPositionTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
TrajectoryPositionTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from SparseTask[source]
TrajectoryPositionTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate normal equations directly from existing sparse rows.

Parameters
var_valuesVarValuesrequired
costswp.arrayrequired
JtJOptional[wp.array]= None
JtrOptional[wp.array]= None
attributeinherited from SparseTask[source]
TrajectoryPositionTask.use_mask: bool = False
attributeinherited from SparseTask[source]
TrajectoryPositionTask.frame_mask: Optional[wp.array] = None
methodinherited from SparseTask[source]
TrajectoryPositionTask.fill_residual_and_jacobian(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

Write residuals and optional sparse Jacobian values into shared buffers.

Parameters
var_valuesVarValuesrequired

Optimization variables.

out_residualwp.arrayrequired

Shared residual buffer.

row_offsetintrequired

First residual row for this task.

out_jacobianOptional[wp.array]= None

Optional shared sparse-value buffer.

nnz_offsetint= 0

First sparse entry for this task.

methodinherited from SparseTask[source]
TrajectoryPositionTask.set_valid_lengths(
lengths: Union[np.ndarray, wp.array]
)

Set the valid trajectory length for each batch element.

Parameters
lengthsUnion[np.ndarray, wp.array]required

Per-batch valid frame counts.

attributeinherited from RobotTask[source]
TrajectoryPositionTask.precompute_collision_geometry: str = ''
methodinherited from RobotTask[source]
TrajectoryPositionTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
attribute[source]
TrajectoryPositionTask.weights: Optional[wp.array]
attribute[source]
TrajectoryPositionTask.device: Optional[wp_device_type]
attribute[source]
TrajectoryPositionTask.target_positions: Optional[wp.array]
attribute[source]
TrajectoryPositionTask.target_point_indices: Optional[wp.array]
attribute[source]
TrajectoryPositionTask.frame_indices: Optional[wp.array]
attribute[source]
TrajectoryPositionTask.ancestor_dof_indices: Optional[wp.array]
attribute[source]
TrajectoryPositionTask.dof_offsets: Optional[wp.array]
attribute[source]
TrajectoryPositionTask.nnz_starts: Optional[wp.array]
attribute[source]
TrajectoryPositionTask.num_frames: int
property[source]
TrajectoryPositionTask.active: bool
method[source]
TrajectoryPositionTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Fill a template with helper links and targets, reading a Warp target directly; unlisted links weigh zero.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
TrajectoryPositionTask.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
property[source]
TrajectoryPositionTask.residual_dim: int
method[source]
TrajectoryPositionTask.compute_weighted_residual(
var_values: VarValues,
args: object = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsobject= {}
Returns
wp.array
method[source]
TrajectoryPositionTask.compute_sparse_jacobian_pattern(
var_values: VarValues,
args: object = (),
offset: int = 0,
out_row_indices: Optional[wp.array] = None,
out_col_indices: Optional[wp.array] = None,
nnz_offset: int = 0,
kwargs: object = {}
) -> SparsityPattern
Parameters
var_valuesVarValuesrequired
argsobject= ()
offsetint= 0
out_row_indicesOptional[wp.array]= None
out_col_indicesOptional[wp.array]= None
nnz_offsetint= 0
kwargsobject= {}
Returns
SparsityPattern
method[source]
TrajectoryPositionTask.compute_weighted_sparse_jacobian_values(
var_values: VarValues,
args: object = (),
out_jacobian_values: Optional[wp.array] = None,
offset: int = 0,
nnz_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_jacobian_valuesOptional[wp.array]= None
offsetint= 0
nnz_offsetint= 0
kwargsobject= {}
Returns
wp.array
robokit.terms.TrajectoryContactTask(
robot: Optional[Robot] = None,
contact_points: Optional[Union[np.ndarray, wp.array, Context]] = None,
contact_link_indices: Optional[Union[np.ndarray, Sequence[int], Context]] = None,
contact_mask: Optional[Union[np.ndarray, wp.array, Context]] = None,
contact_margin: float = 0.01,
weight: float = 1.0,
local_contact_points: Optional[Union[np.ndarray, wp.array, Context]] = None,
name: str = ''
)
Bases: RobotTask, SparseTask

Keep selected link points within a deadband of trajectory contacts: points, or segments along contact_axes.

Parameters
robotOptional[Robot]= None

Robot with FK support.

contact_pointsOptional[Union[np.ndarray, wp.array, Context]]= None

Shared [T, C, 3] or batched [B, T, C, 3] world targets.

contact_link_indicesOptional[Union[np.ndarray, Sequence[int], Context]]= None

Padded [T, C] robot link indices.

contact_maskOptional[Union[np.ndarray, wp.array, Context]]= None

Shared [T, C] or batched [B, T, C] validity mask.

contact_marginfloat= 0.01

Deadband margin; no penalty when distance is within this threshold.

weightfloat= 1.0

Residual weight.

local_contact_pointsOptional[Union[np.ndarray, wp.array, Context]]= None

Optional link-local points. Defaults to each link origin.

namestr= ''
Members
attributeinherited from Task[source]
TrajectoryContactTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
TrajectoryContactTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
TrajectoryContactTask.var_key: Enum
propertyinherited from Task[source]
TrajectoryContactTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
TrajectoryContactTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
TrajectoryContactTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
TrajectoryContactTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
TrajectoryContactTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
TrajectoryContactTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
TrajectoryContactTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
TrajectoryContactTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
TrajectoryContactTask.init_buffers(
device: wp_device_type
)

Allocate Warp buffers on device; a task without any keeps none.

Parameters
devicewp_device_typerequired
methodinherited from ResidualTask[source]
TrajectoryContactTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
TrajectoryContactTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from SparseTask[source]
TrajectoryContactTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate normal equations directly from existing sparse rows.

Parameters
var_valuesVarValuesrequired
costswp.arrayrequired
JtJOptional[wp.array]= None
JtrOptional[wp.array]= None
attributeinherited from SparseTask[source]
TrajectoryContactTask.use_mask: bool = False
attributeinherited from SparseTask[source]
TrajectoryContactTask.frame_mask: Optional[wp.array] = None
methodinherited from SparseTask[source]
TrajectoryContactTask.fill_residual_and_jacobian(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

Write residuals and optional sparse Jacobian values into shared buffers.

Parameters
var_valuesVarValuesrequired

Optimization variables.

out_residualwp.arrayrequired

Shared residual buffer.

row_offsetintrequired

First residual row for this task.

out_jacobianOptional[wp.array]= None

Optional shared sparse-value buffer.

nnz_offsetint= 0

First sparse entry for this task.

methodinherited from SparseTask[source]
TrajectoryContactTask.set_valid_lengths(
lengths: Union[np.ndarray, wp.array]
)

Set the valid trajectory length for each batch element.

Parameters
lengthsUnion[np.ndarray, wp.array]required

Per-batch valid frame counts.

attributeinherited from RobotTask[source]
TrajectoryContactTask.precompute_collision_geometry: str = ''
methodinherited from RobotTask[source]
TrajectoryContactTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
attribute[source]
TrajectoryContactTask.device: Optional[wp_device_type]
attribute[source]
TrajectoryContactTask.contact_points_wp: Optional[wp.array]
attribute[source]
TrajectoryContactTask.local_contact_points_wp: Optional[wp.array]
attribute[source]
TrajectoryContactTask.contact_axes_wp: Optional[wp.array]
attribute[source]
TrajectoryContactTask.contact_mask_wp: Optional[wp.array]
attribute[source]
TrajectoryContactTask.max_ancestor_dofs: int
property[source]
TrajectoryContactTask.active: bool
method[source]
TrajectoryContactTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build from the helper's contact links; its Warp contact buffers are read directly.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
TrajectoryContactTask.set_contacts(
contact_points: wp.array,
contact_mask: wp.array,
local_contact_points: Optional[wp.array] = None,
contact_axes: Optional[wp.array] = None
)

Copy batched runtime contact data into graph-stable device buffers; omitted points and axes are zero. A nonzero axis makes its contact the segment from the point along it: the link point may sit anywhere on it, e.g. a straight move at its own pace.

Parameters
contact_pointswp.arrayrequired
contact_maskwp.arrayrequired
local_contact_pointsOptional[wp.array]= None
contact_axesOptional[wp.array]= None
property[source]
TrajectoryContactTask.residual_dim: int
method[source]
TrajectoryContactTask.compute_weighted_residual(
var_values: VarValues,
args: object = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsobject= {}
Returns
wp.array
method[source]
TrajectoryContactTask.compute_sparse_jacobian_pattern(
var_values: VarValues,
args: object = (),
offset: int = 0,
out_row_indices: Optional[wp.array] = None,
out_col_indices: Optional[wp.array] = None,
nnz_offset: int = 0,
kwargs: object = {}
) -> SparsityPattern
Parameters
var_valuesVarValuesrequired
argsobject= ()
offsetint= 0
out_row_indicesOptional[wp.array]= None
out_col_indicesOptional[wp.array]= None
nnz_offsetint= 0
kwargsobject= {}
Returns
SparsityPattern
method[source]
TrajectoryContactTask.compute_weighted_sparse_jacobian_values(
var_values: VarValues,
args: object = (),
out_jacobian_values: Optional[wp.array] = None,
offset: int = 0,
nnz_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_jacobian_valuesOptional[wp.array]= None
offsetint= 0
nnz_offsetint= 0
kwargsobject= {}
Returns
wp.array
robokit.terms.TrajectoryCollisionTask(
robot: Optional[Robot] = None,
scene: Optional[Union[WarpScene, Context]] = None,
num_frames: Optional[int] = None,
weight: Union[float, Sequence[float]] = 20.0,
margin: Union[float, Sequence[float], np.ndarray] = 0.1,
max_dist: float = 1000000.0,
sphere_indices: Optional[Union[Sequence[int], np.ndarray, Context]] = None,
scene_indices: Optional[Union[wp.array, Context]] = None,
active_actuated_indices: Optional[Union[Sequence[int], np.ndarray]] = None,
sweep_steps: int = 0,
penalty: Literal['smooth', 'plain', 'surface_distance'] = 'plain',
geometry: Optional[BaseGeom] = None,
frame_sphere_mask: Optional[Union[np.ndarray, wp.array, Context]] = None,
speed_dt: Optional[Union[wp.array, Context]] = None,
free_goal_frame: bool = False,
name: str = '',
goal_radius: float = 0.0,
goal_distance: Optional[Union[wp.array, Context]] = None
)
Bases: RobotTask, SparseTask, GradientTask

Evaluate trajectory-sphere costs against geometry, else every scene geometry; one row block per geometry.

Swept-segment evaluation:

  1. Linearly interpolate sphere centers at sweep_steps samples between waypoints.
  2. Differentiate the largest residual through both endpoints.
  3. Include the final segment even if free_goal_frame disables the standalone goal waypoint.
Parameters
robotOptional[Robot]= None
sceneOptional[Union[WarpScene, Context]]= None
num_framesOptional[int]= None
weightUnion[float, Sequence[float]]= 20.0
marginUnion[float, Sequence[float], np.ndarray]= 0.1
max_distfloat= 1000000.0
sphere_indicesOptional[Union[Sequence[int], np.ndarray, Context]]= None
scene_indicesOptional[Union[wp.array, Context]]= None
active_actuated_indicesOptional[Union[Sequence[int], np.ndarray]]= None
sweep_stepsint= 0
penaltyLiteral['smooth', 'plain', 'surface_distance']= 'plain'
geometryOptional[BaseGeom]= None
frame_sphere_maskOptional[Union[np.ndarray, wp.array, Context]]= None
speed_dtOptional[Union[wp.array, Context]]= None
free_goal_framebool= False
namestr= ''
goal_radiusfloat= 0.0
goal_distanceOptional[Union[wp.array, Context]]= None
Members
attributeinherited from Task[source]
TrajectoryCollisionTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
TrajectoryCollisionTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
TrajectoryCollisionTask.var_key: Enum
attributeinherited from RobotTask[source]
TrajectoryCollisionTask.robot: Optional[Robot]
attributeinherited from Task[source]
TrajectoryCollisionTask.weight: Any = 1.0
propertyinherited from Task[source]
TrajectoryCollisionTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
TrajectoryCollisionTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
TrajectoryCollisionTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
TrajectoryCollisionTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
TrajectoryCollisionTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
TrajectoryCollisionTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
TrajectoryCollisionTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
methodinherited from ResidualTask[source]
TrajectoryCollisionTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
TrajectoryCollisionTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from SparseTask[source]
TrajectoryCollisionTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate normal equations directly from existing sparse rows.

Parameters
var_valuesVarValuesrequired
costswp.arrayrequired
JtJOptional[wp.array]= None
JtrOptional[wp.array]= None
attributeinherited from SparseTask[source]
TrajectoryCollisionTask.use_mask: bool = False
attributeinherited from SparseTask[source]
TrajectoryCollisionTask.frame_mask: Optional[wp.array] = None
methodinherited from SparseTask[source]
TrajectoryCollisionTask.set_valid_lengths(
lengths: Union[np.ndarray, wp.array]
)

Set the valid trajectory length for each batch element.

Parameters
lengthsUnion[np.ndarray, wp.array]required

Per-batch valid frame counts.

attributeinherited from RobotTask[source]
TrajectoryCollisionTask.precompute_collision_geometry: str = ''
methodinherited from RobotTask[source]
TrajectoryCollisionTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
attribute[source]
TrajectoryCollisionTask.device: Optional[wp_device_type]
attribute[source]
TrajectoryCollisionTask.frame_sphere_mask: Optional[wp.array]
property[source]
TrajectoryCollisionTask.active: bool

Whether the term adds cost: nonzero weight, a scene, and at least one selected sphere.

method[source]
TrajectoryCollisionTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build for the robot and horizon in var_values, sharing a Warp frame_sphere_mask, unless inactive.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
TrajectoryCollisionTask.init_buffers(
device: wp_device_type
)

Build stable scene/sparsity parameters; query caches grow on first use.

Lifecycle

  1. Upload selected sphere and actuated-column indices.
  2. Build the actuated-column joint CSR mapping.
  3. Allocate scene/margin arrays and invalidate lazy query caches.
Parameters
devicewp_device_typerequired
method[source]
TrajectoryCollisionTask.accumulate_max_penetration(
out: wp.array
)

Max-accumulate penetration from the most recent Jacobian query cache, over every geometry.

Runs over the batch the cache holds: out may be longer (a score task sized for every draw).

Parameters
outwp.arrayrequired
method[source]
TrajectoryCollisionTask.set_frame_sphere_mask(
frame_sphere_mask: wp.array
)

Set the active (batch, frame, selected sphere) collision rows.

Parameters
frame_sphere_maskwp.arrayrequired
property[source]
TrajectoryCollisionTask.residual_dim: int

One block of rows per geometry; an empty scene keeps one block of zeros.

method[source]
TrajectoryCollisionTask.set_scene_indices(
scene_indices: wp.array
)

Set scenes shaped (batch,) or per-frame scenes shaped (batch, frames).

Parameters
scene_indiceswp.arrayrequired
method[source]
TrajectoryCollisionTask.compute_weighted_cost_and_gradient(
var_values: VarValues,
args: object = (),
out_cost: wp.array,
out_gradient: Optional[wp.array] = None,
kwargs: object = {}
)

Compute sparse cost and optional gradient with one scene query.

Lifecycle

  1. Use the base cost-only path when no gradient is requested.
  2. Compute Jacobian values and cache their scene query.
  3. Rebuild residuals from the cache and reduce cost and gradient.
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_costwp.arrayrequired
out_gradientOptional[wp.array]= None
kwargsobject= {}
method[source]
TrajectoryCollisionTask.fill_residual_and_jacobian(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

Fill residuals and sparse values from one shared scene query.

Parameters
var_valuesVarValuesrequired
out_residualwp.arrayrequired
row_offsetintrequired
out_jacobianOptional[wp.array]= None
nnz_offsetint= 0
method[source]
TrajectoryCollisionTask.compute_weighted_residual(
var_values: VarValues,
args: object = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: object = {}
) -> wp.array

Compute trajectory collision residuals.

Lifecycle

  1. Prepare forward kinematics and stable runtime buffers.
  2. Run each geometry's primitive, mesh, volume, or hybrid query kernel.
  3. Evaluate every frame and selected sphere.
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsobject= {}
Returns
wp.array
method[source]
TrajectoryCollisionTask.compute_sparse_jacobian_pattern(
var_values: VarValues,
args: object = (),
offset: int = 0,
out_row_indices: Optional[wp.array] = None,
out_col_indices: Optional[wp.array] = None,
nnz_offset: int = 0,
kwargs: object = {}
) -> SparsityPattern
Parameters
var_valuesVarValuesrequired
argsobject= ()
offsetint= 0
out_row_indicesOptional[wp.array]= None
out_col_indicesOptional[wp.array]= None
nnz_offsetint= 0
kwargsobject= {}
Returns
SparsityPattern
method[source]
TrajectoryCollisionTask.compute_weighted_sparse_jacobian_values(
var_values: VarValues,
args: object = (),
out_jacobian_values: Optional[wp.array] = None,
offset: int = 0,
nnz_offset: int = 0,
query_penetration: bool = True,
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: object = {}
) -> wp.array

Compute sparse trajectory collision Jacobian values.

Lifecycle

  1. Prepare kinematics, motion subspaces, and runtime-sized caches.
  2. Query each geometry and cache its sphere centers and SDF normals.
  3. Assemble active joint and optional floating-base columns.
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_jacobian_valuesOptional[wp.array]= None
offsetint= 0
nnz_offsetint= 0
query_penetrationbool= True
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsobject= {}
Returns
wp.array
robokit.terms.TrajectorySelfCollisionTask(
robot: Optional[Robot] = None,
num_frames: Optional[int] = None,
weight: float = 10.0,
margin: float = 0.02,
penalty: Literal['squared', 'max_linear'] = 'squared',
name: str = ''
)
Bases: RobotTask, SparseTask, GradientTask

Penalize self-collisions between robot collision spheres at all frames.

Parameters
robotOptional[Robot]= None
num_framesOptional[int]= None
weightfloat= 10.0
marginfloat= 0.02
penaltyLiteral['squared', 'max_linear']= 'squared'
namestr= ''
Members
attributeinherited from Task[source]
TrajectorySelfCollisionTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
TrajectorySelfCollisionTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
TrajectorySelfCollisionTask.var_key: Enum
propertyinherited from Task[source]
TrajectorySelfCollisionTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
TrajectorySelfCollisionTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
TrajectorySelfCollisionTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
TrajectorySelfCollisionTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
TrajectorySelfCollisionTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
TrajectorySelfCollisionTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
TrajectorySelfCollisionTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
TrajectorySelfCollisionTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
TrajectorySelfCollisionTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
TrajectorySelfCollisionTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
TrajectorySelfCollisionTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from SparseTask[source]
TrajectorySelfCollisionTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate normal equations directly from existing sparse rows.

Parameters
var_valuesVarValuesrequired
costswp.arrayrequired
JtJOptional[wp.array]= None
JtrOptional[wp.array]= None
attributeinherited from SparseTask[source]
TrajectorySelfCollisionTask.use_mask: bool = False
attributeinherited from SparseTask[source]
TrajectorySelfCollisionTask.frame_mask: Optional[wp.array] = None
methodinherited from SparseTask[source]
TrajectorySelfCollisionTask.fill_residual_and_jacobian(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

Write residuals and optional sparse Jacobian values into shared buffers.

Parameters
var_valuesVarValuesrequired

Optimization variables.

out_residualwp.arrayrequired

Shared residual buffer.

row_offsetintrequired

First residual row for this task.

out_jacobianOptional[wp.array]= None

Optional shared sparse-value buffer.

nnz_offsetint= 0

First sparse entry for this task.

methodinherited from SparseTask[source]
TrajectorySelfCollisionTask.set_valid_lengths(
lengths: Union[np.ndarray, wp.array]
)

Set the valid trajectory length for each batch element.

Parameters
lengthsUnion[np.ndarray, wp.array]required

Per-batch valid frame counts.

methodinherited from RobotTask[source]
TrajectorySelfCollisionTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
attribute[source]
TrajectorySelfCollisionTask.device: Optional[wp_device_type]
attribute[source]
TrajectorySelfCollisionTask.sphere_mask: Optional[wp.array]
attribute[source]
TrajectorySelfCollisionTask.pair_mask: Optional[wp.array]
method[source]
TrajectorySelfCollisionTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build from the robot and horizon of the trajectory var_values holds.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
TrajectorySelfCollisionTask.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
property[source]
TrajectorySelfCollisionTask.residual_dim: int
method[source]
TrajectorySelfCollisionTask.compute_weighted_residual(
var_values: VarValues,
args: object = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
out_jacobianOptional[wp.array]= None
nnz_offsetint= 0
kwargsobject= {}
Returns
wp.array
method[source]
TrajectorySelfCollisionTask.compute_sparse_jacobian_pattern(
var_values: VarValues,
args: object = (),
offset: int = 0,
out_row_indices: Optional[wp.array] = None,
out_col_indices: Optional[wp.array] = None,
nnz_offset: int = 0,
kwargs: object = {}
) -> SparsityPattern
Parameters
var_valuesVarValuesrequired
argsobject= ()
offsetint= 0
out_row_indicesOptional[wp.array]= None
out_col_indicesOptional[wp.array]= None
nnz_offsetint= 0
kwargsobject= {}
Returns
SparsityPattern
method[source]
TrajectorySelfCollisionTask.compute_weighted_sparse_jacobian_values(
var_values: VarValues,
args: object = (),
out_jacobian_values: Optional[wp.array] = None,
offset: int = 0,
nnz_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_jacobian_valuesOptional[wp.array]= None
offsetint= 0
nnz_offsetint= 0
kwargsobject= {}
Returns
wp.array
robokit.terms.TrajectorySmoothnessTask(
robot: Optional[Robot] = None,
num_frames: Optional[int] = None,
weight: Union[float, Sequence[float], np.ndarray] = 1.0,
order: int = 1,
dt: Union[float, Context] = 1.0,
reference_q: Optional[Union[np.ndarray, Context]] = None,
base_weight: Optional[Union[float, Sequence[float], np.ndarray]] = None,
smooth_boundary: bool = True,
virtual_hold_frames: Union[int, Context] = 0,
history: Optional[Union[Tuple[wp.array, wp.array], Context]] = None,
name: str = ''
)
Bases: SparseTask, GradientTask

Penalize joint differences and optional floating-base motion.

Configuration options:

  • robot/num_frames omitted: resolve takes them from the trajectory it reads.
  • smooth_boundary=False: disable the first and last finite-difference rows.
  • history: an executed (q_history, history_valid) prefix, e.g. a helper's shared buffers.
Parameters
robotOptional[Robot]= None
num_framesOptional[int]= None
weightUnion[float, Sequence[float], np.ndarray]= 1.0
orderint= 1
dtUnion[float, Context]= 1.0
reference_qOptional[Union[np.ndarray, Context]]= None
base_weightOptional[Union[float, Sequence[float], np.ndarray]]= None
smooth_boundarybool= True
virtual_hold_framesUnion[int, Context]= 0
historyOptional[Union[Tuple[wp.array, wp.array], Context]]= None
namestr= ''
Members
attributeinherited from Task[source]
TrajectorySmoothnessTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
TrajectorySmoothnessTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
TrajectorySmoothnessTask.var_key: Enum = VarKey.ROBOT
propertyinherited from Task[source]
TrajectorySmoothnessTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
TrajectorySmoothnessTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
TrajectorySmoothnessTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
TrajectorySmoothnessTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
TrajectorySmoothnessTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
TrajectorySmoothnessTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
TrajectorySmoothnessTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
methodinherited from ResidualTask[source]
TrajectorySmoothnessTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
TrajectorySmoothnessTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from SparseTask[source]
TrajectorySmoothnessTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate normal equations directly from existing sparse rows.

Parameters
var_valuesVarValuesrequired
costswp.arrayrequired
JtJOptional[wp.array]= None
JtrOptional[wp.array]= None
attributeinherited from SparseTask[source]
TrajectorySmoothnessTask.use_mask: bool = False
attributeinherited from SparseTask[source]
TrajectorySmoothnessTask.frame_mask: Optional[wp.array] = None
methodinherited from SparseTask[source]
TrajectorySmoothnessTask.fill_residual_and_jacobian(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

Write residuals and optional sparse Jacobian values into shared buffers.

Parameters
var_valuesVarValuesrequired

Optimization variables.

out_residualwp.arrayrequired

Shared residual buffer.

row_offsetintrequired

First residual row for this task.

out_jacobianOptional[wp.array]= None

Optional shared sparse-value buffer.

nnz_offsetint= 0

First sparse entry for this task.

methodinherited from SparseTask[source]
TrajectorySmoothnessTask.set_valid_lengths(
lengths: Union[np.ndarray, wp.array]
)

Set the valid trajectory length for each batch element.

Parameters
lengthsUnion[np.ndarray, wp.array]required

Per-batch valid frame counts.

attribute[source]
TrajectorySmoothnessTask.device: Optional[wp_device_type]
attribute[source]
TrajectorySmoothnessTask.residual_weight: Optional[wp.array]
attribute[source]
TrajectorySmoothnessTask.base_residual_weight: Optional[wp.array]
attribute[source]
TrajectorySmoothnessTask.boundary_weight: Optional[wp.array]
attribute[source]
TrajectorySmoothnessTask.coefficients: Optional[wp.array]
attribute[source]
TrajectorySmoothnessTask.q_history: Optional[wp.array]
attribute[source]
TrajectorySmoothnessTask.history_valid: Optional[wp.array]
attribute[source]
TrajectorySmoothnessTask.reference_q: Optional[wp.array]
method[source]
TrajectorySmoothnessTask.compute_paths(
q: np.ndarray,
costs: np.ndarray,
times: np.ndarray,
weight: float = 0.08,
count: int = 1
) -> np.ndarray

Return [K,T,J] paths, preserving alternative initial pose hypotheses; each initial hypothesis retains a distinct branch, and the output contains at most count paths; periodic joints use angular distances and return continuous equivalent angles within supplied limits; if no continuous lift fits the limits, the original bounded path is retained.

python
>>> q = np.array([[[0.], [3.]], [[3.], [0.1]], [[0.2], [3.]]])
>>> TrajectorySmoothnessTask().compute_paths(q, np.array([[0., .1], [.1, 0.], [0., .1]]), np.arange(3.)).ravel().tolist()
[0.0, 0.1, 0.2]
Parameters
qnp.ndarrayrequired
costsnp.ndarrayrequired
timesnp.ndarrayrequired
weightfloat= 0.08
countint= 1
Returns
np.ndarray
method[source]
TrajectorySmoothnessTask.compute_offset_candidates(
q: np.ndarray,
samples: int = 16
) -> np.ndarray

Sample constant joint shifts that preserve every frame's joint limits; full-turn joints need at most one revolution, and extra cubic samples retain small shifts.

Parameters
qnp.ndarrayrequired
samplesint= 16
Returns
np.ndarray
method[source]
TrajectorySmoothnessTask.init_buffers(
device: wp_device_type
)

Build finite-difference weights and history buffers.

Lifecycle

  1. Build joint and optional base weights.
  2. Build the requested difference stencil.
  3. Allocate history and reference trajectories.
Parameters
devicewp_device_typerequired
property[source]
TrajectorySmoothnessTask.active: bool
method[source]
TrajectorySmoothnessTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build from the robot and horizon of the trajectory var_values holds, and the helper's values.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
TrajectorySmoothnessTask.set_history(
q_history: Optional[wp.array],
num_candidates: int,
history_valid: bool
)

Set the fixed executed prefix. No-op at order=1, which never reads it.

Parameters
q_historyOptional[wp.array]required
num_candidatesintrequired
history_validboolrequired
property[source]
TrajectorySmoothnessTask.residual_dim: int
method[source]
TrajectorySmoothnessTask.compute_weighted_residual(
var_values: VarValues,
args: object = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsobject= {}
Returns
wp.array
method[source]
TrajectorySmoothnessTask.compute_sparse_jacobian_pattern(
var_values: VarValues,
args: object = (),
offset: int = 0,
out_row_indices: Optional[wp.array] = None,
out_col_indices: Optional[wp.array] = None,
nnz_offset: int = 0,
kwargs: object = {}
) -> SparsityPattern
Parameters
var_valuesVarValuesrequired
argsobject= ()
offsetint= 0
out_row_indicesOptional[wp.array]= None
out_col_indicesOptional[wp.array]= None
nnz_offsetint= 0
kwargsobject= {}
Returns
SparsityPattern
method[source]
TrajectorySmoothnessTask.compute_weighted_sparse_jacobian_values(
var_values: VarValues,
args: object = (),
out_jacobian_values: Optional[wp.array] = None,
offset: int = 0,
nnz_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_jacobian_valuesOptional[wp.array]= None
offsetint= 0
nnz_offsetint= 0
kwargsobject= {}
Returns
wp.array
robokit.terms.TrajectoryLimitTask(
robot: Optional[Robot] = None,
num_frames: Optional[int] = None,
order: Union[int, Sequence[int]] = 1,
lower: Optional[Union[float, np.ndarray]] = None,
upper: Optional[Union[float, np.ndarray, Tuple[Any, ...], Context]] = None,
weight: Union[float, Sequence[float], np.ndarray] = 1.0,
dt: Union[float, wp.array, Context] = 1.0,
stencil: Literal['central', 'forward'] = 'central',
dt_power: Optional[Sequence[float]] = None,
activation: Sequence[float] = (0.0, 0.0, 0.0, 0.0),
normalize: bool = False,
name: str = ''
)
Bases: SparseTask, GradientTask

Penalize bound violations with `weight * max(lower - derivative, derivative - upper, 0)`.

Derivative orders:

  • 0: position.
  • 1: velocity.
  • 2: acceleration.
  • 3: jerk.

Difference schemes:

  • `central`: retimer's five-point derivatives with held endpoints; multiple orders share one task and launch.
  • `forward`: consecutive finite differences without padded endpoints; one order only.

Broadcast layouts:

  • Bounds/weights: broadcast over joints, with a leading order axis when `order` is a sequence.
  • Scalar dt: shared by all plans.
  • Warp-vector dt: one per plan, repeated in instance-major order for candidate batches.

Time scaling:

  • Default: divide each derivative by dt raised to its order.
  • Explicit `dt_power`: override the exponent per order.
  • `timing = (frame_segment, segments, time_weight): a bound row's step is its plan's exp(VarKey.SEGMENT_STEP)` for its frame's segment, a Jacobian column (zero-width bounds keep `dt); time_weight` > 0 costs each second.

Unbuilt templates (resolve):

  • `upper` may hold one entry per order; unset bounds default to the robot's position and velocity limits.
  • `lower defaults to the robot's lower position limit and to -upper` for derivatives.
  • `activation` keeps that fraction of each range away from both bounds, indexed by order.
  • `normalize` divides the weights by the bounds.

Example

python
>>> task = TrajectoryLimitTask(robot, 33, order=3, lower=-500.0, upper=500.0)  # doctest: +SKIP
Parameters
robotOptional[Robot]= None
num_framesOptional[int]= None
orderUnion[int, Sequence[int]]= 1
lowerOptional[Union[float, np.ndarray]]= None
upperOptional[Union[float, np.ndarray, Tuple[Any, ...], Context]]= None
weightUnion[float, Sequence[float], np.ndarray]= 1.0
dtUnion[float, wp.array, Context]= 1.0
stencilLiteral['central', 'forward']= 'central'
dt_powerOptional[Sequence[float]]= None
activationSequence[float]= (0.0, 0.0, 0.0, 0.0)
normalizebool= False
namestr= ''
Members
attributeinherited from Task[source]
TrajectoryLimitTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
TrajectoryLimitTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from Task[source]
TrajectoryLimitTask.var_key: Enum = VarKey.ROBOT
propertyinherited from Task[source]
TrajectoryLimitTask.active: bool

Whether the term adds cost; helpers skip templates whose weights are all zero (None weighs 1).

propertyinherited from Task[source]
TrajectoryLimitTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
TrajectoryLimitTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
TrajectoryLimitTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
TrajectoryLimitTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
TrajectoryLimitTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from Task[source]
TrajectoryLimitTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare shared state before this term is evaluated.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
TrajectoryLimitTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
methodinherited from ResidualTask[source]
TrajectoryLimitTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
TrajectoryLimitTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from SparseTask[source]
TrajectoryLimitTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate normal equations directly from existing sparse rows.

Parameters
var_valuesVarValuesrequired
costswp.arrayrequired
JtJOptional[wp.array]= None
JtrOptional[wp.array]= None
attributeinherited from SparseTask[source]
TrajectoryLimitTask.use_mask: bool = False
attributeinherited from SparseTask[source]
TrajectoryLimitTask.frame_mask: Optional[wp.array] = None
methodinherited from SparseTask[source]
TrajectoryLimitTask.set_valid_lengths(
lengths: Union[np.ndarray, wp.array]
)

Set the valid trajectory length for each batch element.

Parameters
lengthsUnion[np.ndarray, wp.array]required

Per-batch valid frame counts.

attribute[source]
TrajectoryLimitTask.device: Optional[wp_device_type]
attribute[source]
TrajectoryLimitTask.timing: Optional[Tuple[wp.array, int, float]]
method[source]
TrajectoryLimitTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build a template's robot, horizon, step and bounds from the trajectory var_values holds.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
TrajectoryLimitTask.fuse(
tasks: Sequence[Any],
dt: Any,
keep: Sequence[Any] = ()
) -> List[Any]

Fuse central bounds at dt and all-frame abs position limits into one launch, skipping tasks in keep.

Parameters
tasksSequence[Any]required
dtAnyrequired
keepSequence[Any]= ()
Returns
List[Any]
method[source]
TrajectoryLimitTask.init_buffers(
device: wp_device_type
)
Parameters
devicewp_device_typerequired
method[source]
TrajectoryLimitTask.set_dt(
dt: Union[float, wp.array]
)

Set a positive scalar time step or a float32 Warp vector with one entry per plan.

Parameters
dtUnion[float, wp.array]required
property[source]
TrajectoryLimitTask.residual_dim: int
method[source]
TrajectoryLimitTask.compute_weighted_residual(
var_values: VarValues,
args: object = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsobject= {}
Returns
wp.array
method[source]
TrajectoryLimitTask.fill_residual_and_jacobian(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

Write the residual and, when asked, the Jacobian values in one launch.

Parameters
var_valuesVarValuesrequired
out_residualwp.arrayrequired
row_offsetintrequired
out_jacobianOptional[wp.array]= None
nnz_offsetint= 0
method[source]
TrajectoryLimitTask.compute_sparse_jacobian_pattern(
var_values: VarValues,
args: object = (),
offset: int = 0,
out_row_indices: Optional[wp.array] = None,
out_col_indices: Optional[wp.array] = None,
nnz_offset: int = 0,
kwargs: object = {}
) -> SparsityPattern
Parameters
var_valuesVarValuesrequired
argsobject= ()
offsetint= 0
out_row_indicesOptional[wp.array]= None
out_col_indicesOptional[wp.array]= None
nnz_offsetint= 0
kwargsobject= {}
Returns
SparsityPattern
method[source]
TrajectoryLimitTask.compute_weighted_sparse_jacobian_values(
var_values: VarValues,
args: object = (),
out_jacobian_values: Optional[wp.array] = None,
offset: int = 0,
nnz_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_jacobian_valuesOptional[wp.array]= None
offsetint= 0
nnz_offsetint= 0
kwargsobject= {}
Returns
wp.array
robokit.terms.TrajectoryRetargetingTask(
robot: Optional[Robot] = None,
target_keypoints: Optional[Union[np.ndarray, wp.array, Context]] = None,
robot_link_indices: Optional[Union[List[int], Context]] = None,
target_joint_indices: Optional[Union[List[int], Context]] = None,
pair_indices: Optional[Union[Sequence[Sequence[int]], np.ndarray, Context]] = None,
position_weight: float = 1.0,
angle_weight: float = 1.0,
target_scale: Union[float, wp.array, Context] = 1.0,
name: str = ''
)
Bases: RobotTask, SparseTask

Pairwise position and direction residuals for trajectory retargeting.

Parameters
robotOptional[Robot]= None
target_keypointsOptional[Union[np.ndarray, wp.array, Context]]= None
robot_link_indicesOptional[Union[List[int], Context]]= None
target_joint_indicesOptional[Union[List[int], Context]]= None
pair_indicesOptional[Union[Sequence[Sequence[int]], np.ndarray, Context]]= None
position_weightfloat= 1.0
angle_weightfloat= 1.0
target_scaleUnion[float, wp.array, Context]= 1.0
namestr= ''
Members
attributeinherited from Task[source]
TrajectoryRetargetingTask.SUPPORTS_CUDA_GRAPH: bool = True
attributeinherited from Task[source]
TrajectoryRetargetingTask.SUPPORTS_AUTODIFF: bool = True

False when the residual kernels have no usable tape adjoint; autodiff then folds in the analytic JᵀR.

attributeinherited from RobotTask[source]
TrajectoryRetargetingTask.var_key: Enum
attributeinherited from Task[source]
TrajectoryRetargetingTask.weight: Any = 1.0
propertyinherited from Task[source]
TrajectoryRetargetingTask.parallel_safe: bool

Whether the term may run on its own CUDA stream; one that reads another term's results runs all in order.

methodinherited from Task[source]
TrajectoryRetargetingTask.initial_vars(
num_candidates: int,
device: Any
) -> Dict[Enum, Var]

Variables this task adds beside the helper's, at their nominal values; usually none.

Parameters
num_candidatesintrequired
deviceAnyrequired
Returns
Dict[Enum, Var]
methodinherited from Task[source]
TrajectoryRetargetingTask.needs() -> set

Return the Context members a template reads, including those of the tasks it wraps.

Example

python
>>> class Inputs(Context):
...     STEP = 0
>>> class Step(Task):
...     def __init__(self, dt):
...         self.dt = dt
>>> Step(dt=(Inputs.STEP, 2.0)).needs() == {Inputs.STEP}
True
Returns
set
propertyinherited from Task[source]
TrajectoryRetargetingTask.cost_name: str

Return the snake-case task name used in cost reports.

propertyinherited from Task[source]
TrajectoryRetargetingTask.dense_task: Task

Return the per-pose task this term applies, which is the term itself unless it wraps one.

methodinherited from RobotTask[source]
TrajectoryRetargetingTask.precompute(
var_values: VarValues,
need_gradient: bool = False
)

Prepare kinematics and geometry required by the task.

Parameters
var_valuesVarValuesrequired
need_gradientbool= False
methodinherited from Task[source]
TrajectoryRetargetingTask.compute_weighted_cost(
var_values: Optional[VarValues],
out_cost: wp.array
)

Add each row's weighted cost into out_cost, for a term without residuals (a simulated rollout, or one of its per-step costs); PopulationSolver calls it on every term that is not a ResidualTask.

Parameters
var_valuesOptional[VarValues]required
out_costwp.arrayrequired
attributeinherited from ResidualTask[source]
TrajectoryRetargetingTask.residual_weight: Optional[Union[float, Sequence[float], np.ndarray]]
methodinherited from ResidualTask[source]
TrajectoryRetargetingTask.compute_weighted_jacobian_analytic(
var_values: VarValues,
args: Any = (),
out_jacobian: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
out_jacobianOptional[wp.array]= None
row_offsetint= 0
kwargsAny= {}
Returns
wp.array
methodinherited from ResidualTask[source]
TrajectoryRetargetingTask.compute_weighted_jacobian(
var_values: VarValues,
args: Any = (),
kwargs: Any = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsAny= ()
kwargsAny= {}
Returns
wp.array
methodinherited from SparseTask[source]
TrajectoryRetargetingTask.accumulate_normal_equations(
var_values: VarValues,
costs: wp.array,
JtJ: Optional[wp.array] = None,
Jtr: Optional[wp.array] = None
)

Accumulate normal equations directly from existing sparse rows.

Parameters
var_valuesVarValuesrequired
costswp.arrayrequired
JtJOptional[wp.array]= None
JtrOptional[wp.array]= None
attributeinherited from SparseTask[source]
TrajectoryRetargetingTask.use_mask: bool = False
attributeinherited from SparseTask[source]
TrajectoryRetargetingTask.frame_mask: Optional[wp.array] = None
methodinherited from SparseTask[source]
TrajectoryRetargetingTask.fill_residual_and_jacobian(
var_values: VarValues,
out_residual: wp.array,
row_offset: int,
out_jacobian: Optional[wp.array] = None,
nnz_offset: int = 0
)

Write residuals and optional sparse Jacobian values into shared buffers.

Parameters
var_valuesVarValuesrequired

Optimization variables.

out_residualwp.arrayrequired

Shared residual buffer.

row_offsetintrequired

First residual row for this task.

out_jacobianOptional[wp.array]= None

Optional shared sparse-value buffer.

nnz_offsetint= 0

First sparse entry for this task.

methodinherited from SparseTask[source]
TrajectoryRetargetingTask.set_valid_lengths(
lengths: Union[np.ndarray, wp.array]
)

Set the valid trajectory length for each batch element.

Parameters
lengthsUnion[np.ndarray, wp.array]required

Per-batch valid frame counts.

attributeinherited from RobotTask[source]
TrajectoryRetargetingTask.precompute_collision_geometry: str = ''
methodinherited from RobotTask[source]
TrajectoryRetargetingTask.set_robot(
robot: Robot
)
Parameters
robotRobotrequired
attribute[source]
TrajectoryRetargetingTask.device: Optional[wp_device_type]
attribute[source]
TrajectoryRetargetingTask.target_keypoints: Optional[wp.array]
attribute[source]
TrajectoryRetargetingTask.target_scales: Optional[wp.array]
attribute[source]
TrajectoryRetargetingTask.target_joint_indices: Optional[wp.array]
attribute[source]
TrajectoryRetargetingTask.pair_rows: Optional[wp.array]
attribute[source]
TrajectoryRetargetingTask.pair_cols: Optional[wp.array]
attribute[source]
TrajectoryRetargetingTask.num_unique_dofs: int
attribute[source]
TrajectoryRetargetingTask.all_ancestor_dof_indices: Optional[wp.array]
attribute[source]
TrajectoryRetargetingTask.num_frames: int
property[source]
TrajectoryRetargetingTask.active: bool
method[source]
TrajectoryRetargetingTask.resolve(
var_values: VarValues,
context: Mapping[Context, Any]
)

Build from the helper's points, links, pairs and scales; Warp points and scales are read directly.

Parameters
var_valuesVarValuesrequired
contextMapping[Context, Any]required
method[source]
TrajectoryRetargetingTask.init_buffers(
device: wp_device_type
)

Build target, pair, and sparse ancestor buffers.

Lifecycle

  1. Upload targets and pair indices.
  2. Build selected-link ancestor masks.
  3. Collect the active actuated columns.
Parameters
devicewp_device_typerequired
property[source]
TrajectoryRetargetingTask.residual_dim: int
method[source]
TrajectoryRetargetingTask.compute_weighted_residual(
var_values: VarValues,
args: object = (),
out_residual: Optional[wp.array] = None,
row_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_residualOptional[wp.array]= None
row_offsetint= 0
kwargsobject= {}
Returns
wp.array
method[source]
TrajectoryRetargetingTask.compute_sparse_jacobian_pattern(
var_values: VarValues,
args: object = (),
offset: int = 0,
out_row_indices: Optional[wp.array] = None,
out_col_indices: Optional[wp.array] = None,
nnz_offset: int = 0,
kwargs: object = {}
) -> SparsityPattern
Parameters
var_valuesVarValuesrequired
argsobject= ()
offsetint= 0
out_row_indicesOptional[wp.array]= None
out_col_indicesOptional[wp.array]= None
nnz_offsetint= 0
kwargsobject= {}
Returns
SparsityPattern
method[source]
TrajectoryRetargetingTask.compute_weighted_sparse_jacobian_values(
var_values: VarValues,
args: object = (),
out_jacobian_values: Optional[wp.array] = None,
offset: int = 0,
nnz_offset: int = 0,
kwargs: object = {}
) -> wp.array
Parameters
var_valuesVarValuesrequired
argsobject= ()
out_jacobian_valuesOptional[wp.array]= None
offsetint= 0
nnz_offsetint= 0
kwargsobject= {}
Returns
wp.array