curobo.rollout.cost.bound_cost module

class curobo.rollout.cost.bound_cost.BoundCostType(value)

Bases: Enum

An enumeration.

POSITION = 0
BOUNDS = 1
BOUNDS_SMOOTH = 2
class curobo.rollout.cost.bound_cost.BoundCostConfig(weight: torch.Tensor | float | List[float], tensor_args: curobo.types.base.TensorDeviceType = None, distance_threshold: float = 0.0, classify: bool = False, terminal: bool = False, run_weight: float | None = None, dof: int = 7, vec_weight: torch.Tensor | List[float] | float | NoneType = None, max_value: float | None = None, hinge_value: float | None = None, vec_convergence: List[float] | None = None, threshold_value: float | None = None, return_loss: bool = False, joint_limits: curobo.cuda_robot_model.types.JointLimits | None = None, smooth_weight: List[float] | None = None, run_weight_velocity: float = 0.0, run_weight_acceleration: float = 0.0, run_weight_jerk: float = 0.0, cspace_distance_weight: Optional[Annotated[torch.Tensor, {'__torchtyping__': True, 'details': ('dof', torch.float32), 'cls_name': 'TensorType'}]] = None, cost_type: curobo.rollout.cost.bound_cost.BoundCostType | None = None, activation_distance: torch.Tensor | float = 0.0, state_finite_difference_mode: str = 'BACKWARD', null_space_weight: List[float] | None = None)

Bases: CostConfig

Parameters:
  • weight (Tensor | float | List[float]) –

  • tensor_args (TensorDeviceType) –

  • distance_threshold (float) –

  • classify (bool) –

  • terminal (bool) –

  • run_weight (float | None) –

  • dof (int) –

  • vec_weight (Tensor | List[float] | float | None) –

  • max_value (float | None) –

  • hinge_value (float | None) –

  • vec_convergence (List[float] | None) –

  • threshold_value (float | None) –

  • return_loss (bool) –

  • joint_limits (JointLimits | None) –

  • smooth_weight (List[float] | None) –

  • run_weight_velocity (float) –

  • run_weight_acceleration (float) –

  • run_weight_jerk (float) –

  • cspace_distance_weight (Tensor | None) –

  • cost_type (BoundCostType | None) –

  • activation_distance (Tensor | float) –

  • state_finite_difference_mode (str) –

  • null_space_weight (List[float] | None) –

joint_limits: JointLimits | None = None
smooth_weight: List[float] | None = None
run_weight_velocity: float = 0.0
run_weight_acceleration: float = 0.0
run_weight_jerk: float = 0.0
cspace_distance_weight: Tensor | None = None
cost_type: BoundCostType | None = None
activation_distance: Tensor | float = 0.0
state_finite_difference_mode: str = 'BACKWARD'
null_space_weight: List[float] | None = None
set_bounds(bounds, teleport_mode=False)
Parameters:
class curobo.rollout.cost.bound_cost.BoundCost(config)

Bases: CostBase, BoundCostConfig

Initialize class

Parameters:
  • config (Optional[CostConfig], optional) – To initialize this class directly, pass a config.

  • class (If this is a base) –

  • CostConfig. (it's assumed that you will initialize the child class with) –

  • None. (Defaults to) –

update_batch_size(batch, horizon, dof)
forward(state_batch, retract_config=None, retract_idx=None)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
  • state_batch (JointState) –

  • retract_config (Tensor | None) –

  • retract_idx (Tensor | None) –

update_dt(dt)
Parameters:

dt (float | Tensor) –

class curobo.rollout.cost.bound_cost.WarpBoundSmoothFunction(*args, **kwargs)

Bases: Function

static forward(ctx, pos, vel, acc, jerk, retract_config, retract_idx, p_b, v_b, a_b, j_b, weight, activation_distance, smooth_weight, cspace_weight, null_space_weight, vec_weight, run_weight_vel, run_weight_acc, run_weight_jerk, out_cost, out_gp, out_gv, out_ga, out_gj)

This function is to be overridden by all subclasses. There are two ways to define forward:

Usage 1 (Combined forward and ctx):

@staticmethod
def forward(ctx: Any, *args: Any, **kwargs: Any) -> Any:
    pass
  • It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).

  • See combining-forward-context for more details

Usage 2 (Separate forward and ctx):

@staticmethod
def forward(*args: Any, **kwargs: Any) -> Any:
    pass

@staticmethod
def setup_context(ctx: Any, inputs: Tuple[Any, ...], output: Any) -> None:
    pass
  • The forward no longer accepts a ctx argument.

  • Instead, you must also override the torch.autograd.Function.setup_context staticmethod to handle setting up the ctx object. output is the output of the forward, inputs are a Tuple of inputs to the forward.

  • See extending-autograd for more details

The context can be used to store arbitrary data that can be then retrieved during the backward pass. Tensors should not be stored directly on ctx (though this is not currently enforced for backward compatibility). Instead, tensors should be saved either with ctx.save_for_backward if they are intended to be used in backward (equivalently, vjp) or ctx.save_for_forward if they are intended to be used for in jvp.

static backward(ctx, grad_out_cost)

