ommx-python-mip-adapter 0.0.2__tar.gz → 0.1.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 (33) hide show
  1. ommx_python_mip_adapter-0.1.1/.github/workflows/docs.yml +72 -0
  2. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/.github/workflows/test_and_lint.yml +23 -2
  3. ommx_python_mip_adapter-0.1.1/PKG-INFO +132 -0
  4. ommx_python_mip_adapter-0.1.1/README.md +100 -0
  5. ommx_python_mip_adapter-0.1.1/docs/source/conf.py +50 -0
  6. ommx_python_mip_adapter-0.1.1/docs/source/index.rst +20 -0
  7. ommx_python_mip_adapter-0.1.1/ommx_python_mip_adapter/__init__.py +11 -0
  8. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/ommx_python_mip_adapter/_version.py +2 -2
  9. ommx_python_mip_adapter-0.1.1/ommx_python_mip_adapter/adapter.py +418 -0
  10. ommx_python_mip_adapter-0.1.1/ommx_python_mip_adapter/exception.py +2 -0
  11. ommx_python_mip_adapter-0.1.1/ommx_python_mip_adapter.egg-info/PKG-INFO +132 -0
  12. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/ommx_python_mip_adapter.egg-info/SOURCES.txt +9 -2
  13. ommx_python_mip_adapter-0.1.1/ommx_python_mip_adapter.egg-info/requires.txt +13 -0
  14. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/pyproject.toml +9 -2
  15. ommx_python_mip_adapter-0.1.1/tests/test_instance_to_model.py +127 -0
  16. ommx_python_mip_adapter-0.1.1/tests/test_integration.py +142 -0
  17. ommx_python_mip_adapter-0.1.1/tests/test_model_to_instance.py +206 -0
  18. ommx_python_mip_adapter-0.1.1/tests/test_model_to_solution.py +27 -0
  19. ommx_python_mip_adapter-0.0.2/PKG-INFO +0 -47
  20. ommx_python_mip_adapter-0.0.2/README.md +0 -22
  21. ommx_python_mip_adapter-0.0.2/ommx_python_mip_adapter/__init__.py +0 -0
  22. ommx_python_mip_adapter-0.0.2/ommx_python_mip_adapter/ommx_to_python_mip.py +0 -2
  23. ommx_python_mip_adapter-0.0.2/ommx_python_mip_adapter.egg-info/PKG-INFO +0 -47
  24. ommx_python_mip_adapter-0.0.2/ommx_python_mip_adapter.egg-info/requires.txt +0 -6
  25. ommx_python_mip_adapter-0.0.2/tests/test_omm_to_python_mip.py +0 -2
  26. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/.github/workflows/publish.yml +0 -0
  27. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/.gitignore +0 -0
  28. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/LICENSE-APACHE +0 -0
  29. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/LICENSE-MIT +0 -0
  30. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/ommx_python_mip_adapter.egg-info/dependency_links.txt +0 -0
  31. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/ommx_python_mip_adapter.egg-info/top_level.txt +0 -0
  32. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/setup.cfg +0 -0
  33. {ommx_python_mip_adapter-0.0.2 → ommx_python_mip_adapter-0.1.1}/tests/conftest.py +0 -0
