From 2ca9773c59b9771b29c1870ef717cbfd032e0b84 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Wed, 15 May 2024 12:46:21 -0400 Subject: [PATCH] Remove use of qasm simulator (#589) * Remove use of qasm simulator Closes #502. * Replace default configuration change with a warning * Add `stacklevel` to warning (cherry picked from commit e3db27bb8a921a1ccd4c1a881abc35eda1636a45) --- .../cutting/cutqc/wire_cutting_evaluation.py | 9 +++ .../tutorial_1_automatic_cut_finding.ipynb | 6 +- .../tutorials/tutorial_2_manual_cutting.ipynb | 65 +++---------------- 3 files changed, 22 insertions(+), 58 deletions(-) diff --git a/circuit_knitting/cutting/cutqc/wire_cutting_evaluation.py b/circuit_knitting/cutting/cutqc/wire_cutting_evaluation.py index 5a35c3f03..dcc27a14d 100644 --- a/circuit_knitting/cutting/cutqc/wire_cutting_evaluation.py +++ b/circuit_knitting/cutting/cutqc/wire_cutting_evaluation.py @@ -17,6 +17,7 @@ import copy from typing import Sequence, Any from multiprocessing.pool import ThreadPool +from warnings import warn import numpy as np @@ -81,6 +82,14 @@ def run_subcircuit_instances( options[i % len(options)] for i, _ in enumerate(subcircuits) ] else: + warn( + "Please provide a list of `backend_names` alongside the `service`. " + "With no backend specified, CutQC defaults to using " + "ibmq_qasm_simulator, but cloud simulators are not expected to be " + "operational past May 15, 2024. For more details, see: " + "https://docs.quantum.ibm.com/announcements/product-updates/2024-03-22-announcement-cloud-simulators-and-lab", + stacklevel=2, + ) backend_names_repeated = ["ibmq_qasm_simulator"] * len(subcircuits) if options: options_repeated = [options[0]] * len(subcircuits) diff --git a/docs/circuit_cutting/cutqc/tutorials/tutorial_1_automatic_cut_finding.ipynb b/docs/circuit_cutting/cutqc/tutorials/tutorial_1_automatic_cut_finding.ipynb index 9177e30fc..82672cf65 100644 --- a/docs/circuit_cutting/cutqc/tutorials/tutorial_1_automatic_cut_finding.ipynb +++ b/docs/circuit_cutting/cutqc/tutorials/tutorial_1_automatic_cut_finding.ipynb @@ -246,8 +246,10 @@ "# Set the Sampler and runtime options\n", "options = Options(execution={\"shots\": 4000})\n", "\n", - "# Run 2 parallel qasm simulator threads\n", - "backend_names = [\"ibmq_qasm_simulator\"] * 2" + "# Use the least busy backend for both threads\n", + "backend_names = None\n", + "if service is not None:\n", + " backend_names = [service.least_busy().name] * 2" ] }, { diff --git a/docs/circuit_cutting/cutqc/tutorials/tutorial_2_manual_cutting.ipynb b/docs/circuit_cutting/cutqc/tutorials/tutorial_2_manual_cutting.ipynb index 4b3037e35..18ba96bcc 100644 --- a/docs/circuit_cutting/cutqc/tutorials/tutorial_2_manual_cutting.ipynb +++ b/docs/circuit_cutting/cutqc/tutorials/tutorial_2_manual_cutting.ipynb @@ -75,60 +75,6 @@ "circuit.draw(\"mpl\", fold=-1, scale=0.75)" ] }, - { - "cell_type": "markdown", - "id": "461e57e3", - "metadata": {}, - "source": [ - "## Set up the Qiskit Runtime Service\n", - "\n", - "The Qiskit Runtime Service provides access to IBM Runtime Primitives and quantum backends.\n", - "Alternatively, a local statevector simulator can be used with the Qiskit primitives." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "5d1fb2ca", - "metadata": {}, - "outputs": [], - "source": [ - "from qiskit_ibm_runtime import (\n", - " QiskitRuntimeService, # noqa: F401\n", - " Options,\n", - ")\n", - "\n", - "# Use local versions of the primitives by default.\n", - "service = None\n", - "\n", - "# Uncomment the following line to instead use Qiskit Runtime.\n", - "# service = QiskitRuntimeService()" - ] - }, - { - "cell_type": "markdown", - "id": "5fb383d2", - "metadata": {}, - "source": [ - "The wire cutter tool uses a `Sampler` primitive to evaluate the probabilities of each subcircuit. Here, we configure the options for the Runtime Sampler and specify the backend(s) to be used to evaluate the subcircuits.\n", - "\n", - "If no service was set up, the `backend_names` argument will be ignored, and Qiskit primitives will be used with statevector simulator." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "d409553d", - "metadata": {}, - "outputs": [], - "source": [ - "# Set the Sampler and runtime options\n", - "options = Options(execution={\"shots\": 4000})\n", - "\n", - "# Run 2 parallel qasm simulator threads\n", - "backend_names = [\"ibmq_qasm_simulator\"] * 2" - ] - }, { "attachments": { "how-to-manual-cut.png": { @@ -244,6 +190,11 @@ "metadata": {}, "outputs": [], "source": [ + "from qiskit_ibm_runtime import (\n", + " QiskitRuntimeService, # noqa: F401\n", + " Options,\n", + ")\n", + "\n", "# Use local versions of the primitives by default.\n", "service = None\n", "\n", @@ -273,8 +224,10 @@ "# Set the Sampler and runtime options\n", "options = Options(execution={\"shots\": 4000})\n", "\n", - "# Run 2 parallel qasm simulator threads\n", - "backend_names = [\"ibmq_qasm_simulator\"] * 2" + "# Use the least busy backend for both threads\n", + "backend_names = None\n", + "if service is not None:\n", + " backend_names = [service.least_busy().name] * 2" ] }, {