Skip to content

Commit

Permalink
Framework update (#26)
Browse files Browse the repository at this point in the history
* Update code

* Update code

* Update code

* Update code

* Update documentation

* Update test

* Update .tolm

* Try to fix problem in model load

* Try to fix problem in model load

* 🎨 pre-commit fixes

* Try to fix problem in model load

* Try to fix problem in model load

* Try to fix problem in model load

* Try to fix problem in model load

* Try to fix problem in model load

* Try to fix problem in model load

* Try to fix problem in model load

* Try to fix problem in model load

* 🎨 pre-commit fixes

* Try to fix problem in model load

* Try to fix problem in model load

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update workflow

* Update code

* clean Nox

* bib

* ⬆️ update pre-commit hooks

* ✏️ fix typos

* 👷 add artifact attestations

* 🔧 update dependencies (drop numpy upper cap)

* ✨ add 3.13 support

* 🚨🎨 code quality fixes

* 🔧 loosen sphinx dependency

* bib

* 🩹 actually cite the reference

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: burgholzer <burgholzer@me.com>
  • Loading branch information
3 people authored Aug 13, 2024
1 parent 9ee7f69 commit 61c7860
Show file tree
Hide file tree
Showing 358 changed files with 2,396 additions and 100 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ on:
release:
types: [published]
workflow_dispatch:
pull_request:
paths:
- .github/workflows/cd.yml

jobs:
python-packaging:
name: 🐍 Packaging
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-packaging.yml@v1.2.1
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-packaging.yml@v1.3
with:
pure-python: true

Expand All @@ -20,11 +23,17 @@ jobs:
url: https://pypi.org/p/mqt.qao
permissions:
id-token: write
attestations: write
contents: read
needs: [python-packaging]
steps:
- uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true
- name: Generate artifact attestation for sdist and wheel(s)
uses: actions/attest-build-provenance@v1.4.0
with:
subject-path: "dist/*"
- uses: pypa/gh-action-pypi-publish@release/v1
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ concurrency:
jobs:
change-detection:
name: 🔍 Change
uses: cda-tum/mqt-workflows/.github/workflows/reusable-change-detection.yml@v1.2.1
uses: cda-tum/mqt-workflows/.github/workflows/reusable-change-detection.yml@v1.3

python-tests:
name: 🐍 Test
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-python-tests)
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-ci.yml@v1.2.1
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-ci.yml@v1.3
with:
skip-testing-latest-python: true

code-ql:
name: 📝 CodeQL
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-code-ql)
uses: cda-tum/mqt-workflows/.github/workflows/reusable-code-ql-python.yml@v1.2.1
uses: cda-tum/mqt-workflows/.github/workflows/reusable-code-ql-python.yml@v1.3

required-checks-pass: # This job does nothing and is only used for branch protection
name: 🚦 Check
Expand Down
25 changes: 19 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,17 @@ repos:
additional_dependencies: [black==24.*]

# Format configuration files with prettier
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.3.3
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]

# Check for spelling
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
- repo: https://github.com/crate-ci/typos
rev: v1.23.6
hooks:
- id: codespell
args: ["-L", "wille,linz", "--skip", "*.ipynb"]
- id: typos

# Catch common capitalization mistakes
- repo: local
Expand All @@ -113,3 +112,17 @@ repos:
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]

# Check JSON schemata
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.1
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs

# Check the pyproject.toml file
- repo: https://github.com/henryiii/validate-pyproject-schema-store
rev: 2024.08.08
hooks:
- id: validate-pyproject
10 changes: 10 additions & 0 deletions CITATION.bib
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ @INPROCEEDINGS{volpe2024towards
PRIMARYCLASS = {quant-ph},
ARCHIVEPREXIX = {arxiv},
}

@INPROCEEDINGS{volpe2024predictive,
AUTHOR = {D. Volpe and N. Quetschlich and M. Graziano and G. Turvani and R. Wille},
TITLE = {{A Predictive Approach for Selecting the Best Quantum Solver for an Optimization Problem}},
YEAR = {2024},
BOOKTITLE = {IEEE International Conference on Quantum Computing and Engineering (QCE)},
EPRINT = {2408.03613},
PRIMARYCLASS = {quant-ph},
ARCHIVEPREXIX = {arxiv},
}
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ solution = Solver().solve_Dwave_quantum_annealer(prb, token=token)

## References

In case you are using the MQT Quantum Auto Optimizer in your work, we would be thankful if you referred to it by citing the following publication:
In case you are using the MQT Quantum Auto Optimizer in your work, we would be thankful if you referred to it by citing the following publications:

```bibtex
@INPROCEEDINGS{volpe2024towards,
Expand All @@ -74,6 +74,16 @@ In case you are using the MQT Quantum Auto Optimizer in your work, we would be t
PRIMARYCLASS = {quant-ph},
ARCHIVEPREXIX = {arxiv},
}
@INPROCEEDINGS{volpe2024predictive,
AUTHOR = {D. Volpe and N. Quetschlich and M. Graziano and G. Turvani and R. Wille},
TITLE = {{A Predictive Approach for Selecting the Best Quantum Solver for an Optimization Problem}},
YEAR = {2024},
BOOKTITLE = {IEEE International Conference on Quantum Computing and Engineering (QCE)},
EPRINT = {2408.03613},
PRIMARYCLASS = {quant-ph},
ARCHIVEPREXIX = {arxiv},
}
```

