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

QAOA compatibility with no dependencies from qiskit-algortithms #634

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d1a232d
Add dependencies from qiskit_algorithms to a separate folder
TolisChal Aug 23, 2024
21f9a23
Add compatibility layer for qaoa
TolisChal Aug 23, 2024
5e08503
Add utils from qiskit-algorithms for qaoa compatibility
TolisChal Aug 23, 2024
b2fd5f6
replace qiskit-algorithm dependencies with internal imports in minimu…
TolisChal Aug 23, 2024
a551027
add and integrate the test of qaoa from qiskit-algorithms
TolisChal Aug 23, 2024
583f111
add rustworkx package in requirements-dev.txt
TolisChal Aug 23, 2024
1251e10
integrate modules from qiskit-algorithms using qiskit-machine_learnin…
TolisChal Aug 27, 2024
ae73011
delete folders algorithms_backend and compat
TolisChal Aug 27, 2024
feef111
remove any reference to backend_algorithms
TolisChal Aug 27, 2024
b3c8c14
fix copyright issues with makefile
TolisChal Sep 2, 2024
ebc88b1
fix mypy errors
TolisChal Sep 2, 2024
19168f5
fix pylint errors
TolisChal Sep 2, 2024
7c87955
add tests from qiskit-qlgorithms for the newly added code
TolisChal Sep 3, 2024
5562a85
fix code style
TolisChal Sep 3, 2024
8f29b25
remove test function test_nlopt
TolisChal Sep 4, 2024
05f1018
remove unused imports
TolisChal Sep 4, 2024
d4055db
fix copyrights in files
TolisChal Sep 4, 2024
0fcd251
remove unused code from exceptions
TolisChal Sep 4, 2024
ed0fb3e
test validation functions properly
TolisChal Sep 4, 2024
665599f
add tests for sampling_vqe
TolisChal Sep 4, 2024
3bfe24b
implement unit-tests for AlgorithmResult class
TolisChal Sep 26, 2024
39a758f
fix errors in unit-tests for AlgorithmResult class
TolisChal Sep 26, 2024
860d774
fix errors in unit-tests for AlgorithmResult class
TolisChal Sep 26, 2024
aaa9da0
fix pylint errors
TolisChal Sep 26, 2024
df5497f
delete unused file
TolisChal Sep 26, 2024
457b46e
fix style and copyright errors
TolisChal Sep 26, 2024
a473905
fix lint errors for the tests that (too-many-positional-arguments) is…
TolisChal Sep 26, 2024
afe5f15
write unit tests for the set_default_batchsize() function
TolisChal Sep 26, 2024
9a20df2
add unit test forObservables Evaluators
TolisChal Sep 26, 2024
38b6ea0
fix errors in observables evaluator unit test
TolisChal Sep 26, 2024
9ca18f6
add new unit tests for member functions of Optimizer class
TolisChal Sep 26, 2024
adaf925
fix spelling errors
TolisChal Sep 26, 2024
31b89db
resolve PR comments
TolisChal Sep 30, 2024
2ecaaae
fix code style
TolisChal Sep 30, 2024
7554c15
disable pylint too-many-positional-arguments error for the lines it p…
TolisChal Oct 23, 2024
b006edc
ignore pylint unknown-option-value message
TolisChal Oct 23, 2024
06d64a9
fix coding style
TolisChal Oct 23, 2024
b7abcbe
Merge branch 'main' into Fix_code_style
TolisChal Oct 25, 2024
4f786d5
Merge branch 'main' into Fix_code_style
t-imamichi Nov 25, 2024
6f30299
update readme to replace qiskit_algorithms
TolisChal Dec 3, 2024
a97e379
Merge branch 'Fix_code_style' of github.com:TolisChal/qiskit-optimiza…
TolisChal Dec 3, 2024
d3e3386
Merge branch 'main' into Fix_code_style
TolisChal Dec 16, 2024
5369be9
write the relese notes
TolisChal Dec 16, 2024
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
52 changes: 52 additions & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ aer's
al
annealers
ansatz
ansatzes
apidocs
apl
applegate
args
arxiv
Expand All @@ -15,14 +17,17 @@ autosummary
backend
backends
barkoutsos
batchsize
benchmarking
bfgs
bitstring
bitstrings
bixby
bool
boolean
boyd
bravyi
callables
catol
cartan
chu
Expand All @@ -35,16 +40,20 @@ conv
const
cplex
cplexoptimizer
crs
cts
currentmodule
cvar
dataclass
deterministically
dic
dicts
dimensionality
disp
dmitry
docplex
docplex's
docstring
doi
dok
dtype
Expand All @@ -55,22 +64,31 @@ eigen
eigensolver
eigensolvers
eigenstate
eigenstates
embeddings
entangler
enum
eq
et
eval
evals
exponentiated
failsafe
farhi
fmin
formatter
frac
func
functools
fred
fval
fx
f'spsa
gambella
geq
getter
getters
globals
glover
goemans
goldstone
Expand All @@ -81,11 +99,13 @@ gurobi
gurobioptimizer
gurobipy
gutmann
hadfield
hamilton
hamiltonian
hamiltonians
hastings
hayashi
hessians
hoyer
https
ibm
Expand All @@ -99,7 +119,9 @@ iprint
ising
iter
iteratively
jac
july
kandala
karimi
kirkpatrick
kwargs
Expand All @@ -108,22 +130,28 @@ len
leq
lhs
lin
linalg
linearconstraint
linexpr
linter
lowerbound
lp
lse
lucas
macos
makefile
marecek
masahito
matplotlib
maxcut
maxfev
maxfun
maxiter
mdl
milp
minimizer
minimumeigenoptimizer
modelspace
mmp
mpm
multiset
Expand All @@ -132,9 +160,13 @@ nannicini
natively
ndarray
ndarrays
nones
noop
nelder
networkx
neven
nfev
nft
nosignatures
np
num
Expand All @@ -147,18 +179,23 @@ optimality
optimizationresult
optimizationresultstatus
optimizers
packagebut
panchenko
param
parameterizations
params
parikh
passmanager
pauli
paulis
peleato
pmm
polyfit
pooya
pos
ppp
pre
preconditioner
preprint
prepend
presolver
Expand Down Expand Up @@ -187,6 +224,8 @@ qubo
readme
repr
representable
resamplings
rescaling
rhobeg
rhoend
rhs
Expand All @@ -196,22 +235,30 @@ robert
ronagh
rtype
runtime
rustworkx
ry
rz
sahar
scipy
sdp
serializable
sherrington
simonetto
slsqp
smode
smoothen
spall
spedalieri
spsa
src
statevector
stdout
stephen
steppable
stepsize
str
subclassed
subclasses
subcollection
subgraph
submodules
Expand All @@ -222,6 +269,7 @@ summands
tavernelli
terra
th
tnc
toctree
todok
tol
Expand All @@ -241,13 +289,17 @@ variational
vartype
vqe
vqeresult
utils
writelines
xatol
xixj
xopt
wavefunction
wecker
whitespace
wiesner
williamson
woerner
xs
ys
zemlin
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ from docplex.mp.model import Model

