From aaa9da0e83e01ef4bf18f1c42ba60f1900a80426 Mon Sep 17 00:00:00 2001 From: Apostolos Chalkis Date: Thu, 26 Sep 2024 14:12:13 +0300 Subject: [PATCH] fix pylint errors --- .../algorithms/admm_optimizer.py | 4 +-- .../algorithms/cobyla_optimizer.py | 2 +- .../goemans_williamson_optimizer.py | 2 +- .../algorithms/grover_optimizer.py | 4 +-- .../algorithms/minimum_eigen_optimizer.py | 2 +- .../algorithms/optimization_algorithm.py | 2 +- .../recursive_minimum_eigen_optimizer.py | 4 +-- .../algorithms/slsqp_optimizer.py | 4 +-- .../algorithms/warm_start_qaoa_optimizer.py | 2 +- .../applications/vehicle_routing.py | 2 +- .../minimum_eigensolvers/sampling_vqe.py | 2 +- qiskit_optimization/optimizers/cobyla.py | 2 +- qiskit_optimization/optimizers/nelder_mead.py | 2 +- qiskit_optimization/optimizers/spsa.py | 2 ++ .../problems/linear_constraint.py | 2 +- .../problems/quadratic_constraint.py | 2 +- .../problems/quadratic_objective.py | 2 +- .../problems/quadratic_program.py | 27 ++++++++++++++++--- qiskit_optimization/problems/variable.py | 2 +- .../translators/prettyprint.py | 2 +- test/optimizers/test_spsa.py | 2 +- test/translators/test_prettyprint.py | 10 +++---- 22 files changed, 54 insertions(+), 31 deletions(-) diff --git a/qiskit_optimization/algorithms/admm_optimizer.py b/qiskit_optimization/algorithms/admm_optimizer.py index e837ee278..a41f1aa95 100644 --- a/qiskit_optimization/algorithms/admm_optimizer.py +++ b/qiskit_optimization/algorithms/admm_optimizer.py @@ -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, @@ -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, diff --git a/qiskit_optimization/algorithms/cobyla_optimizer.py b/qiskit_optimization/algorithms/cobyla_optimizer.py index 8ed291c1e..1d5f2e7bc 100644 --- a/qiskit_optimization/algorithms/cobyla_optimizer.py +++ b/qiskit_optimization/algorithms/cobyla_optimizer.py @@ -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, diff --git a/qiskit_optimization/algorithms/goemans_williamson_optimizer.py b/qiskit_optimization/algorithms/goemans_williamson_optimizer.py index 989744ceb..536d287eb 100644 --- a/qiskit_optimization/algorithms/goemans_williamson_optimizer.py +++ b/qiskit_optimization/algorithms/goemans_williamson_optimizer.py @@ -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, diff --git a/qiskit_optimization/algorithms/grover_optimizer.py b/qiskit_optimization/algorithms/grover_optimizer.py index 469ebce18..548ef5da9 100644 --- a/qiskit_optimization/algorithms/grover_optimizer.py +++ b/qiskit_optimization/algorithms/grover_optimizer.py @@ -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, @@ -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, diff --git a/qiskit_optimization/algorithms/minimum_eigen_optimizer.py b/qiskit_optimization/algorithms/minimum_eigen_optimizer.py index 674ed657f..67d72d0bf 100644 --- a/qiskit_optimization/algorithms/minimum_eigen_optimizer.py +++ b/qiskit_optimization/algorithms/minimum_eigen_optimizer.py @@ -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], diff --git a/qiskit_optimization/algorithms/optimization_algorithm.py b/qiskit_optimization/algorithms/optimization_algorithm.py index 0b5b6ef0c..295456731 100644 --- a/qiskit_optimization/algorithms/optimization_algorithm.py +++ b/qiskit_optimization/algorithms/optimization_algorithm.py @@ -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, diff --git a/qiskit_optimization/algorithms/recursive_minimum_eigen_optimizer.py b/qiskit_optimization/algorithms/recursive_minimum_eigen_optimizer.py index 1e99fcb60..5a967ce5a 100644 --- a/qiskit_optimization/algorithms/recursive_minimum_eigen_optimizer.py +++ b/qiskit_optimization/algorithms/recursive_minimum_eigen_optimizer.py @@ -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, @@ -137,7 +137,7 @@ class RecursiveMinimumEigenOptimizer(OptimizationAlgorithm): from Symmetry Protection. `arXiv:1910.08980 `_ """ - def __init__( + def __init__( # pylint: disable=too-many-positional-arguments self, optimizer: OptimizationAlgorithm, min_num_vars: int = 1, diff --git a/qiskit_optimization/algorithms/slsqp_optimizer.py b/qiskit_optimization/algorithms/slsqp_optimizer.py index 2f4ccc84e..cca1731ed 100644 --- a/qiskit_optimization/algorithms/slsqp_optimizer.py +++ b/qiskit_optimization/algorithms/slsqp_optimizer.py @@ -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, @@ -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, diff --git a/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py b/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py index 7acd04e09..31b4a9bff 100644 --- a/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py +++ b/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py @@ -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, diff --git a/qiskit_optimization/applications/vehicle_routing.py b/qiskit_optimization/applications/vehicle_routing.py index d22727f5e..e31eafee1 100644 --- a/qiskit_optimization/applications/vehicle_routing.py +++ b/qiskit_optimization/applications/vehicle_routing.py @@ -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, diff --git a/qiskit_optimization/minimum_eigensolvers/sampling_vqe.py b/qiskit_optimization/minimum_eigensolvers/sampling_vqe.py index a5e04419c..fec4b5134 100644 --- a/qiskit_optimization/minimum_eigensolvers/sampling_vqe.py +++ b/qiskit_optimization/minimum_eigensolvers/sampling_vqe.py @@ -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, diff --git a/qiskit_optimization/optimizers/cobyla.py b/qiskit_optimization/optimizers/cobyla.py index d7710b1e3..fe4e4a570 100644 --- a/qiskit_optimization/optimizers/cobyla.py +++ b/qiskit_optimization/optimizers/cobyla.py @@ -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, diff --git a/qiskit_optimization/optimizers/nelder_mead.py b/qiskit_optimization/optimizers/nelder_mead.py index 8109b3f48..12b3bb191 100644 --- a/qiskit_optimization/optimizers/nelder_mead.py +++ b/qiskit_optimization/optimizers/nelder_mead.py @@ -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, diff --git a/qiskit_optimization/optimizers/spsa.py b/qiskit_optimization/optimizers/spsa.py index cd31119af..48e7aeb9a 100644 --- a/qiskit_optimization/optimizers/spsa.py +++ b/qiskit_optimization/optimizers/spsa.py @@ -36,6 +36,8 @@ logger = logging.getLogger(__name__) +# pylint: disable=too-many-positional-arguments + class SPSA(Optimizer): """Simultaneous Perturbation Stochastic Approximation (SPSA) optimizer. diff --git a/qiskit_optimization/problems/linear_constraint.py b/qiskit_optimization/problems/linear_constraint.py index fe07a4758..b887772b9 100644 --- a/qiskit_optimization/problems/linear_constraint.py +++ b/qiskit_optimization/problems/linear_constraint.py @@ -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, diff --git a/qiskit_optimization/problems/quadratic_constraint.py b/qiskit_optimization/problems/quadratic_constraint.py index 17f768f8b..4a74eefbd 100644 --- a/qiskit_optimization/problems/quadratic_constraint.py +++ b/qiskit_optimization/problems/quadratic_constraint.py @@ -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, diff --git a/qiskit_optimization/problems/quadratic_objective.py b/qiskit_optimization/problems/quadratic_objective.py index b81444a5c..d41903c89 100644 --- a/qiskit_optimization/problems/quadratic_objective.py +++ b/qiskit_optimization/problems/quadratic_objective.py @@ -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, diff --git a/qiskit_optimization/problems/quadratic_program.py b/qiskit_optimization/problems/quadratic_program.py index bcbfc5d10..3dfe1fe8f 100644 --- a/qiskit_optimization/problems/quadratic_program.py +++ b/qiskit_optimization/problems/quadratic_program.py @@ -39,6 +39,8 @@ logger = logging.getLogger(__name__) +# pylint: disable=too-many-positional-arguments + class QuadraticProgramStatus(Enum): """Status of QuadraticProgram""" @@ -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( @@ -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, @@ -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, diff --git a/qiskit_optimization/problems/variable.py b/qiskit_optimization/problems/variable.py index 37f9ec3c0..de6518eb9 100644 --- a/qiskit_optimization/problems/variable.py +++ b/qiskit_optimization/problems/variable.py @@ -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, diff --git a/qiskit_optimization/translators/prettyprint.py b/qiskit_optimization/translators/prettyprint.py index 7c002e851..9d140d19a 100644 --- a/qiskit_optimization/translators/prettyprint.py +++ b/qiskit_optimization/translators/prettyprint.py @@ -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, diff --git a/test/optimizers/test_spsa.py b/test/optimizers/test_spsa.py index 1f4e61fab..f0a928b41 100644 --- a/test/optimizers/test_spsa.py +++ b/test/optimizers/test_spsa.py @@ -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: diff --git a/test/translators/test_prettyprint.py b/test/translators/test_prettyprint.py index 6fead2566..5cf9ffbf1 100644 --- a/test/translators/test_prettyprint.py +++ b/test/translators/test_prettyprint.py @@ -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},