sdplab 0.0.1__tar.gz

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.
Files changed (44) hide show
  1. sdplab-0.0.1/LICENSE +201 -0
  2. sdplab-0.0.1/PKG-INFO +167 -0
  3. sdplab-0.0.1/README.md +135 -0
  4. sdplab-0.0.1/pyproject.toml +65 -0
  5. sdplab-0.0.1/sdplab/__init__.py +115 -0
  6. sdplab-0.0.1/sdplab/_version.py +17 -0
  7. sdplab-0.0.1/sdplab/examples/__init__.py +56 -0
  8. sdplab-0.0.1/sdplab/examples/_max_cut.py +168 -0
  9. sdplab-0.0.1/sdplab/examples/q_tomography/__init__.py +24 -0
  10. sdplab-0.0.1/sdplab/examples/q_tomography/_build.py +130 -0
  11. sdplab-0.0.1/sdplab/examples/qot/__init__.py +31 -0
  12. sdplab-0.0.1/sdplab/examples/qot/_random.py +132 -0
  13. sdplab-0.0.1/sdplab/linalg/__init__.py +22 -0
  14. sdplab-0.0.1/sdplab/linalg/dense/__init__.py +23 -0
  15. sdplab-0.0.1/sdplab/linalg/dense/_kron.py +66 -0
  16. sdplab-0.0.1/sdplab/linalg/dense/_ptrace.py +65 -0
  17. sdplab-0.0.1/sdplab/problem/__init__.py +70 -0
  18. sdplab-0.0.1/sdplab/problem/_base.py +313 -0
  19. sdplab-0.0.1/sdplab/problem/_constraint.py +253 -0
  20. sdplab-0.0.1/sdplab/problem/_cost.py +434 -0
  21. sdplab-0.0.1/sdplab/regularization/__init__.py +51 -0
  22. sdplab-0.0.1/sdplab/regularization/_base.py +295 -0
  23. sdplab-0.0.1/sdplab/regularization/_eval_space.py +77 -0
  24. sdplab-0.0.1/sdplab/regularization/_functional.py +221 -0
  25. sdplab-0.0.1/sdplab/regularization/entropy.py +87 -0
  26. sdplab-0.0.1/sdplab/regularization/quadratic.py +170 -0
  27. sdplab-0.0.1/sdplab/solvers/__init__.py +30 -0
  28. sdplab-0.0.1/sdplab/solvers/_common.py +80 -0
  29. sdplab-0.0.1/sdplab/solvers/_cvxpy.py +156 -0
  30. sdplab-0.0.1/sdplab/solvers/_regularized.py +234 -0
  31. sdplab-0.0.1/sdplab/special/__init__.py +15 -0
  32. sdplab-0.0.1/sdplab/special/pauli/__init__.py +25 -0
  33. sdplab-0.0.1/sdplab/special/pauli/_operators.py +791 -0
  34. sdplab-0.0.1/sdplab/special/pauli/_pauli.py +110 -0
  35. sdplab-0.0.1/sdplab/special/pauli/_string.py +48 -0
  36. sdplab-0.0.1/sdplab/special/qot/__init__.py +33 -0
  37. sdplab-0.0.1/sdplab/special/qot/_constraint_op.py +398 -0
  38. sdplab-0.0.1/sdplab/special/qot/_cvxpy.py +119 -0
  39. sdplab-0.0.1/sdplab.egg-info/PKG-INFO +167 -0
  40. sdplab-0.0.1/sdplab.egg-info/SOURCES.txt +42 -0
  41. sdplab-0.0.1/sdplab.egg-info/dependency_links.txt +1 -0
  42. sdplab-0.0.1/sdplab.egg-info/requires.txt +12 -0
  43. sdplab-0.0.1/sdplab.egg-info/top_level.txt +1 -0
  44. sdplab-0.0.1/setup.cfg +4 -0
