openscvx 2.dev5__py3-none-any.whl → 2.dev6__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/__init__.py CHANGED
@@ -12,6 +12,7 @@ import openscvx.symbolic.expr.spatial as spatial
12
12
  import openscvx.symbolic.expr.stl as stl
13
13
  import openscvx.symbolic.expr.stljax as stljax
14
14
  from openscvx.algorithms import (
15
+ AdaptiveProximalWeight,
15
16
  AugmentedLagrangian,
16
17
  ConstantProximalWeight,
17
18
  PenalizedTrustRegion,
@@ -190,6 +191,7 @@ __all__ = [
190
191
  # Algorithm & Autotuning
191
192
  "PenalizedTrustRegion",
192
193
  "AugmentedLagrangian",
194
+ "AdaptiveProximalWeight",
193
195
  "ConstantProximalWeight",
194
196
  "RampProximalWeight",
195
197
  ]
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 = '2.dev5'
22
- __version_tuple__ = version_tuple = (2, 'dev5')
21
+ __version__ = version = '2.dev6'
22
+ __version_tuple__ = version_tuple = (2, 'dev6')
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -82,12 +82,19 @@ from typing import Annotated, Any, Dict, List, Optional, Union
82
82
 
83
83
  from pydantic import BaseModel, ConfigDict, Field, field_validator
84
84
 
85
- from .augmented_lagrangian import AugmentedLagrangian, AugmentedLagrangianSpec
85
+ from .autotuner import (
86
+ AdaptiveProximalWeight,
87
+ AdaptiveProximalWeightSpec,
88
+ AugmentedLagrangian,
89
+ AugmentedLagrangianSpec,
90
+ ConstantProximalWeight,
91
+ ConstantProximalWeightSpec,
92
+ RampProximalWeight,
93
+ RampProximalWeightSpec,
94
+ )
86
95
  from .base import Algorithm, AlgorithmState, AutotuningBase, DiscretizationResult
87
- from .constant_proximal_weight import ConstantProximalWeight, ConstantProximalWeightSpec
88
96
  from .optimization_results import OptimizationResults
89
- from .penalized_trust_region import PenalizedTrustRegion
90
- from .ramp_proximal_weight import RampProximalWeight, RampProximalWeightSpec
97
+ from .scvx import PenalizedTrustRegion
91
98
  from .weights import Weights
92
99
 
93
100
  # ---------------------------------------------------------------------------
@@ -97,6 +104,7 @@ from .weights import Weights
97
104
  AutotunerConfig = Annotated[
98
105
  Union[
99
106
  AugmentedLagrangianSpec,
107
+ AdaptiveProximalWeightSpec,
100
108
  RampProximalWeightSpec,
101
109
  ConstantProximalWeightSpec,
102
110
  ],
@@ -173,6 +181,7 @@ __all__ = [
173
181
  "PenalizedTrustRegion",
174
182
  "AutotuningBase",
175
183
  "AugmentedLagrangian",
184
+ "AdaptiveProximalWeight",
176
185
  "ConstantProximalWeight",
177
186
  "RampProximalWeight",
178
187
  # Config models
@@ -0,0 +1,17 @@
1
+ """SCP weight autotuning strategies."""
2
+
3
+ from .adaptive_proximal_weight import AdaptiveProximalWeight, AdaptiveProximalWeightSpec
4
+ from .augmented_lagrangian import AugmentedLagrangian, AugmentedLagrangianSpec
5
+ from .constant_proximal_weight import ConstantProximalWeight, ConstantProximalWeightSpec
6
+ from .ramp_proximal_weight import RampProximalWeight, RampProximalWeightSpec
7
+
8
+ __all__ = [
9
+ "AdaptiveProximalWeight",
10
+ "AdaptiveProximalWeightSpec",
11
+ "AugmentedLagrangian",
12
+ "AugmentedLagrangianSpec",
13
+ "ConstantProximalWeight",
14
+ "ConstantProximalWeightSpec",
15
+ "RampProximalWeight",
16
+ "RampProximalWeightSpec",
17
+ ]
@@ -0,0 +1,190 @@
1
+ """Autotuning functions for SCP (Successive Convex Programming) parameters."""
2
+
3
+ from copy import deepcopy
4
+ from typing import TYPE_CHECKING, Literal
5
+
6
+ import numpy as np
7
+ from pydantic import BaseModel, ConfigDict
8
+
9
+ from openscvx.config import Config
10
+
11
+ from ..base import AutotuningBase
12
+ from .augmented_lagrangian import AugmentedLagrangian
13
+
14
+ if TYPE_CHECKING:
15
+ from openscvx.lowered import LoweredJaxConstraints
16
+
17
+ from ..base import AlgorithmState, CandidateIterate
18
+ from ..weights import Weights
19
+
20
+
21
+ class AdaptiveProximalWeight(AutotuningBase):
22
+ """PTR-style proximal adaptation with fixed virtual penalty weights.
23
+
24
+ Same acceptance-ratio logic as :class:`AugmentedLagrangian` for ``lam_prox``,
25
+ but ``lam_vc`` and ``lam_vb_*`` are held constant at their current state values.
26
+ """
27
+
28
+ COLUMNS = AugmentedLagrangian.COLUMNS
29
+
30
+ def __init__(
31
+ self,
32
+ gamma_1: float = 2.0,
33
+ gamma_2: float = 0.5,
34
+ eta_0: float = 1e-2,
35
+ eta_1: float = 1e-1,
36
+ eta_2: float = 0.8,
37
+ lam_prox_min: float = 1e-3,
38
+ lam_prox_max: float = 1e4,
39
+ lam_cost_drop: int = -1,
40
+ lam_cost_relax: float = 1.0,
41
+ ):
42
+ self.gamma_1 = gamma_1
43
+ self.gamma_2 = gamma_2
44
+ self.eta_0 = eta_0
45
+ self.eta_1 = eta_1
46
+ self.eta_2 = eta_2
47
+ self.lam_prox_min = lam_prox_min
48
+ self.lam_prox_max = lam_prox_max
49
+ self.lam_cost_drop = lam_cost_drop
50
+ self.lam_cost_relax = lam_cost_relax
51
+
52
+ @staticmethod
53
+ def _copy_virtual_weights(
54
+ candidate: "CandidateIterate",
55
+ state: "AlgorithmState",
56
+ ) -> None:
57
+ candidate.lam_vc = state.lam_vc
58
+ candidate.lam_vb_nodal = state.lam_vb_nodal
59
+ candidate.lam_vb_cross = state.lam_vb_cross
60
+
61
+ def update_weights(
62
+ self,
63
+ state: "AlgorithmState",
64
+ candidate: "CandidateIterate",
65
+ nodal_constraints: "LoweredJaxConstraints",
66
+ settings: Config,
67
+ params: dict,
68
+ weights: "Weights",
69
+ ) -> str:
70
+ """Update SCP proximal weight based on acceptance ratio; keep VC/VB fixed."""
71
+ candidate_x_prop = (
72
+ candidate.x_prop_plus[1:] if candidate.x_prop_plus is not None else candidate.x_prop
73
+ )
74
+ (
75
+ nonlinear_cost,
76
+ nonlinear_penalty,
77
+ nodal_penalty,
78
+ ) = self.calculate_nonlinear_penalty(
79
+ candidate_x_prop,
80
+ candidate.x,
81
+ candidate.u,
82
+ state.lam_vc,
83
+ state.lam_vb_nodal,
84
+ state.lam_vb_cross,
85
+ state.lam_cost,
86
+ nodal_constraints,
87
+ params,
88
+ settings,
89
+ )
90
+
91
+ candidate.J_nonlin = nonlinear_cost + nonlinear_penalty + nodal_penalty
92
+
93
+ if state.k > self.lam_cost_drop:
94
+ candidate.lam_cost = state.lam_cost * self.lam_cost_relax
95
+ else:
96
+ candidate.lam_cost = weights.lam_cost
97
+
98
+ lam_prox_k = deepcopy(state.lam_prox)
99
+
100
+ if state.k > 1:
101
+ state_x_prop_plus = state.x_prop_plus()
102
+ state_x_prop = (
103
+ state_x_prop_plus[1:] if state_x_prop_plus is not None else state.x_prop()
104
+ )
105
+ (
106
+ prev_nonlinear_cost,
107
+ prev_nonlinear_penalty,
108
+ prev_nodal_penalty,
109
+ ) = self.calculate_nonlinear_penalty(
110
+ state_x_prop,
111
+ state.x,
112
+ state.u,
113
+ state.lam_vc,
114
+ state.lam_vb_nodal,
115
+ state.lam_vb_cross,
116
+ state.lam_cost,
117
+ nodal_constraints,
118
+ params,
119
+ settings,
120
+ )
121
+
122
+ J_nonlin_prev = prev_nonlinear_cost + prev_nonlinear_penalty + prev_nodal_penalty
123
+
124
+ actual_reduction = J_nonlin_prev - candidate.J_nonlin
125
+ predicted_reduction = J_nonlin_prev - candidate.J_lin
126
+
127
+ if predicted_reduction == 0:
128
+ raise ValueError("Predicted reduction is 0.")
129
+
130
+ rho = actual_reduction / predicted_reduction
131
+
132
+ state.pred_reduction_history.append(predicted_reduction)
133
+ state.actual_reduction_history.append(actual_reduction)
134
+ state.acceptance_ratio_history.append(rho)
135
+
136
+ if rho < self.eta_0:
137
+ lam_prox_k1 = np.minimum(self.lam_prox_max, self.gamma_1 * lam_prox_k)
138
+ candidate.lam_prox = lam_prox_k1
139
+ state.reject_solution(candidate)
140
+ adaptive_state = "Reject Higher"
141
+ elif rho >= self.eta_0 and rho < self.eta_1:
142
+ lam_prox_k1 = np.minimum(self.lam_prox_max, self.gamma_1 * lam_prox_k)
143
+ candidate.lam_prox = lam_prox_k1
144
+ self._copy_virtual_weights(candidate, state)
145
+ state.accept_solution(candidate)
146
+ adaptive_state = "Accept Higher"
147
+ elif rho >= self.eta_1 and rho < self.eta_2:
148
+ candidate.lam_prox = lam_prox_k
149
+ self._copy_virtual_weights(candidate, state)
150
+ state.accept_solution(candidate)
151
+ adaptive_state = "Accept Constant"
152
+ else:
153
+ lam_prox_k1 = np.maximum(self.lam_prox_min, self.gamma_2 * lam_prox_k)
154
+ candidate.lam_prox = lam_prox_k1
155
+ self._copy_virtual_weights(candidate, state)
156
+ state.accept_solution(candidate)
157
+ adaptive_state = "Accept Lower"
158
+
159
+ else:
160
+ candidate.lam_prox = lam_prox_k
161
+ self._copy_virtual_weights(candidate, state)
162
+ state.accept_solution(candidate)
163
+ adaptive_state = "Initial"
164
+
165
+ return adaptive_state
166
+
167
+
168
+ # =============================================================================
169
+ # Pydantic spec for dict / YAML validation
170
+ # =============================================================================
171
+
172
+
173
+ class AdaptiveProximalWeightSpec(BaseModel):
174
+ """Validates AdaptiveProximalWeight configuration from dict/YAML input."""
175
+
176
+ type: Literal["AdaptiveProximalWeight"] = "AdaptiveProximalWeight"
177
+ gamma_1: float = 2.0
178
+ gamma_2: float = 0.5
179
+ eta_0: float = 1e-2
180
+ eta_1: float = 1e-1
181
+ eta_2: float = 0.8
182
+ lam_prox_min: float = 1e-3
183
+ lam_prox_max: float = 1e4
184
+ lam_cost_drop: int = -1
185
+ lam_cost_relax: float = 1.0
186
+
187
+ model_config = ConfigDict(extra="forbid")
188
+
189
+ def build(self) -> AdaptiveProximalWeight:
190
+ return AdaptiveProximalWeight(**self.model_dump(exclude={"type"}, exclude_unset=True))
@@ -14,13 +14,13 @@ from openscvx.utils.printing import (
14
14
  color_adaptive_state,
15
15
  )
16
16
 
17
- from .base import AutotuningBase
17
+ from ..base import AutotuningBase
18
18
 
19
19
  if TYPE_CHECKING:
20
20
  from openscvx.lowered import LoweredJaxConstraints
21
21
 
22
- from .base import AlgorithmState, CandidateIterate
23
- from .weights import Weights
22
+ from ..base import AlgorithmState, CandidateIterate
23
+ from ..weights import Weights
24
24
 
25
25
 
26
26
  class AugmentedLagrangian(AutotuningBase):
@@ -86,8 +86,12 @@ class AugmentedLagrangian(AutotuningBase):
86
86
  eta_2: Threshold above which solution is accepted with lower weight.
87
87
  Defaults to 0.8.
88
88
  ep: Threshold for virtual control weight update (nu > ep vs nu <= ep).
89
- Defaults to 0.5.
90
- eta_lambda: Step size for virtual control weight update. Defaults to 1e0.
89
+ Must lie in (0, 1). Defaults to 0.99; when tuning, try 1e-1 if needed.
90
+ Typically tuned together with ``eta_lambda`` (often the first
91
+ parameters adjusted).
92
+ eta_lambda: Step size for virtual control weight update. Defaults to 1e1.
93
+ Typically tuned together with ``ep`` (often the first parameters
94
+ adjusted).
91
95
  lam_vc_max: Maximum virtual control penalty weight. Defaults to 1e5.
92
96
  lam_prox_min: Minimum trust region (proximal) weight. Defaults to 1e-3.
93
97
  lam_prox_max: Maximum trust region (proximal) weight. Defaults to 2e5.
@@ -6,13 +6,13 @@ from pydantic import BaseModel, ConfigDict
6
6
 
7
7
  from openscvx.config import Config
8
8
 
9
- from .base import AutotuningBase
9
+ from ..base import AutotuningBase
10
10
 
11
11
  if TYPE_CHECKING:
12
12
  from openscvx.lowered import LoweredJaxConstraints
13
13
 
14
- from .base import AlgorithmState, CandidateIterate
15
- from .weights import Weights
14
+ from ..base import AlgorithmState, CandidateIterate
15
+ from ..weights import Weights
16
16
 
17
17
 
18
18
  class ConstantProximalWeight(AutotuningBase):
@@ -7,13 +7,13 @@ from pydantic import BaseModel, ConfigDict
7
7
 
8
8
  from openscvx.config import Config
9
9
 
10
- from .base import AutotuningBase
10
+ from ..base import AutotuningBase
11
11
 
12
12
  if TYPE_CHECKING:
13
13
  from openscvx.lowered import LoweredJaxConstraints
14
14
 
15
- from .base import AlgorithmState, CandidateIterate
16
- from .weights import Weights
15
+ from ..base import AlgorithmState, CandidateIterate
16
+ from ..weights import Weights
17
17
 
18
18
 
19
19
  class RampProximalWeight(AutotuningBase):
@@ -0,0 +1,5 @@
1
+ """Successive convexification algorithm implementations."""
2
+
3
+ from .penalized_trust_region import PenalizedTrustRegion
4
+
5
+ __all__ = ["PenalizedTrustRegion"]
@@ -22,11 +22,11 @@ from openscvx.utils.printing import (
22
22
  color_prob_stat,
23
23
  )
24
24
 
25
- from .augmented_lagrangian import AugmentedLagrangian
26
- from .base import Algorithm, AlgorithmState, CandidateIterate
27
- from .constant_proximal_weight import ConstantProximalWeight
28
- from .ramp_proximal_weight import RampProximalWeight
29
- from .weights import Weights
25
+ from ..autotuner.augmented_lagrangian import AugmentedLagrangian
26
+ from ..autotuner.constant_proximal_weight import ConstantProximalWeight
27
+ from ..autotuner.ramp_proximal_weight import RampProximalWeight
28
+ from ..base import Algorithm, AlgorithmState, CandidateIterate
29
+ from ..weights import Weights
30
30
 
31
31
  if TYPE_CHECKING:
32
32
  from openscvx.lowered import LoweredJaxConstraints
@@ -34,7 +34,7 @@ if TYPE_CHECKING:
34
34
  from openscvx.symbolic.expr.control import Control
35
35
  from openscvx.symbolic.expr.state import State
36
36
 
37
- from .base import AutotuningBase
37
+ from ..base import AutotuningBase
38
38
 
39
39
  warnings.filterwarnings("ignore")
40
40
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openscvx
3
- Version: 2.dev5
3
+ Version: 2.dev6
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,17 +1,20 @@
1
- openscvx/__init__.py,sha256=xmpOTuaULy4YJFhqUpXGSSMu-vjTBJnFIhohXdi8ttc,3688
1
+ openscvx/__init__.py,sha256=a_aE1InLyrFrx4mrOAsvBvnxbExXjZOSNK9UdfRgz_g,3746
2
2
  openscvx/__main__.py,sha256=Hwm7mtVg3tLdvoUPkpcQv8KF3wxl72PNLBp9axFu8GY,2991
3
- openscvx/_version.py,sha256=weTnVwzOsaNm5p3YrseycYmlTphq5sEq-JrqG3LXouM,523
3
+ openscvx/_version.py,sha256=_vMjYm42122ybxhtL6w7zoTQ8XvZX87uR27CauIPs7I,523
4
4
  openscvx/config.py,sha256=qfDDYoCe6WqJglKsx5b2W48YOglXenKr-PVRRdCFhYE,9898
5
5
  openscvx/loader.py,sha256=FvKLkkXd4ihd5FqLFF8Cd9VnPbPwTV_azBRnEipi28c,7654
6
6
  openscvx/problem.py,sha256=GlCxYFhpacIt6Sxte3-K-d_GbGxVL9F9Qzy4y8-hrGc,47675
7
- openscvx/algorithms/__init__.py,sha256=f5VhjFb40JyVPgJJh6fUxRbmyQIglUyiNYL22nOMrgs,5632
8
- openscvx/algorithms/augmented_lagrangian.py,sha256=liEHtqONbpmw7CZJJCkAluPOEbFslFsvCElWHusHpn4,15807
7
+ openscvx/algorithms/__init__.py,sha256=_jbRLwhiHQGCqs3mide1UTj7AzxJlELnDkqSySNCTIM,5688
9
8
  openscvx/algorithms/base.py,sha256=JsaVfS-hyHeGU1GUuQV9i-EpKQ1HBE0RHABIBGrEonM,30205
10
- openscvx/algorithms/constant_proximal_weight.py,sha256=UopFJHFHaFRTUnpeBEc_wYsSDvmxS9-bSKpI8JGYQII,2846
11
9
  openscvx/algorithms/optimization_results.py,sha256=Fk7tiW8IuMZa8Ri9-SHq9kmw3BPxXl1mc0yXy11w_-c,13416
12
- openscvx/algorithms/penalized_trust_region.py,sha256=2UDZMYshpn0Z52JFjqPji5ececD0SGjZqhSrAT1DbD0,30164
13
- openscvx/algorithms/ramp_proximal_weight.py,sha256=19A-oerRMJjajQpHxeUeXdyTV0_Onr9cw1ttlwbY5_w,3383
14
10
  openscvx/algorithms/weights.py,sha256=DQV9NOR_-59lISv6d_el3cpQ-EcFasSGb1oZr4ma-yA,20682
11
+ openscvx/algorithms/autotuner/__init__.py,sha256=xGO4PrYNQU9cITgigb_ud3p8Zy1P1FCwvT-DtP7j7XU,632
12
+ openscvx/algorithms/autotuner/adaptive_proximal_weight.py,sha256=Gg3BQ3qn_2G5SlLs3_1HbRN8OtM4jLTuDiBEuR20fqw,6512
13
+ openscvx/algorithms/autotuner/augmented_lagrangian.py,sha256=SiIet0-yMFydMpSIyIXT8vval432SksJY_r5sbpzF0U,16088
14
+ openscvx/algorithms/autotuner/constant_proximal_weight.py,sha256=1GVFQ-dRpKX6QmyjCx8DcqSlZHya8XwbFpufU4OeZpY,2849
15
+ openscvx/algorithms/autotuner/ramp_proximal_weight.py,sha256=U6cQcSGMv4G7gdmtiaVGFDQcuc7yqOR244J4rXKAQ7I,3386
16
+ openscvx/algorithms/scvx/__init__.py,sha256=uhMalFKvygm7s7LGYwKKg_a8qeKioM92E74o-b8nN2U,154
17
+ openscvx/algorithms/scvx/penalized_trust_region.py,sha256=xk_ZYWncG0mxPKqbCAtSN1rIXEdmzWlRiw0P0mKUVPs,30200
15
18
  openscvx/discretization/__init__.py,sha256=lDMVvJMuaP3s78IqwQ2N-BmPPp7_vnll-TX5cU3ezlo,2799
16
19
  openscvx/discretization/base.py,sha256=90sbQmMCBPaZ0i0s3nnun7_q6eQZWTB7UmNg1hLhzbQ,9673
17
20
  openscvx/discretization/discretize_linearize.py,sha256=1iXgrdtwpw17A1nX3IPXJCclAEmLeUIygMSYzwPkxHw,16912
@@ -138,9 +141,9 @@ openscvx/utils/caching.py,sha256=BPkT_IbmYT-i-BZ-himdWUc_4oBcwXWJxeUMwQWnSNc,934
138
141
  openscvx/utils/printing.py,sha256=zl3IxnKhwITqB5dK0Ru2IlORPqB61Y3DgsTryqMNu9M,13360
139
142
  openscvx/utils/profiling.py,sha256=k2x-i0CpG_kRe6dNcNBGu-ylrOtQw4B4C1UaOTjUMfU,1678
140
143
  openscvx/utils/utils.py,sha256=M25RHE_7DSr3Reaca0xCXnDSY9KHuqYvXdh5m1ZotEc,3047
141
- openscvx-2.dev5.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
142
- openscvx-2.dev5.dist-info/METADATA,sha256=-i1S5BQH7E22WfWRdoGoe1dUnRoWiwt9DK8YfVVPAp4,10662
143
- openscvx-2.dev5.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
144
- openscvx-2.dev5.dist-info/entry_points.txt,sha256=1Oqek8Sy28hmAZFgZXDxFXYVf56YLYWlHjhh9RYJ7wE,52
145
- openscvx-2.dev5.dist-info/top_level.txt,sha256=nUT4Ybefzh40H8tVXqc1RzKESy_MAowElb-CIvAbd4Q,9
146
- openscvx-2.dev5.dist-info/RECORD,,
144
+ openscvx-2.dev6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
145
+ openscvx-2.dev6.dist-info/METADATA,sha256=oVbcoS-ikeTajYCE_jmyk9xoAsTwQ5v39Zc6qsAOxC4,10662
146
+ openscvx-2.dev6.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
147
+ openscvx-2.dev6.dist-info/entry_points.txt,sha256=1Oqek8Sy28hmAZFgZXDxFXYVf56YLYWlHjhh9RYJ7wE,52
148
+ openscvx-2.dev6.dist-info/top_level.txt,sha256=nUT4Ybefzh40H8tVXqc1RzKESy_MAowElb-CIvAbd4Q,9
149
+ openscvx-2.dev6.dist-info/RECORD,,