mlflow-optimization 0.1.0__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.
- mlflow_optimization-0.1.0/LICENSE-APACHE +176 -0
- mlflow_optimization-0.1.0/LICENSE-MIT +21 -0
- mlflow_optimization-0.1.0/PKG-INFO +52 -0
- mlflow_optimization-0.1.0/README.md +39 -0
- mlflow_optimization-0.1.0/pyproject.toml +45 -0
- mlflow_optimization-0.1.0/pyproject.toml.orig +44 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/__init__.py +50 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/_bootstrap.py +129 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/common/diagnostics.py +19 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/common/patching.py +82 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/annotations/annotate.py +97 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/annotations/types.py +22 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/artifacts/policy.py +16 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/artifacts/ports.py +17 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/autolog/ports.py +49 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/autolog/service.py +147 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/autolog/types.py +31 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/metadata/collect.py +52 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/metadata/types.py +42 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/metrics/normalize.py +121 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/metrics/types.py +54 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/outcomes/classify.py +53 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/outcomes/types.py +40 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/runs/ports.py +30 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/runs/record.py +231 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/features/runs/types.py +43 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/cp_sat/__init__.py +5 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/cp_sat/adapter.py +464 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/gurobipy/__init__.py +5 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/gurobipy/adapter.py +474 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/mathopt/__init__.py +1 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/mathopt/adapter.py +939 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/mlflow/artifacts.py +44 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/mlflow/runs.py +480 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/pyomo/__init__.py +5 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/pyomo/adapter.py +1499 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/pyscipopt/__init__.py +5 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/pyscipopt/adapter.py +657 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/routing/__init__.py +5 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/integrations/routing/adapter.py +429 -0
- mlflow_optimization-0.1.0/src/mlflow_optimization/py.typed +0 -0
|
@@ -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,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CoffeeGiNu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mlflow-optimization
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Automatic MLflow logging of mathematical optimization solves
|
|
5
|
+
Author: CoffeeGiNu
|
|
6
|
+
License-Expression: MIT OR Apache-2.0
|
|
7
|
+
License-File: LICENSE-APACHE
|
|
8
|
+
License-File: LICENSE-MIT
|
|
9
|
+
Requires-Dist: mlflow-skinny>=3.18.0
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Project-URL: Repository, https://github.com/CoffeeGiNu/mlflow-optimization
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# mlflow-optimization
|
|
15
|
+
|
|
16
|
+
Automatic MLflow logging of mathematical optimization solves.
|
|
17
|
+
|
|
18
|
+
Supported libraries: [gurobipy, PySCIPOpt, Pyomo, OR-Tools (MathOpt, CP-SAT, Routing)]
|
|
19
|
+
|
|
20
|
+
## install
|
|
21
|
+
|
|
22
|
+
Log to a tracking server (`MLFLOW_TRACKING_URI`):
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install mlflow-optimization
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
> [!NOTE]
|
|
29
|
+
> `mlflow-optimization` installs `mlflow-skinny`, which lacks MLflow's default local store. To log without a tracking server, install `mlflow` as well:
|
|
30
|
+
>
|
|
31
|
+
> ```bash
|
|
32
|
+
> pip install mlflow-optimization mlflow
|
|
33
|
+
> ```
|
|
34
|
+
|
|
35
|
+
## usage
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import mlflow_optimization
|
|
39
|
+
|
|
40
|
+
mlflow_optimization.autolog()
|
|
41
|
+
|
|
42
|
+
with mlflow_optimization.context(instance="knapsack-50", tags={"team": "ops"}):
|
|
43
|
+
model.optimize()
|
|
44
|
+
|
|
45
|
+
run = mlflow_optimization.last_solve()
|
|
46
|
+
if run is not None:
|
|
47
|
+
run.log_metric("gap_to_best_known", 0.02)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
Either of Apache License 2.0 or MIT license, at your option.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# mlflow-optimization
|
|
2
|
+
|
|
3
|
+
Automatic MLflow logging of mathematical optimization solves.
|
|
4
|
+
|
|
5
|
+
Supported libraries: [gurobipy, PySCIPOpt, Pyomo, OR-Tools (MathOpt, CP-SAT, Routing)]
|
|
6
|
+
|
|
7
|
+
## install
|
|
8
|
+
|
|
9
|
+
Log to a tracking server (`MLFLOW_TRACKING_URI`):
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install mlflow-optimization
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
> [!NOTE]
|
|
16
|
+
> `mlflow-optimization` installs `mlflow-skinny`, which lacks MLflow's default local store. To log without a tracking server, install `mlflow` as well:
|
|
17
|
+
>
|
|
18
|
+
> ```bash
|
|
19
|
+
> pip install mlflow-optimization mlflow
|
|
20
|
+
> ```
|
|
21
|
+
|
|
22
|
+
## usage
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import mlflow_optimization
|
|
26
|
+
|
|
27
|
+
mlflow_optimization.autolog()
|
|
28
|
+
|
|
29
|
+
with mlflow_optimization.context(instance="knapsack-50", tags={"team": "ops"}):
|
|
30
|
+
model.optimize()
|
|
31
|
+
|
|
32
|
+
run = mlflow_optimization.last_solve()
|
|
33
|
+
if run is not None:
|
|
34
|
+
run.log_metric("gap_to_best_known", 0.02)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
Either of Apache License 2.0 or MIT license, at your option.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mlflow-optimization"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Automatic MLflow logging of mathematical optimization solves"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT OR Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE-*"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
dependencies = ["mlflow-skinny>=3.18.0"]
|
|
10
|
+
|
|
11
|
+
[[project.authors]]
|
|
12
|
+
name = "CoffeeGiNu"
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Repository = "https://github.com/CoffeeGiNu/mlflow-optimization"
|
|
16
|
+
|
|
17
|
+
[tool.ruff]
|
|
18
|
+
target-version = "py312"
|
|
19
|
+
line-length = 88
|
|
20
|
+
|
|
21
|
+
[tool.basedpyright]
|
|
22
|
+
typeCheckingMode = "standard"
|
|
23
|
+
include = [
|
|
24
|
+
"src",
|
|
25
|
+
"tests",
|
|
26
|
+
]
|
|
27
|
+
venvPath = "."
|
|
28
|
+
venv = ".venv"
|
|
29
|
+
pythonVersion = "3.12"
|
|
30
|
+
|
|
31
|
+
[build-system]
|
|
32
|
+
requires = ["uv_build>=0.13.6,<0.14.0"]
|
|
33
|
+
build-backend = "uv_build"
|
|
34
|
+
|
|
35
|
+
[dependency-groups]
|
|
36
|
+
dev = [
|
|
37
|
+
"basedpyright==1.40.2",
|
|
38
|
+
"gurobipy>=14.0.0",
|
|
39
|
+
"highspy>=1.16.0",
|
|
40
|
+
"ortools>=9.15.6755",
|
|
41
|
+
"pyomo>=6.10.1",
|
|
42
|
+
"pyscipopt>=6.3.0",
|
|
43
|
+
"pytest>=9.2.0",
|
|
44
|
+
"ruff==0.17.3",
|
|
45
|
+
]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mlflow-optimization"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Automatic MLflow logging of mathematical optimization solves"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT OR Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE-*"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "CoffeeGiNu" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"mlflow-skinny>=3.18.0",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Repository = "https://github.com/CoffeeGiNu/mlflow-optimization"
|
|
18
|
+
|
|
19
|
+
[tool.ruff]
|
|
20
|
+
target-version = "py312"
|
|
21
|
+
line-length = 88
|
|
22
|
+
|
|
23
|
+
[tool.basedpyright]
|
|
24
|
+
typeCheckingMode = "standard"
|
|
25
|
+
include = ["src", "tests"]
|
|
26
|
+
venvPath = "."
|
|
27
|
+
venv = ".venv"
|
|
28
|
+
pythonVersion = "3.12"
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["uv_build>=0.13.6,<0.14.0"]
|
|
32
|
+
build-backend = "uv_build"
|
|
33
|
+
|
|
34
|
+
[dependency-groups]
|
|
35
|
+
dev = [
|
|
36
|
+
"basedpyright==1.40.2",
|
|
37
|
+
"gurobipy>=14.0.0",
|
|
38
|
+
"highspy>=1.16.0",
|
|
39
|
+
"ortools>=9.15.6755",
|
|
40
|
+
"pyomo>=6.10.1",
|
|
41
|
+
"pyscipopt>=6.3.0",
|
|
42
|
+
"pytest>=9.2.0",
|
|
43
|
+
"ruff==0.17.3",
|
|
44
|
+
]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Automatic MLflow logging of mathematical optimization solves."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
|
|
5
|
+
from mlflow_optimization import _bootstrap
|
|
6
|
+
from mlflow_optimization.common.diagnostics import MlflowOptimizationWarning
|
|
7
|
+
from mlflow_optimization.features.annotations.annotate import context
|
|
8
|
+
from mlflow_optimization.features.runs.record import SolveRun, last_solve
|
|
9
|
+
|
|
10
|
+
__all__ = ["MlflowOptimizationWarning", "SolveRun", "autolog", "context", "last_solve"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def autolog(
|
|
14
|
+
disable: bool = False,
|
|
15
|
+
*,
|
|
16
|
+
libraries: Iterable[str] | None = None,
|
|
17
|
+
log_solver_parameters: bool = True,
|
|
18
|
+
log_solver_metrics: bool = True,
|
|
19
|
+
log_artifacts: bool = True,
|
|
20
|
+
) -> None:
|
|
21
|
+
"""Configure automatic logging of optimization solves.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
disable : bool, default False
|
|
26
|
+
Disable automatic logging; other settings are ignored when True.
|
|
27
|
+
libraries : Iterable[str] or None, optional
|
|
28
|
+
Supported names: gurobipy, pyscipopt, pyomo, mathopt, cp_sat, routing.
|
|
29
|
+
None selects all available integrations; an empty iterable selects none.
|
|
30
|
+
log_solver_parameters : bool, default True
|
|
31
|
+
Whether solver parameters are logged.
|
|
32
|
+
log_solver_metrics : bool, default True
|
|
33
|
+
Whether native solver metrics are logged.
|
|
34
|
+
log_artifacts : bool, default True
|
|
35
|
+
Whether files attached through ``SolveRun.log_artifact`` are logged.
|
|
36
|
+
|
|
37
|
+
Raises
|
|
38
|
+
------
|
|
39
|
+
ImportError
|
|
40
|
+
An explicitly selected integration cannot be imported.
|
|
41
|
+
ValueError
|
|
42
|
+
An unsupported library name is selected while logging is enabled.
|
|
43
|
+
"""
|
|
44
|
+
_bootstrap.configure(
|
|
45
|
+
disable=disable,
|
|
46
|
+
libraries=libraries,
|
|
47
|
+
log_solver_parameters=log_solver_parameters,
|
|
48
|
+
log_solver_metrics=log_solver_metrics,
|
|
49
|
+
log_artifacts=log_artifacts,
|
|
50
|
+
)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Composition root: wires feature ports to concrete adapters."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
from types import ModuleType
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from mlflow_optimization.features.autolog.ports import SolverIntegration
|
|
12
|
+
from mlflow_optimization.features.autolog.service import AutologManager
|
|
13
|
+
from mlflow_optimization.features.runs.record import RecordSolve
|
|
14
|
+
from mlflow_optimization.features.runs.types import RecordOptions
|
|
15
|
+
from mlflow_optimization.integrations.mlflow.artifacts import MlflowArtifactStore
|
|
16
|
+
from mlflow_optimization.integrations.mlflow.runs import MlflowRunStore
|
|
17
|
+
|
|
18
|
+
INTEGRATION_MODULES: dict[str, tuple[str, str]] = {
|
|
19
|
+
"gurobipy": ("mlflow_optimization.integrations.gurobipy.adapter", "GurobiAdapter"),
|
|
20
|
+
"pyscipopt": (
|
|
21
|
+
"mlflow_optimization.integrations.pyscipopt.adapter",
|
|
22
|
+
"PyScipOptAdapter",
|
|
23
|
+
),
|
|
24
|
+
"pyomo": ("mlflow_optimization.integrations.pyomo.adapter", "PyomoAdapter"),
|
|
25
|
+
"mathopt": ("mlflow_optimization.integrations.mathopt.adapter", "MathOptAdapter"),
|
|
26
|
+
"cp_sat": ("mlflow_optimization.integrations.cp_sat.adapter", "CpSatAdapter"),
|
|
27
|
+
"routing": ("mlflow_optimization.integrations.routing.adapter", "RoutingAdapter"),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
_record_solve: RecordSolve | None = None
|
|
31
|
+
_autolog_manager: AutologManager | None = None
|
|
32
|
+
_integration_cache: dict[type[SolverIntegration], SolverIntegration] = {}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def configure(
|
|
36
|
+
*,
|
|
37
|
+
disable: bool,
|
|
38
|
+
libraries: Iterable[str] | None,
|
|
39
|
+
log_solver_parameters: bool,
|
|
40
|
+
log_solver_metrics: bool,
|
|
41
|
+
log_artifacts: bool,
|
|
42
|
+
) -> None:
|
|
43
|
+
"""Apply an autolog configuration to the process-wide wiring."""
|
|
44
|
+
global _autolog_manager
|
|
45
|
+
global _record_solve
|
|
46
|
+
|
|
47
|
+
integrations: list[SolverIntegration] = []
|
|
48
|
+
if not disable:
|
|
49
|
+
integrations = _resolve_integrations(libraries)
|
|
50
|
+
|
|
51
|
+
if _autolog_manager is None:
|
|
52
|
+
from mlflow_optimization.features.autolog.service import AutologManager
|
|
53
|
+
from mlflow_optimization.features.runs.record import RecordSolve
|
|
54
|
+
from mlflow_optimization.features.runs.types import RecordOptions
|
|
55
|
+
from mlflow_optimization.integrations.mlflow.artifacts import (
|
|
56
|
+
MlflowArtifactStore,
|
|
57
|
+
)
|
|
58
|
+
from mlflow_optimization.integrations.mlflow.runs import MlflowRunStore
|
|
59
|
+
|
|
60
|
+
run_store: MlflowRunStore = MlflowRunStore()
|
|
61
|
+
artifact_store: MlflowArtifactStore = MlflowArtifactStore()
|
|
62
|
+
record_options: RecordOptions = RecordOptions()
|
|
63
|
+
if not disable:
|
|
64
|
+
record_options = RecordOptions(
|
|
65
|
+
log_solver_parameters=log_solver_parameters,
|
|
66
|
+
log_solver_metrics=log_solver_metrics,
|
|
67
|
+
log_artifacts=log_artifacts,
|
|
68
|
+
)
|
|
69
|
+
record_solve: RecordSolve = RecordSolve(
|
|
70
|
+
run_store, artifact_store, record_options
|
|
71
|
+
)
|
|
72
|
+
autolog_manager: AutologManager = AutologManager(record_solve)
|
|
73
|
+
|
|
74
|
+
_record_solve = record_solve
|
|
75
|
+
_autolog_manager = autolog_manager
|
|
76
|
+
else:
|
|
77
|
+
assert _record_solve is not None
|
|
78
|
+
if not disable:
|
|
79
|
+
_record_solve.options.log_solver_parameters = log_solver_parameters
|
|
80
|
+
_record_solve.options.log_solver_metrics = log_solver_metrics
|
|
81
|
+
_record_solve.options.log_artifacts = log_artifacts
|
|
82
|
+
|
|
83
|
+
assert _autolog_manager is not None
|
|
84
|
+
if disable:
|
|
85
|
+
_autolog_manager.disable()
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
_autolog_manager.enable(integrations)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _resolve_integrations(libraries: Iterable[str] | None) -> list[SolverIntegration]:
|
|
92
|
+
"""The selected solver integrations."""
|
|
93
|
+
library_modules: dict[str, tuple[str, str]] = dict(INTEGRATION_MODULES)
|
|
94
|
+
selected_libraries: tuple[str, ...] = (
|
|
95
|
+
tuple(library_modules) if libraries is None else tuple(dict.fromkeys(libraries))
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
for library_name in selected_libraries:
|
|
99
|
+
if library_name not in library_modules:
|
|
100
|
+
valid_library_names: str = ", ".join(library_modules)
|
|
101
|
+
raise ValueError(
|
|
102
|
+
f"Unknown library {library_name!r}. Valid names: {valid_library_names}"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
integrations: list[SolverIntegration] = []
|
|
106
|
+
for library_name in selected_libraries:
|
|
107
|
+
module_name: str
|
|
108
|
+
class_name: str
|
|
109
|
+
module_name, class_name = library_modules[library_name]
|
|
110
|
+
try:
|
|
111
|
+
integration_module: ModuleType = import_module(module_name)
|
|
112
|
+
integration_class: type[SolverIntegration] = getattr(
|
|
113
|
+
integration_module, class_name
|
|
114
|
+
)
|
|
115
|
+
cached_integration: SolverIntegration | None = _integration_cache.get(
|
|
116
|
+
integration_class
|
|
117
|
+
)
|
|
118
|
+
if cached_integration is not None:
|
|
119
|
+
integration: SolverIntegration = cached_integration
|
|
120
|
+
else:
|
|
121
|
+
integration = integration_class()
|
|
122
|
+
_integration_cache[integration_class] = integration
|
|
123
|
+
except ImportError:
|
|
124
|
+
if libraries is not None:
|
|
125
|
+
raise
|
|
126
|
+
continue
|
|
127
|
+
integrations.append(integration)
|
|
128
|
+
|
|
129
|
+
return integrations
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Notification channel shared by every feature and integration."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import warnings
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MlflowOptimizationWarning(UserWarning):
|
|
8
|
+
"""The category of every warning emitted by this library."""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def warn(message: str, *, stacklevel: int = 2) -> None:
|
|
12
|
+
"""Emit an ``MlflowOptimizationWarning``."""
|
|
13
|
+
try:
|
|
14
|
+
warnings.warn(message, MlflowOptimizationWarning, stacklevel=stacklevel + 1)
|
|
15
|
+
except BaseException: # noqa: BLE001
|
|
16
|
+
try:
|
|
17
|
+
logging.getLogger("mlflow_optimization").warning(message)
|
|
18
|
+
except BaseException: # noqa: BLE001,S110
|
|
19
|
+
pass
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Reversible attribute replacement."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from collections.abc import Callable, Mapping
|
|
5
|
+
from inspect import signature
|
|
6
|
+
from types import ModuleType
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def receiver_of(
|
|
11
|
+
original: Callable[..., Any], args: tuple[Any, ...], kwargs: Mapping[str, Any]
|
|
12
|
+
) -> Any:
|
|
13
|
+
"""The receiver of a method call."""
|
|
14
|
+
receiver_name: str | None = next(iter(signature(original).parameters), None)
|
|
15
|
+
if receiver_name is None:
|
|
16
|
+
return None
|
|
17
|
+
if args:
|
|
18
|
+
return args[0]
|
|
19
|
+
return kwargs.get(receiver_name)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def rebind_module_names(
|
|
23
|
+
original: Any,
|
|
24
|
+
replacement: Any,
|
|
25
|
+
) -> list[tuple[ModuleType, str]]:
|
|
26
|
+
"""The module-level names rebound from an original object to a replacement."""
|
|
27
|
+
rebound_names: list[tuple[ModuleType, str]] = []
|
|
28
|
+
modules: tuple[Any, ...] = tuple(sys.modules.values())
|
|
29
|
+
for module_value in modules:
|
|
30
|
+
if not isinstance(module_value, ModuleType):
|
|
31
|
+
continue
|
|
32
|
+
module: ModuleType = module_value
|
|
33
|
+
module_values: dict[str, Any] = vars(module)
|
|
34
|
+
module_bindings: tuple[tuple[str, Any], ...] = tuple(module_values.items())
|
|
35
|
+
for name, value in module_bindings:
|
|
36
|
+
if value is not original:
|
|
37
|
+
continue
|
|
38
|
+
module_values[name] = replacement
|
|
39
|
+
rebound_names.append((module, name))
|
|
40
|
+
return rebound_names
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def restore_module_names(
|
|
44
|
+
rebound_names: list[tuple[ModuleType, str]],
|
|
45
|
+
original: Any,
|
|
46
|
+
replacement: Any,
|
|
47
|
+
) -> None:
|
|
48
|
+
"""A conditional restoration of module-level names."""
|
|
49
|
+
for module, name in reversed(rebound_names):
|
|
50
|
+
module_values: dict[str, Any] = vars(module)
|
|
51
|
+
if name not in module_values or module_values[name] is not replacement:
|
|
52
|
+
continue
|
|
53
|
+
module_values[name] = original
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class Patch:
|
|
57
|
+
"""A reversible replacement of one attribute on a class or module."""
|
|
58
|
+
|
|
59
|
+
def __init__(self, owner: Any, name: str) -> None:
|
|
60
|
+
self.owner: Any = owner
|
|
61
|
+
self.name: str = name
|
|
62
|
+
self._installed: bool = False
|
|
63
|
+
|
|
64
|
+
def install(self, factory: Callable[[Any], Any]) -> None:
|
|
65
|
+
"""Replace the attribute with ``factory(original)``; no-op when installed."""
|
|
66
|
+
if self._installed:
|
|
67
|
+
return
|
|
68
|
+
original: Any = getattr(self.owner, self.name)
|
|
69
|
+
self._own: bool = self.name in vars(self.owner)
|
|
70
|
+
self._descriptor: Any = vars(self.owner).get(self.name)
|
|
71
|
+
setattr(self.owner, self.name, factory(original))
|
|
72
|
+
self._installed = True
|
|
73
|
+
|
|
74
|
+
def uninstall(self) -> None:
|
|
75
|
+
"""Restore the exact original attribute; no-op when not installed."""
|
|
76
|
+
if not self._installed:
|
|
77
|
+
return
|
|
78
|
+
if self._own:
|
|
79
|
+
setattr(self.owner, self.name, self._descriptor)
|
|
80
|
+
else:
|
|
81
|
+
delattr(self.owner, self.name)
|
|
82
|
+
self._installed = False
|