curobo.opt.particle.particle_opt_base module

class curobo.opt.particle.particle_opt_base.SampleMode(value)

Bases: Enum

An enumeration.

MEAN = 0
BEST = 1
SAMPLE = 2
class curobo.opt.particle.particle_opt_base.ParticleOptInfo(info: Dict | None = None)

Bases: object

Parameters:

info (Dict | None) –

info: Dict | None = None
class curobo.opt.particle.particle_opt_base.ParticleOptConfig(d_action: 'int', action_lows: 'List[float]', action_highs: 'List[float]', action_horizon: 'int', horizon: 'int', n_iters: 'int', cold_start_n_iters: 'Union[int, None]', rollout_fn: 'RolloutBase', tensor_args: 'TensorDeviceType', use_cuda_graph: 'bool', store_debug: 'bool', debug_info: 'Any', n_problems: 'int', num_particles: 'Union[int, None]', sync_cuda_time: 'bool', use_coo_sparse: 'bool', gamma: float, sample_mode: curobo.opt.particle.particle_opt_base.SampleMode, seed: int, calculate_value: bool, store_rollouts: bool)

Bases: OptimizerConfig

Parameters:
  • d_action (int) –

  • action_lows (List[float]) –

  • action_highs (List[float]) –

  • action_horizon (int) –

  • horizon (int) –

  • n_iters (int) –

  • cold_start_n_iters (int | None) –

  • rollout_fn (RolloutBase) –

  • tensor_args (TensorDeviceType) –

  • use_cuda_graph (bool) –

  • store_debug (bool) –

  • debug_info (Any) –

  • n_problems (int) –

  • num_particles (int | None) –

  • sync_cuda_time (bool) –

  • use_coo_sparse (bool) –

  • gamma (float) –

  • sample_mode (SampleMode) –

  • seed (int) –

  • calculate_value (bool) –

  • store_rollouts (bool) –

gamma: float
sample_mode: SampleMode
seed: int
calculate_value: bool
store_rollouts: bool
static create_data_dict(data_dict, rollout_fn, tensor_args=TensorDeviceType(device=device(type='cuda', index=0), dtype=torch.float32), child_dict=None)

Helper function to create dictionary from optimizer parameters and rollout class.

Parameters:
  • data_dict (Dict) – optimizer parameters dictionary.

  • rollout_fn (RolloutBase) – rollout function.

  • tensor_args (TensorDeviceType) – tensor cuda device.

  • child_dict (Dict | None) – new dictionary where parameters will be stored.

Returns:

Dictionary with parameters to create a OptimizerConfig

class curobo.opt.particle.particle_opt_base.ParticleOptBase(config=None)

Bases: Optimizer, ParticleOptConfig

Base class for sampling based controllers.

Base optimization solver class

Parameters:

config (ParticleOptConfig | None) – Initialized with parameters from a dataclass.

abstract _get_action_seq(mode=<enum 'SampleMode'>)

Get action sequence to execute on the system based on current control distribution

Parameters:

mode – {‘mean’, ‘sample’} how to choose action to be executed ‘mean’ plays mean action and ‘sample’ samples from the distribution

abstract sample_actions(init_act)

Sample actions from current control distribution

Parameters:

init_act (Tensor) –

update_seed(init_act)
abstract _update_distribution(trajectories)

Update current control distribution using rollout trajectories

Parameters:

trajectories (Trajectory) –

dict Rollout trajectories. Contains the following fields observations : torch.tensor

observations along rollouts

actionstorch.tensor

actions sampled from control distribution along rollouts

coststorch.tensor

step costs along rollouts

reset()

Reset the optimizer

abstract _calc_val(trajectories)

Calculate value of state given rollouts from a policy

Parameters:

trajectories (Trajectory) –

check_convergence()

Checks if controller has converged Returns False by default

generate_rollouts(init_act=None)

Samples a batch of actions, rolls out trajectories for each particle and returns the resulting observations, costs, actions

Parameters:

state (dict or np.ndarray) – Initial state to set the simulation problem to

_optimize(init_act, shift_steps=0, n_iters=None)

Optimize for best action at current state

Parameters:
  • state (torch.Tensor) – state to calculate optimal action from

  • calc_val (bool) – If true, calculate the optimal value estimate of the state along with action

  • init_act (Tensor) –

Returns:

  • action (torch.Tensor) – next action to execute

  • value (float) – optimal value estimate (default: 0.)

  • info (dict) – dictionary with side-information

_initialize_cuda_graph(init_act, shift_steps=0)
Parameters:

init_act (Tensor) –

_call_cuda_opt_iters(init_act)
Parameters:

init_act (Tensor) –

_run_opt_iters(init_act, shift_steps=0, n_iters=None)
Parameters:

init_act (Tensor) –

update_nproblems(n_problems)

Update the number of problems that need to be optimized.

Parameters:

n_problems – number of problems.

update_num_particles_per_problem(num_particles_per_problem)