pyoptexplain 0.1.0rc1__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.
- pyoptexplain-0.1.0rc1/CHANGELOG.md +1 -0
- pyoptexplain-0.1.0rc1/CONTRIBUTING.md +30 -0
- pyoptexplain-0.1.0rc1/LICENSE +176 -0
- pyoptexplain-0.1.0rc1/MANIFEST.in +4 -0
- pyoptexplain-0.1.0rc1/PKG-INFO +312 -0
- pyoptexplain-0.1.0rc1/README.md +262 -0
- pyoptexplain-0.1.0rc1/pyproject.toml +94 -0
- pyoptexplain-0.1.0rc1/setup.cfg +4 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/__init__.py +126 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/_version.py +3 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/__init__.py +40 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/analyzer.py +659 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/diagnostics/__init__.py +31 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/diagnostics/_common.py +92 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/diagnostics/capabilities.py +139 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/diagnostics/rows.py +413 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/diagnostics/tables.py +291 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/experiments/__init__.py +30 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/experiments/ablation.py +55 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/experiments/base.py +142 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/experiments/group.py +63 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/experiments/relaxation.py +150 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/utils.py +104 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/workflows/__init__.py +20 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/workflows/batch.py +118 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/workflows/grid.py +690 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/workflows/robustness.py +942 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/workflows/scenarios.py +641 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/analysis/workflows/sensitivity.py +370 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/core/__init__.py +77 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/core/blocks.py +131 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/core/certificates.py +115 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/core/changes.py +169 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/core/handles.py +24 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/core/representations.py +26 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/core/results.py +125 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/core/solvers.py +154 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/__init__.py +35 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/_common.py +196 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/basic.py +50 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/cplex.py +934 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/cvxpy.py +1720 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/gurobi.py +1244 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/linear_matrix.py +890 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/ortools.py +1342 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/pyomo.py +1070 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/handles/quadratic_matrix.py +233 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/__init__.py +27 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/_cvxpy_common.py +96 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/_native_scenario.py +75 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/basic.py +156 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/cplex_scenario.py +346 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/cvxpy_scenario.py +368 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/gurobi_scenario.py +432 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/linear_matrix.py +1758 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/matrix_scenario.py +283 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/pyomo_scenario.py +358 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/representations/quadratic_matrix.py +712 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/solvers/__init__.py +31 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/solvers/_common.py +66 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/solvers/cplex.py +419 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/solvers/defaults.py +31 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/solvers/gurobi.py +793 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/solvers/highs.py +658 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/solvers/osqp.py +386 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/solvers/scip.py +342 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/utils/matrices.py +103 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain/utils/names.py +34 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain.egg-info/PKG-INFO +312 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain.egg-info/SOURCES.txt +71 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain.egg-info/dependency_links.txt +1 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain.egg-info/requires.txt +40 -0
- pyoptexplain-0.1.0rc1/src/pyoptexplain.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Changelog
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
`pyoptexplain` is pre-release software. Preserve practitioner-facing block
|
|
4
|
+
identity, require explicit representation selection, and do not claim analyses
|
|
5
|
+
that are not justified by both a representation certificate and backend
|
|
6
|
+
behavior.
|
|
7
|
+
|
|
8
|
+
## Development setup
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
python -m pip install -e ".[dev,cvxpy,pyomo,scip]"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Commercial backend tests additionally require the corresponding package and
|
|
15
|
+
solver license.
|
|
16
|
+
|
|
17
|
+
## Required checks
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
python -W error -m pytest
|
|
21
|
+
python -m pyflakes src
|
|
22
|
+
python -m build
|
|
23
|
+
python -m compileall src tests
|
|
24
|
+
python -m twine check dist/*
|
|
25
|
+
git diff --check
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Add behavior-level tests for every new advertised capability. Keep optional
|
|
29
|
+
solver imports lazy. Do not add compatibility aliases for removed pre-release
|
|
30
|
+
APIs.
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyoptexplain
|
|
3
|
+
Version: 0.1.0rc1
|
|
4
|
+
Summary: Practitioner-first post-optimization analysis for linear, quadratic, and mixed-integer optimization.
|
|
5
|
+
Author: pyoptexplain contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/h-fellahi/pyoptexplain
|
|
8
|
+
Project-URL: Repository, https://github.com/h-fellahi/pyoptexplain
|
|
9
|
+
Project-URL: Issues, https://github.com/h-fellahi/pyoptexplain/issues
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: numpy
|
|
20
|
+
Requires-Dist: scipy
|
|
21
|
+
Requires-Dist: pandas
|
|
22
|
+
Requires-Dist: highspy
|
|
23
|
+
Requires-Dist: osqp
|
|
24
|
+
Requires-Dist: xarray
|
|
25
|
+
Provides-Extra: cvxpy
|
|
26
|
+
Requires-Dist: cvxpy; extra == "cvxpy"
|
|
27
|
+
Provides-Extra: gurobi
|
|
28
|
+
Requires-Dist: gurobipy; extra == "gurobi"
|
|
29
|
+
Provides-Extra: highs
|
|
30
|
+
Requires-Dist: highspy; extra == "highs"
|
|
31
|
+
Provides-Extra: osqp
|
|
32
|
+
Requires-Dist: osqp; extra == "osqp"
|
|
33
|
+
Provides-Extra: cplex
|
|
34
|
+
Requires-Dist: cplex; extra == "cplex"
|
|
35
|
+
Requires-Dist: docplex; extra == "cplex"
|
|
36
|
+
Provides-Extra: scip
|
|
37
|
+
Requires-Dist: pyscipopt>=4.2.0; extra == "scip"
|
|
38
|
+
Provides-Extra: pyomo
|
|
39
|
+
Requires-Dist: pyomo; extra == "pyomo"
|
|
40
|
+
Provides-Extra: ortools
|
|
41
|
+
Requires-Dist: ortools>=9.8; extra == "ortools"
|
|
42
|
+
Provides-Extra: plot
|
|
43
|
+
Requires-Dist: matplotlib; extra == "plot"
|
|
44
|
+
Provides-Extra: dev
|
|
45
|
+
Requires-Dist: build; extra == "dev"
|
|
46
|
+
Requires-Dist: pytest; extra == "dev"
|
|
47
|
+
Requires-Dist: pyflakes; extra == "dev"
|
|
48
|
+
Requires-Dist: twine; extra == "dev"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
# pyoptexplain
|
|
52
|
+
|
|
53
|
+
Practitioner-first post-optimality analysis and explanation for linear,
|
|
54
|
+
quadratic, and mixed-integer optimization.
|
|
55
|
+
|
|
56
|
+
`pyoptexplain` sits *above* the modeling languages used to build a model and the
|
|
57
|
+
solvers used to solve it. It is not a modeling language and not a solver. A model
|
|
58
|
+
authored in any supported front end is adapted into one normalized internal
|
|
59
|
+
representation, solved through a choice of backends, and interrogated through a
|
|
60
|
+
single uniform interface: which constraints bind, what the solution is worth at
|
|
61
|
+
the margin, how it moves under perturbation, and how it changes under what-if
|
|
62
|
+
scenarios.
|
|
63
|
+
|
|
64
|
+
Its guiding principle is honesty. A post-optimality quantity is reported only
|
|
65
|
+
when both the representation and the chosen backend can justify it; unavailable
|
|
66
|
+
information is reported as unavailable rather than approximated.
|
|
67
|
+
|
|
68
|
+
## Install
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install pyoptexplain
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The base install ships NumPy, SciPy, pandas, xarray, and the HiGHS and OSQP
|
|
75
|
+
solvers, so direct-matrix LP, MILP, and QP workflows run immediately. Front ends
|
|
76
|
+
and extra backends are optional extras:
|
|
77
|
+
|
|
78
|
+
| Extra | Pulls in | Use for |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| `pyoptexplain[cvxpy]` | cvxpy | cvxpy model inspection |
|
|
81
|
+
| `pyoptexplain[pyomo]` | Pyomo | Pyomo model inspection |
|
|
82
|
+
| `pyoptexplain[gurobi]` | gurobipy | Gurobi front end + backend |
|
|
83
|
+
| `pyoptexplain[cplex]` | cplex, docplex | CPLEX front end + backend |
|
|
84
|
+
| `pyoptexplain[ortools]` | ortools | OR-Tools front end |
|
|
85
|
+
| `pyoptexplain[scip]` | pyscipopt | SCIP backend (default MIQP) |
|
|
86
|
+
| `pyoptexplain[plot]` | matplotlib | grid plotting helpers |
|
|
87
|
+
|
|
88
|
+
Optional commercial solvers (Gurobi, CPLEX) still require their own licenses.
|
|
89
|
+
All optional imports are lazy, so the base install stays light.
|
|
90
|
+
|
|
91
|
+
## Quickstart
|
|
92
|
+
|
|
93
|
+
A two-product factory that maximizes profit subject to two resource capacities:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from pyoptexplain import Analyzer, LinearMatrixProblemHandle
|
|
97
|
+
|
|
98
|
+
handle = LinearMatrixProblemHandle(
|
|
99
|
+
sense="max",
|
|
100
|
+
c=[40.0, 30.0],
|
|
101
|
+
A_ub=[[2.0, 1.0], [1.0, 2.0]],
|
|
102
|
+
b_ub=[100.0, 80.0],
|
|
103
|
+
bounds=[(0.0, None), (0.0, None)],
|
|
104
|
+
variable_names=["chairs", "tables"],
|
|
105
|
+
inequality_names=["labor", "material"],
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
analyzer = Analyzer(handle.linear_representation())
|
|
109
|
+
analyzer.summary() # status, objective, primal values
|
|
110
|
+
analyzer.constraints() # binding, slack, and shadow price per named block
|
|
111
|
+
analyzer.duals() # block-level duals
|
|
112
|
+
analyzer.rhs_ranges() # classical sensitivity (HiGHS / Gurobi / CPLEX)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The optimum makes 40 chairs and 20 tables for a profit of 2200, with both
|
|
116
|
+
capacities binding and priced at their shadow values (labor 16.67, material 6.67).
|
|
117
|
+
|
|
118
|
+
## The pipeline
|
|
119
|
+
|
|
120
|
+
`pyoptexplain` is a single, explicit pipeline. Each stage is chosen by hand and
|
|
121
|
+
never collapsed into the next:
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
user-authored model -> ProblemHandle -> AnalysisRepresentation -> Analyzer
|
|
125
|
+
|
|
|
126
|
+
RepresentationCertificate
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- **`ProblemHandle`** wraps an already-built model, preserves its native identity,
|
|
130
|
+
and exposes the representations it can honestly support
|
|
131
|
+
(`basic_representation()`, `linear_representation()`,
|
|
132
|
+
`quadratic_representation()`, `scenario_representation()`).
|
|
133
|
+
- **`AnalysisRepresentation`** is the normalized, provenance-agnostic surface the
|
|
134
|
+
analyses run on. The same LP is analyzed identically whether it came from a raw
|
|
135
|
+
matrix, a cvxpy inspection, or a Pyomo model.
|
|
136
|
+
- **`RepresentationCertificate`** is the trust-and-provenance record: a status
|
|
137
|
+
(`verified` / `asserted` / `unknown`), the capabilities the representation
|
|
138
|
+
supports, and the mappings from each user-level block to the canonical rows it
|
|
139
|
+
lowered into.
|
|
140
|
+
- **`Analyzer`** is the single user-facing gateway. It is a factory:
|
|
141
|
+
`Analyzer(representation)` returns a representation-specific subclass exposing
|
|
142
|
+
only the methods that representation can actually run.
|
|
143
|
+
|
|
144
|
+
The user's unit of meaning is the **block**. A `ConstraintBlock` is one
|
|
145
|
+
constraint as written, a `VariableBlock` its variable-side peer. A block may lower
|
|
146
|
+
into several canonical rows (`abs(x) <= b` becomes two rows), but every report and
|
|
147
|
+
experiment targets the named block, not the rows.
|
|
148
|
+
|
|
149
|
+
## Certificate-gated honesty
|
|
150
|
+
|
|
151
|
+
Analysis is gated at three levels, so the library never guesses:
|
|
152
|
+
|
|
153
|
+
1. **Method presence** — an unsupported operation is simply absent on the returned
|
|
154
|
+
analyzer. `reduced_costs()` exists only on a linear analyzer, `run_scenarios()`
|
|
155
|
+
only on a scenario analyzer.
|
|
156
|
+
2. **Certificate** — structural analyses (LP/QP duals, classical sensitivity,
|
|
157
|
+
integrality relaxation, ...) require a `verified` or `asserted` status.
|
|
158
|
+
3. **Backend** — the configured backend must actually implement the diagnostic.
|
|
159
|
+
|
|
160
|
+
`Analyzer.capabilities()` reports the effective set as the intersection of the
|
|
161
|
+
certificate and the backend. Unavailable information stays explicitly unavailable,
|
|
162
|
+
reported as `None`, `NaN`, or an `UnsupportedFeature`.
|
|
163
|
+
|
|
164
|
+
## A progression of questions
|
|
165
|
+
|
|
166
|
+
The analyses form a progression, ordered by how far they depart from the problem
|
|
167
|
+
as originally stated.
|
|
168
|
+
|
|
169
|
+
**Solve report** — the static view of the current optimum:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
analyzer.summary()
|
|
173
|
+
analyzer.constraints()
|
|
174
|
+
analyzer.duals()
|
|
175
|
+
analyzer.dual_details() # per-row component duals for multi-row blocks
|
|
176
|
+
analyzer.representation_mappings() # how each block lowered into canonical rows
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
For linear representations on a basis-exposing backend (HiGHS, Gurobi, CPLEX),
|
|
180
|
+
classical sensitivity is available: `reduced_costs()`, `basis_status()`,
|
|
181
|
+
`rhs_ranges()`, `objective_ranges()`. A mixed-integer optimum carries no duals, so
|
|
182
|
+
valuations are read on an explicitly derived relaxation via `lp_relaxation()` or
|
|
183
|
+
`qp_relaxation()`.
|
|
184
|
+
|
|
185
|
+
**Perturbation analysis** — does the solution stay stable under small data
|
|
186
|
+
changes? Complete parameter families (objective, RHS, LHS, and for QPs the
|
|
187
|
+
quadratic objective) are perturbed one at a time and re-solved:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
robustness = analyzer.perturbation_robustness() # +-1%, +-2%, +-5%, +-10% by default
|
|
191
|
+
robustness.summary()
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Scenarios and grids** — change the model itself and compare against the
|
|
195
|
+
baseline. A scenario is a typed, ordered set of changes; a grid is the Cartesian
|
|
196
|
+
product of scenario axes:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
from pyoptexplain import (
|
|
200
|
+
Analyzer, ChangeRHS, GridAxis,
|
|
201
|
+
LinearMatrixScenarioRepresentation, ScenarioCase, SetObjectiveCoefficient,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
scenario_analyzer = Analyzer(
|
|
205
|
+
LinearMatrixScenarioRepresentation.from_matrix(handle.linear_representation())
|
|
206
|
+
)
|
|
207
|
+
scenario_analyzer.run_scenarios({
|
|
208
|
+
"base": ScenarioCase(),
|
|
209
|
+
"pricier_chairs": ScenarioCase((SetObjectiveCoefficient("chairs", 55.0),)),
|
|
210
|
+
"less_material": ScenarioCase((ChangeRHS("material", delta=-20.0),)),
|
|
211
|
+
})
|
|
212
|
+
scenario_analyzer.explore_grid([
|
|
213
|
+
GridAxis.rhs_change("material", [10.0, 0.0, -10.0]),
|
|
214
|
+
])
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The typed changes include `RemoveConstraint`, `RemoveConstraintGroup`,
|
|
218
|
+
`RelaxConstraint`, `ChangeRHS`, `RemoveVariable`, `SetVariableBounds`,
|
|
219
|
+
`ChangeVariableBounds`, `RelaxIntegrality`, `SetObjectiveCoefficient`,
|
|
220
|
+
`ChangeObjectiveCoefficient`, `ScaleQuadraticObjective`, `ScaleQuadraticDiagonal`,
|
|
221
|
+
and `SetParameter`.
|
|
222
|
+
|
|
223
|
+
## One model, many front ends
|
|
224
|
+
|
|
225
|
+
The same analysis surface is recovered no matter how the model was written. Wrap a
|
|
226
|
+
native model in the matching handle and call `linear_representation()` or
|
|
227
|
+
`quadratic_representation()`; everything after the handle is identical.
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
import cvxpy as cp
|
|
231
|
+
from pyoptexplain import Analyzer, CvxpyProblemHandle
|
|
232
|
+
|
|
233
|
+
chairs = cp.Variable(nonneg=True, name="chairs")
|
|
234
|
+
tables = cp.Variable(nonneg=True, name="tables")
|
|
235
|
+
labor = 2 * chairs + tables <= 100
|
|
236
|
+
material = chairs + 2 * tables <= 80
|
|
237
|
+
problem = cp.Problem(cp.Maximize(40 * chairs + 30 * tables), [labor, material])
|
|
238
|
+
|
|
239
|
+
handle = CvxpyProblemHandle(
|
|
240
|
+
problem,
|
|
241
|
+
variables={"chairs": chairs, "tables": tables},
|
|
242
|
+
constraints={"labor": labor, "material": material},
|
|
243
|
+
)
|
|
244
|
+
Analyzer(handle.linear_representation()).duals() # same answer as the matrix path
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
| Front end | Handle | Notes |
|
|
248
|
+
| --- | --- | --- |
|
|
249
|
+
| Direct matrix | `LinearMatrixProblemHandle`, `QuadraticMatrixProblemHandle` | structure known by construction |
|
|
250
|
+
| cvxpy | `CvxpyProblemHandle` | inspects DCP canonicalization; scenarios via `cp.Parameter` |
|
|
251
|
+
| Pyomo | `PyomoProblemHandle` | algebraic inspection; in-place RHS/bound/ablation scenarios |
|
|
252
|
+
| Gurobi | `GurobiProblemHandle` | direct-model scenarios (obj/bound/RHS, in-place ablation) |
|
|
253
|
+
| CPLEX | `CplexProblemHandle` | direct-model scenarios |
|
|
254
|
+
| OR-Tools | `OrToolsProblemHandle` | `pywraplp` (LP/MILP) or MathOpt (also QP/MIQP); scenarios via the matrix path |
|
|
255
|
+
|
|
256
|
+
Where a native object cannot be extracted to a matrix (nonlinear, conic), the
|
|
257
|
+
basic and native scenario paths still apply; structural matrix analyses do not.
|
|
258
|
+
|
|
259
|
+
## Solver backends
|
|
260
|
+
|
|
261
|
+
Structured representations are provenance-agnostic and accept any compatible
|
|
262
|
+
backend, defaulting sensibly per problem class:
|
|
263
|
+
|
|
264
|
+
| Problem class | Default backend | Also supported |
|
|
265
|
+
| --- | --- | --- |
|
|
266
|
+
| LP / MILP | `HiGHSBackend` | `GurobiBackend`, `CPLEXBackend`, `SCIPBackend` |
|
|
267
|
+
| QP | `OSQPBackend` | `GurobiBackend`, `CPLEXBackend`, `SCIPBackend` |
|
|
268
|
+
| MIQP | `SCIPBackend` | `GurobiBackend`, `CPLEXBackend` |
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
from pyoptexplain.solvers import HiGHSBackend, GurobiBackend
|
|
272
|
+
|
|
273
|
+
Analyzer(handle.linear_representation(), backend=GurobiBackend())
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Switching backend is what unlocks different diagnostics: a structured
|
|
277
|
+
representation can be sent to whichever backend exposes the information an analysis
|
|
278
|
+
needs. Custom backends implement the exported `SolverBackend` contract.
|
|
279
|
+
|
|
280
|
+
## Scenarios at scale
|
|
281
|
+
|
|
282
|
+
Repeated what-if studies are the case the architecture optimizes. A **scenario
|
|
283
|
+
representation** amortizes the analysis surface across a batch instead of
|
|
284
|
+
rebuilding and re-solving from scratch each time.
|
|
285
|
+
|
|
286
|
+
- The **structured (matrix) scenario representation** extracts the problem into
|
|
287
|
+
arrays once and builds its certificate once. Structure- and dimension-preserving
|
|
288
|
+
changes (RHS shifts, inequality relaxation, inequality removal by *deactivation*,
|
|
289
|
+
variable-bound changes) edit only the touched arrays on a warm solver session;
|
|
290
|
+
structure-changing cases fall back to a fresh derivation. Available whenever the
|
|
291
|
+
problem is extractable.
|
|
292
|
+
- The **native scenario representation** mutates the original modeling object in
|
|
293
|
+
place and restores it, available even for models that cannot be extracted, and
|
|
294
|
+
able to apply changes the live object exposes directly (e.g. a Gurobi
|
|
295
|
+
objective-coefficient edit).
|
|
296
|
+
|
|
297
|
+
Across LP and QP batches this cuts per-scenario cost several-fold, reaching 10–25×
|
|
298
|
+
once a batch exceeds a handful of cases. Solve-dominated integer problems see no
|
|
299
|
+
benefit, as expected. See `notebooks/scenario_scaling_study.ipynb` for the full
|
|
300
|
+
study.
|
|
301
|
+
|
|
302
|
+
## Notebooks
|
|
303
|
+
|
|
304
|
+
`notebooks/` holds runnable, end-to-end demonstrations: one per modeling language,
|
|
305
|
+
the matrix LP/MILP/QP walkthroughs, the perturbation and scenario workflows, and
|
|
306
|
+
the performance and scaling studies. They are the canonical worked examples.
|
|
307
|
+
|
|
308
|
+
## Status and license
|
|
309
|
+
|
|
310
|
+
First release (`0.1.0`). Apache-2.0 licensed. Requires Python 3.9+.
|
|
311
|
+
|
|
312
|
+
Contributions are welcome; see [CONTRIBUTING.md](CONTRIBUTING.md).
|