openscvx 0.5.3.dev33__py3-none-any.whl → 0.5.3.dev35__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
openscvx/_version.py CHANGED
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.5.3.dev33'
22
- __version_tuple__ = version_tuple = (0, 5, 3, 'dev33')
21
+ __version__ = version = '0.5.3.dev35'
22
+ __version_tuple__ = version_tuple = (0, 5, 3, 'dev35')
23
23
 
24
- __commit_id__ = commit_id = 'g3d6f6768a'
24
+ __commit_id__ = commit_id = 'g43f7b7f31'
@@ -50,6 +50,14 @@ class OptimizationResults:
50
50
  Added by propagate_trajectory_results.
51
51
  ctcs_violation (Optional[np.ndarray]): Continuous-time constraint violations.
52
52
  Added by propagate_trajectory_results.
53
+ parameters (dict[str, np.ndarray]): Parameter values the solve used, recorded
54
+ by :meth:`~openscvx.problem.Problem.solve` and
55
+ :meth:`~openscvx.problem.Problem.solve_batched` (batched solves store every
56
+ value with a leading ``(B,)`` axis, shared values replicated). Results
57
+ record what happened: post-processing propagates with these values, and
58
+ the Problem's parameter dict only seeds the next solve. Empty when no
59
+ snapshot was recorded (e.g. ``solve_jax``, whose callers manage
60
+ parameters themselves).
53
61
  plotting_data (dict[str, Any]): Flexible storage for plotting and application data.
54
62
 
55
63
  !!! note "JAX pytree registration"
@@ -59,8 +67,9 @@ class OptimizationResults:
59
67
  ``converged``, ``t_final``, ``nodes``, ``trajectory``, ``X``, ``U``,
60
68
  and every ``*_history`` field — the data the user actually consumes.
61
69
  Post-process fields (``t_full``, ``x_full``, ``u_full``, ``cost``,
62
- ``ctcs_violation``), ``plotting_data``, and the internal ``_states`` /
63
- ``_controls`` metadata are stashed in the treedef's *aux* instead, so
70
+ ``ctcs_violation``), ``parameters``, ``plotting_data``, and the
71
+ internal ``_states`` / ``_controls`` metadata are stashed in the
72
+ treedef's *aux* instead, so
64
73
  a batched ``solve_jax`` doesn't force callers to handle ``None``
65
74
  leaves and ``post_process()`` outputs stay outside the vmap surface
66
75
  (post-process per element after the batched solve).
@@ -217,6 +226,10 @@ class OptimizationResults:
217
226
  cost: Optional[float] = field(default=None, metadata={"npz": "optional_scalar"})
218
227
  ctcs_violation: Optional[np.ndarray] = field(default=None, metadata={"npz": "optional_array"})
219
228
 
229
+ # Parameter values the solve used (recorded by Problem.solve() /
230
+ # Problem.solve_batched(); empty when nothing was recorded)
231
+ parameters: dict[str, np.ndarray] = field(default_factory=dict, metadata={"npz": "dict"})
232
+
220
233
  # Additional plotting/application data (added by user)
221
234
  plotting_data: dict[str, Any] = field(default_factory=dict, metadata={"npz": "dict"})
222
235
 
@@ -245,6 +258,7 @@ class OptimizationResults:
245
258
  self.u_full,
246
259
  self.cost,
247
260
  self.ctcs_violation,
261
+ self.parameters,
248
262
  self.plotting_data,
249
263
  )
250
264
  return children, aux
@@ -260,6 +274,7 @@ class OptimizationResults:
260
274
  u_full,
261
275
  cost,
262
276
  ctcs_violation,
277
+ parameters,
263
278
  plotting_data,
264
279
  ) = aux
265
280
  return cls(
@@ -271,6 +286,7 @@ class OptimizationResults:
271
286
  u_full=u_full,
272
287
  cost=cost,
273
288
  ctcs_violation=ctcs_violation,
289
+ parameters=parameters,
274
290
  plotting_data=plotting_data,
275
291
  )
