diff --git a/demos/PauliWebs.ipynb b/demos/PauliWebs.ipynb index 6ec7d08e..c382e4a3 100644 --- a/demos/PauliWebs.ipynb +++ b/demos/PauliWebs.ipynb @@ -28,13 +28,59 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 7, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CNOT(0,1)\n", + "CNOT(1,0)\n", + "CNOT(2,0)\n", + "HAD(2)\n", + "CNOT(2,1)\n", + "HAD(2)\n", + "CNOT(1,0)\n", + "CNOT(0,2)\n", + "CNOT(1,2)\n", + "T(0)\n", + "T(1)\n", + "HAD(2)\n", + "T(2)\n", + "HAD(1)\n", + "HAD(0)\n", + "CNOT(0,2)\n", + "CNOT(0,2)\n", + "CNOT(1,0)\n", + "T(2)\n", + "HAD(2)\n", + "HAD(1)\n", + "CNOT(1,0)\n", + "CNOT(0,1)\n", + "CNOT(2,1)\n", + "T(0)\n", + "CNOT(2,0)\n", + "T(0)\n", + "T(0)\n", + "T(0)\n", + "CNOT(2,0)\n", + "CNOT(0,2)\n", + "T(2)\n", + "T(1)\n", + "T(1)\n", + "T(0)\n", + "HAD(1)\n", + "T(1)\n", + "CNOT(1,0)\n", + "CNOT(1,2)\n", + "CNOT(1,0)\n" + ] + }, { "data": { "text/html": [ - "
\n", + "\n", "" ], "text/plain": [ @@ -413,19 +459,20 @@ "source": [ "# Generate a random CNOT, H, T circuit\n", "random.seed(1330)\n", - "c = zx.generate.CNOT_HAD_PHASE_circuit(qubits=3, depth=50)\n", + "c = zx.generate.CNOT_HAD_PHASE_circuit(qubits=3, depth=40)\n", + "for g in c.gates: print(g)\n", "zx.draw(c)" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "\n", + "\n", "" ], @@ -823,13 +870,13 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "\n", + "\n", "" ], @@ -1208,7 +1255,16 @@ "source": [ "# Once the Pauli webs have been computed, a specific web can be highlighted by `zx.draw` by passing it in as\n", "# an optional argument. Note that webs change color when they cross Hadamard edges.\n", - "zx.draw(g, labels=True, pauli_web=webs[87])" + "zx.draw(g, labels=True, pauli_web=webs[67])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We now show how this works in some simpler cases. The first is a single T gate.\n", + "\n", + "The T gate becomes a single, 1-legged phase gadget, connected to the input. This can be implemented by Z-merging a T magic state, then doing either an X or a Y measurement, depending on the parity of the Pauli web." ] }, { @@ -1219,7 +1275,7 @@ { "data": { "text/html": [ - "\n", + "\n", "" @@ -1593,21 +1649,7 @@ }, "metadata": {}, "output_type": "display_data" - } - ], - "source": [ - "c = zx.qasm(\"\"\"\n", - "qreg q[1];\n", - "t q[0];\n", - "\"\"\")\n", - "zx.draw(c)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ + }, { "name": "stdout", "output_type": "stream", @@ -1618,7 +1660,7 @@ { "data": { "text/html": [ - "\n", + "\n", "" ], "text/plain": [ @@ -1995,12 +2037,825 @@ } ], "source": [ + "c = zx.qasm(\"\"\"\n", + "qreg q[1];\n", + "t q[0];\n", + "\"\"\")\n", + "zx.draw(c)\n", + "\n", "g = c.to_graph()\n", "zx.full_reduce(g)\n", "in_circ, out_circ = preprocess(g)\n", "order, webs = compute_pauli_webs(g)\n", "print(f'{in_circ.gates} {out_circ.gates}')\n", - "zx.draw(g)" + "\n", + "# highlight the web associated to the T spider\n", + "zx.draw(g, labels=True, pauli_web=webs[3])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The next example is a circuit with some CNOT gates and a T gate, which can be simplified to a single phase gadget. I'm doing this manually here, since the automated simplifier comes up with a different answer (which is equivalent to this one, up to local Cliffords, but less clear what is going on)." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "" + ], + "text/plain": [ + "