Skip to content

Commit

Permalink
added template for exercise 03
Browse files Browse the repository at this point in the history
  • Loading branch information
tobsto committed May 8, 2024
1 parent 9b67a44 commit 70b29ff
Showing 1 changed file with 220 additions and 0 deletions.
220 changes: 220 additions & 0 deletions template-exercise-03.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "fb789dfb",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Template to Exercise 3\n",
"\n",
"Author: Tobias Stollenwerk, Institute for Quantum Computing Analytics (PGI-12), FZ Jülich\n",
"\n",
"**Please use this template for exercise 3**\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "b0602cae",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"import qiskit\n",
"# numerics\n",
"import numpy as np\n",
"# functional programmin tools\n",
"import itertools\n",
"import functools\n",
"import operator\n",
"# plotting\n",
"import matplotlib.pyplot as plt\n",
"import seaborn\n",
"# data analysis\n",
"import pandas as pd\n",
"# qiskit \n",
"from qiskit import QuantumCircuit, transpile\n",
"from qiskit_aer import QasmSimulator, AerSimulator\n",
"from qiskit.quantum_info import Pauli\n",
"from qiskit.visualization import array_to_latex, plot_histogram\n",
"from qiskit.quantum_info import Kraus, SuperOp, SparsePauliOp, Operator, DensityMatrix, Statevector\n",
"from qiskit_aer.noise import NoiseModel, QuantumError, ReadoutError, depolarizing_error\n",
"from qiskit.circuit import ParameterVector\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a65a8836",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXEAAADuCAYAAADPwDeGAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8fJSN1AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAehElEQVR4nO3de1iU5b438O/AMIAclKMDIgIGhihC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BUVBR27dqF06dPm2X7xvR1sS+cqGcxtk+co1MAXLx4EY888gicnJyQnZ2NwYMHW7sk9oUTUZfwYh8AsbGxeOqpp9Dc3IwpU6bg2LFjbeaXl5dj3bp1qK21zDBBXp1JRF3FlvhvqqqqMHPmTN0tJPv164fAwECUlZWhpKQEWq0WlZWV6NOnj9lrYSuciLqKLfHfeHp64siRI9i+fTvGjRuHuro6XLp0CQ4ODpg0aRK2b98ODw8Pi9Ti7uYKF2cZW+FE9EBsiduohsYmOMucGOJE1CmGOBGRwNidQkQkMIY4EZHAGOJERAJjiBMRCYwhTkQkMIY4EZHAGOJERAJjiBMRCYwhTkQkMIY4EZHAGOJERAJjiBMRCYwhTkQkMIY4EZHAGOJERAJjiBMRCYwhTkQkMIY4EZHAGOJERAJjiBMRCYwhTkQkMIY4EZHAGOJERAJjiBMRCYwhTkQkMIY4EZHAGOJERAJjiBMRCYwhTkQkMIY4EZHAGOJERAJjiBMRCYwhTkQkMIY4EZHAGOJERAJjiBMRCYwhTkQkMIY4EZHAGOJERAL7H1iA7zaNPGxQAAAAAElFTkSuQmCC",
"text/plain": [
"<Figure size 454.517x284.278 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"circuit = QuantumCircuit(2, 2)\n",
"circuit.h(0)\n",
"circuit.cx(0, 1)\n",
"circuit.measure(0, 0)\n",
"circuit.measure(1, 1);\n",
"# display the circuit\n",
"display(circuit.draw('mpl'))\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6947dacd-c4ef-4640-a005-ccacace9ade0",
"metadata": {},
"outputs": [],
"source": [
"p = 0.1\n",
"\n",
"error_1 = depolarizing_error(p, 1)\n",
"error_2 = error_1.tensor(error_1)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "959f011f-9c47-4b36-929c-82430417ee0e",
"metadata": {},
"outputs": [],
"source": [
"# ... build noise model "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Hints for exercise 3.2 - quantum optimization\n",
"\n",
"Consider the MaxCut case\n",
"\n",
"$$\n",
"H_f = \\sum_{u, v \\in E} Z_u Z_v\n",
"$$\n",
"\n",
"for the edge set $E = \\{(1, 2), (2, 3), (2, 4), (3, 4)\\}$"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"E = [(1, 2), (2, 3), (2, 4), (3, 4)]\n",
"V = [1, 2, 3, 4]\n",
"\n",
"pauli_strings = []\n",
"for u, v in E:\n",
" pauli_strings.append(\"\".join([\"I\" if i not in (u, v) else \"Z\" for i in V ]))\n",
"H = SparsePauliOp(pauli_strings)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dict_keys([(0, 0, 0, 0), (0, 0, 0, 1), (0, 0, 1, 0), (0, 0, 1, 1), (0, 1, 0, 0), (0, 1, 0, 1), (0, 1, 1, 0), (0, 1, 1, 1), (1, 0, 0, 0), (1, 0, 0, 1), (1, 0, 1, 0), (1, 0, 1, 1), (1, 1, 0, 0), (1, 1, 0, 1), (1, 1, 1, 0), (1, 1, 1, 1)])\n"
]
}
],
"source": [
"basis_states = {}\n",
"ket = {0: Statevector([1, 0]), 1: Statevector([0, 1])}\n",
"for i, bitstring in enumerate(itertools.product([0, 1], repeat=4)):\n",
" state = ket[bitstring[0]]\n",
" for k in range(len(bitstring) - 1):\n",
" state = state.tensor(ket[bitstring[k + 1]])\n",
" basis_states[bitstring] = state\n",
"print(basis_states.keys())"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<(0, 0, 0, 0)|H|(0, 0, 0, 0)> = (4+0j)\n",
"<(0, 0, 0, 1)|H|(0, 0, 0, 1)> = 0j\n",
"<(0, 0, 1, 0)|H|(0, 0, 1, 0)> = 0j\n",
"<(0, 0, 1, 1)|H|(0, 0, 1, 1)> = 0j\n",
"<(0, 1, 0, 0)|H|(0, 1, 0, 0)> = (-2+0j)\n",
"<(0, 1, 0, 1)|H|(0, 1, 0, 1)> = (-2+0j)\n",
"<(0, 1, 1, 0)|H|(0, 1, 1, 0)> = (-2+0j)\n",
"<(0, 1, 1, 1)|H|(0, 1, 1, 1)> = (2+0j)\n",
"<(1, 0, 0, 0)|H|(1, 0, 0, 0)> = (2+0j)\n",
"<(1, 0, 0, 1)|H|(1, 0, 0, 1)> = (-2+0j)\n",
"<(1, 0, 1, 0)|H|(1, 0, 1, 0)> = (-2+0j)\n",
"<(1, 0, 1, 1)|H|(1, 0, 1, 1)> = (-2+0j)\n",
"<(1, 1, 0, 0)|H|(1, 1, 0, 0)> = 0j\n",
"<(1, 1, 0, 1)|H|(1, 1, 0, 1)> = 0j\n",
"<(1, 1, 1, 0)|H|(1, 1, 1, 0)> = 0j\n",
"<(1, 1, 1, 1)|H|(1, 1, 1, 1)> = (4+0j)\n"
]
}
],
"source": [
"for bitstring, state in basis_states.items():\n",
" f = state.expectation_value(H)\n",
" print(\"<{}|H|{}> = {}\".format(bitstring, bitstring, f))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 70b29ff

Please sign in to comment.