Skip to content

TrajOptProblem

openscvx.trajoptproblem.TrajOptProblem.__init__(dynamics: Dynamics, constraints: List[Union[CTCSConstraint, NodalConstraint]], x: State, u: Control, N: int, idx_time: int, params: Optional[dict] = None, dynamics_prop: Optional[callable] = None, x_prop: State = None, scp: Optional[ScpConfig] = None, dis: Optional[DiscretizationConfig] = None, prp: Optional[PropagationConfig] = None, sim: Optional[SimConfig] = None, dev: Optional[DevConfig] = None, cvx: Optional[ConvexSolverConfig] = None, licq_min=0.0, licq_max=0.0001, time_dilation_factor_min=0.3, time_dilation_factor_max=3.0)

The primary class in charge of compiling and exporting the solvers

Parameters:

Name Type Description Default
dynamics Dynamics

Dynamics function decorated with @dynamics

required
constraints List[Union[CTCSConstraint, NodalConstraint]]

List of constraints decorated with @ctcs or @nodal

required
idx_time int

Index of the time variable in the state vector

required
N int

Number of segments in the trajectory

required
time_init float

Initial time for the trajectory

required
x_guess ndarray

Initial guess for the state trajectory

required
u_guess ndarray

Initial guess for the control trajectory

required
initial_state BoundaryConstraint

Initial state constraint

required
final_state BoundaryConstraint

Final state constraint

required
x_max ndarray

Upper bound on the state variables

required
x_min ndarray

Lower bound on the state variables

required
u_max ndarray

Upper bound on the control variables

required
u_min ndarray

Lower bound on the control variables

required
dynamics_prop Optional[callable]

Propagation dynamics function decorated with @dynamics

None
initial_state_prop

Propagation initial state constraint

required
scp Optional[ScpConfig]

SCP configuration object

None
dis Optional[DiscretizationConfig]

Discretization configuration object

None
prp Optional[PropagationConfig]

Propagation configuration object

None
sim Optional[SimConfig]

Simulation configuration object

None
dev Optional[DevConfig]

Development configuration object

None
cvx Optional[ConvexSolverConfig]

Convex solver configuration object

None

Returns:

Type Description

None

ScpConfig

openscvx.config.ScpConfig.__init__(n: Optional[int] = None, k_max: int = 200, w_tr: float = 1.0, lam_vc: float = 1.0, ep_tr: float = 0.0001, ep_vb: float = 0.0001, ep_vc: float = 1e-08, lam_cost: float = 0.0, lam_vb: float = 0.0, uniform_time_grid: bool = False, cost_drop: int = -1, cost_relax: float = 1.0, w_tr_adapt: float = 1.0, w_tr_max: Optional[float] = None, w_tr_max_scaling_factor: Optional[float] = None)

Configuration class for Sequential Convex Programming (SCP).

This class defines the parameters used to configure the SCP solver. You will very likely need to modify the weights for your problem. Please refer to my guide here for more information.

Attributes:

Name Type Description
n int

The number of discretization nodes. Defaults to None.

k_max int

The maximum number of SCP iterations. Defaults to 200.

w_tr float

The trust region weight. Defaults to 1.0.

lam_vc float

The penalty weight for virtual control. Defaults to 1.0.

ep_tr float

The trust region convergence tolerance. Defaults to 1e-4.

ep_vb float

The boundary constraint convergence tolerance. Defaults to 1e-4.

ep_vc float

The virtual constraint convergence tolerance. Defaults to 1e-8.

lam_cost float

The weight for original cost. Defaults to 0.0.

lam_vb float

The weight for virtual buffer. This is only used if there are nonconvex nodal constraints present. Defaults to 0.0.

uniform_time_grid bool

Whether to use a uniform time grid. Defaults to False.

cost_drop int

The number of iterations to allow for cost stagnation before termination. Defaults to -1 (disabled).

cost_relax float

The relaxation factor for cost reduction. Defaults to 1.0.

w_tr_adapt float

The adaptation factor for the trust region weight. Defaults to 1.0.

w_tr_max float

The maximum allowable trust region weight. Defaults to None.

w_tr_max_scaling_factor float

The scaling factor for the maximum trust region weight. Defaults to None.

DiscretizationConfig

openscvx.config.DiscretizationConfig.__init__(dis_type: str = 'FOH', custom_integrator: bool = False, solver: str = 'Tsit5', args: Optional[dict] = None, atol: float = 0.001, rtol: float = 1e-06)

Configuration class for discretization settings.

This class defines the parameters required for discretizing system dynamics.

Main arguments: These are the arguments most commonly used day-to-day.

Parameters:

Name Type Description Default
dis_type str

The type of discretization to use (e.g., "FOH" for First-Order Hold). Defaults to "FOH".

'FOH'
custom_integrator bool

This enables our custom fixed-step RK45 algorithm. This tends to be faster than Diffrax but unless you're going for speed, it's recommended to stick with Diffrax for robustness and other solver options. Defaults to False.

False
solver str

Not used if custom_integrator is enabled. Any choice of solver in Diffrax is valid, please refer here, How to Choose a Solver. Defaults to "Tsit5".

'Tsit5'

Other arguments: These arguments are less frequently used, and for most purposes you shouldn't need to understand these.

Parameters:

Name Type Description Default
args Dict

Additional arguments to pass to the solver which can be found here. Defaults to an empty dictionary.

None
atol float

Absolute tolerance for the solver. Defaults to 1e-3.

0.001
rtol float

