decompose.ipynb
1 line
| 2.2 KiB
| text/plain
|
TextLexer
Brian Granger
|
r4337 | {"cells":[{"cell_type":"text","text":"<h1>Gate Decomposition</h1>"},{"code":"%load_ext sympyprinting","cell_type":"code","prompt_number":1},{"code":"from sympy import sqrt, symbols, Rational\nfrom sympy import expand, Eq, Symbol, simplify, exp, sin\nfrom sympy.physics.quantum import *\nfrom sympy.physics.quantum.qubit import *\nfrom sympy.physics.quantum.gate import *\nfrom sympy.physics.quantum.grover import *\nfrom sympy.physics.quantum.qft import QFT, IQFT, Fourier\nfrom sympy.physics.quantum.circuitplot import circuit_plot","cell_type":"code","prompt_number":2},{"cell_type":"text","text":"<h2>Example 1</h2>"},{"cell_type":"text","text":"Create a symbolic controlled-Y gate"},{"code":"CY10 = CGate(1, Y(0)); CY10\n","cell_type":"code","prompt_number":3},{"cell_type":"text","text":"Decompose it into elementary gates and plot it"},{"code":"CY10.decompose()\n","cell_type":"code","prompt_number":4},{"code":"circuit_plot(CY10.decompose(), nqubits=2)","cell_type":"code","prompt_number":5},{"cell_type":"text","text":"<h2>Example 2</h2>"},{"cell_type":"text","text":"Create a controlled-Z gate"},{"code":"CZ01 = CGate(0, Z(1)); CZ01\n","cell_type":"code","prompt_number":6},{"cell_type":"text","text":"Decompose and plot it"},{"code":"CZ01.decompose()\n","cell_type":"code","prompt_number":7},{"code":"circuit_plot(CZ01.decompose(), nqubits=2)","cell_type":"code","prompt_number":8},{"cell_type":"text","text":"<h2>Example 3</h2>"},{"cell_type":"text","text":"Create a SWAP gate"},{"code":"SWAP10 = SWAP(1, 0); SWAP10\n","cell_type":"code","prompt_number":9},{"cell_type":"text","text":"Decompose and plot it"},{"code":"SWAP10.decompose()","cell_type":"code","prompt_number":10},{"code":"circuit_plot(SWAP10.decompose(), nqubits=2)","cell_type":"code","prompt_number":11},{"cell_type":"text","text":"<h2>All together now</h2>"},{"code":"gates = [CGate(1,Y(0)), CGate(0,Z(1)), SWAP(1, 0)]","cell_type":"code","prompt_number":12},{"code":"for g in gates:\n dg = g.decompose()\n display(Eq(g, dg))\n circuit_plot(g, nqubits=2)\n circuit_plot(dg, nqubits=2) ","cell_type":"code","prompt_number":13},{"code":"%notebook save decompose.ipynb","cell_type":"code","prompt_number":30},{"code":"%notebook load gate_rules.ipynb","cell_type":"code","prompt_number":53}]} |