## Acknowledgements
Expand Down
2 changes: 1 addition & 1 deletion docs/References.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
References
==========

If you use *MQT Quantum Auto Optimizer* in your work, we would appreciate if you cited :cite:labelpar:`volpe2024towards`.
If you use the *MQT Quantum Auto Optimizer* in your work, we would appreciate if you cited :cite:labelpar:`volpe2024towards,volpe2024predictive`.

.. bibliography::
63 changes: 63 additions & 0 deletions docs/Solver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,36 @@ The class provides for exploiting the solver:

For each of them, the outcome is a Solution object.

Best Solver Prediction:
-----------------------
- solve(
self,
problem: Problem,
num_runs: int = 10,
coeff_precision: float = 1.0,
token: str = "",
max_lambda_update: int = 5,
lambda_update_mechanism: str = "sequential penalty increase",
lambda_strategy: str = "upper lower bound posiform and negaform method",
lambda_value: float = 1.0,
save_time: bool = False,
save_compilation_time: bool = False,
) -> Solution | bool | None: Solve the problem using the best solver. The parameters are:
- *problem*: the problem to solve
- *num_runs*: the number of trial
- *coeff_precision*: the wanted precision for coefficients (in case of Grover Adaptive Search)
- *token*: the token to access the D-Wave API
- *max_lambda_update*: the maximum lambda update if the constraints are not satisfied
- *lambda_update_mechanism*: the lambda update mechanism among:
- *sequential penalty increase*
- *scaled sequential penalty increase*
- *binary search penalty algorithm*
- *lambda_strategy*: for selecting the lambda generation mechanisms
- *save_time*: if save the time required for solver execution
- *save_compilation_time*: if save the time required for compilation




Examples:
---------
Expand Down Expand Up @@ -313,6 +343,12 @@ Variational Quantum Eigensolver
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
from mqt.qao.constraints import Constraints
from mqt.qao.variables import Variables
from mqt.qao.objectivefunction import ObjectiveFunction
from mqt.qao.problem import Problem
from mqt.qao.solver import Solver
variables = Variables()
constraint = Constraints()
a0 = variables.add_binary_variable("a")
Expand All @@ -328,3 +364,30 @@ Variational Quantum Eigensolver
problem,
num_runs=10,
)
Predicted Best Solver
~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
from mqt.qao.constraints import Constraints
from mqt.qao.variables import Variables
from mqt.qao.objectivefunction import ObjectiveFunction
from mqt.qao.problem import Problem
from mqt.qao.solver import Solver
variables = Variables()
constraint = Constraints()
a0 = variables.add_binary_variable("a")
b0 = variables.add_binary_variable("b")
c0 = variables.add_binary_variable("c")
cost_function = cast(Expr, -a0 + 2 * b0 - 3 * c0 - 2 * a0 * c0 - 1 * b0 * c0)
objective_function = ObjectiveFunction()
objective_function.add_objective_function(cost_function)
problem = Problem()
problem.create_problem(variables, constraint, objective_function)
solver = Solver()
solution = solver.solve(
problem,
num_runs=10,
)
10 changes: 10 additions & 0 deletions docs/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ @INPROCEEDINGS{volpe2024towards
PRIMARYCLASS = {quant-ph},
ARCHIVEPREXIX = {arxiv},
}

@INPROCEEDINGS{volpe2024predictive,
AUTHOR = {D. Volpe and N. Quetschlich and M. Graziano and G. Turvani and R. Wille},
TITLE = {{A Predictive Approach for Selecting the Best Quantum Solver for an Optimization Problem}},
YEAR = {2024},
BOOKTITLE = {IEEE International Conference on Quantum Computing and Engineering (QCE)},
EPRINT = {2408.03613},
PRIMARYCLASS = {quant-ph},
ARCHIVEPREXIX = {arxiv},
}
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
nox.needs_version = ">=2024.3.2"
nox.options.default_venv_backend = "uv|virtualenv"

PYTHON_ALL_VERSIONS = ["3.9", "3.10", "3.11", "3.12"]
PYTHON_ALL_VERSIONS = ["3.9", "3.10", "3.11", "3.12", "3.13"]

