From 2163fe444b5cb92880c0a966d99b6dbd801d92c4 Mon Sep 17 00:00:00 2001 From: Purva Thakre Date: Tue, 27 Feb 2024 13:07:22 -0600 Subject: [PATCH] temporary fixes: .qasm() to dumps and change fake provider path --- dev_requirements.txt | 1 + docs/source/examples/calibration-tutorial.md | 2 +- docs/source/examples/ddd_on_ibmq_ghz.md | 4 ++-- docs/source/examples/ggi_summer_school_solved.md | 2 +- docs/source/examples/ggi_summer_school_unsolved.md | 2 +- mitiq/interface/mitiq_qiskit/conversions.py | 3 ++- .../interface/mitiq_qiskit/tests/test_conversions_qiskit.py | 5 +++-- mitiq/interface/mitiq_qiskit/tests/test_qiskit_utils.py | 2 +- mitiq/tests/test_conversions.py | 3 ++- mitiq/zne/tests/test_zne.py | 2 +- 10 files changed, 15 insertions(+), 11 deletions(-) diff --git a/dev_requirements.txt b/dev_requirements.txt index 15633c6e3..facdfa4e7 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -2,6 +2,7 @@ qiskit~=1.0.1 qiskit-aer~=0.13.2 qiskit-ibm-provider~=0.8.0 +qiskit-ibm-runtime pyquil~=3.5.4 pennylane-qiskit~=0.34.0 pennylane~=0.34.0 diff --git a/docs/source/examples/calibration-tutorial.md b/docs/source/examples/calibration-tutorial.md index f6edf0575..38cd7b50d 100644 --- a/docs/source/examples/calibration-tutorial.md +++ b/docs/source/examples/calibration-tutorial.md @@ -43,7 +43,7 @@ from mitiq import ( MeasurementResult, ) -from qiskit.providers.fake_provider import FakeJakarta # Fake (simulated) QPU +from qiskit_ibm_runtime.fake_provider import FakeJakarta # Fake (simulated) QPU ``` ### Define the circuit to study diff --git a/docs/source/examples/ddd_on_ibmq_ghz.md b/docs/source/examples/ddd_on_ibmq_ghz.md index 546f84606..2b2cc361e 100644 --- a/docs/source/examples/ddd_on_ibmq_ghz.md +++ b/docs/source/examples/ddd_on_ibmq_ghz.md @@ -16,7 +16,7 @@ kernelspec: In this notebook DDD is applied to improve the success rate of the computation on a real hardware backend. A similar approach can be taken on a simulated backend, by setting the ``USE_REAL_HARDWARE`` option to ``False`` -and specifying a simulated backend from `qiskit.providers.fake_provider`, which includes a noise model that approximates the noise of the +and specifying a simulated backend from `qiskit_ibm_runtime.fake_provider`, which includes a noise model that approximates the noise of the real device. In DDD, sequences of gates are applied to slack windows, i.e. single-qubit idle windows, in a quantum circuit. @@ -148,7 +148,7 @@ if USE_REAL_HARDWARE: provider = IBMProvider() backend = provider.get_backend("ibmq_lima") else: - from qiskit.providers.fake_provider import FakeLima as FakeLima + from qiskit_ibm_runtime.fake_provider import FakeLima as FakeLima backend = FakeLima() diff --git a/docs/source/examples/ggi_summer_school_solved.md b/docs/source/examples/ggi_summer_school_solved.md index 508cb6275..705c75eea 100644 --- a/docs/source/examples/ggi_summer_school_solved.md +++ b/docs/source/examples/ggi_summer_school_solved.md @@ -116,7 +116,7 @@ from qiskit import QuantumCircuit from qiskit.providers.aer import AerSimulator from qiskit.tools.visualization import plot_histogram from qiskit import transpile -from qiskit.providers.fake_provider import FakeJakarta # Fake (simulated) QPUs +from qiskit_ibm_runtime.fake_provider import FakeJakarta # Fake (simulated) QPUs # Number of measurements shots = 10 ** 5 diff --git a/docs/source/examples/ggi_summer_school_unsolved.md b/docs/source/examples/ggi_summer_school_unsolved.md index eb4e02bf9..c0007df76 100644 --- a/docs/source/examples/ggi_summer_school_unsolved.md +++ b/docs/source/examples/ggi_summer_school_unsolved.md @@ -114,7 +114,7 @@ from qiskit import QuantumCircuit from qiskit_aer import AerSimulator from qiskit.tools.visualization import plot_histogram from qiskit import transpile -from qiskit.providers.fake_provider import FakeJakarta # Fake (simulated) QPUs +from qiskit_ibm_runtime.fake_provider import FakeJakarta # Fake (simulated) QPUs # Number of measurements shots = 10 ** 5 diff --git a/mitiq/interface/mitiq_qiskit/conversions.py b/mitiq/interface/mitiq_qiskit/conversions.py index 98c80a7ba..d2f4bf5f1 100644 --- a/mitiq/interface/mitiq_qiskit/conversions.py +++ b/mitiq/interface/mitiq_qiskit/conversions.py @@ -14,6 +14,7 @@ import numpy as np import qiskit from cirq.contrib.qasm_import import circuit_from_qasm +from qiskit.qasm2 import dumps from mitiq.utils import _simplify_circuit_exponents @@ -283,7 +284,7 @@ def from_qiskit(circuit: qiskit.QuantumCircuit) -> cirq.Circuit: Returns: Mitiq circuit representation equivalent to the input Qiskit circuit. """ - return from_qasm(circuit.qasm()) + return from_qasm(dumps(circuit)) def from_qasm(qasm: QASMType) -> cirq.Circuit: diff --git a/mitiq/interface/mitiq_qiskit/tests/test_conversions_qiskit.py b/mitiq/interface/mitiq_qiskit/tests/test_conversions_qiskit.py index 93bc7276d..e2400afc8 100644 --- a/mitiq/interface/mitiq_qiskit/tests/test_conversions_qiskit.py +++ b/mitiq/interface/mitiq_qiskit/tests/test_conversions_qiskit.py @@ -10,6 +10,7 @@ import numpy as np import pytest import qiskit +from qiskit.qasm2 import dumps from mitiq.interface import convert_to_mitiq from mitiq.interface.mitiq_qiskit.conversions import ( @@ -209,7 +210,7 @@ def test_convert_with_barrier(as_qasm): qiskit_circuit.barrier() if as_qasm: - cirq_circuit = from_qasm(qiskit_circuit.qasm()) + cirq_circuit = from_qasm(dumps(qiskit_circuit)) else: cirq_circuit = from_qiskit(qiskit_circuit) @@ -229,7 +230,7 @@ def test_convert_with_multiple_barriers(as_qasm): qiskit_circuit.barrier() if as_qasm: - cirq_circuit = from_qasm(qiskit_circuit.qasm()) + cirq_circuit = from_qasm(dumps(qiskit_circuit)) else: cirq_circuit = from_qiskit(qiskit_circuit) diff --git a/mitiq/interface/mitiq_qiskit/tests/test_qiskit_utils.py b/mitiq/interface/mitiq_qiskit/tests/test_qiskit_utils.py index c2ce90ce7..9bf4a1401 100644 --- a/mitiq/interface/mitiq_qiskit/tests/test_qiskit_utils.py +++ b/mitiq/interface/mitiq_qiskit/tests/test_qiskit_utils.py @@ -7,7 +7,7 @@ import numpy as np import pytest from qiskit import QuantumCircuit -from qiskit.providers.fake_provider import FakeLima +from qiskit_ibm_runtime.fake_provider import FakeLima from mitiq import MeasurementResult, Observable, PauliString from mitiq.interface.mitiq_qiskit.qiskit_utils import ( diff --git a/mitiq/tests/test_conversions.py b/mitiq/tests/test_conversions.py index 953b48a77..f3d7223f4 100644 --- a/mitiq/tests/test_conversions.py +++ b/mitiq/tests/test_conversions.py @@ -17,6 +17,7 @@ from braket.circuits import Instruction from braket.circuits import gates as braket_gates from pyquil import Program, gates +from qiskit.qasm2 import dumps from mitiq import SUPPORTED_PROGRAM_TYPES from mitiq.interface import ( @@ -44,7 +45,7 @@ qiskit_circuit = qiskit.QuantumCircuit(qiskit_qreg) qiskit_circuit.h(qiskit_qreg[0]) qiskit_circuit.cx(*qiskit_qreg) -qasm_str = qiskit_circuit.qasm() +qasm_str = dumps(qiskit_circuit) # pyQuil Bell circuit. diff --git a/mitiq/zne/tests/test_zne.py b/mitiq/zne/tests/test_zne.py index faae74c44..13dc8a084 100644 --- a/mitiq/zne/tests/test_zne.py +++ b/mitiq/zne/tests/test_zne.py @@ -525,7 +525,7 @@ def test_execute_with_zne_transpiled_qiskit_circuit(): """Tests ZNE when transpiling to a Qiskit device. Note transpiling can introduce idle (unused) qubits to the circuit. """ - from qiskit.providers.fake_provider import FakeSantiago + from qiskit_ibm_runtime.fake_provider import FakeSantiago santiago = FakeSantiago() backend = qiskit.providers.aer.AerSimulator.from_backend(santiago)