@@ -0,0 +1,72 @@
1
+ name: Documents
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ workflow_dispatch:
9
+
10
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
11
+ permissions:
12
+ contents: read
13
+ pages: write
14
+ id-token: write
15
+
16
+ # Allow one concurrent deployment
17
+ concurrency:
18
+ group: "pages"
19
+ cancel-in-progress: true
20
+
21
+ jobs:
22
+ build:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - name: Checkout
26
+ uses: actions/checkout@v4
27
+
28
+ - name: Setup Python
29
+ uses: actions/setup-python@v5
30
+ with:
31
+ python-version: "3.8"
32
+
33
+ - name: Install dependencies
34
+ run: |
35
+ python -m pip install ".[dev]"
36
+
37
+ - name: Build Python documentation
38
+ run: |
39
+ sphinx-build -b html ./docs/source ./docs/build
40
+
41
+ - name: Upload HTML
42
+ uses: actions/upload-artifact@v4
43
+ with:
44
+ name: docs
45
+ path: ./docs/build
46
+ retention-days: 30
47
+
48
+ deploy:
49
+ if: github.ref == 'refs/heads/main'
50
+ needs: build
51
+ environment:
52
+ name: github-pages
53
+ url: ${{ steps.deployment.outputs.page_url }}
54
+ runs-on: ubuntu-latest
55
+ steps:
56
+ - name: Download HTML
57
+ uses: actions/download-artifact@v4
58
+ with:
59
+ name: docs
60
+ path: .
61
+
62
+ - name: Configure GitHub Pages
63
+ uses: actions/configure-pages@v4
64
+
65
+ - name: Upload artifact
66
+ uses: actions/upload-pages-artifact@v3
67
+ with:
68
+ path: "."
69
+
70
+ - name: Deploy to GitHub Pages
71
+ id: deployment
72
+ uses: actions/deploy-pages@v4
@@ -28,7 +28,7 @@ jobs:
28
28
 
29
29
  - name: Run Tests
30
30
  run: |
31
- python -m pytest
31
+ python -m pytest --doctest-modules -vv
32
32
 
33
33
  lint:
34
34
  runs-on: ubuntu-latest
@@ -50,5 +50,26 @@ jobs:
50
50
 
51
51
  - name: Lint
52
52
  run: |
53
- python -m mypy ./ommx_python_mip_adapter
54
53
  python -m pyright ./ommx_python_mip_adapter
