Skip to content

Commit

Permalink
fix pylint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TolisChal committed Sep 26, 2024
1 parent 860d774 commit aaa9da0
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 31 deletions.
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
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
2 changes: 1 addition & 1 deletion qiskit_optimization/algorithms/minimum_eigen_optimizer.py
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

0 comments on commit aaa9da0

Please sign in to comment.