eqc-models 0.9.8__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 (111) hide show
  1. eqc_models-0.9.8/.gitlab-ci.yml +63 -0
  2. eqc_models-0.9.8/LICENSE.txt +202 -0
  3. eqc_models-0.9.8/MANIFEST.in +11 -0
  4. eqc_models-0.9.8/PKG-INFO +139 -0
  5. eqc_models-0.9.8/README.md +115 -0
  6. eqc_models-0.9.8/compile_extensions.py +23 -0
  7. eqc_models-0.9.8/docs/Makefile +20 -0
  8. eqc_models-0.9.8/docs/build/html/_static/basic.css +925 -0
  9. eqc_models-0.9.8/docs/build/html/_static/css/badge_only.css +1 -0
  10. eqc_models-0.9.8/docs/build/html/_static/css/theme.css +4 -0
  11. eqc_models-0.9.8/docs/build/html/_static/custom.css +24 -0
  12. eqc_models-0.9.8/docs/build/html/_static/file.png +0 -0
  13. eqc_models-0.9.8/docs/build/html/_static/minus.png +0 -0
  14. eqc_models-0.9.8/docs/build/html/_static/plus.png +0 -0
  15. eqc_models-0.9.8/docs/build/html/_static/pygments.css +75 -0
  16. eqc_models-0.9.8/docs/build/html/_static/white_logo.png +0 -0
  17. eqc_models-0.9.8/docs/make.bat +35 -0
  18. eqc_models-0.9.8/docs/source/_static/custom.css +24 -0
  19. eqc_models-0.9.8/docs/source/_static/white_logo.png +0 -0
  20. eqc_models-0.9.8/docs/source/conf.py +83 -0
  21. eqc_models-0.9.8/docs/source/dependencies.rst +13 -0
  22. eqc_models-0.9.8/docs/source/eqc_models.rst +79 -0
  23. eqc_models-0.9.8/docs/source/index.rst +47 -0
  24. eqc_models-0.9.8/docs/source/modules.rst +7 -0
  25. eqc_models-0.9.8/docs/source/usage.rst +24 -0
  26. eqc_models-0.9.8/eqc_models/__init__.py +15 -0
  27. eqc_models-0.9.8/eqc_models/algorithms/__init__.py +4 -0
  28. eqc_models-0.9.8/eqc_models/algorithms/base.py +10 -0
  29. eqc_models-0.9.8/eqc_models/algorithms/penaltymultiplier.py +169 -0
  30. eqc_models-0.9.8/eqc_models/allocation/__init__.py +6 -0
  31. eqc_models-0.9.8/eqc_models/allocation/allocation.py +367 -0
  32. eqc_models-0.9.8/eqc_models/allocation/portbase.py +128 -0
  33. eqc_models-0.9.8/eqc_models/allocation/portmomentum.py +137 -0
  34. eqc_models-0.9.8/eqc_models/assignment/__init__.py +5 -0
  35. eqc_models-0.9.8/eqc_models/assignment/qap.py +82 -0
  36. eqc_models-0.9.8/eqc_models/assignment/setpartition.py +170 -0
  37. eqc_models-0.9.8/eqc_models/base/__init__.py +72 -0
  38. eqc_models-0.9.8/eqc_models/base/base.py +150 -0
  39. eqc_models-0.9.8/eqc_models/base/constraints.py +276 -0
  40. eqc_models-0.9.8/eqc_models/base/operators.py +201 -0
  41. eqc_models-0.9.8/eqc_models/base/polyeval.c +11363 -0
  42. eqc_models-0.9.8/eqc_models/base/polyeval.pyx +72 -0
  43. eqc_models-0.9.8/eqc_models/base/polynomial.py +274 -0
  44. eqc_models-0.9.8/eqc_models/base/quadratic.py +250 -0
  45. eqc_models-0.9.8/eqc_models/decoding.py +20 -0
  46. eqc_models-0.9.8/eqc_models/graph/__init__.py +5 -0
  47. eqc_models-0.9.8/eqc_models/graph/base.py +63 -0
  48. eqc_models-0.9.8/eqc_models/graph/hypergraph.py +307 -0
  49. eqc_models-0.9.8/eqc_models/graph/maxcut.py +155 -0
  50. eqc_models-0.9.8/eqc_models/graph/maxkcut.py +184 -0
  51. eqc_models-0.9.8/eqc_models/ml/__init__.py +15 -0
  52. eqc_models-0.9.8/eqc_models/ml/classifierbase.py +99 -0
  53. eqc_models-0.9.8/eqc_models/ml/classifierqboost.py +423 -0
  54. eqc_models-0.9.8/eqc_models/ml/classifierqsvm.py +237 -0
  55. eqc_models-0.9.8/eqc_models/ml/clustering.py +323 -0
  56. eqc_models-0.9.8/eqc_models/ml/clusteringbase.py +112 -0
  57. eqc_models-0.9.8/eqc_models/ml/decomposition.py +363 -0
  58. eqc_models-0.9.8/eqc_models/ml/forecast.py +255 -0
  59. eqc_models-0.9.8/eqc_models/ml/forecastbase.py +139 -0
  60. eqc_models-0.9.8/eqc_models/ml/regressor.py +220 -0
  61. eqc_models-0.9.8/eqc_models/ml/regressorbase.py +97 -0
  62. eqc_models-0.9.8/eqc_models/ml/reservoir.py +106 -0
  63. eqc_models-0.9.8/eqc_models/sequence/__init__.py +5 -0
  64. eqc_models-0.9.8/eqc_models/sequence/tsp.py +217 -0
  65. eqc_models-0.9.8/eqc_models/solvers/__init__.py +12 -0
  66. eqc_models-0.9.8/eqc_models/solvers/qciclient.py +707 -0
  67. eqc_models-0.9.8/eqc_models/utilities/__init__.py +6 -0
  68. eqc_models-0.9.8/eqc_models/utilities/fileio.py +38 -0
  69. eqc_models-0.9.8/eqc_models/utilities/polynomial.py +137 -0
  70. eqc_models-0.9.8/eqc_models/utilities/qplib.py +375 -0
  71. eqc_models-0.9.8/eqc_models.egg-info/PKG-INFO +139 -0
  72. eqc_models-0.9.8/eqc_models.egg-info/SOURCES.txt +109 -0
  73. eqc_models-0.9.8/eqc_models.egg-info/dependency_links.txt +1 -0
  74. eqc_models-0.9.8/eqc_models.egg-info/requires.txt +13 -0
  75. eqc_models-0.9.8/eqc_models.egg-info/top_level.txt +2 -0
  76. eqc_models-0.9.8/pyproject.toml +67 -0
  77. eqc_models-0.9.8/scripts/binary_job_example.py +22 -0
  78. eqc_models-0.9.8/scripts/c6h6_graph_clustering.py +89 -0
  79. eqc_models-0.9.8/scripts/clustering.py +46 -0
  80. eqc_models-0.9.8/scripts/continuous_job_example.py +17 -0
  81. eqc_models-0.9.8/scripts/duality_example.py +73 -0
  82. eqc_models-0.9.8/scripts/graph_clustering.py +73 -0
  83. eqc_models-0.9.8/scripts/hamiltonian_to_polynomial.py +28 -0
  84. eqc_models-0.9.8/scripts/hypergraph.py +67 -0
  85. eqc_models-0.9.8/scripts/integer_job_example.py +35 -0
  86. eqc_models-0.9.8/scripts/karate_graph_clustering.py +34 -0
  87. eqc_models-0.9.8/scripts/lin_reg_dirac3.py +36 -0
  88. eqc_models-0.9.8/scripts/mackey_glass_cell_production_series.csv +10001 -0
  89. eqc_models-0.9.8/scripts/pca_iris_dirac3.py +42 -0
  90. eqc_models-0.9.8/scripts/port_opt_dirac3.py +73 -0
  91. eqc_models-0.9.8/scripts/qboost_iris_dirac3.py +98 -0
  92. eqc_models-0.9.8/scripts/qplib_benchmark_config.py +83 -0
  93. eqc_models-0.9.8/scripts/qplib_reader.py +40 -0
  94. eqc_models-0.9.8/scripts/qplib_runner.py +34 -0
  95. eqc_models-0.9.8/scripts/qsvm_iris_dirac3.py +101 -0
  96. eqc_models-0.9.8/scripts/reservoir_forecast.py +47 -0
  97. eqc_models-0.9.8/scripts/rundoctests.py +5 -0
  98. eqc_models-0.9.8/scripts/utils.py +233 -0
  99. eqc_models-0.9.8/setup.cfg +4 -0
  100. eqc_models-0.9.8/test/doctest_base.py +9 -0
  101. eqc_models-0.9.8/test/testallocationmodel.py +464 -0
  102. eqc_models-0.9.8/test/testconstraint.py +51 -0
  103. eqc_models-0.9.8/test/testeqcdirectsolver.py +19 -0
  104. eqc_models-0.9.8/test/testhypergraphmodel.py +79 -0
  105. eqc_models-0.9.8/test/testmaxcutmodel.py +71 -0
  106. eqc_models-0.9.8/test/testpolynomialmodel.py +32 -0
  107. eqc_models-0.9.8/test/testqapmodel.py +54 -0
  108. eqc_models-0.9.8/test/testqciclientsolver.py +48 -0
  109. eqc_models-0.9.8/test/testquadraticmodel.py +29 -0
  110. eqc_models-0.9.8/test/testsetpartitionmodel.py +73 -0
  111. eqc_models-0.9.8/test/testtsp.py +60 -0