sdplab-0.0.1/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Pavlo Pelikh
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
sdplab-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.4
2
+ Name: sdplab
3
+ Version: 0.0.1
4
+ Summary: Tools for constructing and solving regularized semidefinite programming problems.
5
+ Author: Pavlo Pelikh
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Pavlo3P/SDPLab
8
+ Project-URL: Repository, https://github.com/Pavlo3P/SDPLab
9
+ Project-URL: Issues, https://github.com/Pavlo3P/SDPLab/issues
10
+ Project-URL: Changelog, https://github.com/Pavlo3P/SDPLab/blob/master/CHANGELOG.md
11
+ Keywords: semidefinite-programming,conic-optimization,convex-optimization,regularization,quantum,jax,numpy
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: numpy
22
+ Requires-Dist: scipy
23
+ Requires-Dist: cvxpy
24
+ Requires-Dist: spacecore<0.5,>=0.4.2
25
+ Provides-Extra: jax
26
+ Requires-Dist: spacecore[jax]; extra == "jax"
27
+ Requires-Dist: jax>=0.9.1; extra == "jax"
28
+ Requires-Dist: optax>=0.2; extra == "jax"
29
+ Provides-Extra: test
30
+ Requires-Dist: pytest>=8.0; extra == "test"
31
+ Dynamic: license-file
32
+
33
+ # SDPLab
34
+
35
+ A library for building semidefinite and conic programs and solving them
36
+ through their **smoothed dual**. Problem data, spectral regularizers, and the
37
+ dual functional live here; every first-order optimization loop is delegated to
38
+ [spacecore](https://pypi.org/project/spacecore/).
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ pip install sdplab
44
+ ```
45
+
46
+ The JAX backend and the optax optimizer are optional:
47
+
48
+ ```bash
49
+ pip install "sdplab[jax]"
50
+ ```
51
+
52
+ ## The problem
53
+
54
+ $$
55
+ \begin{aligned}
56
+ \min_{X \in \mathrm{dom}(\mathcal{A})}\quad
57
+ & \langle C, X\rangle \\
58
+ \text{s.t.}\quad
59
+ & \mathcal{A}X = b, \\
60
+ & X \succeq 0.
61
+ \end{aligned}
62
+ $$
63
+
64
+ | symbol | code | meaning |
65
+ | --- | --- | --- |
66
+ | $\mathrm{dom}(\mathcal{A})$ | `problem.dom` | space of $X$ and $C$ |
67
+ | $\mathrm{cod}(\mathcal{A})$ | `problem.cod` | space of $\mathcal{A}X$, $b$, and the dual $y$ |
68
+ | $\mathcal{A}$ | `problem.A` | linear constraint operator, a spacecore `LinOp` |
69
+ | $\mathcal{A}^\dagger y - C$ | `problem.dual_slack(y)` | dual slack |
70
+
71
+ $X$ is a plain element of a spacecore Euclidean Jordan algebra space — a
72
+ Hermitian matrix (classic SDP), a nonnegative vector (LP), or a tree of such
73
+ blocks — and $X \succeq 0$ means a nonnegative Jordan spectrum. Solvers accept
74
+ and return raw arrays and trees; there are no wrapper objects.
75
+
76
+ ```python
77
+ import numpy as np
78
+ from spacecore import Context, DenseLinOp, DenseVectorSpace, HermitianSpace, NumpyOps
79
+ from sdplab import SDPProblem
80
+
81
+ ctx = Context(NumpyOps()) # optional; see the spacecore docs
82
+ dom = HermitianSpace(n, ctx=ctx) # X and C live here
83
+ cod = DenseVectorSpace((m,), ctx=ctx) # A X, b, and the dual y live here
84
+
85
+ A = DenseLinOp(A_mats, dom, cod, ctx=ctx)
86
+ problem = SDPProblem(C, A, b, ctx=ctx)
87
+ ```
88
+
89
+ Solve it directly with the CVXPY reference backend:
90
+
91
+ ```python
92
+ from sdplab.solvers import run_cvxpy_solver
93
+
94
+ X, y = run_cvxpy_solver(problem, solver="CLARABEL")
95
+ ```
96
+
97
+ ## The smoothed dual
98
+
99
+ Penalize the primal with a superlinear convex $\varphi$ at strength
100
+ $\varepsilon > 0$:
101
+
102
+ $$
103
+ \min_X\ \langle C, X\rangle + \varepsilon\,\mathrm{Tr}[\varphi(X)]
104
+ \quad\text{s.t.}\quad \mathcal{A}X = b,\ X \succeq 0.
105
+ $$
106
+
107
+ Its dual is unconstrained and differentiable:
108
+
109
+ $$
110
+ \max_{y}\ D_\varepsilon(y) = \langle b, y\rangle - \varepsilon\,
111
+ \mathrm{Tr}\!\left[\psi\!\left(\frac{\mathcal{A}^\dagger y - C}{\varepsilon}\right)\right],
112
+ $$
113
+
114
+ with $\psi$ the Legendre transform of $\varphi$. Gradient methods apply, and the
115
+ primal is read back off the eigenvalues $s_i$ of the dual slack:
116
+ $\lambda_i(X) = \psi'(s_i/\varepsilon)$.
117
+
118
+ This route **assumes a unit-trace primal** — `primal_from_dual` normalizes to
119
+ $\mathrm{Tr}\,X = 1$ — so pose the problem accordingly, hence `unit_trace=True`
120
+ below. On a problem whose feasible set has a different trace the recovered $X$
121
+ is not feasible for it.
122
+
123
+ ```python
124
+ from sdplab import EntropyReg, RegularizedSDPDualFunctional, run_regularized_solver
125
+ from sdplab.examples import generate_max_cut
126
+
127
+ problem = generate_max_cut(8, seed=0, unit_trace=True)
128
+ dual = RegularizedSDPDualFunctional(problem, EntropyReg(problem.dom))
129
+
130
+ result = run_regularized_solver(dual.bind(0.1), verbose=0)
131
+ X = dual.primal_from_dual(result.dual, 0.1)
132
+
133
+ problem.primal_objective(X) # -5.0859, against -5.0990 from CVXPY
134
+ ```
135
+
136
+ $\varepsilon$ is a per-call argument, so a continuation schedule can lower it
137
+ without rebuilding anything; `bind(eps)` fixes it and yields a standard
138
+ single-argument `spacecore.Functional`.
139
+
140
+ The theoretical basis for the regularized SDP formulation — the smoothed dual,
141
+ the primal recovery map, and the $\varepsilon \downarrow 0$ limit — is developed
142
+ in [arXiv:2602.23144](https://arxiv.org/abs/2602.23144).
143
+
144
+ ## Regularizers
145
+
146
+ | class | $\varphi(t)$ |
147
+ | --- | --- |
148
+ | `EntropyReg` | $t(\log t - 1)$ |
149
+ | `QuadraticReg` | $t^2/2$ |
150
+
151
+ ## Examples
152
+
153
+ `sdplab.examples` ships three instances, chosen to differ in the structure of
154
+ $\mathcal{A}$:
155
+
156
+ - `generate_max_cut` — real, diagonal extraction. `unit_trace=True` rescales the
157
+ variable so $\mathrm{Tr}\,X = 1$.
158
+ - `generate_random_qot` — quantum optimal transport: complex, with a stacked
159
+ Hermitian-block codomain, so the dual is a tuple of matrices.
160
+ - `generate_qubit_tomography` — zero cost, so pure feasibility.
161
+
162
+ ## Backends
163
+
164
+ Everything is written against spacecore's backend contract, so NumPy, JAX, and
165
+ torch contexts all work. `run_regularized_solver` picks
166
+ `spacecore.minimize_optax` on a JAX backend and `spacecore.minimize_scipy`
167
+ otherwise.
sdplab-0.0.1/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # SDPLab
2
+
3
+ A library for building semidefinite and conic programs and solving them
4
+ through their **smoothed dual**. Problem data, spectral regularizers, and the
5
+ dual functional live here; every first-order optimization loop is delegated to
6
+ [spacecore](https://pypi.org/project/spacecore/).
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ pip install sdplab
12
+ ```
13
+
14
+ The JAX backend and the optax optimizer are optional:
15
+
16
+ ```bash
17
+ pip install "sdplab[jax]"
18
+ ```
19
+
20
+ ## The problem
21
+
22
+ $$
23
+ \begin{aligned}
24
+ \min_{X \in \mathrm{dom}(\mathcal{A})}\quad
25
+ & \langle C, X\rangle \\
26
+ \text{s.t.}\quad
27
+ & \mathcal{A}X = b, \\
28
+ & X \succeq 0.
29
+ \end{aligned}
30
+ $$
31
+
32
+ | symbol | code | meaning |
33
+ | --- | --- | --- |
34
+ | $\mathrm{dom}(\mathcal{A})$ | `problem.dom` | space of $X$ and $C$ |
35
+ | $\mathrm{cod}(\mathcal{A})$ | `problem.cod` | space of $\mathcal{A}X$, $b$, and the dual $y$ |
36
+ | $\mathcal{A}$ | `problem.A` | linear constraint operator, a spacecore `LinOp` |
37
+ | $\mathcal{A}^\dagger y - C$ | `problem.dual_slack(y)` | dual slack |
38
+
39
+ $X$ is a plain element of a spacecore Euclidean Jordan algebra space — a
40
+ Hermitian matrix (classic SDP), a nonnegative vector (LP), or a tree of such
41
+ blocks — and $X \succeq 0$ means a nonnegative Jordan spectrum. Solvers accept
42
+ and return raw arrays and trees; there are no wrapper objects.
43
+
44
+ ```python
45
+ import numpy as np
46
+ from spacecore import Context, DenseLinOp, DenseVectorSpace, HermitianSpace, NumpyOps
47
+ from sdplab import SDPProblem
48
+
49
+ ctx = Context(NumpyOps()) # optional; see the spacecore docs
50
+ dom = HermitianSpace(n, ctx=ctx) # X and C live here
51
+ cod = DenseVectorSpace((m,), ctx=ctx) # A X, b, and the dual y live here
52
+
53
+ A = DenseLinOp(A_mats, dom, cod, ctx=ctx)
54
+ problem = SDPProblem(C, A, b, ctx=ctx)
55
+ ```
56
+
57
+ Solve it directly with the CVXPY reference backend:
58
+
59
+ ```python
60
+ from sdplab.solvers import run_cvxpy_solver
61
+
62
+ X, y = run_cvxpy_solver(problem, solver="CLARABEL")
63
+ ```
64
+
65
+ ## The smoothed dual
66
+
67
+ Penalize the primal with a superlinear convex $\varphi$ at strength
68
+ $\varepsilon > 0$:
69
+
70
+ $$
71
+ \min_X\ \langle C, X\rangle + \varepsilon\,\mathrm{Tr}[\varphi(X)]
72
+ \quad\text{s.t.}\quad \mathcal{A}X = b,\ X \succeq 0.
73
+ $$
74
+
75
+ Its dual is unconstrained and differentiable:
76
+
77
+ $$
78
+ \max_{y}\ D_\varepsilon(y) = \langle b, y\rangle - \varepsilon\,
79
+ \mathrm{Tr}\!\left[\psi\!\left(\frac{\mathcal{A}^\dagger y - C}{\varepsilon}\right)\right],
80
+ $$
81
+
82
+ with $\psi$ the Legendre transform of $\varphi$. Gradient methods apply, and the
83
+ primal is read back off the eigenvalues $s_i$ of the dual slack:
84
+ $\lambda_i(X) = \psi'(s_i/\varepsilon)$.
85
+
86
+ This route **assumes a unit-trace primal** — `primal_from_dual` normalizes to
87
+ $\mathrm{Tr}\,X = 1$ — so pose the problem accordingly, hence `unit_trace=True`
88
+ below. On a problem whose feasible set has a different trace the recovered $X$
89
+ is not feasible for it.
90
+
91
+ ```python
92
+ from sdplab import EntropyReg, RegularizedSDPDualFunctional, run_regularized_solver
93
+ from sdplab.examples import generate_max_cut
94
+
95
+ problem = generate_max_cut(8, seed=0, unit_trace=True)
96
+ dual = RegularizedSDPDualFunctional(problem, EntropyReg(problem.dom))
97
+
98
+ result = run_regularized_solver(dual.bind(0.1), verbose=0)
99
+ X = dual.primal_from_dual(result.dual, 0.1)
100
+
101
+ problem.primal_objective(X) # -5.0859, against -5.0990 from CVXPY
102
+ ```
103
+
104
+ $\varepsilon$ is a per-call argument, so a continuation schedule can lower it
105
+ without rebuilding anything; `bind(eps)` fixes it and yields a standard
106
+ single-argument `spacecore.Functional`.
107
+
108
+ The theoretical basis for the regularized SDP formulation — the smoothed dual,
109
+ the primal recovery map, and the $\varepsilon \downarrow 0$ limit — is developed
110
+ in [arXiv:2602.23144](https://arxiv.org/abs/2602.23144).
111
+
112
+ ## Regularizers
113
+
114
+ | class | $\varphi(t)$ |
115
+ | --- | --- |
116
+ | `EntropyReg` | $t(\log t - 1)$ |
117
+ | `QuadraticReg` | $t^2/2$ |
118
+
119
+ ## Examples
120
+
121
+ `sdplab.examples` ships three instances, chosen to differ in the structure of
122
+ $\mathcal{A}$:
123
+
124
+ - `generate_max_cut` — real, diagonal extraction. `unit_trace=True` rescales the
125
+ variable so $\mathrm{Tr}\,X = 1$.
126
+ - `generate_random_qot` — quantum optimal transport: complex, with a stacked
127
+ Hermitian-block codomain, so the dual is a tuple of matrices.
128
+ - `generate_qubit_tomography` — zero cost, so pure feasibility.
129
+
130
+ ## Backends
131
+
132
+ Everything is written against spacecore's backend contract, so NumPy, JAX, and
133
+ torch contexts all work. `run_regularized_solver` picks
134
+ `spacecore.minimize_optax` on a JAX backend and `spacecore.minimize_scipy`
135
+ otherwise.
@@ -0,0 +1,65 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sdplab"
7
+ dynamic = ["version"]
8
+ description = "Tools for constructing and solving regularized semidefinite programming problems."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ { name = "Pavlo Pelikh" }
15
+ ]
16
+ dependencies = [
17
+ "numpy",
18
+ "scipy",
19
+ "cvxpy",
20
+ "spacecore>=0.4.2,<0.5",
21
+ ]
22
+
23
+ keywords = [
24
+ "semidefinite-programming",
25
+ "conic-optimization",
26
+ "convex-optimization",
27
+ "regularization",
28
+ "quantum",
29
+ "jax",
30
+ "numpy",
31
+ ]
32
+
33
+ classifiers = [
34
+ "Development Status :: 3 - Alpha",
35
+ "Intended Audience :: Science/Research",
36
+ "Programming Language :: Python :: 3",
37
+ "Programming Language :: Python :: 3.11",
38
+ "Programming Language :: Python :: 3.12",
39
+ "Topic :: Scientific/Engineering :: Mathematics",
40
+ ]
41
+
42
+ [project.optional-dependencies]
43
+ jax = [
44
+ "spacecore[jax]",
45
+ "jax>=0.9.1",
46
+ "optax>=0.2",
47
+ ]
48
+ test = [
49
+ "pytest>=8.0",
50
+ ]
51
+
52
+ [project.urls]
53
+ Homepage = "https://github.com/Pavlo3P/SDPLab"
54
+ Repository = "https://github.com/Pavlo3P/SDPLab"
55
+ Issues = "https://github.com/Pavlo3P/SDPLab/issues"
56
+ Changelog = "https://github.com/Pavlo3P/SDPLab/blob/master/CHANGELOG.md"
57
+
58
+ [tool.setuptools.dynamic]
59
+ version = { attr = "sdplab._version.__version__" }
60
+
61
+ [tool.setuptools.packages.find]
62
+ include = ["sdplab*"]
63
+
64
+ [tool.pytest.ini_options]
65
+ testpaths = ["tests"]
@@ -0,0 +1,115 @@
1
+ # Copyright 2026 Pavlo Pelikh
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ r"""Semidefinite and conic programs over spacecore Euclidean Jordan algebras.
16
+
17
+ .. math::
18
+
19
+ \min_X \quad \langle C, X\rangle
20
+ \quad \text{s.t.} \quad \mathcal{A}X = b,\quad X \succeq 0
21
+
22
+ ``X`` is any Jordan-algebra element -- Hermitian matrix, nonnegative vector, or
23
+ a tree of such blocks -- and :math:`X \succeq 0` means a nonnegative spectrum.
24
+ Build with ``SDPProblem(C, A, b)``; solve with :func:`run_cvxpy_solver`, or
25
+ smooth it: a :class:`Regularizer` through
26
+ :class:`RegularizedSDPDualFunctional`, ``.bind(eps)``, then
27
+ :func:`run_regularized_solver`.
28
+
29
+ Smoothing adds :math:`\varepsilon \operatorname{Tr}[\varphi(X)]` to the primal,
30
+ giving the differentiable dual
31
+
32
+ .. math::
33
+
34
+ D_\varepsilon(y) = \langle b, y\rangle - \varepsilon
35
+ \operatorname{Tr}\!\big[\psi\big(
36
+ (\mathcal{A}^\dagger y - C)/\varepsilon\big)\big],
37
+
38
+ maximized over ``y`` in ``cod``, with :math:`\psi'` of the dual slack
39
+ recovering the primal. :math:`\varepsilon` is per-call, so continuation needs
40
+ no rebuild.
41
+
42
+ Subpackages: :mod:`~sdplab.problem`, :mod:`~sdplab.regularization`,
43
+ :mod:`~sdplab.solvers`, :mod:`~sdplab.examples`, :mod:`~sdplab.linalg`,
44
+ :mod:`~sdplab.special`.
45
+ """
46
+
47
+ from __future__ import annotations
48
+
49
+ from typing import TYPE_CHECKING
50
+
51
+ from .problem import (
52
+ ConstraintOp,
53
+ Cost,
54
+ DenseConstraintOp,
55
+ MatrixFreeConstraintOp,
56
+ SDPProblem,
57
+ SparseConstraintOp,
58
+ )
59
+ from .regularization import (
60
+ BoundDualFunctional,
61
+ EntropyReg,
62
+ QuadraticReg,
63
+ RegularizedSDPDualFunctional,
64
+ Regularizer,
65
+ )
66
+ from ._version import __version__
67
+
68
+ # Solvers pull in CVXPY (~1.2s), making an optional backend a hard requirement
69
+ # for anyone who only builds problems. PEP 562 keeps them reachable as
70
+ # ``sdplab.run_*`` while deferring the cost to first use.
71
+ _LAZY = {
72
+ "run_regularized_solver": "sdplab.solvers",
73
+ "run_cvxpy_solver": "sdplab.solvers",
74
+ }
75
+
76
+ if TYPE_CHECKING: # type checkers and IDEs do not run __getattr__
77
+ from .solvers import run_cvxpy_solver, run_regularized_solver
78
+
79
+
80
+ def __getattr__(name: str):
81
+ """Resolve the lazily-exported solver entry points on first access."""
82
+ module = _LAZY.get(name)
83
+ if module is None:
84
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
85
+ import importlib
86
+
87
+ value = getattr(importlib.import_module(module), name)
88
+ globals()[name] = value # cache, so this runs once per name
89
+ return value
90
+
91
+
92
+ def __dir__() -> list[str]:
93
+ """Include the lazy names in ``dir(sdplab)`` and tab completion."""
94
+ return sorted(set(globals()) | set(_LAZY))
95
+
96
+
97
+ __all__ = [
98
+ "__version__",
99
+ # problem data
100
+ "SDPProblem",
101
+ "Cost",
102
+ "ConstraintOp",
103
+ "DenseConstraintOp",
104
+ "SparseConstraintOp",
105
+ "MatrixFreeConstraintOp",
106
+ # regularization and the smoothed dual
107
+ "Regularizer",
108
+ "EntropyReg",
109
+ "QuadraticReg",
110
+ "RegularizedSDPDualFunctional",
111
+ "BoundDualFunctional",
112
+ # solvers (lazy)
113
+ "run_regularized_solver",
114
+ "run_cvxpy_solver",
115
+ ]