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 1 commit
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
4 changes: 2 additions & 2 deletions qiskit_optimization/algorithms/admm_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
class ADMMParameters:
"""Defines a set of parameters for ADMM optimizer."""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
TolisChal marked this conversation as resolved.
Show resolved Hide resolved
self,
rho_initial: float = 10000,
factor_c: float = 100000,
Expand Down Expand Up @@ -175,7 +175,7 @@ def __init__(self, op: QuadraticProgram, rho_initial: float) -> None:
class ADMMOptimizationResult(OptimizationResult):
"""ADMMOptimization Result."""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
x: np.ndarray,
fval: float,
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/algorithms/cobyla_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CobylaOptimizer(MultiStartOptimizer):
>>> result = optimizer.solve(problem)
"""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
rhobeg: float = 1.0,
rhoend: float = 1e-4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GoemansWilliamsonOptimizationResult(OptimizationResult):
values of just one solution. Explore ``samples`` for all possible solutions.
"""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
x: Optional[Union[List[float], np.ndarray]],
fval: float,
Expand Down
4 changes: 2 additions & 2 deletions qiskit_optimization/algorithms/grover_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class GroverOptimizer(OptimizationAlgorithm):
"""Uses Grover Adaptive Search (GAS) to find the minimum of a QUBO function."""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
num_value_qubits: int,
num_iterations: int = 3,
Expand Down Expand Up @@ -325,7 +325,7 @@ def _bin_to_int(v: str, num_value_bits: int) -> int:
class GroverOptimizationResult(OptimizationResult):
"""A result object for Grover Optimization methods."""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
x: Union[List[float], np.ndarray],
fval: float,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
class MinimumEigenOptimizationResult(OptimizationResult):
"""Minimum Eigen Optimizer Result."""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
x: Optional[Union[List[float], np.ndarray]],
fval: Optional[float],
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/algorithms/optimization_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class OptimizationResult:
should maintain the order when generating a new ``OptimizationResult`` object.
"""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
x: Union[List[float], np.ndarray] | None,
fval: float | None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class IntermediateResult(Enum):
class RecursiveMinimumEigenOptimizationResult(OptimizationResult):
"""Recursive Eigen Optimizer Result."""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
x: Union[List[float], np.ndarray],
fval: float,
Expand Down Expand Up @@ -137,7 +137,7 @@ class RecursiveMinimumEigenOptimizer(OptimizationAlgorithm):
from Symmetry Protection. `arXiv:1910.08980 <http://arxiv.org/abs/1910.08980>`_
"""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
optimizer: OptimizationAlgorithm,
min_num_vars: int = 1,
Expand Down
4 changes: 2 additions & 2 deletions qiskit_optimization/algorithms/slsqp_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SlsqpOptimizationResult(OptimizationResult):
SLSQP optimization result, defines additional properties that may be returned by the optimizer.
"""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
x: Union[List[float], np.ndarray],
fval: float,
Expand Down Expand Up @@ -104,7 +104,7 @@ class SlsqpOptimizer(MultiStartOptimizer):
"""

# pylint: disable=redefined-builtin
def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
iter: int = 100,
acc: float = 1.0e-6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class WarmStartQAOAOptimizer(MinimumEigenOptimizer):

"""

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
pre_solver: OptimizationAlgorithm,
relax_for_pre_solver: bool,
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/applications/vehicle_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def depot(self, depot: int) -> None:

@staticmethod
# pylint: disable=undefined-variable
def create_random_instance(
def create_random_instance( # pylint: disable=too-many-positional-arguments
n: int,
low: int = 0,
high: int = 100,
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/minimum_eigensolvers/sampling_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def evaluate_energy(parameters: np.ndarray) -> np.ndarray | float:

return evaluate_energy

def _build_sampling_vqe_result(
def _build_sampling_vqe_result( # pylint: disable=too-many-positional-arguments
self,
ansatz: QuantumCircuit,
optimizer_result: OptimizerResult,
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/optimizers/cobyla.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class COBYLA(SciPyOptimizer):
_OPTIONS = ["maxiter", "disp", "rhobeg"]

# pylint: disable=unused-argument
def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
maxiter: int = 1000,
disp: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/optimizers/nelder_mead.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NELDER_MEAD(SciPyOptimizer): # pylint: disable=invalid-name
_OPTIONS = ["maxiter", "maxfev", "disp", "xatol", "adaptive"]

# pylint: disable=unused-argument
def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
maxiter: int | None = None,
maxfev: int = 1000,
Expand Down
2 changes: 2 additions & 0 deletions qiskit_optimization/optimizers/spsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

logger = logging.getLogger(__name__)

# pylint: disable=too-many-positional-arguments


class SPSA(Optimizer):
"""Simultaneous Perturbation Stochastic Approximation (SPSA) optimizer.
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/problems/linear_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LinearConstraint(Constraint):
# Note: added, duplicating in effect that in Constraint, to avoid issues with Sphinx
Sense = ConstraintSense

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
quadratic_program: Any,
name: str,
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/problems/quadratic_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QuadraticConstraint(Constraint):
# Note: added, duplicating in effect that in Constraint, to avoid issues with Sphinx
Sense = ConstraintSense

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
quadratic_program: Any,
name: str,
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/problems/quadratic_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class QuadraticObjective(QuadraticProgramElement):

