Skip to content

Commit

Permalink
Qiskit version update
Browse files Browse the repository at this point in the history
  • Loading branch information
DeborahVolpe committed May 22, 2024
1 parent 66014b1 commit fe6e5a7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ repos:
- dwave-samplers
- dwave.system
- docplex==2.25.236
- qiskit==0.45.0
- qiskit==0.45.3
- qiskit_optimization==0.4.0
- qiskit-algorithms==0.2.1
- qiskit_ibm_runtime==0.14.0
- matplotlib
- pandas
- PyPortfolioOpt
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ filterwarnings = [
"ignore::DeprecationWarning:.*(docplex).*",
"ignore:.*pytorch.*:UserWarning:",
"ignore::DeprecationWarning:.*(importlib).*",
"ignore:.*:DeprecationWarning:qiskit.*",
"ignore:.*:PendingDeprecationWarning:qiskit.*",
"ignore:.*:ImportWarning:.*",
"ignore:.*:DeprecationWarning:qiskit.providers.ibmq.*",
"ignore:.*qiskit.algorithms.*:DeprecationWarning:.*",
"ignore::sklearn.exceptions.InconsistentVersionWarning:sklearn:",
]

Expand Down
69 changes: 35 additions & 34 deletions src/mqt/qao/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from dwave.system import DWaveSampler, EmbeddingComposite
from matplotlib import rc
from qiskit.algorithms import QAOA, VQE
from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.circuit import QuantumCircuit, Parameter
from qiskit.circuit.library import TwoLocal
from qiskit.exceptions import QiskitError
from qiskit_optimization.algorithms import (
Expand All @@ -24,8 +24,9 @@
MinimumEigenOptimizer,
OptimizationResult,
)
from qiskit.providers import Provider
from qiskit_ibm_runtime import QiskitRuntimeService # type: ignore[import-untyped]
from qiskit_optimization.translators import from_docplex_mp
from qiskit.providers.basicaer import BasicAer
from qubovert import PUBO, QUBO

