Remove "warning suppression" code (#1307)

Closes #1279 
Closes #1331 

I removed the "ignore warning" code from all relevant tutorials (in
addition to VQE and CHSH) and ran them all locally on simulators to make
sure we aren't getting warnings. I also added Requirements sections to
VQE and CHSH.

Working on re-generating the output for CHSH since it currently runs on
a 27Q system, but I'm in the queue for 16 hrs.

---------

Co-authored-by: Frank Harkins <frankharkins@hotmail.co.uk>
This commit is contained in:
Rebecca Dimock 2024-05-10 13:52:25 -05:00 committed by GitHub
parent 5d11cc4bd7
commit 7d1970e610
6 changed files with 109 additions and 61 deletions

View File

@ -5,6 +5,8 @@ all_notebooks = "[!.]*/**/*.ipynb"
notebooks_exclude = [
"scripts/ibm-quantum-learning-uploader/test/template.ipynb",
"**/.ipynb_checkpoints/**",
# The following notebooks are broken and need fixing
"tutorials/submitting-transpiled-circuits/submitting-transpiled-circuits.ipynb",
]
# The following notebooks submit jobs that can be mocked with a simulator
@ -14,7 +16,6 @@ notebooks_that_submit_jobs = [
"tutorials/grovers-algorithm/grovers.ipynb",
"tutorials/quantum-approximate-optimization-algorithm/qaoa.ipynb",
"tutorials/repeat-until-success/repeat-until-success.ipynb",
"tutorials/submitting-transpiled-circuits/submitting-transpiled-circuits.ipynb",
"tutorials/variational-quantum-eigensolver/vqe.ipynb",
]

File diff suppressed because one or more lines are too long

View File

@ -13,6 +13,19 @@
"Here, we demonstrate how to construct Grover oracles and use the `GroverOperator` from the Qiskit circuit library to easily set up a Grover's search instance. The runtime `Sampler` primitive allows seamless execution of Grover circuits."
]
},
{
"cell_type": "markdown",
"id": "152c479f",
"metadata": {},
"source": [
"## Requirements\n",
"\n",
"Before starting this tutorial, ensure that you have the following installed:\n",
"\n",
"* Qiskit SDK 1.0 or later, with visualization support (`pip install 'qiskit[visualization]'`)\n",
"* Qiskit Runtime (`pip install qiskit-ibm-runtime`) 0.22 or later"
]
},
{
"attachments": {},
"cell_type": "markdown",
@ -33,9 +46,6 @@
"source": [
"# Built-in modules\n",
"import math\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
"# Imports from Qiskit\n",
"from qiskit import QuantumCircuit\n",

View File

@ -13,6 +13,21 @@
"In a max-cut problem, we want to partition nodes of a graph in a way that maximizes the number of edges between nodes in differing groups. The desired max-cut partition for the following graph is clear: the 0th-node on the left should be separated from the rest of the nodes on the right by a cut. We will find this answer by applying QAOA by using Qiskit Runtime primitives and sessions."
]
},
{
"cell_type": "markdown",
"id": "9fb04860",
"metadata": {},
"source": [
"## Requirements\n",
"\n",
"Before starting this tutorial, ensure that you have the following installed:\n",
"\n",
"* Qiskit SDK 1.0 or later, with visualization support (`pip install 'qiskit[visualization]'`)\n",
"* Qiskit Runtime (`pip install qiskit-ibm-runtime`) 0.22 or later\n",
"* SciPy (`python -m pip install scipy`)\n",
"* rustworkx (`pip install rustworkx`)"
]
},
{
"attachments": {},
"cell_type": "markdown",
@ -31,9 +46,6 @@
"source": [
"# General imports\n",
"import numpy as np\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
"# Pre-defined ansatz circuit, operator class and visualization tools\n",
"from qiskit.circuit.library import QAOAAnsatz\n",

View File

@ -11,8 +11,27 @@
"\n",
"To get the best performance from your circuits, the Qiskit Runtime service will pass all circuits through Qiskit's transpiler before running them. While this is usually a good thing, we might sometimes want to disable this by passing the argument `skip_transpilation=True` to the primitive we're using.\n",
"\n",
"For example, we may know better than the transpiler in some cases, or want to target a specific subset of qubits on a specific device. In this tutorial, we'll disable automatic transpilation to test the performance of different transpiler settings. This example will take you through the full process of creating, transpiling, and submitting circuits.\n",
"For example, we may know better than the transpiler in some cases, or want to target a specific subset of qubits on a specific device. In this tutorial, we'll disable automatic transpilation to test the performance of different transpiler settings. This example will take you through the full process of creating, transpiling, and submitting circuits."
]
},
{
"cell_type": "markdown",
"id": "4cfec570-9959-428c-96f8-54a54263cd1b",
"metadata": {},
"source": [
"## Requirements\n",
"\n",
"Before starting this tutorial, ensure that you have the following installed:\n",
"\n",
"* Qiskit SDK 1.0 or later, with visualization support (`pip install 'qiskit[visualization]'`)\n",
"* Qiskit Runtime (`pip install qiskit-ibm-runtime`) 0.22 or later"
]
},
{
"cell_type": "markdown",
"id": "f8688ec1-8e07-4183-b03c-79d352c389fd",
"metadata": {},
"source": [
"## Setup"
]
},
@ -23,11 +42,6 @@
"metadata": {},
"outputs": [],
"source": [
"# General\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
"# Create circuit to test transpiler on\n",
"from qiskit import QuantumCircuit, transpile\n",
"from qiskit.circuit.library import GroverOperator, Diagonal\n",
@ -37,7 +51,7 @@
"from qiskit.visualization import plot_histogram\n",
"\n",
"# Qiskit Runtime\n",
"from qiskit_ibm_runtime import QiskitRuntimeService, Batch, Sampler"
"from qiskit_ibm_runtime import QiskitRuntimeService, Batch"
]
},
{
@ -281,14 +295,14 @@
}
],
"source": [
"binary_prob = [quasi_dist.binary_probabilities() for quasi_dist in result.quasi_dists]\n",
"binary_prob = [{k: v / res.data.meas.num_shots for k, v in res.data.meas.get_counts().items()} for res in result]\n",
"plot_histogram(\n",
" binary_prob + [ideal_distribution],\n",
" bar_labels=False,\n",
" legend=[\n",
" \"optimization_level=0\",\n",
" \"optimization_level=3\",\n",
" \"optimization_level=3 + dd\",\n",
" \"optimization_level=1\",\n",
" \"optimization_level=1 + dd\",\n",
" \"ideal distribution\",\n",
" ],\n",
")"
@ -321,8 +335,8 @@
"source": [
"from qiskit.quantum_info import hellinger_fidelity\n",
"\n",
"for counts in result.quasi_dists:\n",
" print(f\"{hellinger_fidelity(counts.binary_probabilities(), ideal_distribution):.3f}\")"
"for prob in binary_prob:\n",
" print(f\"{hellinger_fidelity(prob, ideal_distribution):.3f}\")"
]
},
{

View File

@ -20,6 +20,20 @@
"Although the Hamiltonian and ansatz require domain specific knowledge to construct, these details are immaterial to the Runtime, and we can execute a wide class of VQE problems in the same manner."
]
},
{
"cell_type": "markdown",
"id": "55b94021",
"metadata": {},
"source": [
"## Requirements\n",
"\n",
"Before starting this tutorial, ensure that you have the following installed:\n",
"\n",
"* Qiskit SDK 1.0 or later, with visualization support (`pip install 'qiskit[visualization]'`)\n",
"* Qiskit Runtime (`pip install qiskit-ibm-runtime`) 0.22 or later\n",
"* SciPy (`python -m pip install scipy`)"
]
},
{
"attachments": {},
"cell_type": "markdown",
@ -40,9 +54,6 @@
"source": [
"# General imports\n",
"import numpy as np\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
"# Pre-defined ansatz circuit and operator class for Hamiltonian\n",
"from qiskit.circuit.library import EfficientSU2\n",
@ -306,6 +317,7 @@
" ansatz (QuantumCircuit): Parameterized ansatz circuit\n",
" hamiltonian (SparsePauliOp): Operator representation of Hamiltonian\n",
" estimator (EstimatorV2): Estimator primitive instance\n",
" callback_dict: dictionary for storing intermediate results\n",
"\n",
" Returns:\n",
" float: Energy estimate\n",
@ -314,6 +326,11 @@
" result = estimator.run(pubs=[pub]).result()\n",
" energy = result[0].data.evs[0]\n",
"\n",
" callback_dict[\"iters\"] += 1\n",
" callback_dict[\"prev_vector\"] = params\n",
" callback_dict[\"cost_history\"].append(energy)\n",
" print(f\"Iters. done: {callback_dict['iters']} [Current cost: {energy}]\")\n",
"\n",
" return energy"
]
},
@ -470,12 +487,9 @@
}
],
"source": [
"# To run on local simulator:\n",
"# 1. Use the Estimator from qiskit.primitives instead.\n",
"# 2. Remove the Session context manager below.\n",
"with Session(backend=backend) as session:\n",
" estimator = Estimator(session=session)\n",
" estimator.options.default_shots = 10_000\n",
" estimator.options.default_shots = 10000\n",
"\n",
" callback = build_callback(ansatz_isa, hamiltonian_isa, estimator, callback_dict)\n",
"\n",