diff --git a/README.md b/README.md index 5e55d38ce..cedd16911 100644 --- a/README.md +++ b/README.md @@ -68,9 +68,9 @@ from docplex.mp.model import Model from qiskit_optimization.algorithms import MinimumEigenOptimizer from qiskit_optimization.translators import from_docplex_mp -from qiskit.utils import algorithm_globals, QuantumInstance -from qiskit import BasicAer -from qiskit.algorithms import QAOA +from qiskit.utils import algorithm_globals +from qiskit.primitives import Sampler +from qiskit.algorithms.minimum_eigensolvers import QAOA from qiskit.algorithms.optimizers import SPSA # Generate a graph of 4 nodes @@ -97,9 +97,8 @@ seed = 1234 algorithm_globals.random_seed = seed spsa = SPSA(maxiter=250) -backend = BasicAer.get_backend('qasm_simulator') -q_i = QuantumInstance(backend=backend, seed_simulator=seed, seed_transpiler=seed) -qaoa = QAOA(optimizer=spsa, reps=5, quantum_instance=q_i) +sampler = Sampler() +qaoa = QAOA(sampler=sampler, optimizer=spsa, reps=5) algorithm = MinimumEigenOptimizer(qaoa) result = algorithm.solve(problem) print(result.prettyprint()) # prints solution, x=[1, 0, 1, 0], the cost, fval=4 diff --git a/qiskit_optimization/algorithms/admm_optimizer.py b/qiskit_optimization/algorithms/admm_optimizer.py index 40c3911e7..881e05be7 100644 --- a/qiskit_optimization/algorithms/admm_optimizer.py +++ b/qiskit_optimization/algorithms/admm_optimizer.py @@ -17,21 +17,21 @@ from typing import List, Optional, Tuple, cast import numpy as np -from qiskit.algorithms import NumPyMinimumEigensolver +from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver +from ..converters import MaximizeToMinimize +from ..problems.constraint import Constraint +from ..problems.linear_constraint import LinearConstraint +from ..problems.linear_expression import LinearExpression +from ..problems.quadratic_program import QuadraticProgram +from ..problems.variable import Variable, VarType from .minimum_eigen_optimizer import MinimumEigenOptimizer from .optimization_algorithm import ( - OptimizationResultStatus, OptimizationAlgorithm, OptimizationResult, + OptimizationResultStatus, ) from .slsqp_optimizer import SlsqpOptimizer -from ..problems.constraint import Constraint -from ..problems.linear_constraint import LinearConstraint -from ..problems.linear_expression import LinearExpression -from ..problems.quadratic_program import QuadraticProgram -from ..problems.variable import VarType, Variable -from ..converters import MaximizeToMinimize UPDATE_RHO_BY_TEN_PERCENT = 0 UPDATE_RHO_BY_RESIDUALS = 1 diff --git a/qiskit_optimization/algorithms/recursive_minimum_eigen_optimizer.py b/qiskit_optimization/algorithms/recursive_minimum_eigen_optimizer.py index 26c1184a6..737fc56d9 100644 --- a/qiskit_optimization/algorithms/recursive_minimum_eigen_optimizer.py +++ b/qiskit_optimization/algorithms/recursive_minimum_eigen_optimizer.py @@ -14,28 +14,22 @@ from copy import deepcopy from enum import Enum -from typing import Optional, Union, List, Tuple, Dict, cast +from typing import Dict, List, Optional, Tuple, Union, cast import numpy as np -from qiskit.algorithms import NumPyMinimumEigensolver +from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver from qiskit.utils.validation import validate_min -from .minimum_eigen_optimizer import ( - MinimumEigenOptimizer, - MinimumEigenOptimizationResult, -) +from ..converters.quadratic_program_to_qubo import QuadraticProgramConverter, QuadraticProgramToQubo +from ..exceptions import QiskitOptimizationError +from ..problems import Variable +from ..problems.quadratic_program import QuadraticProgram +from .minimum_eigen_optimizer import MinimumEigenOptimizationResult, MinimumEigenOptimizer from .optimization_algorithm import ( - OptimizationResultStatus, OptimizationAlgorithm, OptimizationResult, + OptimizationResultStatus, ) -from ..converters.quadratic_program_to_qubo import ( - QuadraticProgramToQubo, - QuadraticProgramConverter, -) -from ..exceptions import QiskitOptimizationError -from ..problems import Variable -from ..problems.quadratic_program import QuadraticProgram class IntermediateResult(Enum): diff --git a/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py b/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py index 98016cbdd..62dbbe9a5 100644 --- a/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py +++ b/qiskit_optimization/algorithms/warm_start_qaoa_optimizer.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021. +# (C) Copyright IBM 2021, 2022. # # 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 @@ -14,26 +14,19 @@ import copy from abc import ABC, abstractmethod -from typing import Optional, List, Union, Dict, Tuple, cast +from typing import Dict, List, Optional, Tuple, Union, cast import numpy as np from qiskit import QuantumCircuit -from qiskit.algorithms import QAOA +from qiskit.algorithms.minimum_eigensolvers import QAOA from qiskit.circuit import Parameter -from .minimum_eigen_optimizer import ( - MinimumEigenOptimizer, - MinimumEigenOptimizationResult, -) -from .optimization_algorithm import ( - OptimizationAlgorithm, - OptimizationResultStatus, - SolutionSample, -) from ..converters.quadratic_program_converter import QuadraticProgramConverter from ..exceptions import QiskitOptimizationError from ..problems.quadratic_program import QuadraticProgram from ..problems.variable import VarType +from .minimum_eigen_optimizer import MinimumEigenOptimizationResult, MinimumEigenOptimizer +from .optimization_algorithm import OptimizationAlgorithm, OptimizationResultStatus, SolutionSample class BaseAggregator(ABC):