276
292
 
openscvx/problem.py CHANGED
@@ -23,6 +23,7 @@ import os
23
23
  import queue
24
24
  import threading
25
25
  import time
26
+ import warnings
26
27
  from dataclasses import fields as dc_fields
27
28
  from dataclasses import replace as dc_replace
28
29
  from typing import Any, Dict, List, Optional, Tuple, Union
@@ -62,7 +63,11 @@ from openscvx.lowered.jax_constraints import (
62
63
  LoweredJaxConstraints,
63
64
  LoweredNodalConstraint,
64
65
  )
65
- from openscvx.propagation import get_propagation_solver, propagate_trajectory_results
66
+ from openscvx.propagation import (
67
+ get_propagation_solver,
68
+ propagate_trajectory_results,
69
+ s_to_t,
70
+ )
66
71
  from openscvx.solvers import ConvexSolver, resolve_solver_config
67
72
  from openscvx.symbolic.builder import preprocess_symbolic_problem
68
73
  from openscvx.symbolic.expr import CTCS, Constraint
@@ -672,6 +677,7 @@ class Problem:
672
677
  # Final solution state (saved after successful solve)
673
678
  self._solution: Optional[AlgorithmState] = None
674
679
  self._solution_history: Optional[AlgorithmHistory] = None
680
+ self._solution_parameters: Optional[Dict[str, np.ndarray]] = None
675
681
 
676
682
  # SCP algorithm (resolved from `algorithm` parameter above)
677
683
 
@@ -1287,6 +1293,7 @@ class Problem:
1287
1293
  # Reset solution
1288
1294
  self._solution = None
1289
1295
  self._solution_history = None
1296
+ self._solution_parameters = None
1290
1297
 
1291
1298
  # Reset timing
1292
1299
  self.timing_solve = None
@@ -1355,7 +1362,10 @@ class Problem:
1355
1362
 
1356
1363
  Returns:
1357
1364
  OptimizationResults with trajectory and convergence info
1358
- (call post_process() for full propagation)
1365
+ (call post_process() for full propagation). The parameter
1366
+ values used for the solve are recorded on
1367
+ ``results.parameters``; :meth:`post_process` propagates
1368
+ with them.
1359
1369
  """
1360
1370
  # Sync parameters, boundary conditions, and SCP constants before solving
1361
1371
  self._sync_parameters()
@@ -1408,16 +1418,22 @@ class Problem:
1408
1418
 
1409
1419
  profiling.profiling_end(pr, "solve")
1410
1420
 
1411
- # Snapshot state + history for post_process() / plotting reuse.
1421
+ # Snapshot state, history, and parameters for post_process() / plotting
1422
+ # reuse.
1412
1423
  self._solution = self._state
1413
1424
  self._solution_history = copy.deepcopy(self._history)
1425
+ self._solution_parameters = {
1426
+ name: np.array(value) for name, value in self._parameters.items()
1427
+ }
1414
1428
 
1415
1429
  timed_out = t_max is not None and self.timing_solve >= t_max
1416
- return self._format_result(
1430
+ result = self._format_result(
1417
1431
  self._state,
1418
1432
  self._history,
1419
1433
  int(self._state.k) <= k_max and not timed_out,
1420
1434
  )
1435
+ result.parameters = self._solution_parameters
1436
+ return result
1421
1437
 
1422
1438
  def _default_state(self) -> AlgorithmState:
1423
1439
  """Fresh :class:`AlgorithmState` from settings and the algorithm's SCP constants.
@@ -1665,6 +1681,11 @@ class Problem:
1665
1681
  parameters: Problem parameters dict for the current solve. Use
1666
1682
  this rather than mutating ``self.parameters`` if the
1667
1683
  parameters are traced. ``None`` reuses ``self._parameters``.