Defines a formula for differentiating the operation with backward mode automatic differentiation (alias to the vjp function).

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by as many outputs as the forward returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs to forward. Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.

The context can be used to retrieve tensors saved during the forward pass. It also has an attribute ctx.needs_input_grad as a tuple of booleans representing whether each input needs gradient. E.g., backward will have ctx.needs_input_grad[0] = True if the first input to forward needs gradient computed w.r.t. the output.

_backward_cls

alias of WarpBoundSmoothFunctionBackward

class curobo.rollout.cost.bound_cost.WarpBoundFunction(*args, **kwargs)

Bases: Function

static forward(ctx, pos, vel, acc, jerk, retract_config, retract_idx, p_b, v_b, a_b, j_b, weight, activation_distance, null_space_weight, vec_weight, out_cost, out_gp, out_gv, out_ga, out_gj)

This function is to be overridden by all subclasses. There are two ways to define forward:

Usage 1 (Combined forward and ctx):

@staticmethod
def forward(ctx: Any, *args: Any, **kwargs: Any) -> Any:
    pass
  • It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).

  • See combining-forward-context for more details

Usage 2 (Separate forward and ctx):

@staticmethod
def forward(*args: Any, **kwargs: Any) -> Any:
    pass

@staticmethod
def setup_context(ctx: Any, inputs: Tuple[Any, ...], output: Any) -> None:
    pass
  • The forward no longer accepts a ctx argument.

  • Instead, you must also override the torch.autograd.Function.setup_context staticmethod to handle setting up the ctx object. output is the output of the forward, inputs are a Tuple of inputs to the forward.

  • See extending-autograd for more details

The context can be used to store arbitrary data that can be then retrieved during the backward pass. Tensors should not be stored directly on ctx (though this is not currently enforced for backward compatibility). Instead, tensors should be saved either with ctx.save_for_backward if they are intended to be used in backward (equivalently, vjp) or ctx.save_for_forward if they are intended to be used for in jvp.

static backward(ctx, grad_out_cost)

Defines a formula for differentiating the operation with backward mode automatic differentiation (alias to the vjp function).

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by as many outputs as the forward returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs to forward. Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.

The context can be used to retrieve tensors saved during the forward pass. It also has an attribute ctx.needs_input_grad as a tuple of booleans representing whether each input needs gradient. E.g., backward will have ctx.needs_input_grad[0] = True if the first input to forward needs gradient computed w.r.t. the output.

_backward_cls

alias of WarpBoundFunctionBackward

class curobo.rollout.cost.bound_cost.WarpBoundPosFunction(*args, **kwargs)

Bases: Function

static forward(ctx, pos, retract_config, retract_idx, p_l, weight, activation_distance, null_space_weight, vec_weight, out_cost, out_gp)

This function is to be overridden by all subclasses. There are two ways to define forward:

Usage 1 (Combined forward and ctx):

@staticmethod
def forward(ctx: Any, *args: Any, **kwargs: Any) -> Any:
    pass
  • It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).

  • See combining-forward-context for more details

Usage 2 (Separate forward and ctx):

@staticmethod
def forward(*args: Any, **kwargs: Any) -> Any:
    pass

@staticmethod
def setup_context(ctx: Any, inputs: Tuple[Any, ...], output: Any) -> None:
    pass
  • The forward no longer accepts a ctx argument.

  • Instead, you must also override the torch.autograd.Function.setup_context staticmethod to handle setting up the ctx object. output is the output of the forward, inputs are a Tuple of inputs to the forward.

  • See extending-autograd for more details

The context can be used to store arbitrary data that can be then retrieved during the backward pass. Tensors should not be stored directly on ctx (though this is not currently enforced for backward compatibility). Instead, tensors should be saved either with ctx.save_for_backward if they are intended to be used in backward (equivalently, vjp) or ctx.save_for_forward if they are intended to be used for in jvp.

static backward(ctx, grad_out_cost)

Defines a formula for differentiating the operation with backward mode automatic differentiation (alias to the vjp function).

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by as many outputs as the forward returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs to forward. Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.

The context can be used to retrieve tensors saved during the forward pass. It also has an attribute ctx.needs_input_grad as a tuple of booleans representing whether each input needs gradient. E.g., backward will have ctx.needs_input_grad[0] = True if the first input to forward needs gradient computed w.r.t. the output.

_backward_cls

alias of WarpBoundPosFunctionBackward

class curobo.rollout.cost.bound_cost.WarpBoundPosLoss(*args, **kwargs)

Bases: WarpBoundPosFunction

static backward(ctx, grad_out_cost)

Defines a formula for differentiating the operation with backward mode automatic differentiation (alias to the vjp function).

This function is to be overridden by all subclasses.

It must accept a context ctx as the first argument, followed by as many outputs as the forward returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs to forward. Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.

The context can be used to retrieve tensors saved during the forward pass. It also has an attribute ctx.needs_input_grad as a tuple of booleans representing whether each input needs gradient. E.g., backward will have ctx.needs_input_grad[0] = True if the first input to forward needs gradient computed w.r.t. the output.

_backward_cls

alias of WarpBoundPosLossBackward