Skip to content

Commit

Permalink
Fix bug in max-cut solver (issue #611) (#635)
Browse files Browse the repository at this point in the history
* fix bug in max-cut solver (issue #611)

* fix copyrights

* add unknown-option-value as an error message to be ignored by pylint

* disable pylint too-many-positional-arguments error for the lines it pops up

* fix copyrights

* fix max-cut bug

(cherry picked from commit 8a7e09e)
  • Loading branch information
TolisChal authored and mergify[bot] committed Oct 25, 2024
1 parent a3646c8 commit 6e614c9
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 45 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ disable=fixme, # disabled as TODOs would show up as warnings
no-else-return, # relax "elif" after a clause with a return
docstring-first-line-empty, # relax docstring style
import-outside-toplevel,
unknown-option-value,


[REPORTS]
Expand Down
6 changes: 3 additions & 3 deletions qiskit_optimization/algorithms/admm_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2020, 2023.
# (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
Expand Down 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
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
4 changes: 2 additions & 2 deletions qiskit_optimization/algorithms/cobyla_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2020, 2023.
# (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
Expand Down 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
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2023.
# (C) Copyright IBM 2021, 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
Expand Down 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
4 changes: 2 additions & 2 deletions qiskit_optimization/algorithms/minimum_eigen_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2020, 2023.
# (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
Expand Down 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
4 changes: 2 additions & 2 deletions qiskit_optimization/algorithms/optimization_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2020, 2023.
# (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
Expand Down 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
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2020, 2023.
# (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
Expand Down 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
6 changes: 3 additions & 3 deletions qiskit_optimization/algorithms/slsqp_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2020, 2023.
# (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
Expand Down 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
4 changes: 2 additions & 2 deletions qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2023.
# (C) Copyright IBM 2021, 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
Expand Down 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
6 changes: 3 additions & 3 deletions qiskit_optimization/applications/max_cut.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2018, 2023.
# (C) Copyright IBM 2018, 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
Expand Down Expand Up @@ -114,10 +114,10 @@ def parse_gset_format(filename: str) -> np.ndarray:
w = np.zeros((n, n))
header = False
else:
s__, t__, _ = v
s__, t__, w__ = v
s__ -= 1 # adjust 1-index
t__ -= 1 # ditto
w[s__, t__] = t__
w[s__, t__] = w__
count += 1
assert m == count
w += w.T
Expand Down
4 changes: 2 additions & 2 deletions qiskit_optimization/applications/vehicle_routing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2018, 2023.
# (C) Copyright IBM 2018, 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
Expand Down 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
4 changes: 2 additions & 2 deletions qiskit_optimization/problems/linear_constraint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2019, 2023.
# (C) Copyright IBM 2019, 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
Expand All @@ -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
4 changes: 2 additions & 2 deletions qiskit_optimization/problems/quadratic_constraint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2019, 2023.
# (C) Copyright IBM 2019, 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
Expand Down 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
4 changes: 2 additions & 2 deletions qiskit_optimization/problems/quadratic_objective.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2019, 2023.
# (C) Copyright IBM 2019, 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
Expand Down 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
18 changes: 9 additions & 9 deletions qiskit_optimization/problems/quadratic_program.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2019, 2023.
# (C) Copyright IBM 2019, 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
Expand Down Expand Up @@ -185,7 +185,7 @@ def _add_variable(
key_format = ""
return self._add_variables(1, lowerbound, upperbound, vartype, name, key_format)[1][0]

def _add_variables(
def _add_variables( # pylint: disable=too-many-positional-arguments
self,
keys: Union[int, Sequence],
lowerbound: Union[float, int],
Expand Down Expand Up @@ -239,7 +239,7 @@ def _find_name(name, key_format, k):
variables.append(variable)
return names, variables

def _var_dict(
def _var_dict( # pylint: disable=too-many-positional-arguments
self,
keys: Union[int, Sequence],
lowerbound: Union[float, int],
Expand Down Expand Up @@ -277,7 +277,7 @@ def _var_dict(
zip(*self._add_variables(keys, lowerbound, upperbound, vartype, name, key_format))
)

def _var_list(
def _var_list( # pylint: disable=too-many-positional-arguments
self,
keys: Union[int, Sequence],
lowerbound: Union[float, int],
Expand Down Expand Up @@ -333,7 +333,7 @@ def continuous_var(
"""
return self._add_variable(lowerbound, upperbound, Variable.Type.CONTINUOUS, name)

def continuous_var_dict(
def continuous_var_dict( # pylint: disable=too-many-positional-arguments
self,
keys: Union[int, Sequence],
lowerbound: Union[float, int] = 0,
Expand Down Expand Up @@ -367,7 +367,7 @@ def continuous_var_dict(
keys, lowerbound, upperbound, Variable.Type.CONTINUOUS, name, key_format
)

def continuous_var_list(
def continuous_var_list( # pylint: disable=too-many-positional-arguments
self,
keys: Union[int, Sequence],
lowerbound: Union[float, int] = 0,
Expand Down Expand Up @@ -494,7 +494,7 @@ def integer_var(
"""
return self._add_variable(lowerbound, upperbound, Variable.Type.INTEGER, name)

def integer_var_dict(
def integer_var_dict( # pylint: disable=too-many-positional-arguments
self,
keys: Union[int, Sequence],
lowerbound: Union[float, int] = 0,
Expand Down Expand Up @@ -526,7 +526,7 @@ def integer_var_dict(
"""
return self._var_dict(keys, lowerbound, upperbound, Variable.Type.INTEGER, name, key_format)

def integer_var_list(
def integer_var_list( # pylint: disable=too-many-positional-arguments
self,
keys: Union[int, Sequence],
lowerbound: Union[float, int] = 0,
Expand Down Expand Up @@ -717,7 +717,7 @@ def quadratic_constraints_index(self) -> Dict[str, int]:
"""
return self._quadratic_constraints_index

def quadratic_constraint(
def quadratic_constraint( # pylint: disable=too-many-positional-arguments
self,
linear: Union[ndarray, spmatrix, List[float], Dict[Union[int, str], float]] = None,
quadratic: Union[
Expand Down
4 changes: 2 additions & 2 deletions qiskit_optimization/problems/variable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2019, 2023.
# (C) Copyright IBM 2019, 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
Expand Down 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
4 changes: 2 additions & 2 deletions qiskit_optimization/translators/prettyprint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2022, 2023.
# (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
Expand Down 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

0 comments on commit 6e614c9

Please sign in to comment.