Skip to content

Commit

Permalink
Update NB for QCVV session 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis-S-IBM committed Oct 15, 2020
1 parent 1b30ffd commit c0c67f3
Showing 1 changed file with 145 additions and 13 deletions.
158 changes: 145 additions & 13 deletions QCVV/Session 1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"source": [
"# Session 1: Qubit-level benchmarks & measurement error mitigation\n",
"\n",
"This notebook gives examples for how to use the ``ignis.characterization.coherence`` module for measuring $T_1$ and $T_2$."
"This notebook gives examples for how to use the ``ignis.characterization.coherence`` module for measuring $T_1$ and $T_2$, and performing measurement error mitigation."
]
},
{
Expand All @@ -20,13 +20,71 @@
"%matplotlib inline\n",
"\n",
"import qiskit\n",
"from qiskit import Aer\n",
"from qiskit.providers.aer.noise.errors.standard_errors import thermal_relaxation_error\n",
"from qiskit.providers.aer.noise import NoiseModel\n",
"\n",
"from qiskit.ignis.characterization.coherence import T1Fitter, T2StarFitter, T2Fitter\n",
"from qiskit.ignis.characterization.coherence import t1_circuits, t2_circuits, t2star_circuits"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from qiskit import IBMQ\n",
"IBMQ.load_account()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hub = 'ibm-q'\n",
"group = 'open'\n",
"project = 'main'\n",
"\n",
"provider = IBMQ.get_provider(hub, group, project)\n",
"\n",
"provider.backends()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"backend = provider.get_backend('ibmq_valencia')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"props = backend.properties()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Let's grab the T1 and T2 times of each qubit on valencia\n",
"T1Times = np.round(np.array([props.t1(j)*10**6 for j in range(5)]), 4)\n",
"T2Times = np.round(np.array([props.t2(j)*10**6 for j in range(5)]), 4)\n",
"\n",
"print(T1Times)\n",
"print(T2Times)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -186,7 +244,7 @@
"source": [
"# Run the simulator, where we mock up repeating each circuit\n",
"# in the experiment design 500 times (\"shots\").\n",
"backend = qiskit.Aer.get_backend('qasm_simulator')\n",
"backend = Aer.get_backend('qasm_simulator')\n",
"shots = 500\n",
"\n",
"t1_backend_result = qiskit.execute(t1_circs, backend, shots=shots,\n",
Expand Down Expand Up @@ -358,6 +416,13 @@
"t2echo_circs[0].draw()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -383,6 +448,13 @@
"t2star_circs[0].draw()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -410,6 +482,13 @@
"t2cpmg_circs[0].draw()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -456,7 +535,7 @@
"source": [
"# Run the simulator, where we mock up repeating each circuit\n",
"# in the experiment design 500 times (\"shots\").\n",
"backend = qiskit.Aer.get_backend('qasm_simulator')\n",
"backend = Aer.get_backend('qasm_simulator')\n",
"shots = 500\n",
"\n",
"t2star_backend_result = qiskit.execute(t2star_circs, backend, shots=shots,\n",
Expand Down Expand Up @@ -656,7 +735,35 @@
"\n",
"The measurement calibration is used to mitigate measurement errors. From these calibrations, it is possible to correct the average results of another experiment of interest. This notebook gives examples for how to use the ``ignis.mitigation.measurement`` module.\n",
"\n",
"Here, we will do a \"complete\" measurement calibration; for more details on this and other measurement error mitigation techniques, see [this chapter](https://qiskit.org/textbook/ch-quantum-hardware/measurement-error-mitigation.html) in the Qiskit textbook."
"Here, we will do a \"complete\" measurement calibration; for more details on this and other measurement error mitigation techniques, see [this chapter](https://qiskit.org/textbook/ch-quantum-hardware/measurement-error-mitigation.html) in the Qiskit textbook.\n",
"\n",
"Readout error occurs when the state of the qubit is mis-read, and is quantified as\n",
"\n",
"$$\\text{Readout error} = \\frac{1}{2}\\left(\\mathrm{Pr}(\\text{read \"0\"}|\\text{qubit in } |1\\rangle) + \\mathrm{Pr}(\\text{read \"1\"}|\\text{qubit in } |0\\rangle) \\right)$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's look at these numbers for Valencia."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for j in range(5):\n",
" a = np.round(props.qubit_property(j)['prob_meas0_prep1'][0], 5)\n",
" b = np.round(props.qubit_property(j)['prob_meas1_prep0'][0], 5)\n",
" error = (a+b)/2\n",
" print('Qubit {0}'.format(j))\n",
" print('Probability of reading 0 given state 1: {0}'.format(a))\n",
" print('Probability of reading 1 given state 0: {0}'.format(b))\n",
" print('Readout error: {0}'.format(error))\n",
" print('------------')"
]
},
{
Expand All @@ -665,14 +772,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Import general libraries (needed for functions)\n",
"import numpy as np\n",
"import time\n",
"\n",
"# Import Qiskit classes\n",
"import qiskit \n",
"from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister, Aer\n",
"from qiskit.providers.aer import noise\n",
"from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister\n",
"from qiskit.providers.aer.noise.errors.readout_error import ReadoutError\n",
"from qiskit.tools.visualization import plot_histogram\n",
"\n",
"# Import measurement calibration functions\n",
Expand Down Expand Up @@ -804,9 +906,9 @@
"# Encode measurement probabilities for |1> state\n",
"readout_error1 = [.25, .75]\n",
"\n",
"noise_model = noise.NoiseModel()\n",
"noise_model = NoiseModel()\n",
"for qi in range(3):\n",
" read_err = noise.errors.readout_error.ReadoutError([readout_error0, readout_error1])\n",
" read_err = ReadoutError([readout_error0, readout_error1])\n",
" noise_model.add_readout_error(read_err, [qi])"
]
},
Expand All @@ -833,6 +935,15 @@
"print(meas_fitter.cal_matrix)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"np.sum(meas_fitter.cal_matrix[0, 0])"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1098,6 +1209,27 @@
"source": [
"Again, the mitigated results are in much closer agreement to the ideal probabilities."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit c0c67f3

Please sign in to comment.