mirror of
https://github.com/quantumjim/Quantum-Computation-course-Basel.git
synced 2026-02-14 08:44:28 +01:00
update for 2024
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,146 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Exercise Sheet 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 1 - Trotter-Suzuki Simulations\n",
|
||||
"\n",
|
||||
"Consider the following Hamiltonian defined on four qubits.\n",
|
||||
"\n",
|
||||
"$$\n",
|
||||
"\\tilde H = - J_x (X_0 X_1 + X_2 X_3) - J_z (Z_0 Z_2 + Z_1 Z_3) - h\\sum_j X_j + Z_j\n",
|
||||
"$$\n",
|
||||
"\n",
|
||||
"Here $X_1 = I \\otimes \\sigma^x \\otimes I \\otimes I$, etc. The Hamiltonian is denoted $\\tilde H$ here to distingush it from the Hadamard, $H$.\n",
|
||||
"\n",
|
||||
"The time evolution of this Hamiltonian can be approximated by\n",
|
||||
"\n",
|
||||
"$$\n",
|
||||
"e^{i \\tilde H t} \\approx \\left( e^{-i X_0 X_1 \\, J_x t/n} e^{-i X_2 X_3 \\, J_x t/n} e^{-i Z_0 Z_2 \\, J_z t/n} e^{-i Z_1 Z_3 J_z \\, t/n}\\prod_j e^{-i(X_j +Z_j)\\, ht/n} \\right)^n\n",
|
||||
"$$\n",
|
||||
"\n",
|
||||
"where the approximation becomes increasing accurate as $n$ is increased.\n",
|
||||
"\n",
|
||||
"To complete the following questions, first write a Qiskit circuit to implement such a simulation of the time evolution.\n",
|
||||
"\n",
|
||||
"(a) For $J_x=1$ and $J_z=h=0$,$e^{i\\tilde H t} \\sim X_1 X_2 X_3 X_4$ for a suitable value of $t$. Determine the required value of $t$, and show that your simulation has this effect by appling to an initial $|0\\rangle^{\\otimes 4}$ state.\n",
|
||||
"\n",
|
||||
"(b) For $J_z=1$ and $J_x=h=0$, $e^{i\\tilde H t} \\sim Z_1 Z_2 Z_3 Z_4$ for a suitable value of $t$. Determine the required value of $t$, and show that your simulation has this effect by appling to an initial $|+\\rangle^{\\otimes 4}$ state.\n",
|
||||
"\n",
|
||||
"(c) For $J_x=J_z=0$ and $h=1$, $e^{i\\tilde H t} \\sim H_1 H_2 H_3 H_4$ for a suitable value of $t$. Determine the required value of $t$, and show that your simulation has this effect by appling to an initial $|0\\rangle^{\\otimes 4}$ state.\n",
|
||||
"\n",
|
||||
"(d) Find $W$, a four-qubit Pauli observable (non-trivial on all qubits) that commutes with all the two-qubit terms in the Hamiltonian.\n",
|
||||
"\n",
|
||||
"(e) For what value of $n$ (approximately) does the error in the simulation for the next question become on the same order as sampling error for $10^3$ shots? Assume that $n=1000$ yields a perfect approximation and use $J_x=J_z=1$, $h=2$.\n",
|
||||
"\n",
|
||||
"(f) For $J_x=J_z=1$ and starting in an eigenstate of $W$, calculate $\\langle W \\rangle$ for various times in the interval $0 < t \\leq 2 \\pi$, and for a sufficiently large $n$. Plot the results for $h=0.1$, $h=1$ and $h=2$.\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"# 2 - Inverse QFT\n",
|
||||
"Using Qiskit, implement an inverse Quantum Fourier transform for any general number of qubits.\n",
|
||||
"* Unlike the QFT in the lecture notes, your inverse QFT should not reverse qubit\n",
|
||||
"order.\n",
|
||||
"* You must implement the $R_n$ rotations using only single qubit gates and\n",
|
||||
"controlled-NOT gates.\n",
|
||||
"\n",
|
||||
"To demonstrate that your circuit does what it is supposed to, you can use the following function. This prepares the state that is QFT of the binary representation of a given integer $j$ on a\n",
|
||||
"given quantum register `qr``. Applying your inverse QFT, you should be able to rotate\n",
|
||||
"back to the binary representation of $j$.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"# this function creates the state prep circuit\n",
|
||||
"def state_prep(j,qr):\n",
|
||||
" n = qr.size\n",
|
||||
" N = 2**n\n",
|
||||
" state = [0]*N\n",
|
||||
" for k in range(N):\n",
|
||||
" state[k] = np.exp( 1j * 2*np.pi*j*k/N ) / np.sqrt(N)\n",
|
||||
" qc_prep = QuantumCircuit(qr)\n",
|
||||
" qc_prep.initialize(state,qr)\n",
|
||||
" return qc_prep\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Here's an example of using this function to show that an inverse QFT circuit works. Here I use the inverse QFT from Qiskit (which of course you cannot submit as your solution)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from qiskit import transpile\n",
|
||||
"from qiskit.circuit.library import QFT\n",
|
||||
"from qiskit_aer import AerSimulator\n",
|
||||
"\n",
|
||||
"# set an integer\n",
|
||||
"j = 8\n",
|
||||
"# and a number of qubits\n",
|
||||
"n = 5\n",
|
||||
"\n",
|
||||
"# create an inverse qft circuit\n",
|
||||
"qc_qft = QFT(n, inverse=True)\n",
|
||||
"# prepare the QFT of the integer on the same quanntum register\n",
|
||||
"qc_prep = state_prep(j, qc_qft.qregs[0])\n",
|
||||
"# create the combined circuit: first the prep, then the inverse qft\n",
|
||||
"qc = qc_prep.compose(qc_qft)\n",
|
||||
"# measure all qubits\n",
|
||||
"qc.measure_all()\n",
|
||||
"\n",
|
||||
"# run it, and see what integer comes out for 10 samples\n",
|
||||
"# (hopefully, it's the one you put in)\n",
|
||||
"backend = AerSimulator()\n",
|
||||
"for string in backend.run(transpile(qc,backend), shots=10, memory=True).result().get_memory():\n",
|
||||
" print(int(string, 2))"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "arc-decoder",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.6"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Exercise Sheet 3 - Decoding the Repetition Code\n",
|
||||
"\n",
|
||||
"*These exercises require you to use a quantum SDK such as Qiskit. If you are having trouble setting up Qiskit or Python locally, you can use [this online service](https://lab.quantum-computing.ibm.com).*\n",
|
||||
"\n",
|
||||
"*For information about how many points each question is worth, contact the TA.*"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 1 - Repetition code circuits\n",
|
||||
"\n",
|
||||
"*Note: You should not use Qiskit QEC for this exercise.*\n",
|
||||
"\n",
|
||||
"(a) Write a function to create Qisit circuits for linear repetition codes, for arbitrary code distance `d`, number of syndrome measurement rounds `T` and for both a stored logical `0` and logical `1`. Remember that, for the final set of syndrome measurememnts, there is no need for the `reset` gate after the final measurement. So leave this out in your circuits.\n",
|
||||
"\n",
|
||||
"(b) Transpile these to the backend `FakeSherbrooke` for distances from `d=3` to `d=55` and with `T=1`. This should be done such that the number of two-qubit gates prior to transpilation should be equal to the number of two-qubit gates after transpilation. Note that the native two-qubit gate for Sherbrooke is the `'ecr'` gate. The backend can be obtained with\n",
|
||||
"\n",
|
||||
" from qiskit.providers.fake_provider import FakeSherbrooke\n",
|
||||
" backend = FakeSherbrooke()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### 2 - Decoding graphs\n",
|
||||
"\n",
|
||||
"*Note: You should not use Qiskit QEC for this exercise.*\n",
|
||||
"\n",
|
||||
"In the lecture [Decoding 2: Correcting Errors](https://github.com/quantumjim/qec_lectures/blob/main/lecture-2.ipynb) we saw Qiskit QEC create a decoding graph for a Qiskit QEC repetition code. In this exercise, you will create the same thing for your own repetition code.\n",
|
||||
"\n",
|
||||
"(a) Write a function that can process the output of your repetition code, to find syndrome changes and create nodes for your decoding graph. For this you can draw heavy inspiration from [Decoding 1: Running Circuits and Interpreting Outputs](https://github.com/quantumjim/qec_lectures/blob/main/lecture-1.ipynb). To demonstrate your function, apply it to a few example output strings that result in both normal nodes and boundary nodes, and explain why it does what it does.\n",
|
||||
"\n",
|
||||
"(b) Using this, insert all possible single Paulis into your circuit to see what nodes result. Using `rustworkx` or `networkx`, create a graph in which edges link nodes that were found to result from the same inserted Paulis. In the end you should create an image such as the following one in [Decoding 2: Correcting Errors](https://github.com/quantumjim/qec_lectures/blob/main/lecture-2.ipynb) (but the numbers don't need to be the same).\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"For an idea of how to insert Paulis into a circuit, see the following example.\n",
|
||||
"\n",
|
||||
" from qiskit import QuantumCircuit\n",
|
||||
"\n",
|
||||
" # here's a circuit, into which we'll insert a Pauli\n",
|
||||
" qc = QuantumCircuit(2,2)\n",
|
||||
" qc.h(0)\n",
|
||||
" qc.cx(0,1)\n",
|
||||
" qc.measure([0,1],[0,1])\n",
|
||||
"\n",
|
||||
" # first we make a blank circuit\n",
|
||||
" error_qc = QuantumCircuit()\n",
|
||||
" for reg in qc.qregs + qc.cregs:\n",
|
||||
" error_qc.add_register(reg)\n",
|
||||
"\n",
|
||||
" # go through all the gates in the circuit\n",
|
||||
" for gate in qc.data:\n",
|
||||
" # add them to the new circuit\n",
|
||||
" error_qc.data.append(gate)\n",
|
||||
" # if one of them is a cnot\n",
|
||||
" if gate[0].name == 'cx':\n",
|
||||
" # find out what the control qubit is\n",
|
||||
" q = gate[1][0]\n",
|
||||
" # add an x as an 'error'\n",
|
||||
" error_qc.x(q)\n",
|
||||
"\n",
|
||||
" # the resulting circuit now has an x inserted on the control qubit\n",
|
||||
" # after every cnot\n",
|
||||
" error_qc.draw()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### 3 - A hexagonal code\n",
|
||||
"\n",
|
||||
"Consider a hexagonal lattice with periodic boundary conditions (wrapped around a torus), with a qubit at each vertex. A portion of this lattice is shown in Fig. (a) below, with the qubits in black.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Consider a QEC code in which the stabilizer generators consist of:\n",
|
||||
"* The $Z \\otimes Z$ operator on every vertical link, as seen in Fig. (b).\n",
|
||||
"* A plaquette operator $W_p = X \\otimes Y \\otimes Z\\otimes X\\otimes Y \\otimes Z$ defined on the 6 qubits around each hexagon. The qubits from left to right in this tensor product are those numbered from 0 to 5 in Fig. (b).\n",
|
||||
"\n",
|
||||
"(a) Show that these stabilizer generators mutually commute.\n",
|
||||
"\n",
|
||||
"(b) Find logical $X$ and $Z$ operators for the two stored logical qubits. Show that they have the correct communtation relations.\n",
|
||||
"\n",
|
||||
"(c) Repeat (a) and (b), but with for the code in which the $Y \\otimes Y$ operators are the stabilizer generators instead of the $Z \\otimes Z$ operators.\n",
|
||||
"\n",
|
||||
"(d) Devise circuits for mmeasuring the $Z \\otimes Z$, $Y \\otimes Y$ and $X \\otimes X$ operators. For these, use the additional grey qubits located on the edges of the lattice, and assume that two-qubit gates exist between these and their neighbouring black qubits.\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "arc-decoder",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.6"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 59 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 100 KiB |
Reference in New Issue
Block a user