from qiskit_optimization.algorithms import MinimumEigenOptimizer
from qiskit_optimization.translators import from_docplex_mp
from qiskit_optimization.utils import algorithm_globals
from qiskit_optimization.minimum_eigensolvers import QAOA
from qiskit_optimization.optimizers import SPSA

from qiskit.primitives import Sampler

from qiskit_algorithms.utils import algorithm_globals
from qiskit_algorithms import QAOA
from qiskit_algorithms.optimizers import SPSA

# Generate a graph of 4 nodes
n = 4
edges = [(0, 1, 1.0), (0, 2, 1.0), (0, 3, 1.0), (1, 2, 1.0), (2, 3, 1.0)] # (node_i, node_j, weight)
Expand Down
10 changes: 8 additions & 2 deletions qiskit_optimization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@

"""

from .exceptions import QiskitOptimizationError
from .exceptions import QiskitOptimizationError, AlgorithmError
from .infinity import INFINITY # must be at the top of the file
from .problems.quadratic_program import QuadraticProgram
from .version import __version__

__all__ = ["__version__", "QuadraticProgram", "QiskitOptimizationError", "INFINITY"]
__all__ = [
"__version__",
"QuadraticProgram",
"QiskitOptimizationError",
"AlgorithmError",
"INFINITY",
]
45 changes: 45 additions & 0 deletions qiskit_optimization/algorithm_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2022, 2024.
#
# 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.

"""
AlgorithmJob class
"""
from qiskit.primitives.primitive_job import PrimitiveJob


class AlgorithmJob(PrimitiveJob):
"""
This class is introduced for typing purposes and provides no
additional function beyond that inherited from its parents.

Update: :meth:`AlgorithmJob.submit()` method added. See its
documentation for more info.
"""

def submit(self) -> None:
"""
Submit the job for execution.

For V1 primitives, Qiskit ``PrimitiveJob`` subclassed JobV1 and defined ``submit()``.
``PrimitiveJob`` was updated for V2 primitives, no longer subclasses ``JobV1``, and
now has a private ``_submit()`` method, with ``submit()`` being deprecated as of
Qiskit version 0.46. This maintains the ``submit()`` for ``AlgorithmJob`` here as
it's called in many places for such a job. An alternative could be to make
0.46 the required minimum version and alter all algorithm's call sites to use
``_submit()`` and make this an empty class again as it once was. For now this
way maintains compatibility with the current min version of 0.44.
"""
# TODO: Considering changing this in the future - see above docstring.
try:
super()._submit()
except AttributeError:
super().submit() # pylint: disable=no-member
65 changes: 65 additions & 0 deletions qiskit_optimization/algorithm_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2020, 2024.
#
# 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.

"""
This module implements the abstract base class for algorithm results.
"""

from abc import ABC
import inspect
import pprint


class AlgorithmResult(ABC):
"""Abstract Base Class for algorithm results."""

def __str__(self) -> str:
result = {}
for name, value in inspect.getmembers(self):
if (
not name.startswith("_")
and not inspect.ismethod(value)
and not inspect.isfunction(value)
and hasattr(self, name)
):

result[name] = value

return pprint.pformat(result, indent=4)

def combine(self, result: "AlgorithmResult") -> None:
"""
Any property from the argument that exists in the receiver is
updated.
Args:
result: Argument result with properties to be set.
Raises:
TypeError: Argument is None
"""
if result is None:
raise TypeError("Argument result expected.")
if result == self:
return

# find any result public property that exists in the receiver
for name, value in inspect.getmembers(result):
if (
not name.startswith("_")
and not inspect.ismethod(value)
and not inspect.isfunction(value)
and hasattr(self, name)
):
try:
setattr(self, name, value)
except AttributeError:
# some attributes may be read only
pass
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import numpy as np
from qiskit.quantum_info import SparsePauliOp
from qiskit_algorithms import (
from ..minimum_eigensolvers import (
NumPyMinimumEigensolver,
NumPyMinimumEigensolverResult,
SamplingMinimumEigensolver,
Expand Down
Loading
Loading