54
+
55
+ markdown-code-runner:
56
+ runs-on: ubuntu-latest
57
+ strategy:
58
+ fail-fast: false
59
+ matrix:
60
+ python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
61
+ steps:
62
+ - uses: actions/checkout@v4
63
+
64
+ - name: Setup Python ${{ matrix.python-version }}
65
+ uses: actions/setup-python@v5
66
+ with:
67
+ python-version: ${{ matrix.python-version }}
68
+
69
+ - name: Install Dependencies
70
+ run: |
71
+ python -m pip install ".[dev]"
72
+
73
+ - name: Lint
74
+ run: |
75
+ markdown-code-runner --verbose README.md
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.1
2
+ Name: ommx_python_mip_adapter
3
+ Version: 0.1.1
4
+ Summary: An adapter for the Python-MIP from/to OMMX.
5
+ Author-email: "Jij Inc." <info@j-ij.com>
6
+ Project-URL: Repository, https://github.com/Jij-Inc/ommx-python-mip-adapter
7
+ Project-URL: Issues, https://github.com/Jij-Inc/ommx-python-mip-adapter/issues
8
+ Classifier: Programming Language :: Python :: 3 :: Only
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Requires-Python: >=3.8
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE-APACHE
19
+ License-File: LICENSE-MIT
20
+ Requires-Dist: ommx<0.3.0,>=0.2.0
21
+ Requires-Dist: mip
22
+ Provides-Extra: dev
23
+ Requires-Dist: markdown-code-runner; extra == "dev"
24
+ Requires-Dist: mypy; extra == "dev"
25
+ Requires-Dist: numpy; extra == "dev"
26
+ Requires-Dist: pyright; extra == "dev"
27
+ Requires-Dist: pytest; extra == "dev"
28
+ Requires-Dist: sphinx; extra == "dev"
29
+ Requires-Dist: sphinx_rtd_theme; extra == "dev"
30
+ Requires-Dist: sphinx_fontawesome; extra == "dev"
31
+ Requires-Dist: sphinx-autoapi; extra == "dev"
32
+
33
+ OMMX adaptor for Python-MIP
34
+ ============================
35
+ ![PyPI - Version](https://img.shields.io/pypi/v/ommx-python-mip-adapter)
36
+
37
+ This package provides an adaptor for the [Python-MIP](https://www.python-mip.com/) from/to [OMMX](https://github.com/Jij-Inc/ommx)
38
+
39
+ Python-MIP as a solver in OMMX toolchain
40
+ -----------------------------------------
41
+ ```mermaid
42
+ sequenceDiagram
43
+ participant U as User
44
+ participant A as Adapter
45
+ participant P as Python-MIP
46
+ U->>A: ommx.v1.Instance
47
+ A->>U: Python-MIP model
48
+ U->>P: Python-MIP model and Parameters for Python-MIP;
49
+ P->>P: Solve with CBC, Gurobi, or other solvers
50
+ P->>U: Optimized model
51
+ U->>A: Optimized model and ommx.v1.Instance
52
+ A->>U: ommx:SolutionList
53
+ ```
54
+
55
+ Python-MIP as a user interface to create OMMX instance
56
+ -------------------------------------------------------
57
+ ```mermaid
58
+ sequenceDiagram
59
+ participant U as User
60
+ participant A as Adapter
61
+ participant O as Other OMMX toolchain
62
+ U->>A: Python-MIP model
63
+ A->>U: ommx.v1.Instance
64
+ U->>O: ommx.v1.Instance and Parameters for other solver
65
+ O->>O: Solve the instance with other solver using other adapter
66
+ O->>U: ommx.v1.Solution
67
+ ```
68
+
69
+ Usage
70
+ ======
71
+ `ommx-python-mip-adapter` can be installed from PyPI as follows:
72
+
73
+ ```bash
74
+ pip install ommx-python-mip-adapter
75
+ ```
76
+
77
+ Python-MIP can be used through `ommx-python-mip-adapter` by using the following:
78
+
79
+ ```python markdown-code-runner
80
+ import ommx_python_mip_adapter as adapter
81
+ from ommx.v1.decision_variables_pb2 import DecisionVariable, Bound
82
+ from ommx.v1.instance_pb2 import Instance
83
+ from ommx.v1.function_pb2 import Function
84
+ from ommx.v1.linear_pb2 import Linear
85
+ from ommx.v1.solution_pb2 import SolutionList
86
+
87
+ ommx_instance = Instance(
88
+ decision_variables=[
89
+ DecisionVariable(
90
+ id=1,
91
+ kind=DecisionVariable.KIND_INTEGER,
92
+ bound=Bound(lower=0, upper=5),
93
+ ),
94
+ ],
95
+ objective=Function(
96
+ linear=Linear(
97
+ terms=[Linear.Term(id=1, coefficient=1)]
98
+ ),
99
+ ),
100
+ )
101
+ ommx_instance_bytes = ommx_instance.SerializeToString()
102
+
103
+ # Convert from `ommx.v1.Instance` to `mip.Model`
104
+ model = adapter.instance_to_model(ommx_instance_bytes)
105
+ model.optimize()
106
+ # Create `ommx.v1.SolutionList` from Optimized `mip.Model`
107
+ ommx_solutions_bytes = adapter.model_to_solution(
108
+ model, ommx_instance_bytes
109
+ )
110
+
111
+ print(SolutionList.FromString(ommx_solutions_bytes))
112
+ ```
113
+ You can get `ommx.v1.Instance` from a Python-MIP model as the following:
114
+ ```python markdown-code-runner
115
+ import mip
116
+ import ommx_python_mip_adapter as adapter
117
+ from ommx.v1.instance_pb2 import Instance
118
+
119
+ model = mip.Model()
120
+ x1=model.add_var(name="1", var_type=mip.INTEGER, lb=0, ub=5)
121
+ x2=model.add_var(name="2", var_type=mip.CONTINUOUS, lb=0, ub=5)
122
+ model.objective = - x1 - 2 * x2
123
+ model.add_constr(x1 + x2 - 6 <= 0)
124
+
125
+ ommx_instance_bytes = adapter.model_to_instance(model)
126
+
127
+ print(Instance.FromString(ommx_instance_bytes))
128
+ ```
129
+
130
+ Reference
131
+ ==============
132
+ - [OMMX-Python-MIP-Adapter API Reference](https://jij-inc.github.io/ommx-python-mip-adapter/index.html)
@@ -0,0 +1,100 @@
1
+ OMMX adaptor for Python-MIP
2
+ ============================
3
+ ![PyPI - Version](https://img.shields.io/pypi/v/ommx-python-mip-adapter)
4
+
5
+ This package provides an adaptor for the [Python-MIP](https://www.python-mip.com/) from/to [OMMX](https://github.com/Jij-Inc/ommx)
6
+
7
+ Python-MIP as a solver in OMMX toolchain
8
+ -----------------------------------------
9
+ ```mermaid
10
+ sequenceDiagram
11
+ participant U as User
12
+ participant A as Adapter
13
+ participant P as Python-MIP
14
+ U->>A: ommx.v1.Instance
15
+ A->>U: Python-MIP model
16
+ U->>P: Python-MIP model and Parameters for Python-MIP;
17
+ P->>P: Solve with CBC, Gurobi, or other solvers
18
+ P->>U: Optimized model
19
+ U->>A: Optimized model and ommx.v1.Instance
20
+ A->>U: ommx:SolutionList
21
+ ```
22
+
23
+ Python-MIP as a user interface to create OMMX instance
24
+ -------------------------------------------------------
25
+ ```mermaid
26
+ sequenceDiagram
27
+ participant U as User
28
+ participant A as Adapter
29
+ participant O as Other OMMX toolchain
30
+ U->>A: Python-MIP model
31
+ A->>U: ommx.v1.Instance
32
+ U->>O: ommx.v1.Instance and Parameters for other solver
33
+ O->>O: Solve the instance with other solver using other adapter
34
+ O->>U: ommx.v1.Solution
35
+ ```
36
+
37
+ Usage
38
+ ======
39
+ `ommx-python-mip-adapter` can be installed from PyPI as follows:
40
+
41
+ ```bash
42
+ pip install ommx-python-mip-adapter
43
+ ```
44
+
45
+ Python-MIP can be used through `ommx-python-mip-adapter` by using the following:
46
+
47
+ ```python markdown-code-runner
48
+ import ommx_python_mip_adapter as adapter
49
+ from ommx.v1.decision_variables_pb2 import DecisionVariable, Bound
50
+ from ommx.v1.instance_pb2 import Instance
51
+ from ommx.v1.function_pb2 import Function
52
+ from ommx.v1.linear_pb2 import Linear
53
+ from ommx.v1.solution_pb2 import SolutionList
54
+
55
+ ommx_instance = Instance(
56
+ decision_variables=[
57
+ DecisionVariable(
58
+ id=1,
59
+ kind=DecisionVariable.KIND_INTEGER,
60
+ bound=Bound(lower=0, upper=5),
61
+ ),
62
+ ],
63
+ objective=Function(
64
+ linear=Linear(
65
+ terms=[Linear.Term(id=1, coefficient=1)]
66
+ ),
67
+ ),
68
+ )
69
+ ommx_instance_bytes = ommx_instance.SerializeToString()
70
+
71
+ # Convert from `ommx.v1.Instance` to `mip.Model`
72
+ model = adapter.instance_to_model(ommx_instance_bytes)
73
+ model.optimize()
74
+ # Create `ommx.v1.SolutionList` from Optimized `mip.Model`
75
+ ommx_solutions_bytes = adapter.model_to_solution(
76
+ model, ommx_instance_bytes
77
+ )
78
+
79
+ print(SolutionList.FromString(ommx_solutions_bytes))
80
+ ```
81
+ You can get `ommx.v1.Instance` from a Python-MIP model as the following:
82
+ ```python markdown-code-runner
83
+ import mip
84
+ import ommx_python_mip_adapter as adapter
85
+ from ommx.v1.instance_pb2 import Instance
86
+
87
+ model = mip.Model()
88
+ x1=model.add_var(name="1", var_type=mip.INTEGER, lb=0, ub=5)
89
+ x2=model.add_var(name="2", var_type=mip.CONTINUOUS, lb=0, ub=5)
90
+ model.objective = - x1 - 2 * x2
91
+ model.add_constr(x1 + x2 - 6 <= 0)
92
+
93
+ ommx_instance_bytes = adapter.model_to_instance(model)
94
+
95
+ print(Instance.FromString(ommx_instance_bytes))
96
+ ```
97
+
98
+ Reference
99
+ ==============
100
+ - [OMMX-Python-MIP-Adapter API Reference](https://jij-inc.github.io/ommx-python-mip-adapter/index.html)
@@ -0,0 +1,50 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # For the full list of built-in configuration values, see the documentation:
4
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
5
+
6
+ import sphinx_rtd_theme
7
+ import sphinx_fontawesome
8
+
9
+ # -- Project information -----------------------------------------------------
10
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
11
+
12
+ project = 'ommx-python-mip-adapter'
13
+ copyright = '2024, Jij Inc.'
14
+ author = 'Jij Inc.'
15
+
16
+ version = '0.1.0'
17
+ release = '0.1.0'
18
+
19
+ # -- General configuration ---------------------------------------------------
20
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
21
+
22
+ extensions = [
23
+ 'sphinx.ext.autodoc',
24
+ 'sphinx.ext.napoleon',
25
+ 'sphinx_rtd_theme',
26
+ 'sphinx_fontawesome',
27
+ 'autoapi.extension',
28
+ ]
29
+ source_suffix = {
30
+ '.rst': 'restructuredtext',
31
+ '.md': 'markdown',
32
+ }
33
+
34
+ templates_path = ['_templates']
35
+ language = 'en'
36
+ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
37
+
38
+ # -- Options for HTML output -------------------------------------------------
39
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
40
+
41
+ html_theme = "sphinx_rtd_theme"
42
+ html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
43
+ html_show_sourcelink = False
44
+ html_static_path = ['_static']
45
+
46
+ # -- AutoAPI settings --------------------------------------------------------
47
+ # https://sphinx-autoapi.readthedocs.io/en/latest/reference/config.html#event-autoapi-skip-member
48
+
49
+ autoapi_dirs = ['../../ommx_python_mip_adapter']
50
+ autoapi_member_order = 'groupwise'
@@ -0,0 +1,20 @@
1
+ .. ommx-python-mip-adapter documentation master file, created by
2
+ sphinx-quickstart on Mon Apr 22 14:29:19 2024.
3
+ You can adapt this file completely to your liking, but it should at least
4
+ contain the root `toctree` directive.
5
+
6
+ Welcome to ommx-python-mip-adapter's documentation!
7
+ ===================================================
8
+
9
+ .. toctree::
10
+ :maxdepth: 2
11
+ :caption: Contents:
12
+
13
+
14
+
15
+ Indices and tables
16
+ ==================
17
+
18
+ * :ref:`genindex`
19
+ * :ref:`modindex`
20
+ * :ref:`search`
@@ -0,0 +1,11 @@
1
+ from ommx_python_mip_adapter.adapter import (
2
+ instance_to_model,
3
+ model_to_instance,
4
+ model_to_solution,
5
+ )
6
+
7
+ __all__ = [
8
+ "instance_to_model",
9
+ "model_to_instance",
10
+ "model_to_solution",
11
+ ]
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.0.2'
16
- __version_tuple__ = version_tuple = (0, 0, 2)
15
+ __version__ = version = '0.1.1'
16
+ __version_tuple__ = version_tuple = (0, 1, 1)