Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate QRAO into Qiskit Optimization #487

Merged
merged 89 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
14b75fa
add qrao files
a-matsuo Mar 24, 2023
837326b
support primitives and remove opflow
a-matsuo Apr 13, 2023
6e914ce
update qrao
a-matsuo Apr 16, 2023
32acacb
update qrao
a-matsuo Apr 17, 2023
31507c1
add expecation_values getter
a-matsuo Apr 17, 2023
b210cb0
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo Apr 17, 2023
11a5e40
inherit OptimizationAlgorithm
a-matsuo Apr 21, 2023
ba244a2
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo May 8, 2023
6a67943
add unittests for encoding
a-matsuo May 8, 2023
41f86eb
add unittests for optimizer
a-matsuo May 9, 2023
b4277ad
add unittests for optimizer
a-matsuo May 9, 2023
4408846
add reno and unittests for magic rounding
a-matsuo May 10, 2023
efcb66d
clean up
a-matsuo May 10, 2023
30c8794
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo May 10, 2023
2ae38b0
remove a unnecessary file
a-matsuo May 11, 2023
fc4d379
update the code
a-matsuo May 11, 2023
27ca8f1
add tutorial and update the code
a-matsuo May 12, 2023
668add2
update pylintdict
a-matsuo May 12, 2023
305a46e
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo May 12, 2023
9c3ac42
fix lint
a-matsuo May 12, 2023
872927d
Update docs/tutorials/13_quantum_random_access_optimizer.ipynb
a-matsuo May 17, 2023
59ecdd6
Update qiskit_optimization/algorithms/qrao/magic_rounding.py
a-matsuo May 17, 2023
40ae277
Update releasenotes/notes/qrao-89d5ff1d2927de64.yaml
a-matsuo May 17, 2023
7fb0f40
update the code
a-matsuo May 17, 2023
96784fa
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo May 17, 2023
d7513bb
add explanations and reflect comments
a-matsuo May 18, 2023
558ee28
update codes
a-matsuo May 19, 2023
0c438d5
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo May 19, 2023
02ec72a
fix
a-matsuo May 22, 2023
da34116
update the code
a-matsuo May 23, 2023
8c710d3
fix lint
a-matsuo May 23, 2023
a9fed9c
Fix docs so they build
woodsp-ibm May 23, 2023
f6c6e05
fix lint
a-matsuo May 24, 2023
9ecfd1c
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo May 24, 2023
8610ca1
Merge branch 'qrao' of github.com:a-matsuo/qiskit-optimization into qrao
a-matsuo May 24, 2023
810dc45
fix spell
a-matsuo May 24, 2023
6d62a05
fix spell
a-matsuo May 24, 2023
373987e
fix spell
a-matsuo May 24, 2023
0e787fc
test
a-matsuo May 29, 2023
58973a3
test
a-matsuo May 29, 2023
cc643ae
update
a-matsuo May 29, 2023
5a87be2
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo May 29, 2023
133105a
fix lint
a-matsuo May 29, 2023
73de655
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo May 29, 2023
ba59e95
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo May 29, 2023
424ea00
use assertalmost equal in unittest
a-matsuo May 29, 2023
7f4e5bd
update
a-matsuo May 30, 2023
402b025
fix
a-matsuo May 30, 2023
863f73a
Merge branch 'main' into qrao
a-matsuo Jun 1, 2023
f76c50b
rerun tutorial
a-matsuo Jun 2, 2023
12809dd
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo Jun 2, 2023
32c01a8
Merge branch 'qrao' of github.com:a-matsuo/qiskit-optimization into qrao
a-matsuo Jun 2, 2023
02c0a7c
add unittests for max per qubit= 2 and 1
a-matsuo Jun 5, 2023
df37bd9
Merge branch 'main' into qrao
woodsp-ibm Jun 5, 2023
3523a44
Update docs/tutorials/13_quantum_random_access_optimizer.ipynb
a-matsuo Jun 7, 2023
a8be7b4
Update docs/tutorials/13_quantum_random_access_optimizer.ipynb
a-matsuo Jun 7, 2023
1e8bc6f
Update docs/tutorials/13_quantum_random_access_optimizer.ipynb
a-matsuo Jun 7, 2023
dfde28b
fix docs
a-matsuo Jun 7, 2023
cdc675d
lint
a-matsuo Jun 7, 2023
948152d
add unittest quadratic objective
a-matsuo Jun 7, 2023
e71f660
update optimizer unittest
a-matsuo Jun 7, 2023
7b3c9e3
replaces rustworkx with networkx
t-imamichi Jun 12, 2023
0d6e7ce
minor updates of explanation
t-imamichi Jun 12, 2023
d16fca9
Merge branch 'main' into qrao
t-imamichi Jun 12, 2023
da4142e
fix docstrings
t-imamichi Jun 13, 2023
8b13f0c
update an error message
t-imamichi Jun 14, 2023
d0dec2c
Merge branch 'main' into qrao
t-imamichi Jun 14, 2023
d458560
update error messages
t-imamichi Jun 15, 2023
6380107
fix lint
t-imamichi Jun 15, 2023
0fb1656
Merge branch 'main' into qrao
woodsp-ibm Aug 29, 2023
ff8ee8e
update tutorial and qiskit_algorithms
a-matsuo Sep 4, 2023
a90bea3
Merge branch 'main' into qrao
woodsp-ibm Sep 5, 2023
57119a4
Merge branch 'main' into qrao
woodsp-ibm Sep 5, 2023
caac634
update
a-matsuo Sep 6, 2023
27c6c73
Merge branch 'qrao' of github.com:a-matsuo/qiskit-optimization into qrao
a-matsuo Sep 6, 2023
0fa0025
fix lint
a-matsuo Sep 6, 2023
8e0cb42
fix
a-matsuo Sep 7, 2023
74dec95
Update docs/tutorials/13_quantum_random_access_optimizer.ipynb
a-matsuo Sep 7, 2023
a5ec643
Update docs/tutorials/13_quantum_random_access_optimizer.ipynb
a-matsuo Sep 7, 2023
c1c329d
fix
a-matsuo Sep 7, 2023
cbba4f8
Update qiskit_optimization/algorithms/qrao/__init__.py
a-matsuo Sep 7, 2023
4b2ea88
Update releasenotes/notes/qrao-89d5ff1d2927de64.yaml
a-matsuo Sep 7, 2023
9f61f4c
Update test/algorithms/qrao/test_magic_rounding.py
a-matsuo Sep 7, 2023
bf16e25
Update test/algorithms/qrao/test_quantum_random_access_optimizer.py
a-matsuo Sep 7, 2023
3b4570e
fix mypy
a-matsuo Sep 7, 2023
e494613
Merge remote-tracking branch 'upstream/main' into qrao
a-matsuo Sep 7, 2023
6e1f1c3
fix
a-matsuo Sep 7, 2023
d5ffb28
fix
a-matsuo Sep 7, 2023
208daad
change the index number
a-matsuo Sep 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions qiskit_optimization/algorithms/qrao/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
Quantum Random Access Optimization (:mod:`qiskit_optimization.algorithms.qrao`)
===============================================================================