if TYPE_CHECKING:
Expand Down Expand Up @@ -384,7 +385,9 @@ def solve_grover_adaptive_search_qubo(
auto_setting: bool = False,
simulator: bool = True,
backend_name: str = "qasm_simulator",
ibmaccount: str = "",
channel: str = "",
token: str = "",
instance: str = "",
qubit_values: int = 0,
coeff_precision: float = 1.0,
threshold: int = 10,
Expand Down Expand Up @@ -467,21 +470,19 @@ def solve_grover_adaptive_search_qubo(
)

if simulator:
try:
provider = Provider(token=ibmaccount)
backend = provider.get_backend(backend_name)
try: # Load your IBM Quantum account
QiskitRuntimeService.save_account(channel=channel, token=token, instance=instance, overwrite=True)
backend = QiskitRuntimeService().backend(backend_name)
except QiskitError:
print("The chosen simulator doesn't exist or the IBM cannot be used. Qasm simulator will used.")
provider = Provider()
backend = provider.get_backend("ibmq_qasm_simulator")
backend = BasicAer.get_backend("qasm_simulator")
else:
try:
provider = Provider(token=ibmaccount)
backend = provider.get_backend(backend_name)
QiskitRuntimeService.save_account(channel=channel, token=token, instance=instance, overwrite=True)
backend = QiskitRuntimeService().backend(backend_name)
except QiskitError:
print("The chosen backend doesn't exist or the IBM cannot be used. Qasm simulator will used.")
provider = Provider()
backend = provider.get_backend("ibmq_qasm_simulator")
backend = BasicAer.get_backend("qasm_simulator")
grover_optimizer = GroverOptimizer(qubit_values, num_iterations=threshold, quantum_instance=backend)

if save_time:
Expand Down Expand Up @@ -580,7 +581,9 @@ def solve_qaoa_qubo(
auto_setting: bool = False,
simulator: bool = True,
backend_name: str = "qasm_simulator",
ibmaccount: str = "",
channel: str = "",
token: str = "",
instance: str = "",
num_runs: int = 10,
optimizer: Optimizer = None,
reps: int = 1,
Expand Down Expand Up @@ -650,20 +653,18 @@ def solve_qaoa_qubo(
initial_state.h(_idx)
if simulator:
try:
provider = Provider(token=ibmaccount) if ibmaccount else Provider()
backend = provider.get_backend(backend_name)
QiskitRuntimeService.save_account(channel=channel, token=token, instance=instance, overwrite=True)
backend = QiskitRuntimeService().backend(backend_name)
except QiskitError:
print("The chosen simulator doesn't exist or the IBM cannot be used. Qasm simulator will used.")
provider = Provider()
backend = provider.get_backend("ibmq_qasm_simulator")
print("The chosen backend doesn't exist or the IBM cannot be used. Qasm simulator will used.")
backend = BasicAer.get_backend("qasm_simulator")
else:
try:
provider = Provider(token=ibmaccount)
backend = provider.get_backend(backend_name)
QiskitRuntimeService.save_account(channel=channel, token=token, instance=instance, overwrite=True)
backend = QiskitRuntimeService().backend(backend_name)
except QiskitError:
print("The chosen simulator doesn't exist or the IBM cannot be used. Qasm simulator will used.")
provider = Provider()
backend = provider.get_backend("ibmq_qasm_simulator")
print("The chosen backend doesn't exist or the IBM cannot be used. Qasm simulator will used.")
backend = BasicAer.get_backend("qasm_simulator")
qaoa_mes = QAOA(
quantum_instance=backend,
optimizer=optimizer,
Expand Down Expand Up @@ -745,7 +746,9 @@ def solve_vqe_qubo(
auto_setting: bool = False,
simulator: bool = True,
backend_name: str = "qasm_simulator",
ibmaccount: str = "",
channel: str = "",
token: str = "",
instance: str = "",
num_runs: int = 10,
optimizer: Optimizer | None = None,
ansatz: QuantumCircuit | OperatorBase | None = None,
Expand Down Expand Up @@ -802,20 +805,18 @@ def solve_vqe_qubo(

if simulator:
try:
provider = Provider(token=ibmaccount) if ibmaccount else Provider()
backend = provider.get_backend(backend_name)
QiskitRuntimeService.save_account(channel=channel, token=token, instance=instance, overwrite=True)
backend = QiskitRuntimeService().backend(backend_name)
except QiskitError:
print("The chosen simulator doesn't exist or the IBM cannot be used. Qasm simulator will used.")
provider = Provider()
backend = provider.get_backend("ibmq_qasm_simulator")
print("The chosen backend doesn't exist or the IBM cannot be used. Qasm simulator will used.")
backend = BasicAer.get_backend("qasm_simulator")
else:
try:
provider = Provider(token=ibmaccount)
backend = provider.get_backend(backend_name)
QiskitRuntimeService.save_account(channel=channel, token=token, instance=instance, overwrite=True)
backend = QiskitRuntimeService().backend(backend_name)
except QiskitError:
print("The chosen simulator doesn't exist or the IBM cannot be used. Qasm simulator will used.")
provider = Provider()
backend = provider.get_backend("ibmq_qasm_simulator")
print("The chosen backend doesn't exist or the IBM cannot be used. Qasm simulator will used.")
backend = BasicAer.get_backend("qasm_simulator")
vqe_mes = VQE(
quantum_instance=backend,
optimizer=optimizer,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ def test_gas_solver_basic() -> None:
assert solution


'''

def test_qaoa_solver_qubo_basic() -> None:
"""Test for the problem constructions"""
variables = Variables()
Expand Down Expand Up @@ -1643,7 +1643,7 @@ def test_vqe_solver_qubo_basic() -> None:
else:
assert solution

'''
@pytest.mark.parametrize(
"lambda_strategy",
[
Expand Down

0 comments on commit fe6e5a7

Please sign in to comment.