Sense = ObjSense

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
quadratic_program: Any,
constant: float = 0.0,
Expand Down
27 changes: 24 additions & 3 deletions qiskit_optimization/problems/quadratic_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

logger = logging.getLogger(__name__)

# pylint: disable=too-many-positional-arguments


class QuadraticProgramStatus(Enum):
"""Status of QuadraticProgram"""
Expand Down Expand Up @@ -364,7 +366,12 @@ def continuous_var_dict(
nested substitution.
"""
return self._var_dict(
keys, lowerbound, upperbound, Variable.Type.CONTINUOUS, name, key_format
keys=keys,
lowerbound=lowerbound,
upperbound=upperbound,
vartype=Variable.Type.CONTINUOUS,
name=name,
key_format=key_format,
)

def continuous_var_list(
Expand Down Expand Up @@ -442,7 +449,14 @@ def binary_var_dict(
QiskitOptimizationError: if `key_format` has more than one substitution or a
nested substitution.
"""
return self._var_dict(keys, 0, 1, Variable.Type.BINARY, name, key_format)
return self._var_dict(
keys=keys,
lowerbound=0,
upperbound=1,
vartype=Variable.Type.BINARY,
name=name,
key_format=key_format,
)

def binary_var_list(
self,
Expand Down Expand Up @@ -524,7 +538,14 @@ def integer_var_dict(
QiskitOptimizationError: if `key_format` has more than one substitution or a
nested substitution.
"""
return self._var_dict(keys, lowerbound, upperbound, Variable.Type.INTEGER, name, key_format)
return self._var_dict(
keys=keys,
lowerbound=lowerbound,
upperbound=upperbound,
vartype=Variable.Type.INTEGER,
name=name,
key_format=key_format,
)

def integer_var_list(
self,
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/problems/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Variable(QuadraticProgramElement):

Type = VarType

def __init__(
def __init__( # pylint: disable=too-many-positional-arguments
self,
quadratic_program: Any,
name: str,
Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/translators/prettyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _concatenate_terms(terms: List[str], wrap: int, indent: int) -> str:
return buf


def expr2str(
def expr2str( # pylint: disable=too-many-positional-arguments
constant: float = 0.0,
linear: Optional[LinearExpression] = None,
quadratic: Optional[QuadraticExpression] = None,
Expand Down
2 changes: 1 addition & 1 deletion test/optimizers/test_spsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class TerminationChecker:
def __init__(self):
self.values = []

def __call__(self, nfev, point, fvalue, stepsize, accepted) -> bool:
def __call__(self, nfev, point, fvalue, stepsize, accepted) -> bool: # pylint: disable=too-many-positional-arguments
self.values.append(fvalue)

if len(self.values) > 10:
Expand Down
10 changes: 5 additions & 5 deletions test/translators/test_prettyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def test_prettyprint(self):
q_p.linear_constraint({"x": 1, "y": 2}, "<=", 1, "lin_leq")
q_p.linear_constraint({"x": 1, "y": 2}, ">=", 1, "lin_geq")
q_p.quadratic_constraint(
{"x": 1, "y": 1},
{("x", "x"): 1, ("y", "z"): -1, ("z", "z"): 2},
"==",
1,
"quad_eq",
linear={"x": 1, "y": 1},
quadratic={("x", "x"): 1, ("y", "z"): -1, ("z", "z"): 2},
sense="==",
rhs=1,
name="quad_eq",
)
q_p.quadratic_constraint(
{"x": 1, "y": 1},
Expand Down
Loading