Relative tolerance for the solver. Defaults to 1e-6.

1e-06

PropagationConfig

openscvx.config.PropagationConfig.__init__(inter_sample: int = 30, dt: float = 0.01, solver: str = 'Dopri8', max_tau_len: int = 1000, args: Optional[dict] = None, atol: float = 0.001, rtol: float = 1e-06)

Configuration class for propagation settings.

This class defines the parameters required for propagating the nonlinear system dynamics using the optimal control sequence.

Main arguments: These are the arguments most commonly used day-to-day.

Other arguments: The solver should likely not be changed as it is a high accuracy 8th-order Runge-Kutta method.

Parameters:

Name Type Description Default
inter_sample int

How dense the propagation within multishot discretization should be. Defaults to 30.

30
dt float

The time step for propagation. Defaults to 0.1.

0.01
solver str

The numerical solver to use for propagation (e.g., "Dopri8"). Defaults to "Dopri8".

'Dopri8'
max_tau_len int

The maximum length of the time vector for propagation. Defaults to 1000.

1000
args Dict

Additional arguments to pass to the solver. Defaults to an empty dictionary.

None
atol float

Absolute tolerance for the solver. Defaults to 1e-3.

0.001
rtol float

Relative tolerance for the solver. Defaults to 1e-6.

1e-06

SimConfig

openscvx.config.SimConfig.__init__(x: State, x_prop: State, u: Control, total_time: float, idx_x_true: slice, idx_x_true_prop: slice, idx_u_true: slice, idx_t: slice, idx_y: slice, idx_y_prop: slice, idx_s: slice, save_compiled: bool = True, ctcs_node_intervals: Optional[list] = None, constraints_ctcs: Optional[list[Callable]] = None, constraints_nodal: Optional[list[Callable]] = None, n_states: Optional[int] = None, n_states_prop: Optional[int] = None, n_controls: Optional[int] = None, scaling_x_overrides: Optional[list] = None, scaling_u_overrides: Optional[list] = None)

Configuration class for simulation settings.

This class defines the parameters required for simulating a trajectory optimization problem.

Main arguments: These are the arguments most commonly used day-to-day.

Parameters:

Name Type Description Default
x State

State object, must have .min and .max attributes for bounds.

required
x_prop State

Propagation state object, must have .min and .max attributes for bounds.

required
u Control

Control object, must have .min and .max attributes for bounds.

required
total_time float

The total simulation time.

required
idx_x_true slice

Slice for true state indices.

required
idx_x_true_prop slice

Slice for true propagation state indices.

required
idx_u_true slice

Slice for true control indices.

required
idx_t slice

Slice for time index.

required
idx_y slice

Slice for constraint violation indices.

required
idx_y_prop slice

Slice for propagation constraint violation indices.

required
idx_s slice

Slice for time dilation index.

required
save_compiled bool

If True, save and reuse compiled solver functions. Defaults to True.

True
ctcs_node_intervals list

Node intervals for CTCS constraints.

None
constraints_ctcs list

List of CTCS constraints.

None
constraints_nodal list

List of nodal constraints.

None
n_states int

The number of state variables. Defaults to None (inferred from x.max).

None
n_states_prop int

The number of propagation state variables. Defaults to None (inferred from x_prop.max).

None
n_controls int

The number of control variables. Defaults to None (inferred from u.max).

None
scaling_x_overrides list

List of (upper_bound, lower_bound, idx) for custom state scaling. Each can be scalar or array, idx can be int, list, or slice.

None
scaling_u_overrides list

List of (upper_bound, lower_bound, idx) for custom control scaling. Each can be scalar or array, idx can be int, list, or slice.

None
Note

You can specify custom scaling for specific states/controls using scaling_x_overrides and scaling_u_overrides. Any indices not covered by overrides will use the default min/max bounds.

ConvexSolverConfig

openscvx.config.ConvexSolverConfig.__init__(solver: str = 'QOCO', solver_args: Optional[dict] = None, cvxpygen: bool = False, cvxpygen_override: bool = False)

Configuration class for convex solver settings.

This class defines the parameters required for configuring a convex solver.

These are the arguments most commonly used day-to-day. Generally I have found QOCO to be the most performant of the CVXPY solvers for these types of problems (I do have a bias as the author is from my group) and can handle up to SOCP's. CLARABEL is also a great option with feasibility checking and can handle a few more problem types. CVXPYGen is also great if your problem isn't too large. I have found qocogen to be the most performant of the CVXPYGen solvers.

Parameters:

Name Type Description Default
solver str

The name of the CVXPY solver to use. A list of options can be found here. Defaults to "QOCO".

'QOCO'
solver_args dict

Ensure you are using the correct arguments for your solver as they are not all common. Additional arguments to configure the solver, such as tolerances. Defaults to {"abstol": 1e-6, "reltol": 1e-9}.

None
cvxpygen bool

Whether to enable CVXPY code generation for the solver. Defaults to False.

False

DevConfig

openscvx.config.DevConfig.__init__(profiling: bool = False, debug: bool = False, printing: bool = True)

Configuration class for development settings.

This class defines the parameters used for development and debugging purposes.

Main arguments: These are the arguments most commonly used day-to-day.

Parameters:

Name Type Description Default
profiling bool

Whether to enable profiling for performance analysis. Defaults to False.

False
debug bool

Disables all precompilation so you can place breakpoints and inspect values. Defaults to False.

False
printing bool

Whether to enable printing during development. Defaults to True.

True