1684
+ Unlike :meth:`solve` / :meth:`solve_batched`, the merged
1685
+ values are *not* recorded on the returned results — under a
1686
+ caller's ``jit`` / ``vmap`` they are tracers, which must not
1687
+ leak into the pytree's aux — so callers that post-process
1688
+ manage parameter bookkeeping themselves.
1668
1689
  x_guess: Initial state trajectory guess, shape ``(N, n_states)``.
1669
1690
  Replaces ``state.x``; ``None`` uses the default from
1670
1691
  settings (``State.guess`` at ``initialize()``).
@@ -1846,7 +1867,12 @@ class Problem:
1846
1867
 
1847
1868
  Returns:
1848
1869
  :class:`OptimizationResults` pytree with a leading ``B`` axis on
1849
- every leaf and empty per-iteration histories.
1870
+ every leaf and empty per-iteration histories. The merged
1871
+ parameter values used for the solve are recorded on
1872
+ ``results.parameters``, post-broadcast — every value carries the
1873
+ leading ``(B,)`` axis, shared values replicated — and
1874
+ :meth:`post_process_batched` propagates each element with its
1875
+ own values.
1850
1876
  """
1851
1877
  if self._iteration_fn_jit_inner is None:
1852
1878
  raise ValueError(
@@ -1953,7 +1979,16 @@ class Problem:
1953
1979
  final_states = batched_solve(states, params_for_solve)
1954
1980
  jax.block_until_ready(final_states)
1955
1981
  self.timing_solve = time.time() - t_0_solve
1956
- return OptimizationResults.from_final_state(final_states, problem=self)
1982
+ results = OptimizationResults.from_final_state(final_states, problem=self)
1983
+ # Record the as-used parameter values with a leading (B,) axis on
1984
+ # every leaf, so post_process_batched() can index element b directly.
1985
+ results.parameters = {
1986
+ name: np.array(np.moveaxis(np.asarray(value), param_axes[name], 0))
1987
+ if param_axes[name] is not None
1988
+ else np.broadcast_to(np.asarray(value), (B,) + np.shape(value)).copy()
1989
+ for name, value in params_for_solve.items()
1990
+ }
1991
+ return results
1957
1992
 
1958
1993
  def post_process(self) -> OptimizationResults:
1959
1994
  """Propagate solution through full nonlinear dynamics for high-fidelity trajectory.
@@ -1961,6 +1996,10 @@ class Problem:
1961
1996
  Integrates the converged SCP solution through the nonlinear dynamics to
1962
1997
  produce x_full, u_full, and t_full. Call after solve() for final results.
1963
1998
 
1999
+ Propagation uses the parameter values recorded at solve time
2000
+ (``results.parameters``), so mutating ``self.parameters`` between
2001
+ :meth:`solve` and here only seeds the next solve.
2002
+
1964
2003
  Returns:
1965
2004
  OptimizationResults with propagated trajectory fields
1966
2005
 
@@ -1980,9 +2019,11 @@ class Problem:
1980
2019
  int(self._solution.k) <= self._algorithm.k_max,
1981
2020
  )
1982
2021
 
2022
+ result.parameters = self._solution_parameters
2023
+
1983
2024
  t_0_post = time.time()
