time
Tau
¶
Bases: Leaf
Normalized node coordinate, running 0 at the first node to 1 at the last.
Tau is internal plumbing for initial guesses, not part of the user-facing
vocabulary. A user who needs the node coordinate writes their guess as a
callable of one argument::
pos.guess = lambda tau: p0 + (pf - p0) * tau
and the library applies that callable once, at assignment, with a Tau
instance. The result is an ordinary expression that the guess-resolution pass
evaluates node by node (see
:func:openscvx.symbolic.preprocessing.resolve_guess_exprs).
Physical time is a Time state; Tau is the dimensionless grid
coordinate the trajectory is discretized on, and is meaningful only while
building a guess.
Source code in openscvx/symbolic/expr/time.py
check_shape() -> Tuple[int, ...]
¶
Reject tau outside of an initial-guess expression.
Raises:
| Type | Description |
|---|---|
ValueError
|
Always. Dynamics, constraints, and costs are shape-checked
eagerly, so this fires exactly when a captured |
Source code in openscvx/symbolic/expr/time.py
Time
¶
Bases: State
Time state variable for trajectory optimization.
Time is a State representing physical time along the trajectory. Used for time-optimal control and problems with time-dependent dynamics/constraints.
Since Time is a State, it can be:
- Used directly in constraint expressions (e.g.,
time[0] <= 5.0) - Added to the states list, or auto-added via the
time=argument
The constructor accepts scalar values for convenience, which are converted to arrays internally to match State's API. All parameters can also be set via property setters after construction.
Time dilation bounds and guesses can also be configured here via
time_dilation_min, time_dilation_max, and time_dilation_guess.
These control the augmented time dilation variable that the solver adds
internally, and can be updated between solves (e.g. in a receding horizon
loop) without reconstructing the problem.
Note
time_dilation_min and time_dilation_max are absolute bounds
on the time dilation control variable.
Attributes:
| Name | Type | Description |
|---|---|---|
derivative |
float
|
Always 1.0 - time derivative in normalized coordinates. |
Example
Constructor style::
time = ox.Time(initial=0.0, final=10.0, min=0.0, max=20.0)
problem = Problem(..., time=time)
Setter style::
time = ox.Time()
time.min = 0.0
time.max = 20.0
time.initial = 0.0
time.final = ox.Minimize(10.0)
With guess and time-dilation overrides::
time = ox.Time(
initial=0.0,
final=("minimize", 10.0),
min=0.0,
max=20.0,
guess=np.linspace(0, 10, 50).reshape(-1, 1),
time_dilation_min=1.0,
time_dilation_max=30.0,
)
Using time in constraints::
time = ox.Time(initial=0.0, final=10.0, min=0.0, max=20.0)
states = [position, velocity, time]
constraint = ox.ctcs(time[0] <= 5.0)
Source code in openscvx/symbolic/expr/time.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
time_dilation_guess: Optional[np.ndarray]
property
writable
¶
Initial guess for time dilation, shape (N, 1). Arrays only.
time_dilation_max: Optional[float]
property
writable
¶
Absolute maximum bound for time dilation.
time_dilation_min: Optional[float]
property
writable
¶
Absolute minimum bound for time dilation.
__init__(initial: Optional[Union[float, tuple]] = None, final: Optional[Union[float, tuple]] = None, min: Optional[float] = None, max: Optional[float] = None, *, guess: Optional[np.ndarray] = None, time_dilation_min: Optional[float] = None, time_dilation_max: Optional[float] = None, time_dilation_guess: Optional[np.ndarray] = None, uniform_time_grid: bool = False)
¶
Initialize a Time state.
All parameters are optional and can be set later via property setters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial
|
Optional[Union[float, tuple]]
|
Initial time. Either a float (fixed) or tuple like ("free", value), ("minimize", value), ("maximize", value). |
None
|
final
|
Optional[Union[float, tuple]]
|
Final time. Same format as initial. |
None
|
min
|
Optional[float]
|
Minimum time bound. |
None
|
max
|
Optional[float]
|
Maximum time bound. |
None
|
guess
|
Optional[ndarray]
|
Initial guess for the time trajectory. 1D array of shape
(N,), 2D of shape (N, 1), or any symbolic form accepted by
:attr: |
None
|
time_dilation_min
|
Optional[float]
|
Absolute minimum bound for time dilation.
Defaults to |
None
|
time_dilation_max
|
Optional[float]
|
Absolute maximum bound for time dilation.
Defaults to |
None
|
time_dilation_guess
|
Optional[ndarray]
|
Initial guess for time dilation. 1D array of shape (N,) or 2D of shape (N, 1) — arrays only, symbolic guesses are not accepted here. Overrides the default finite-difference computation. |
None
|
uniform_time_grid
|
bool
|
If True, constrain the time dilation to be the same across all nodes (uniform time steps). Defaults to False. |
False
|
Source code in openscvx/symbolic/expr/time.py
final(val)
¶
Set the final time. Accepts a scalar, tuple, or array.
guess(value)
¶
Set the time guess.
Accepts everything :attr:Variable.guess accepts — an array, a symbolic
expression, or a callable of tau — and additionally reshapes a 1D (N,)
array to (N, 1) since Time is always shape (1,). A symbolic guess
resolving to one value per node is reshaped the same way at build time::
time.guess = lambda tau: t0 + (tf - t0) * tau**2
Note
time_dilation_guess is a separate, array-only setting; it is not
resolved from expressions.
Source code in openscvx/symbolic/expr/time.py
initial(val)
¶
Set the initial time. Accepts a scalar, tuple, or array.
max(val)
¶
Set the maximum time bound. Accepts a scalar or array.
min(val)
¶
Set the minimum time bound. Accepts a scalar or array.
TimeSpec
¶
Bases: StateSpec
Validates Time configuration from YAML/JSON/dict input.
Extends :class:StateSpec with time-specific fields. name and
shape are fixed ("time" and [1]), and initial/final
are required (a Time must have boundary conditions).
YAML scalars and [tag, value] pairs are normalised into the
List forms that :class:StateSpec expects via field_validator
so that no field type overrides are needed.