Skip to content

State

openscvx.backend.state.State

Bases: Variable

A class representing the state variables in an optimal control problem.

The State class extends Variable to handle state-specific properties like initial and final conditions, as well as true and augmented state dimensions. It supports various boundary condition types: - Fixed values (Fix) - Free variables (Free) - Minimization objectives (Minimize) - Maximization objectives (Maximize)

Attributes:

Name Type Description
name str

Name of the state variable.

shape tuple

Shape of the state variable array.

min ndarray

Minimum bounds for the state variables. Shape: (n_states,).

max ndarray

Maximum bounds for the state variables. Shape: (n_states,).

guess ndarray

Used to initialize SCP and contains the current SCP solution for the state trajectory. Shape: (n_nodes, n_states).

initial ndarray

Initial state values or boundary condition objects (Free, Fixed, Minimize, Maximize). Shape: (n_states,).

final ndarray

Final state values or boundary condition objects (Free, Fixed, Minimize, Maximize). Shape: (n_states,).

_initial ndarray

Internal storage for initial state values.

_final ndarray

Internal storage for final state values.

initial_type str

Type of initial boundary condition ('fix', 'free', 'minimize', 'maximize').

final_type str

Type of final boundary condition ('fix', 'free', 'minimize', 'maximize').

_true_dim int

True dimensionality of the state variables.

_true_slice slice

Slice for accessing true state variables.

_augmented_slice slice

Slice for accessing augmented state variables.

Notes

Attributes prefixed with underscore (_) are for internal use only and should not be accessed directly.

Example
state = State("position", (3,))
state.min = np.array([0, 0, 10])
state.max = np.array([10, 10, 200])
state.guess = np.linspace([0, 1, 2], [10, 5, 8], 3)
state.initial = np.array([Fix(0), Free(1), 2])
state.final = np.array([Fix(10), Free(5), Maximize(8)])
augmented property

Get the augmented state variables.

Returns:

Name Type Description
State

A new State object containing only the augmented state variables

final property writable

Get the final state values.

Returns:

Type Description

np.ndarray: Array of final state values

initial property writable

Get the initial state values.

Returns:

Type Description

np.ndarray: Array of initial state values

max property writable

Get the maximum bounds for the state variables.

Returns:

Type Description

np.ndarray: Array of maximum values for each state variable

min property writable

Get the minimum bounds for the state variables.

Returns:

Type Description

np.ndarray: Array of minimum values for each state variable

true property

Get the true state variables (excluding augmented states).

Returns:

Name Type Description
State

A new State object containing only the true state variables

_check_bounds_against_initial_final()

Check if initial and final values respect the bounds.

Raises:

Type Description
ValueError

If any fixed initial or final value violates the bounds

_update_slices()

Update the slice objects for true and augmented states.

append(other=None, *, min=-np.inf, max=np.inf, guess=0.0, initial=0.0, final=0.0, augmented=False)

Append another state or create a new state variable.

Parameters:

Name Type Description Default
other State

Another State object to append

None
min float

Minimum bound for new state. Defaults to -np.inf

-inf
max float

Maximum bound for new state. Defaults to np.inf

inf
guess float

Initial guess for new state. Defaults to 0.0

0.0
initial float

Initial value for new state. Defaults to 0.0

0.0
final float

Final value for new state. Defaults to 0.0

0.0
augmented bool

Whether the new state is augmented. Defaults to False

False

Boundary Conditions

openscvx.backend.state.Free

Class representing a free state variable in the optimization problem.

A free state variable is one that is not constrained to any specific value but can be optimized within its bounds.

Attributes:

Name Type Description
guess

The initial guess value for optimization.

openscvx.backend.state.Fix

Class representing a fixed state variable in the optimization problem.

A fixed state variable is one that is constrained to a specific value and cannot be optimized.

Attributes:

Name Type Description
value

The fixed value that the state variable must take.

openscvx.backend.state.Minimize

Class representing a state variable to be minimized in the optimization problem.

A minimized state variable is one that is optimized to achieve the lowest possible value within its bounds.

Attributes:

Name Type Description
guess

The initial guess value for optimization.

openscvx.backend.state.Maximize

Class representing a state variable to be maximized in the optimization problem.

A maximized state variable is one that is optimized to achieve the highest possible value within its bounds.

Attributes:

Name Type Description
guess

The initial guess value for optimization.