1984
2025
  result = propagate_trajectory_results(
1985
- self._parameters,
2026
+ self._solution_parameters,
1986
2027
  self.settings,
1987
2028
  result,
1988
2029
  self._propagation_solver,
@@ -2022,9 +2063,11 @@ class Problem:
2022
2063
  - ``results.cost`` — ``(B,)``
2023
2064
  - ``results.ctcs_violation`` — ``(B, ...)`` or ``None``
2024
2065
 
2025
- Propagation runs sequentially over the batch in a Python loop;
2026
- all elements share ``self._parameters`` for any parameter values not
2027
- embedded in the trajectory state vector.
2066
+ Propagation runs sequentially over the batch in a Python loop; each
2067
+ element propagates with its own parameter values from the snapshot
2068
+ :meth:`solve_batched` recorded on ``results.parameters``. Results
2069
+ without a snapshot (e.g. loaded from an older save) fall back to
2070
+ ``self.parameters`` with a warning.
2028
2071
 
2029
2072
  Args:
2030
2073
  results: Batched :class:`~openscvx.algorithms.OptimizationResults`
@@ -2035,7 +2078,12 @@ class Problem:
2035
2078
  ``ceil(T_max / settings.prp.dt) + 1`` where ``T_max`` is the
2036
2079
  longest terminal time across the batch. All ``B`` elements are
2037
2080
  interpolated to the **same** ``n_times`` so the output arrays
2038
- have uniform shape.
2081
+ have uniform shape. The requested (or default) value is capped
2082
+ so no single segment of any element receives more dense samples
2083
+ than the propagation solver's compiled per-segment capacity
2084
+ (``settings.prp.max_tau_len``); the cap binds on the largest
2085
+ segment-duration fraction across the batch, so trajectories with
2086
+ near-uniform segments are left untouched.
2039
2087
 
2040
2088
  Returns:
2041
2089
  The same ``results`` object with ``t_full``, ``x_full``, ``u_full``,
@@ -2056,10 +2104,24 @@ class Problem:
2056
2104
  n_times = max(int(np.ceil(T_max / self.settings.prp.dt)) + 1, 2)
2057
2105
 
2058
2106
  # The propagation solver is compiled with a per-segment tau capacity of
2059
- # ``max_tau_len``. A uniform ``linspace`` grid sized from the batch
2060
- # ``T_max`` can place more output times into one normalized segment than
2061
- # that capacity when shorter trajectories are padded to the same count.
2062
- n_times = min(n_times, self.settings.prp.max_tau_len)
2107
+ # ``max_tau_len`` the *per-segment* buffer width, not a total-point
2108
+ # budget. A uniform ``linspace`` grid over an element's real time span
2109
+ # drops about ``(n_times - 1) * seg_dur / span`` points into each
2110
+ # segment, so the binding quantity is the largest segment-duration
2111
+ # fraction across the batch, not the total point count. Bound
2112
+ # ``n_times`` so the busiest segment of any element — plus the endpoint
2113
+ # sample ``simulate_nonlinear_time`` appends — stays within
2114
+ # ``max_tau_len``:
2115
+ # (n_times - 1) * frac_max + 2 <= max_tau_len.
2116
+ u_batch = np.asarray(results.U[-1]) # (B, N, n_u)
2117
+ frac_max = 0.0
2118
+ for b in range(B):
2119
+ t_b = np.asarray(
2120
+ s_to_t(x_batch[b], u_batch[b], self.settings, self._discretizer)
2121
+ ).reshape(-1)
2122
+ frac_max = max(frac_max, float(np.diff(t_b).max() / (t_b[-1] - t_b[0])))
2123
+ per_segment_bound = max(int((self.settings.prp.max_tau_len - 2) / frac_max) + 1, 2)
2124
+ n_times = min(n_times, per_segment_bound)
2063
2125
 
2064
2126
  t_fulls: List[np.ndarray] = []
2065
2127
  x_fulls: List[np.ndarray] = []
@@ -2068,11 +2130,23 @@ class Problem:
2068
2130
  costs: List[float] = []
2069
2131
  ctcs_violations = []
2070
2132
 
2133
+ # Empty for results saved before the snapshot existed — those fall
2134
+ # back to the Problem's current values, the pre-snapshot behaviour.
2135
+ snapshot = getattr(results, "parameters", None) or {}
2136
+ if not snapshot and self._parameters:
2137
+ warnings.warn(
2138
+ "results carry no record of the parameter values they were solved "
2139
+ "with; propagating every element with the Problem's current "
2140
+ "parameters, which may differ from the solved values.",
2141
+ UserWarning,
2142
+ stacklevel=2,
2143
+ )
2144
+
2071
2145
  t_0_post = time.time()
2072
2146
  for b in range(B):
2073
2147
  single = _make_single_result(results, b)
2074
2148
  prop = propagate_trajectory_results(
2075
- self._parameters,
2149
+ dict(self._parameters, **{k: np.asarray(v)[b] for k, v in snapshot.items()}),
2076
2150
  self.settings,
2077
2151
  single,
2078
2152
  self._propagation_solver,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openscvx
3
- Version: 0.5.3.dev33
3
+ Version: 0.5.3.dev35
4
4
  Summary: A general Python-based successive convexification implementation which uses a JAX backend.
5
5
  Author-email: Chris Hayner and Griffin Norris <haynec@uw.edu>
6
6
  License: Apache Software License
@@ -1,15 +1,15 @@
1
1
  openscvx/__init__.py,sha256=sxiqBoS5jv9UmNSxnrokFXeFMnDSkAxUCtC4X-s-vHk,4456
2
2
  openscvx/__main__.py,sha256=Hwm7mtVg3tLdvoUPkpcQv8KF3wxl72PNLBp9axFu8GY,2991
3
- openscvx/_version.py,sha256=g5nYICDm7jUmHCfdE4DnOzSswCJ-WfqBIpwo1JvydrE,543
3
+ openscvx/_version.py,sha256=zYvwhGhbvK9AbmgQE8S1Hgf833v_MnaaaIPnD1k7tlc,543
4
4
  openscvx/config.py,sha256=qfDDYoCe6WqJglKsx5b2W48YOglXenKr-PVRRdCFhYE,9898
5
5
  openscvx/loader.py,sha256=5WDLVA6CQxnyi1pRBfP8jQQc0r8RiAM2O_ItKgMXxAk,7660
6
- openscvx/problem.py,sha256=0hsAdpj74XXsYfOn8VBPzjCpO3mH5bSzHOwpezIBiYY,96230
6
+ openscvx/problem.py,sha256=aJlXbpwQ9_8gP8N2Ff1pz8biF0FoIZTyDYvLX65DLfw,100224
7
7
  openscvx/algorithms/__init__.py,sha256=xEB2sZ_fFbQUSOJY4hOzsZe0cdCuD5LawvrF4fzSt8E,5645
8
8
  openscvx/algorithms/base.py,sha256=jMneNL5lc-qg24vvcGQ4NP93d71boRiUGh6uKBykOlM,11638
9
9
  openscvx/algorithms/history.py,sha256=aAS3VWT5d4kfsIl5a34YFYglHayPqn0hZGmhXVGbE0g,17456
10
10
  openscvx/algorithms/hyperparams.py,sha256=BmNDHerJ-eWi5wO5aryXMSe9jDzLsMxXNcCSeNHOCYY,4560
11
11
  openscvx/algorithms/loop.py,sha256=S03KlW_z4hWdrP50rfEzWmDRaOOl7XHmlzImpkKXGX4,3927
12
- openscvx/algorithms/optimization_results.py,sha256=TVZVeoUpbAmEILmxFrLZz0GT9ze4Apzwm_tXfpBOPjQ,23614
12
+ openscvx/algorithms/optimization_results.py,sha256=BViVL39Y2QmqI-qfGN5NrZj9Cy9DK1cvjJnKff3Bzck,24548
13
13
  openscvx/algorithms/penalty.py,sha256=sqfH11bVr-ZG1VUUA4FjF6ETYDuA06ZXiOAvxBPBcts,4329
14
14
  openscvx/algorithms/state.py,sha256=-ooDqgPezM-GwcWj8Y4q7yB_GQGjlvVucIeGbl8271Q,15787
15
15
  openscvx/algorithms/weights.py,sha256=DQV9NOR_-59lISv6d_el3cpQ-EcFasSGb1oZr4ma-yA,20682
@@ -159,11 +159,11 @@ openscvx/utils/caching.py,sha256=Uw2e0G1UNn_vmMDqUZGszIH-O9LJhR4wdVKSPToHiy0,169
159
159
  openscvx/utils/printing.py,sha256=dsccZ9sXc3TBWShQvBg1Al4UFGMP77ApblfxteEJHLQ,16515
160
160
  openscvx/utils/profiling.py,sha256=k2x-i0CpG_kRe6dNcNBGu-ylrOtQw4B4C1UaOTjUMfU,1678
161
161
  openscvx/utils/utils.py,sha256=M25RHE_7DSr3Reaca0xCXnDSY9KHuqYvXdh5m1ZotEc,3047
162
- openscvx-0.5.3.dev33.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
163
- openscvx-0.5.3.dev33.dist-info/METADATA,sha256=ZnngKgG1V-Z76KjLfpkcyh2xzr2b8Om2FSxRwlldwNc,10924
164
- openscvx-0.5.3.dev33.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
165
- openscvx-0.5.3.dev33.dist-info/entry_points.txt,sha256=1Oqek8Sy28hmAZFgZXDxFXYVf56YLYWlHjhh9RYJ7wE,52
166
- openscvx-0.5.3.dev33.dist-info/scm_file_list.json,sha256=LsBg6YSb5CTgXZVsnmrZNQ3_4o5wSJReFmZGCm66mI8,18001
167
- openscvx-0.5.3.dev33.dist-info/scm_version.json,sha256=gaYW5X0wxdBiVUwvFb3BD5j2X9LvNbsSoIEQCHp6dRg,161
168
- openscvx-0.5.3.dev33.dist-info/top_level.txt,sha256=nUT4Ybefzh40H8tVXqc1RzKESy_MAowElb-CIvAbd4Q,9
169
- openscvx-0.5.3.dev33.dist-info/RECORD,,
162
+ openscvx-0.5.3.dev35.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
163
+ openscvx-0.5.3.dev35.dist-info/METADATA,sha256=zPUnmSxAXkoEBCyp8VD6xerMp6zXIyMuix9WvCgrIUI,10924
164
+ openscvx-0.5.3.dev35.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
165
+ openscvx-0.5.3.dev35.dist-info/entry_points.txt,sha256=1Oqek8Sy28hmAZFgZXDxFXYVf56YLYWlHjhh9RYJ7wE,52
166
+ openscvx-0.5.3.dev35.dist-info/scm_file_list.json,sha256=SlBGAndk9F0hQaBc0H6_xbLqjPOhzhpxfYjAYRvf1M8,18093
167
+ openscvx-0.5.3.dev35.dist-info/scm_version.json,sha256=Cx_YDZgQq_q8oE32xSp_vT9pYGqjZ26SBE6bmsrbdT4,161
168
+ openscvx-0.5.3.dev35.dist-info/top_level.txt,sha256=nUT4Ybefzh40H8tVXqc1RzKESy_MAowElb-CIvAbd4Q,9
169
+ openscvx-0.5.3.dev35.dist-info/RECORD,,
@@ -220,6 +220,8 @@
220
220
  "tests/test_propagation.py",
221
221
  "tests/hohmann_analytical.py",
222
222
  "tests/test_expert.py",
223
+ "tests/test_results_parameters.py",
224
+ "tests/test_post_process_batched_tau_clamp.py",
223
225
  "tests/test_solve_batched_inference.py",
224
226
  "tests/test_solve_jax_bare_brachistochrone.py",
225
227
  "tests/test_cvxpygen_optional.py",
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "0.5.2",
3
+ "distance": 35,
4
+ "node": "g43f7b7f313888f19e8586f108d8e11bed332f87f",
5
+ "dirty": false,
6
+ "branch": "main",
7
+ "node_date": "2026-07-06"
8
+ }
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "0.5.2",
3
- "distance": 33,
4
- "node": "g3d6f6768a9d011c99ab12c85b6695002b0606580",
5
- "dirty": false,
6
- "branch": "main",
7
- "node_date": "2026-07-05"
8
- }