|
72 | 72 | None, |
73 | 73 | 'controlled-phase-rotation'), |
74 | 74 | ('Circuit Diagram', 2, None, 'circuit-diagram'), |
| 75 | + ('Swap gates', 2, None, 'swap-gates'), |
| 76 | + ('Swap gates and step-by-step mathematical derivation', |
| 77 | + 2, |
| 78 | + None, |
| 79 | + 'swap-gates-and-step-by-step-mathematical-derivation'), |
| 80 | + ('Circuit‐level decomposition and implicit bit reversal', |
| 81 | + 2, |
| 82 | + None, |
| 83 | + 'circuit-level-decomposition-and-implicit-bit-reversal'), |
| 84 | + ('Qubit ordering', 2, None, 'qubit-ordering'), |
| 85 | + ('Change of basis order', 2, None, 'change-of-basis-order'), |
| 86 | + ('The bit-reversal permutation and Swap gates', |
| 87 | + 2, |
| 88 | + None, |
| 89 | + 'the-bit-reversal-permutation-and-swap-gates'), |
| 90 | + ('Can we avoid them?', 2, None, 'can-we-avoid-them'), |
75 | 91 | ('Python code with PennyLane', |
76 | 92 | 2, |
77 | 93 | None, |
|
213 | 229 | <!-- navigation toc: --> <li><a href="#qft-on-three-qubits" style="font-size: 80%;">QFT on three qubits</a></li> |
214 | 230 | <!-- navigation toc: --> <li><a href="#controlled-phase-rotation" style="font-size: 80%;">Controlled Phase Rotation</a></li> |
215 | 231 | <!-- navigation toc: --> <li><a href="#circuit-diagram" style="font-size: 80%;">Circuit Diagram</a></li> |
| 232 | + <!-- navigation toc: --> <li><a href="#swap-gates" style="font-size: 80%;">Swap gates</a></li> |
| 233 | + <!-- navigation toc: --> <li><a href="#swap-gates-and-step-by-step-mathematical-derivation" style="font-size: 80%;">Swap gates and step-by-step mathematical derivation</a></li> |
| 234 | + <!-- navigation toc: --> <li><a href="#circuit-level-decomposition-and-implicit-bit-reversal" style="font-size: 80%;">Circuit‐level decomposition and implicit bit reversal</a></li> |
| 235 | + <!-- navigation toc: --> <li><a href="#qubit-ordering" style="font-size: 80%;">Qubit ordering</a></li> |
| 236 | + <!-- navigation toc: --> <li><a href="#change-of-basis-order" style="font-size: 80%;">Change of basis order</a></li> |
| 237 | + <!-- navigation toc: --> <li><a href="#the-bit-reversal-permutation-and-swap-gates" style="font-size: 80%;">The bit-reversal permutation and Swap gates</a></li> |
| 238 | + <!-- navigation toc: --> <li><a href="#can-we-avoid-them" style="font-size: 80%;">Can we avoid them?</a></li> |
216 | 239 | <!-- navigation toc: --> <li><a href="#python-code-with-pennylane" style="font-size: 80%;">Python code with PennyLane</a></li> |
217 | 240 | <!-- navigation toc: --> <li><a href="#complexity" style="font-size: 80%;">Complexity</a></li> |
218 | 241 | <!-- navigation toc: --> <li><a href="#inverse-qft-and-the-phase-estimation-algorithm" style="font-size: 80%;">Inverse QFT and the phase estimation algorithm</a></li> |
@@ -464,6 +487,126 @@ <h2 id="circuit-diagram" class="anchor">Circuit Diagram </h2> |
464 | 487 | </center> |
465 | 488 | <br/><br/> |
466 | 489 |
|
| 490 | +<!-- !split --> |
| 491 | +<h2 id="swap-gates" class="anchor">Swap gates </h2> |
| 492 | + |
| 493 | +<p>In the circuit implementation of the \( n \)-qubit Quantum Fourier |
| 494 | +Transform (QFT), one finds at the end a cascade of Swap gates |
| 495 | +<em>crossing</em> qubit \( 1 \) with qubit \( n \), qubit \( 2 \) with qubit \( n-1 \), and |
| 496 | +so on. These are not arbitrary extra operations, but arise inevitably |
| 497 | +from the fact that the standard QFT—when written as a matrix—maps |
| 498 | +computational‐basis states into <em>bit‐reversed</em> amplitudes. The Swap |
| 499 | +gates simply undo that bit-reversal so that the output register has |
| 500 | +its qubits in the natural (most‐significant–to–least‐significant) |
| 501 | +order. |
| 502 | +</p> |
| 503 | + |
| 504 | +<!-- !split --> |
| 505 | +<h2 id="swap-gates-and-step-by-step-mathematical-derivation" class="anchor">Swap gates and step-by-step mathematical derivation </h2> |
| 506 | + |
| 507 | +<p>On an \( n \)-qubit register, label the computational basis states by integers</p> |
| 508 | + |
| 509 | +$$ |
| 510 | +\vert x\rangle \quad,\quad x\in\{0,1,\dots,2^n-1\}\,. |
| 511 | +$$ |
| 512 | + |
| 513 | +<p>The QFT is the linear map</p> |
| 514 | +$$ |
| 515 | +\mathrm{QFT}n:\;\vert x \rangle \;\mapsto\;\frac{1}{\sqrt{2^n}}\sum{y=0}^{2^n-1} |
| 516 | +\exp{(2\pi i\,xy / 2^n)}\,\vert y\rangle. |
| 517 | +$$ |
| 518 | + |
| 519 | +<p>Viewed as a \( 2^n\times2^n \) unitary matrix \( F_{2^n} \), its \( (y,x) \)–entry is</p> |
| 520 | +$$ |
| 521 | +[F_{2^n}]_{y,x} \;=\;\frac{1}{\sqrt{2^n}}\,e^{2\pi i\,x y / 2^n}\,. |
| 522 | +$$ |
| 523 | + |
| 524 | +<!-- !split --> |
| 525 | +<h2 id="circuit-level-decomposition-and-implicit-bit-reversal" class="anchor">Circuit‐level decomposition and implicit bit reversal </h2> |
| 526 | + |
| 527 | +<p>A standard circuit for \( \mathrm{QFT}_n \) proceeds qubit by qubit (from |
| 528 | +most significant qubit down to least significant), applying: |
| 529 | +</p> |
| 530 | +<ol> |
| 531 | +<li> A Hadamard on qubit \( j \);</li> |
| 532 | +<li> Controlled-\( R_2,R_3,\dots,R_{n-j+1} \) phase gates from qubit \( k>j \) to qubit \( j \), where</li> |
| 533 | +</ol> |
| 534 | +$$ |
| 535 | +R_m \;=\;\begin{pmatrix}1&0\\0&e^{2\pi i/2^m}\end{pmatrix}. |
| 536 | +$$ |
| 537 | + |
| 538 | +<ol> |
| 539 | +<li> Move on to the next qubit \( j+1 \).</li> |
| 540 | +</ol> |
| 541 | +<!-- !split --> |
| 542 | +<h2 id="qubit-ordering" class="anchor">Qubit ordering </h2> |
| 543 | + |
| 544 | +<p>If you label the input qubits as |
| 545 | +\( \vert x_{n-1}\rangle\otimes\vert x_{n-2}\rangle\otimes\cdots\otimes\vert x_0\rangle \) (with |
| 546 | +\( x_{n-1} \) the most‐significant bit), then the order in which |
| 547 | +phase‐gates tie those bits ends up producing output amplitudes in the |
| 548 | +reverse bit‐order, that is |
| 549 | +</p> |
| 550 | +$$ |
| 551 | +\mathrm{QFT}n \;=\; (\text{controlled‐phase and Hadamard layers})\;\times\; \underbrace{\bigl(\mathrm{bit\!-\!reversal}\bigr)}{P}, |
| 552 | +$$ |
| 553 | + |
| 554 | +<p>where \( P \) is the permutation matrix that sends</p> |
| 555 | +$$ |
| 556 | +\vert y_{n-1}y_{n-2}\dots y_0\rangle \longmapsto \vert y_{0}y_{1}\dots y_{n-1}\rangle. |
| 557 | +$$ |
| 558 | + |
| 559 | + |
| 560 | +<!-- !split --> |
| 561 | +<h2 id="change-of-basis-order" class="anchor">Change of basis order </h2> |
| 562 | + |
| 563 | +<p>Concretely, one finds for each basis vector</p> |
| 564 | +$$ |
| 565 | +(\text{circuit without swaps})\;\vert x_{n-1}\dots x_0\rangle\;=\;\frac{1}{\sqrt{2^n}} |
| 566 | +\sum_{y} \exp{(2\pi i\,x\,y/2^n)}\;\vert y_{\text{reversed}}\rangle, |
| 567 | +$$ |
| 568 | + |
| 569 | +<p>where \( y_{\text{reversed}} = \sum_j y_j,2^{n-1-j} \) instead of the natural \( \sum_j y_j,2^j \).</p> |
| 570 | + |
| 571 | +<!-- !split --> |
| 572 | +<h2 id="the-bit-reversal-permutation-and-swap-gates" class="anchor">The bit-reversal permutation and Swap gates </h2> |
| 573 | + |
| 574 | +<p>The bit-reversal permutation \( P \) is exactly the unitary that swaps |
| 575 | +qubit \( j \) with qubit \( (n-1-j) \) for all |
| 576 | +\( j=0,\dots,\lfloor(n-1)/2\rfloor \). In matrix form, |
| 577 | +</p> |
| 578 | +$$ |
| 579 | +\Pi \;=\;\prod_{j=0}^{\lfloor(n-1)/2\rfloor}\;\mathrm{SWAP}{j,\;n-1-j}, |
| 580 | +$$ |
| 581 | + |
| 582 | +<p>where each \( \mathrm{SWAP}{a,b} \) acts as</p> |
| 583 | +$$ |
| 584 | +\mathrm{SWAP}:\;\vert u\rangle_a\!\otimes\!\vert v\rangle_b \;\longmapsto\;\vert v\rangle_a\!\otimes\!\vert u\rangle_b. |
| 585 | +$$ |
| 586 | + |
| 587 | +<p>Since the circuit we built implements \( F{2^n},\Pi \) rather than |
| 588 | +\( F{2^n} \), appending those swaps at the end yields exactly the matrix |
| 589 | +\( F{2^n} \) in the natural qubit ordering. |
| 590 | +</p> |
| 591 | + |
| 592 | +<!-- !split --> |
| 593 | +<h2 id="can-we-avoid-them" class="anchor">Can we avoid them? </h2> |
| 594 | + |
| 595 | +<p>One might ask: <em>Couldn’t we just re‐label wires?</em> In principle yes, |
| 596 | +but in a physical device the wiring corresponds to real qubit lines. |
| 597 | +If you want the logical output bit \( y_{n-1} \) on the same physical wire |
| 598 | +as the input \( x_{n-1} \), you must physically swap the states. Hence |
| 599 | +the Swap gates are unavoidable whenever you demand that qubit indices |
| 600 | +retain their original semantic meaning. |
| 601 | +</p> |
| 602 | + |
| 603 | +<p>In summary, the Swap gates at the end of the QFT circuit correct the |
| 604 | +inherent bit-reversal that arises from the order in which Hadamard and |
| 605 | +controlled-phase gates entangle the qubits. Without them, the output |
| 606 | +register would hold the Fourier‐transformed amplitudes in |
| 607 | +reverse‐index order. |
| 608 | +</p> |
| 609 | + |
467 | 610 | <!-- !split --> |
468 | 611 | <h2 id="python-code-with-pennylane" class="anchor">Python code with PennyLane </h2> |
469 | 612 | <p>We now implement a full QFT circuit manually for three qubits using PennyLane.</p> |
|
0 commit comments