BUILD_REQUIREMENTS = [
"setuptools>=66.1",
Expand Down
35 changes: 28 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ dependencies = [
"qubovert>=1.2.5",
"matplotlib>=3.8",
"docplex>=2.21.207",
"dwave-system>=1.21.0",
"dwave-samplers>=1.2.0",
"numpy<2.0.0"
"dwave-system>=1.25.0",
"dwave-samplers>=1.3.0",
"scikit-learn>=1.4.2",
]

classifiers = [
Expand All @@ -45,6 +45,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Intended Audience :: Science/Research",
"Natural Language :: English",
"Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
Expand All @@ -55,7 +56,7 @@ test = ["pytest>=7.2"]
coverage = ["mqt.qao[test]", "pytest-cov>=4"]
docs = [
"furo>=2023.08.17",
"sphinx~=7.0",
"sphinx>=7.0",
"setuptools-scm>=7",
"sphinxcontrib-bibtex>=2.4.2",
"sphinx-copybutton",
Expand Down Expand Up @@ -130,8 +131,9 @@ module = [
"qiskit_ibm_runtime.*",
"matplotlib.*",
"docplex.*",
"dwave.*",
"dimod.*",
"dwave.*"
"scikit-learn.*",
]
ignore_missing_imports = true

Expand Down Expand Up @@ -204,8 +206,6 @@ isort.required-imports = ["from __future__ import annotations"]
"typing.Self".msg = "Use scikit_build_core._compat.typing.Self instead."
"typing_extensions.Self".msg = "Use scikit_build_core._compat.typing.Self instead."
"typing.assert_never".msg = "Use scikit_build_core._compat.typing.assert_never instead."
"importlib.resources".msg = "Use scikit_build_core._compat.importlib.resources instead."
"importlib_resources".msg = "Use scikit_build_core._compat.importlib.resources instead."

[tool.ruff.lint.per-file-ignores]
"tests/**" = ["T20", "ANN"]
Expand All @@ -220,3 +220,24 @@ isort.required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.pydocstyle]
convention = "google"


[tool.typos]
default.extend-ignore-re = [
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$", # ignore line
"(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on" # ignore block
]
default.extend-ignore-identifiers-re = [
"BasicAer",
"qiskit_aer",
"AerSimulator",
]
[tool.typos.default.extend-words]
wille = "wille"


[tool.repo-review]
ignore = [
"PC160", # "Uses codespell" -> switched to https://github.com/crate-ci/typos
"PC180", # "Uses prettier" -> switched to different prettier-mirror that is not recognized by the check
]
26 changes: 13 additions & 13 deletions scripts/linear_regression/LinearRegression.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
X = np.zeros([N, d])
Y = np.zeros(N)
TrainingPercentage = 0.7
N_Traning = int(N * TrainingPercentage)
N_Test = N - N_Traning
N_Training = int(N * TrainingPercentage)
N_Test = N - N_Training
i = 0
for key in df:
j = 0
Expand All @@ -38,21 +38,21 @@
j += 1
pca = PCA(n_components=feat)
X = pca.fit_transform(X=X, y=Y)
X_traning = np.hstack((X[:N_Traning, :], np.ones((N_Traning, 1))))
X_test = np.hstack((X[N_Traning:, :], np.ones((N_Test, 1))))
X_training = np.hstack((X[:N_Training, :], np.ones((N_Training, 1))))
X_test = np.hstack((X[N_Training:, :], np.ones((N_Test, 1))))

Y_traning = Y[:N_Traning]
Y_test = Y[N_Traning:]
Y_training = Y[:N_Training]
Y_test = Y[N_Training:]
variables = Variables()
w = variables.add_continuous_variables_array("w", [feat + 1, 1], -0.25, 0.25, 0.25)
objective_function = ObjectiveFunction()
objective_function.add_objective_function(
cast(
Expr,
(
np.dot(np.dot(np.dot(np.transpose(w), np.transpose(X_traning)), X_traning), w)
- 2 * np.dot(np.dot(np.transpose(w), np.transpose(X_traning)), Y_traning)
+ np.dot(np.transpose(Y_traning), Y_traning)
np.dot(np.dot(np.dot(np.transpose(w), np.transpose(X_training)), X_training), w)
- 2 * np.dot(np.dot(np.transpose(w), np.transpose(X_training)), Y_training)
+ np.dot(np.transpose(Y_training), Y_training)
)[0, 0],
)
)
Expand All @@ -73,18 +73,18 @@
print(solution.best_energy)
solution.wring_json_reports(filename="simulated_annealing_linear_regression_Iris", problem_features=True)
w_conf = solution.best_solution["w"]
Y_obtained_training = np.dot(X_traning, w_conf)
Y_obtained_training = np.dot(X_training, w_conf)
TP_tr = 0
TN_tr = 0
FP_tr = 0
FN_tr = 0
for i in range(N_Traning):
for i in range(N_Training):
if Y_obtained_training[i] > 0:
if Y_traning[i] == 1:
if Y_training[i] == 1:
TP_tr += 1
else:
FP_tr += 1
elif Y_traning[i] == 1:
elif Y_training[i] == 1:
FN_tr += 1
else:
TN_tr += 1
Expand Down
Binary file added src/mqt/qao/model/RandomForest/Scaler.pkl
Binary file not shown.
Binary file added src/mqt/qao/model/RandomForest/ScalerKCross.pkl
Binary file not shown.
Binary file added src/mqt/qao/model/RandomForest/model.pkl
Binary file not shown.
Loading

0 comments on commit 61c7860

Please sign in to comment.