@@ -0,0 +1,63 @@
1
+ image: python:3.10
2
+
3
+ workflow:
4
+ rules:
5
+ - if: $CI_MERGE_REQUEST_IID
6
+
7
+ stages:
8
+ - build
9
+ - test
10
+ # - deploy
11
+
12
+ variables:
13
+ PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
14
+ VENV_DIR: "$CI_PROJECT_DIR/venv"
15
+ GIT_TOKEN: "glpat-Cf3vWyPDyvmQyBv6BmB3"
16
+ GIT_USERNAME: "uchukwu"
17
+
18
+ before_script:
19
+ - python -V
20
+ - pip -V
21
+
22
+ cache:
23
+ paths:
24
+ - .cache/pip
25
+
26
+ build:
27
+ stage: build
28
+ script:
29
+ - python -m venv $VENV_DIR
30
+ - source $VENV_DIR/bin/activate
31
+ - pip install --upgrade pip
32
+ - pip install build
33
+ - python -m build
34
+ artifacts:
35
+ paths:
36
+ - $VENV_DIR
37
+
38
+ test:
39
+ stage: test
40
+ script:
41
+ - ls -la $VENV_DIR
42
+ - source $VENV_DIR/bin/activate
43
+ - pip install --upgrade pip
44
+ - git config --global url."https://${GIT_USERNAME}:${GIT_TOKEN}@git.qci-dev.com".insteadOf "https://git.qci-dev.com"
45
+ - pip install .[dev]
46
+ - pytest --cov=eqc-models --cov-report=xml
47
+ artifacts:
48
+ reports:
49
+ junit: junit.xml
50
+ coverage_report:
51
+ coverage_format: cobertura
52
+ path: coverage.xml
53
+ paths:
54
+ - coverage.xml
55
+ # coverage: /TOTAL.*?(\d+\%)/
56
+
57
+ #deploy:
58
+ # stage: deploy
59
+ # script:
60
+ # - echo "Deploy stage - implement deployment steps here"
61
+ # # Add deployment steps here
62
+ # only:
63
+ # - main # only deploy from the main branch
@@ -0,0 +1,202 @@
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 2021 Quantum Computing, Inc.
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.
202
+
@@ -0,0 +1,11 @@
1
+ recursive-include docs *.bat
2
+ recursive-include docs *.css
3
+ recursive-include docs *.png
4
+ recursive-include docs *.py
5
+ recursive-include docs *.rst
6
+ recursive-include docs Makefile
7
+ recursive-include eqc_models *.py
8
+ recursive-include eqc_models *.pyx
9
+ recursive-include scripts *.csv
10
+ recursive-include scripts *.py
11
+ recursive-include test *.py
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.1
2
+ Name: eqc-models
3
+ Version: 0.9.8
4
+ Summary: Optimization and ML modeling package targeting EQC devices
5
+ Author: Quantum Computing Inc.
6
+ Author-email: support@quantumcomputinginc.com
7
+ Project-URL: Homepage, https://quantumcomputinginc.com
8
+ Project-URL: Documentation, https://quantumcomputinginc.com/learn/support/software-packages/
9
+ Project-URL: Issues, https://support.quantumcomputinginc.com/
10
+ Requires-Python: <3.11,>=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.txt
13
+ Requires-Dist: numpy<2,>=1.22.1
14
+ Requires-Dist: networkx<3,>=2.6.3
15
+ Requires-Dist: pandas>=2.1.0
16
+ Requires-Dist: qci-client<5,>=4.3.0
17
+ Requires-Dist: emucore-direct==1.0.6
18
+ Provides-Extra: direct
19
+ Requires-Dist: eqc-direct<2,>=1.3.0; extra == "direct"
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest<8,>=7.1.0; extra == "dev"
22
+ Requires-Dist: pytest-cov; extra == "dev"
23
+ Requires-Dist: sphinx_rtd_theme<2,>=1.3.0; extra == "dev"
24
+
25
+ # EQC Models
26
+
27
+ ## Quick Reference
28
+
29
+ ### Installation
30
+
31
+ Install from the Python Package Index (PyPI) using
32
+ ```bash
33
+ pip install eqc-models
34
+ ```
35
+
36
+ For pre-release and source versions, install `eqc-models` by extracting the source package and running
37
+
38
+ ```bash
39
+ pip install -e .
40
+ ```
41
+
42
+ from the folder with the `pyproject.toml` file. This will create an editable installation that is local to your user environment.
43
+ Certain optimizations require extension modules, in particular `eqc_models.base.polyeval`. This is a C extension produced from
44
+ a Cython module which evaluates polynomial expressions. Since there could be thousands of terms, the C extension can greatly
45
+ improve performance of some algorithms. Installing from source with pip will build the module.
46
+
47
+ ### Modeling
48
+
49
+ Implement a model by selecting from the most appropriate model class from the available models
50
+ and pass the required data. The model classes are (in depth first order by hierarchy)
51
+
52
+ - `eqc_models.base.EQCModel`: a base class for all models
53
+ - `eqc_models.ml.classifierbase.ClassifierBase`: a base model for machine learning classifier models
54
+ - `eqc_models.ml.classifierqboost.QBoostClassifier`: a machine learning classifier model using QBoost
55
+ - `eqc_models.ml.classifierqsvm.QSVMClassifier`: a machine learning classifier model using QSVM
56
+ - `eqc_models.ml.communitydetection.CommunityDetectionModel`: a model for modeling community detection problems
57
+ - `eqc_models.base.QuadraticModel`: a base class for all models with up to quadratic terms
58
+ - `eqc_models.base.ConstrainedQuadraticModel`: a base class for all models with up to quadratic objective functions and linear equality constraints
59
+ - `eqc_models.base.PolynomialModel`: a base class for all models that utilize a polynomial formulation (up to fifth order)
60
+ - `eqc_models.allocation.AllocationModel`: an allocation model with equality resource constraints
61
+ - `eqc_models.allocation.AllocationModelX`: an allocation model with equality and inequality resource constraints
62
+ - `eqc_models.allocation.portmomentum.PortMomentum`: a portfolio allocation momentum model
63
+ - `eqc_models.portbase.PortBase`: a portfolio allocation base model
64
+ - `eqc_models.graph.MaxCutModel`: a maximum cut model
65
+ - `eqc_models.assignment.qap.QAPModel`: a quadratic assignment problem model
66
+ - `eqc_models.sequence.tsp.TSPModel`: a base class for TSP models
67
+ - `eqc_models.sequence.tsp.MTZTSPModel`: a traveling salesman model using the MTZ formulation
68
+ - `eqc_models.utilities.qplib.QGLModel`: a model based on `ConstrainedQuadraticModel` to solve problems
69
+ from qplib
70
+
71
+ ### Solvers
72
+
73
+ The hierarchy of solvers uses `QciClient` from the `qci-client` package. Both Dirac-1 and Dirac-3 can be accessed using these solvers. Specific classes exist for the devices.
74
+
75
+ - `eqc_models.qciclientsolver.Dirac1CloudSolver`: A solver class that accesses Dirac-1 via the Qatalyst cloud service
76
+ - `eqc_models.qciclientsolver.Dirac3ContinuousCloudSolver`: A solver class for quasi-continuous models that accesses Dirac-3 via the Qatalyst cloud service
77
+ - `eqc_models.qciclientsolver.Dirac3IntegerCloudSolver`: A solver class for integer models that accesses Dirac-3 via the Qatalyst cloud service
78
+
79
+ ### Using Classifier Models
80
+
81
+ Use of classification models is based on the well known pattern of fitting a model, then
82
+ using the fitted model to predict classifications. Here is a snippet from the `qsvm_iris_dirac3.py` script:
83
+
84
+ ```python
85
+ # Get QSVM model
86
+ obj = QSVMClassifier(
87
+ relaxation_schedule=2,
88
+ num_samples=1,
89
+ upper_limit=1.0,
90
+ gamma=1.0,
91
+ eta=1.0,
92
+ zeta=1.0,
93
+ )
94
+
95
+ # Train
96
+ obj.fit(X_train, y_train)
97
+
98
+ y_train_prd = obj.predict(X_train)
99
+ y_test_prd = obj.predict(X_test)
100
+ ```
101
+
102
+ ### Using Decision Optimization Models
103
+
104
+ Decision optimization models can be utilized by building a model, then passing the model to a solver's `solve` method. The following snippet of code is taken from the `qplib_runner.py` script.
105
+
106
+ ```python
107
+ # C, J are the linear and quadratic components of the expression
108
+ # A and b are left hand and right hand side values for linear constraints
109
+ # R is the summation constraint value for the Dirac-3 requirement
110
+ model = QGLModel(C, J, A, b)
111
+ domains = [R if types[j] == "REAL" else 1 for j in range(num_variables)]
112
+ model.domains = np.array(domains)
113
+ model.penalty_multiplier = alpha
114
+ # set the machine slacks to 1 to add a dummy variable to capture slack value from the summation constraint
115
+ model.machine_slacks = 1
116
+ print(f"Constructed model with R={R} alpha={alpha}")
117
+ solver = Dirac3CloudSolver()
118
+ print(f"Running model with relaxation_schedule={schedule}")
119
+ response = solver.solve(model, basename, sum_constraint=R, relaxation_schedule=schedule)
120
+ print(f"Energy {response['results']['energies'][0]}")
121
+ ```
122
+
123
+ ## Design Overview
124
+
125
+ This package is designed around two central base classes. The first, `EqcModel`, includes the most basic common elements of an
126
+ optimization model. The second, `ModelSolver`, includes the most basic elements of a solver class. While not all classes in this package
127
+ inherit from one of these two classes, the core functionality exists in thie hierarchy. Additional things, such as algorithms and
128
+ supporting methods take advantage of these classes. Another design choice in the package is to utilize multiple inheritance and class
129
+ mixins for construction of functional classes. This design is not intended to impact the end user, who can simply instantiate a certain
130
+ model or solver class for usage. If a new model class is desired, the mixin design may be utilized to construct this new class.
131
+ Additionally, a hybrid solver could be implemented using this same design.
132
+
133
+ ## Troubleshooting Common Errors
134
+
135
+ **No module named '_bz2'** This error occurs because NetworkX, a dependency of `eqc-models`, requires the bzip 2 library and it has not been found. On some linux environments, the OS package `libbzip2-dev` can be installed with apt or yum, then the python environment must be installed again.
136
+
137
+ ## Further Information
138
+
139
+ Most of the classes in this package have doctests, see these docstrings for specific concrete examples. Also, the `scripts` and `test` directories have examples on modeling and solving with `eqc-models`.
@@ -0,0 +1,115 @@
1
+ # EQC Models
2
+
3
+ ## Quick Reference
4
+
5
+ ### Installation
6
+
7
+ Install from the Python Package Index (PyPI) using
8
+ ```bash
9
+ pip install eqc-models
10
+ ```
11
+
12
+ For pre-release and source versions, install `eqc-models` by extracting the source package and running
13
+
14
+ ```bash
15
+ pip install -e .
16
+ ```
17
+
18
+ from the folder with the `pyproject.toml` file. This will create an editable installation that is local to your user environment.
19
+ Certain optimizations require extension modules, in particular `eqc_models.base.polyeval`. This is a C extension produced from
20
+ a Cython module which evaluates polynomial expressions. Since there could be thousands of terms, the C extension can greatly
21
+ improve performance of some algorithms. Installing from source with pip will build the module.
22
+
23
+ ### Modeling
24
+
25
+ Implement a model by selecting from the most appropriate model class from the available models
26
+ and pass the required data. The model classes are (in depth first order by hierarchy)
27
+
28
+ - `eqc_models.base.EQCModel`: a base class for all models
29
+ - `eqc_models.ml.classifierbase.ClassifierBase`: a base model for machine learning classifier models
30
+ - `eqc_models.ml.classifierqboost.QBoostClassifier`: a machine learning classifier model using QBoost
31
+ - `eqc_models.ml.classifierqsvm.QSVMClassifier`: a machine learning classifier model using QSVM
32
+ - `eqc_models.ml.communitydetection.CommunityDetectionModel`: a model for modeling community detection problems
33
+ - `eqc_models.base.QuadraticModel`: a base class for all models with up to quadratic terms
34
+ - `eqc_models.base.ConstrainedQuadraticModel`: a base class for all models with up to quadratic objective functions and linear equality constraints
35
+ - `eqc_models.base.PolynomialModel`: a base class for all models that utilize a polynomial formulation (up to fifth order)
36
+ - `eqc_models.allocation.AllocationModel`: an allocation model with equality resource constraints
37
+ - `eqc_models.allocation.AllocationModelX`: an allocation model with equality and inequality resource constraints
38
+ - `eqc_models.allocation.portmomentum.PortMomentum`: a portfolio allocation momentum model
39
+ - `eqc_models.portbase.PortBase`: a portfolio allocation base model
40
+ - `eqc_models.graph.MaxCutModel`: a maximum cut model
41
+ - `eqc_models.assignment.qap.QAPModel`: a quadratic assignment problem model
42
+ - `eqc_models.sequence.tsp.TSPModel`: a base class for TSP models
43
+ - `eqc_models.sequence.tsp.MTZTSPModel`: a traveling salesman model using the MTZ formulation
44
+ - `eqc_models.utilities.qplib.QGLModel`: a model based on `ConstrainedQuadraticModel` to solve problems
45
+ from qplib
46
+
47
+ ### Solvers
48
+
49
+ The hierarchy of solvers uses `QciClient` from the `qci-client` package. Both Dirac-1 and Dirac-3 can be accessed using these solvers. Specific classes exist for the devices.
50
+
51
+ - `eqc_models.qciclientsolver.Dirac1CloudSolver`: A solver class that accesses Dirac-1 via the Qatalyst cloud service
52
+ - `eqc_models.qciclientsolver.Dirac3ContinuousCloudSolver`: A solver class for quasi-continuous models that accesses Dirac-3 via the Qatalyst cloud service
53
+ - `eqc_models.qciclientsolver.Dirac3IntegerCloudSolver`: A solver class for integer models that accesses Dirac-3 via the Qatalyst cloud service
54
+
55
+ ### Using Classifier Models
56
+
57
+ Use of classification models is based on the well known pattern of fitting a model, then
58
+ using the fitted model to predict classifications. Here is a snippet from the `qsvm_iris_dirac3.py` script:
59
+
60
+ ```python
61
+ # Get QSVM model
62
+ obj = QSVMClassifier(
63
+ relaxation_schedule=2,
64
+ num_samples=1,
65
+ upper_limit=1.0,
66
+ gamma=1.0,
67
+ eta=1.0,
68
+ zeta=1.0,
69
+ )
70
+
71
+ # Train
72
+ obj.fit(X_train, y_train)
73
+
74
+ y_train_prd = obj.predict(X_train)
75
+ y_test_prd = obj.predict(X_test)
76
+ ```
77
+
78
+ ### Using Decision Optimization Models
79
+
80
+ Decision optimization models can be utilized by building a model, then passing the model to a solver's `solve` method. The following snippet of code is taken from the `qplib_runner.py` script.
81
+
82
+ ```python
83
+ # C, J are the linear and quadratic components of the expression
84
+ # A and b are left hand and right hand side values for linear constraints
85
+ # R is the summation constraint value for the Dirac-3 requirement
86
+ model = QGLModel(C, J, A, b)
87
+ domains = [R if types[j] == "REAL" else 1 for j in range(num_variables)]
88
+ model.domains = np.array(domains)
89
+ model.penalty_multiplier = alpha
90
+ # set the machine slacks to 1 to add a dummy variable to capture slack value from the summation constraint
91
+ model.machine_slacks = 1
92
+ print(f"Constructed model with R={R} alpha={alpha}")
93
+ solver = Dirac3CloudSolver()
94
+ print(f"Running model with relaxation_schedule={schedule}")
95
+ response = solver.solve(model, basename, sum_constraint=R, relaxation_schedule=schedule)
96
+ print(f"Energy {response['results']['energies'][0]}")
97
+ ```
98
+
99
+ ## Design Overview
100
+
101
+ This package is designed around two central base classes. The first, `EqcModel`, includes the most basic common elements of an
102
+ optimization model. The second, `ModelSolver`, includes the most basic elements of a solver class. While not all classes in this package
103
+ inherit from one of these two classes, the core functionality exists in thie hierarchy. Additional things, such as algorithms and
104
+ supporting methods take advantage of these classes. Another design choice in the package is to utilize multiple inheritance and class
105
+ mixins for construction of functional classes. This design is not intended to impact the end user, who can simply instantiate a certain
106
+ model or solver class for usage. If a new model class is desired, the mixin design may be utilized to construct this new class.
107
+ Additionally, a hybrid solver could be implemented using this same design.
108
+
109
+ ## Troubleshooting Common Errors
110
+
111
+ **No module named '_bz2'** This error occurs because NetworkX, a dependency of `eqc-models`, requires the bzip 2 library and it has not been found. On some linux environments, the OS package `libbzip2-dev` can be installed with apt or yum, then the python environment must be installed again.
112
+
113
+ ## Further Information
114
+
115
+ Most of the classes in this package have doctests, see these docstrings for specific concrete examples. Also, the `scripts` and `test` directories have examples on modeling and solving with `eqc-models`.
@@ -0,0 +1,23 @@
1
+ from setuptools import Extension
2
+ from setuptools.command.build_py import build_py as _build_py
3
+ import numpy
4
+
5
+ # Modules to be compiled and include_dirs when necessary
6
+ extensions = [
7
+ Extension(
8
+ "eqc_models.base.polyeval",
9
+ ["eqc_models/base/polyeval.pyx"], include_dirs=[numpy.get_include()],
10
+ ),
11
+ ]
12
+
13
+ class build_py(_build_py):
14
+ def run(self):
15
+ self.run_command("build_ext")
16
+ return super().run()
17
+
18
+ def initialize_options(self):
19
+ super().initialize_options()
20
+ if self.distribution.ext_modules == None:
21
+ self.distribution.ext_modules = []
22
+
23
+ self.distribution.ext_modules.extend(extensions)
@@ -0,0 +1,20 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line, and also
5
+ # from the environment for the first two.
6
+ SPHINXOPTS ?=
7
+ SPHINXBUILD ?= sphinx-build
8
+ SOURCEDIR = source
9
+ BUILDDIR = build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)