Forráskód Böngészése

Added qiskit benchmarking

Adam Kelly 5 éve
szülő
commit
555a4b2a25
1 módosított fájl, 61 hozzáadás és 120 törlés
  1. 61 120
      notebooks/Benchmarking.ipynb

+ 61 - 120
notebooks/Benchmarking.ipynb

@@ -19,12 +19,15 @@
     "import projectq.ops as ops\n",
     "from projectq.backends import Simulator\n",
     "from projectq.types import Qureg\n",
-    "\n"
+    "\n",
+    "# Qiskit Imports\n",
+    "from qiskit import ClassicalRegister, QuantumRegister\n",
+    "from qiskit import QuantumCircuit, execute"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
+   "execution_count": 11,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -33,7 +36,7 @@
     "\n",
     "    h = qcgpu.gate.h()\n",
     "    x = qcgpu.gate.x()\n",
-    "    sqrt_x = qcgpu.gate.sqrt_x()\n",
+    "    t = qcgpu.gate.t()\n",
     "\n",
     "    print('started')\n",
     "    start = time.time()\n",
@@ -42,7 +45,7 @@
     "        for q in range(n):\n",
     "    \n",
     "            state.apply_gate(h, q)\n",
-    "            state.apply_gate(sqrt_x, q)\n",
+    "            state.apply_gate(t, q)\n",
     "\n",
     "            if q != 0:\n",
     "                state.apply_controlled_gate(x, q, 0)\n",
@@ -62,7 +65,7 @@
     "        print(depth-level)\n",
     "        for q in qbits:\n",
     "            ops.H | q\n",
-    "            ops.SqrtX | q\n",
+    "            ops.T | q\n",
     "            if q != qbits[0]:\n",
     "                ops.CNOT | (q, qbits[0])\n",
     "\n",
@@ -72,12 +75,49 @@
     "    for q in qbits:\n",
     "        ops.Measure | q\n",
     "    eng.flush()\n",
+    "    return runtime\n",
+    "\n",
+    "def bench_qiskit(n, depth):\n",
+    "    q = QuantumRegister(n)\n",
+    "    c = ClassicalRegister(n)\n",
+    "    qc = QuantumCircuit(q, c)\n",
+    "\n",
+    "    \n",
+    "    \n",
+    "    for level in range(depth):\n",
+    "        for i in range(n):\n",
+    "            qc.h(q[i])\n",
+    "            qc.t(q[i])\n",
+    "\n",
+    "            if i != 0:\n",
+    "                qc.cx(q[i], q[0])\n",
+    "        \n",
+    "    \n",
+    "    \n",
+    "    qc.measure(q, c)\n",
+    "\n",
+    "    print('started')\n",
+    "    start = time.time()\n",
+    "    \n",
+    "    job_sim = execute(qc, \"local_qasm_simulator\")\n",
+    "    \n",
+    "    runtime = time.time() - start\n",
+    "    print('ended: ', runtime)\n",
     "    return runtime\n"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "bench_qcgpu(28,100)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 16,
    "metadata": {},
    "outputs": [
     {
@@ -85,27 +125,28 @@
      "output_type": "stream",
      "text": [
       "started\n",
-      "('ended: ', 202.95192885398865)\n"
+      "1\n",
+      "ended:  8.024413824081421\n"
      ]
     },
     {
      "data": {
       "text/plain": [
-       "202.95192885398865"
+       "8.024413824081421"
       ]
      },
-     "execution_count": 10,
+     "execution_count": 16,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "bench_qcgpu(28,100)"
+    "bench_projectq(25,1)"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 13,
+   "execution_count": 17,
    "metadata": {},
    "outputs": [
     {
@@ -113,122 +154,22 @@
      "output_type": "stream",
      "text": [
       "started\n",
-      "100\n",
-      "99\n",
-      "98\n",
-      "97\n",
-      "96\n",
-      "95\n",
-      "94\n",
-      "93\n",
-      "92\n",
-      "91\n",
-      "90\n",
-      "89\n",
-      "88\n",
-      "87\n",
-      "86\n",
-      "85\n",
-      "84\n",
-      "83\n",
-      "82\n",
-      "81\n",
-      "80\n",
-      "79\n",
-      "78\n",
-      "77\n",
-      "76\n",
-      "75\n",
-      "74\n",
-      "73\n",
-      "72\n",
-      "71\n",
-      "70\n",
-      "69\n",
-      "68\n",
-      "67\n",
-      "66\n",
-      "65\n",
-      "64\n",
-      "63\n",
-      "62\n",
-      "61\n",
-      "60\n",
-      "59\n",
-      "58\n",
-      "57\n",
-      "56\n",
-      "55\n",
-      "54\n",
-      "53\n",
-      "52\n",
-      "51\n",
-      "50\n",
-      "49\n",
-      "48\n",
-      "47\n",
-      "46\n",
-      "45\n",
-      "44\n",
-      "43\n",
-      "42\n",
-      "41\n",
-      "40\n",
-      "39\n",
-      "38\n",
-      "37\n",
-      "36\n",
-      "35\n",
-      "34\n",
-      "33\n",
-      "32\n",
-      "31\n",
-      "30\n",
-      "29\n",
-      "28\n",
-      "27\n",
-      "26\n",
-      "25\n",
-      "24\n",
-      "23\n",
-      "22\n",
-      "21\n",
-      "20\n",
-      "19\n",
-      "18\n",
-      "17\n",
-      "16\n",
-      "15\n",
-      "14\n",
-      "13\n",
-      "12\n",
-      "11\n",
-      "10\n",
-      "9\n",
-      "8\n",
-      "7\n",
-      "6\n",
-      "5\n",
-      "4\n",
-      "3\n",
-      "2\n",
-      "1\n",
-      "('ended: ', 971.3228080272675)\n"
+      "ended:  0.2896561622619629\n"
      ]
     },
     {
      "data": {
       "text/plain": [
-       "971.3228080272675"
+       "0.2896561622619629"
       ]
      },
-     "execution_count": 13,
+     "execution_count": 17,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "bench_projectq(28,100)"
+    "bench_qiskit(25,1)"
    ]
   },
   {
@@ -241,21 +182,21 @@
  ],
  "metadata": {
   "kernelspec": {
-   "display_name": "Python 2",
+   "display_name": "Python 3",
    "language": "python",
-   "name": "python2"
+   "name": "python3"
   },
   "language_info": {
    "codemirror_mode": {
     "name": "ipython",
-    "version": 2
+    "version": 3
    },
    "file_extension": ".py",
    "mimetype": "text/x-python",
    "name": "python",
    "nbconvert_exporter": "python",
-   "pygments_lexer": "ipython2",
-   "version": "2.7.15rc1"
+   "pygments_lexer": "ipython3",
+   "version": "3.6.5"
   }
  },
  "nbformat": 4,