.. currentmodule:: qiskit_optimization.algorithms.qrao


a-matsuo marked this conversation as resolved.
Show resolved Hide resolved
Quantum Random Access Encoding and Optimization
===============================================
.. autosummary::
:toctree: ../stubs/
:nosignatures:

EncodingCommutationVerifier
QuantumRandomAccessEncoding
QuantumRandomAccessOptimizer
QuantumRandomAccessOptimizationResult

Rounding schemes
================

.. autosummary::
:toctree: ../stubs/
:nosignatures:

MagicRounding
MagicRoundingResult
RoundingScheme
RoundingContext
RoundingResult
SemideterministicRounding
SemideterministicRoundingResult

"""

from .encoding_commutation_verifier import EncodingCommutationVerifier
from .quantum_random_access_encoding import QuantumRandomAccessEncoding
from .magic_rounding import MagicRounding, MagicRoundingResult
from .quantum_random_access_optimizer import (
QuantumRandomAccessOptimizationResult,
QuantumRandomAccessOptimizer,
)
from .rounding_common import RoundingContext, RoundingResult, RoundingScheme
from .semideterministic_rounding import SemideterministicRounding, SemideterministicRoundingResult

__all__ = [
"EncodingCommutationVerifier",
"QuantumRandomAccessEncoding",
"RoundingScheme",
"RoundingContext",
"RoundingResult",
"SemideterministicRounding",
"SemideterministicRoundingResult",
"MagicRounding",
"MagicRoundingResult",
"QuantumRandomAccessOptimizer",
"QuantumRandomAccessOptimizationResult",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""The EncodingCommutationVerifier."""

from typing import Tuple

from qiskit.primitives import Estimator

from qiskit_optimization.exceptions import QiskitOptimizationError

from .quantum_random_access_encoding import QuantumRandomAccessEncoding


class EncodingCommutationVerifier:
a-matsuo marked this conversation as resolved.
Show resolved Hide resolved
"""Class for verifying that the relaxation commutes with the objective function."""

def __init__(self, encoding: QuantumRandomAccessEncoding, estimator: Estimator = None):
a-matsuo marked this conversation as resolved.
Show resolved Hide resolved
"""
Args:
encoding: The encoding to verify.
a-matsuo marked this conversation as resolved.
Show resolved Hide resolved
"""
self._encoding = encoding
if estimator is not None:
self._estimator = estimator
else:
self._estimator = Estimator()

def __len__(self) -> int:
return 2**self._encoding.num_vars

def __iter__(self):
for i in range(len(self)):
yield self[i]

def __getitem__(self, i: int) -> Tuple[str, float, float]:
if i not in range(len(self)):
a-matsuo marked this conversation as resolved.
Show resolved Hide resolved
raise IndexError(f"Index out of range: {i}")

encoding = self._encoding
str_dvars = f"{i:0{encoding.num_vars}b}"
dvars = [int(b) for b in str_dvars]
encoded_bitstr_qc = encoding.state_preparation_circuit(dvars)

# Evaluate the original objective function
problem = encoding.problem
sense = problem.objective.sense.value
obj_val = problem.objective.evaluate(dvars) * sense

# Evaluate the encoded Hamiltonian
encoded_op = encoding.qubit_op
offset = encoding.offset

job = self._estimator.run([encoded_bitstr_qc], [encoded_op])

try:
encoded_obj_val = job.result().values[0] + offset
except Exception as exc:
raise QiskitOptimizationError(
"The primitive job to verify commutation failed!"
) from exc

return (str_dvars, obj_val, encoded_obj_val)
Loading