Lecture 7 - System Dynamics, Simulation, and Polynomial Functions

Lecture 7 - System Dynamics, Simulation, and Polynomial Functions

Updated 27 Nov 2026

Chapter map

  • 1. Quantum Finite-State Automaton: system dynamics, DFA → PFA → QFA, Szegedy's algorithm (quantum walk), quantum lattice, PennyLane code, Exercise 7.1
  • 2. Quantum System (Hamiltonian matrix): simulation, Hamiltonian U=cis⁡(−H^)\mathbf{U}=\operatorname{cis}(-\hat{\mathbf{H}}), Pauli decomposition (Final Q6), commutator, BCH, Trotter–Suzuki, qubitization, Exercises 7.2–7.4
  • 3. Polynomial Functions: QSP, GQSP, QSVT, Exercise 7.5 (skipped in class)
  • 4. HHL Algorithm: linear equation systems, Hermitian embedding / block encoding, HHL, Exercise 7.6 (skipped in class)
  • 5. Conclusion + Target Learning Outcomes
  • Final exam from this chapter: Q6 [Hamiltonian Matrix]: slides 19–23. Manually compute the Hamiltonian matrix of a single-qubit operator. This is one of only two computation questions on the final.
  • In class he said he would only cover the first two topics (QFA + Hamiltonian). Qubitization, polynomial functions and HHL are not in the final (Nov 10).
  • See also Final - Instructor Hints

Related

Quantum Computing: Chapter 07: System Dynamics, Simulation, and Polynomial Functions

  • Prachya Boonkwan (P' Arm), SIIT, Thammasat University
  • Version: January 15, 2026 · License: CC-BY-NC 4.0

Who? Me?

  • Nickname: Arm (P'/N' Arm, etc.)
  • Born: Aug 1981
  • Work
    • Researcher at NECTEC 2005–2024
    • Lecturer at SIIT, Thammasat University 2025–now
  • Education
    • B.Eng & M.Eng in Computer Engineering, Kasetsart University, Thailand
    • Ministry of Science and Technology Scholarship of Thailand (early 2008)
    • PhD in Informatics (AI & Computational Linguistics), University of Edinburgh, UK (2008–2013)

Table of Contents

  1. Quantum Finite-State Automaton
  2. Quantum System
  3. Polynomial Functions
  4. HHL Algorithm
  5. Conclusion

📝 Instructor's annotation: next to "2. Quantum System" he wrote ": Hamiltonian matrix" and underlined it in red. This is the part that matters for the final.

🎙️ In class (Nov 10, 12:10): "For this class we will study only the first two topics. That will be more than enough. The rest is for non-linear simulation, we don't care about it." He also said the Hamiltonian matrix "can be computed by hand, and it's quite easy too."


1. Quantum Finite-State Automaton

System Dynamics

  • A complex system is a system made of multiple elements that interact with one another
  • System dynamics is a mathematical model that represents the non-linear behavior of a complex system over time, in terms of state transitions
  • There are two types of system dynamics:
    • deterministic
    • probabilistic
  • Simulating system dynamics helps us understand how the system behaves in the long run
  • Figure 1: Vending machine (six states: Start, Idle, Wait for coins, Dispense item, Dispense change, Stop)
    • The start state is marked with a triangle; each final state has double circles
    • A state transition happens when there is an input stimulus at a particular state
    • E.g. the machine moves from Idle to Wait for coins when the customer selects an item
    • Transitions: Start →(Power on)→ Idle →(Select item)→ Wait for coins (loops on "Deposit coin or Reselect item") →(Coin ≥ item cost)→ Dispense item →(Pick up item)→ Dispense change →(Pick up change)→ Idle; Wait for coins →(Cancel)→ Dispense change; Idle →(Power off)→ Stop

📝 Instructor's annotation: the input arrows (Power on, Select item) are labeled "interaction with the environment". The states (Wait for coins, Dispense item) are labeled "action to the environment".

🎙️ In class (Nov 10, 14:39): a state machine where each state also performs an action on the environment is called a Moore machine, which is a finite-state automaton plus state actions. The vending machine downstairs works exactly like this.

💡 Analogy: a 7-Eleven coffee machine. Pressing buttons and inserting coins are inputs from you. Pouring and giving change are actions back to you. The "state" is what screen it's showing.

Deterministic Finite-State Automaton

  • A finite-state automaton (FSA) describes system dynamics over a finite set of possible internal configurations
  • A Deterministic FSA (DFA) is a quintuple (K,Σ,δ,s,F)(K, \Sigma, \delta, s, F):
    • KK = finite set of states
    • Σ\Sigma = alphabet (set of input symbols)
    • s∈Ks \in K = the start state
    • F⊆KF \subseteq K = the set of final states
    • δ:K×Σ↦K\delta : K \times \Sigma \mapsto K = transition function: takes the current state and an input symbol and returns the next state

δ(qcurr,a)=qnext\boxed{\delta(q_{\text{curr}}, a) = q_{\text{next}}}

  • Derivation (one step):

(qcurr,aw)⊢(qnext,w)where δ(qcurr,a)=qnext\boxed{(q_{\text{curr}}, aw) \vdash (q_{\text{next}}, w) \quad\text{where } \delta(q_{\text{curr}}, a) = q_{\text{next}}}

  • Time evolution of an input sequence a1…aNa_1 \dots a_N is a derivation

(q(0),a1…aN)⊢(q(1),a2…aN)⊢(q(2),a3…aN)⊢⋯⊢(q(N),ε)(q^{(0)}, a_1\dots a_N) \vdash (q^{(1)}, a_2\dots a_N) \vdash (q^{(2)}, a_3\dots a_N) \vdash \dots \vdash (q^{(N)}, \varepsilon)

  • where q(0)=sq^{(0)} = s and q(N)∈Fq^{(N)} \in F
  • Acceptance: (s,w)⊢∗(q,ε)(s, w) \vdash^* (q, \varepsilon) and q∈Fq \in F
  • Figure 2: a 4-state DFA (q1…q4q_1 \dots q_4) over {0,1}\{0,1\}; the start state has a triangle, the final state (q3q_3) has double circles

📝 Instructor's annotation: q(0)q^{(0)} is labeled "the start state" and q(N)q^{(N)} is labeled "a final state".

🎙️ In class (Nov 10, 17:41 / 21:23): "Determinism means you have all cases of the if-clause covered. You consume one symbol and you know exactly where to go, no hesitation." δ\delta is a function, so it gives exactly one output. Recall: a function allows one-to-one and many-to-one mappings. A relation also allows one-to-many and many-to-many.

🎙️ In class (Nov 10, 25:46): "In TOC we didn't use this term. We call it time evolution": state derivation one symbol at a time. We call it that because we are now running a simulation. Deterministic → one input string gives exactly one path.

💡 Analogy: a BTS route with no transfers. If you know the station and the direction you take, the next station is fixed.

Probabilistic Finite-State Automaton

  • A Probabilistic FSA (PFA) is a quintuple (K,Σ,Δ,s,F)(K, \Sigma, \Delta, s, F):
    • K,Σ,s,FK, \Sigma, s, F are the same as in the DFA
    • Δ\Delta is a conditional probability over the next states, given a current state and an input symbol: Δ(qnext∣qcurr,a)\Delta(q_{\text{next}} \mid q_{\text{curr}}, a)
  • Probability of time evolution:

P(q(1),…,q(N)∣a1,…,aN)=∏k=1NΔ(q(k)∣q(k−1),ak)\boxed{P(q^{(1)}, \dots, q^{(N)} \mid a_1, \dots, a_N) = \prod_{k=1}^{N} \Delta(q^{(k)} \mid q^{(k-1)}, a_k)}

  • where q(0)=sq^{(0)} = s and q(N)∈Fq^{(N)} \in F
  • Example: transition from state q1q_1 with input symbols 0 and 1:
    • Δ(q2∣q1,0)=0.6\Delta(q_2 \mid q_1, 0) = 0.6, Δ(q4∣q1,0)=0.4\Delta(q_4 \mid q_1, 0) = 0.4 (highlighted yellow)
    • Δ(q2∣q1,1)=0.3\Delta(q_2 \mid q_1, 1) = 0.3, Δ(q4∣q1,1)=0.7\Delta(q_4 \mid q_1, 1) = 0.7 (highlighted red)
    • Each (state, symbol) row sums to 1
  • Figure 3: the PFA with every edge labeled by symbol (probability)

📝 Instructor's annotation: he highlighted the q1q_1 edges on the diagram, "0 (0.6)" and "0 (0.4)" in yellow and "1 (0.3)" and "1 (0.7)" in red, to match the four Δ\Delta values.

🎙️ In class (Nov 10, 30:32): read P(B∣A)P(B \mid A) as "P of B if A". AA is the premise (condition) and BB is the consequence: P(B∣A)=P(A,B)/P(A)P(B\mid A) = P(A,B)/P(A). For three steps: P(q1,q2,q3∣a1,a2,a3)=Δ(q1∣s,a1) Δ(q2∣q1,a2) Δ(q3∣q2,a3)P(q_1,q_2,q_3 \mid a_1,a_2,a_3) = \Delta(q_1\mid s,a_1)\,\Delta(q_2\mid q_1,a_2)\,\Delta(q_3\mid q_2,a_3).

❓ Why do we need a PFA? Nature is not deterministic. The same input string can follow many paths (e.g. weather cycles). The only change from a DFA is that the transition function becomes a conditional probability (Nov 10, 28:12).

💡 Analogy: a Bangkok taxi driver. Same destination (input), but which road he takes is "60% expressway, 40% Rama 4". You only know the odds.

Quantum Finite-State Automaton

  • A Quantum FSA (QFA) is a quintuple (K,Σ,U,s,F)(K, \Sigma, \mathbf{U}, s, \mathbf{F}):
    • KK = a Hilbert space of NN dimensions
    • Σ\Sigma = alphabet
    • s∈Ks \in K = a start quantum state
    • F\mathbf{F} = a projector matrix of final states
    • U:Σ↦CL×CL\mathbf{U} : \Sigma \mapsto \mathbb{C}^L \times \mathbb{C}^L = a function giving one quantum operator per input symbol, used for probabilistic state transition
  • Derivation: (qcurr,aw)⊢(qnext,w)(q_{\text{curr}}, aw) \vdash (q_{\text{next}}, w) is a probability distribution over the next states:

P(qnext∣qcurr,a)=∣Ua∣qcurr⟩∣2\boxed{P(q_{\text{next}} \mid q_{\text{curr}}, a) = \lvert \mathbf{U}_a \lvert q_{\text{curr}}\rangle \rvert^2}

  • Time evolution: (q(0),a1…aN)⊢∗(q(N),ε)(q^{(0)}, a_1\dots a_N) \vdash^* (q^{(N)}, \varepsilon)

∣ψ(N)⟩=UaN⋯Ua1∣ψ(0)⟩\boxed{\lvert\psi^{(N)}\rangle = \mathbf{U}_{a_N} \cdots \mathbf{U}_{a_1} \lvert\psi^{(0)}\rangle}

  • where ∣ψ(0)⟩\lvert\psi^{(0)}\rangle is the quantum equivalent of the start state ss:

∣ψ(0)⟩=1∣K∣∑q∣s,q⟩=∣s⟩⊗∣+⟩⊗log⁡2∣K∣\boxed{\lvert\psi^{(0)}\rangle = \frac{1}{\sqrt{|K|}} \sum_q \lvert s, q\rangle = \lvert s\rangle \otimes \lvert +\rangle^{\otimes \log_2 |K|}}

  • Acceptance:

Pacc(ψ)=⟨F⟩ψ=⟨ψ∣ F ∣ψ⟩\boxed{P_{\text{acc}}(\psi) = \langle \mathbf{F} \rangle_{\psi} = \langle\psi|\,\mathbf{F}\,|\psi\rangle}

📝 Instructor's annotation: next to U\mathbf{U} he wrote "Each Ua\mathbf{U}_a is a quantum operator". Under ∣s⟩⊗∣+⟩⊗log⁡2∣K∣\lvert s\rangle \otimes \lvert+\rangle^{\otimes\log_2|K|} he wrote "start state".

🎙️ In class (Nov 10, 47:13–49:31): the initial state has two parts: the start state, and a uniform superposition (average) of all possible next states, which is ∣+⟩\lvert+\rangle. For acceptance you need a projector (X, Y or Z). "In most cases we choose F\mathbf{F} to be Z", because you just want the expectation over all possible final states.

❓ Why does the state carry a "next state" register too? Every quantum operator must be unitary, so it can't simply overwrite the current state the way a classical machine does. Storing the pair ∣q,q′⟩\lvert q, q'\rangle (current, next) gives the walk operator room to stay reversible.

Related

Szegedy's Algorithm

  • Conversion from PFA to QFA: for every input symbol a∈Σa \in \Sigma, convert each state into its quantum equivalent:

∣ψa,q⟩=∑q′∣q,q′⟩Δ(q′∣q,a)\boxed{\lvert\psi_{a,q}\rangle = \sum_{q'} \lvert q, q'\rangle \sqrt{\Delta(q' \mid q, a)}}

  • Compute the diffusion matrix for each input symbol aa:

Πa=∑q∣ψa,q⟩⟨ψa,q∣\boxed{\Pi_a = \sum_q \lvert\psi_{a,q}\rangle\langle\psi_{a,q}\rvert}

  • Then compute the reflection matrix:

Ra=2Πa−I\boxed{\mathbf{R}_a = 2\Pi_a - \mathbf{I}}

  • The quantum walk operator Ua\mathbf{U}_a is

Ua=SWAP(Ra)where SWAP(∣i⟩⟨j∣)=∣j⟩⟨i∣\boxed{\mathbf{U}_a = \mathrm{SWAP}(\mathbf{R}_a) \quad\text{where } \mathrm{SWAP}(\lvert i\rangle\langle j\rvert) = \lvert j\rangle\langle i\rvert}

  • Figure 4: a quantum walk is a sequence of reflections about the axis Ra\mathbf{R}_a plus axis rotation via swapping. Together they imitate the state transition from qiq_i to qjq_j by symbol aa

📝 Instructor's annotation:

  • On the title: "In practice, qq and q′q' may be multi-qubit. E.g. ∣q2,q4⟩=∣010,100⟩=∣010100⟩\lvert q_2, q_4\rangle = \lvert 010, 100\rangle = \lvert 010100\rangle"
  • Over ∣ψa,q⟩\lvert\psi_{a,q}\rangle: "a superposition of all state transitions from qq with aa"
  • qq = current state, q′q' = next state, and the square root is P(next q′∣curr q,input a)\sqrt{P(\text{next } q' \mid \text{curr } q, \text{input } a)}

🎙️ In class (Nov 10, 55:15): "This is a square root of the conditional probability. You need the square root." It's an amplitude, so squaring it on measurement gives the probability back.

🎙️ In class (Nov 10, 56:20): geometric picture: "You are at state qiq_i. If the input symbol is aa, use Ra\mathbf{R}_a as a mirror and compute the reflection of qiq_i across it. That's the next state qjq_j. The more input symbols, you do the mirror over and over again." Ra\mathbf{R}_a is a Householder reflection (Chapter 3). Then swap bra and ket (∣i⟩⟨j∣→∣j⟩⟨i∣\lvert i\rangle\langle j\rvert \to \lvert j\rangle\langle i\rvert) to finish.

❓ Why the square root? Quantum states store amplitudes, and P=∣amplitude∣2P = |\text{amplitude}|^2. If you take Δ\sqrt{\Delta}, then measuring gives back exactly Δ(q′∣q,a)\Delta(q'\mid q,a).

❓ Why can't we use the Markov matrix P\mathbf{P} directly as U\mathbf{U}? (Exercise 7.1 Q4.) A Markov matrix has columns that sum to 1 (L1-norm). A quantum operator must be unitary (U∗U=I\mathbf{U}^*\mathbf{U} = \mathbf{I}, so the L2-norm is preserved). In general P\mathbf{P} is not unitary. Szegedy builds a reflection 2Πa−I2\Pi_a - \mathbf{I}, which is always unitary and Hermitian, because Πa\Pi_a is a projector.

❓ Why a reflection? A reflection is the simplest unitary that "pulls" a state toward the subspace spanned by the allowed transitions ∣ψa,q⟩\lvert\psi_{a,q}\rangle. The diffusion matrix Πa\Pi_a defines the mirror (the subspace of legal transitions for symbol aa). Ra\mathbf{R}_a is the mirror. SWAP turns "where I came from" into "where I am now".

💡 Analogy: a kaleidoscope. Each input symbol is a mirror, and every time light (your state) bounces off a mirror it ends up somewhere new. Feed in the symbols "a, a, b" and you get three bounces in a row.

Related

Szegedy's Algorithm (cont'd): Example

Example: Convert the PFA in Fig 5 to QFA

  • Markov matrices for each input symbol (column = current state, row = next state; each column sums to 1):

Pa=[9/253/416/251/4]Pb=[16/251/49/253/4]\mathbf{P}_a = \begin{bmatrix} 9/25 & 3/4 \\ 16/25 & 1/4 \end{bmatrix} \qquad \mathbf{P}_b = \begin{bmatrix} 16/25 & 1/4 \\ 9/25 & 3/4 \end{bmatrix}

  • Figure 5 (Simple PFA): q1→q1q_1 \to q_1: a (9/25), b (16/25). q1→q2q_1 \to q_2: a (16/25), b (9/25). q2→q2q_2 \to q_2: a (3/4), b (1/4). q2→q1q_2 \to q_1: a (1/4), b (3/4)

  • Let's construct the unitary operators.

  • Step 1: convert each state qq to its quantum equivalent ∣ψa,q⟩\lvert\psi_{a,q}\rangle (state q1=∣0⟩q_1 = \lvert 0\rangle, q2=∣1⟩q_2 = \lvert 1\rangle):

  • As printed on the slide (and as he did it in class: "take the first row of Pa\mathbf{P}_a, square-root it"):

∣ψa,q1⟩=35∣00⟩+32∣01⟩\lvert\psi_{a,q_1}\rangle = \tfrac{3}{5}\lvert 00\rangle + \tfrac{\sqrt3}{2}\lvert 01\rangle

∣ψa,q2⟩=45∣10⟩+12∣11⟩\lvert\psi_{a,q_2}\rangle = \tfrac{4}{5}\lvert 10\rangle + \tfrac{1}{2}\lvert 11\rangle

∣ψb,q1⟩=45∣00⟩+12∣01⟩\lvert\psi_{b,q_1}\rangle = \tfrac{4}{5}\lvert 00\rangle + \tfrac{1}{2}\lvert 01\rangle

∣ψb,q2⟩=35∣10⟩+32∣11⟩\lvert\psi_{b,q_2}\rangle = \tfrac{3}{5}\lvert 10\rangle + \tfrac{\sqrt3}{2}\lvert 11\rangle

  • ⚠️ Careful: using rows gives states that are not normalized, e.g. (3/5)2+(3/2)2=9/25+3/4≠1(3/5)^2 + (\sqrt3/2)^2 = 9/25 + 3/4 \neq 1. The formula Δ(q′∣q,a)\sqrt{\Delta(q'\mid q,a)} with "each column sums to 1" gives normalized states: ∣ψa,q1⟩=35∣00⟩+45∣01⟩\lvert\psi_{a,q_1}\rangle = \tfrac35\lvert00\rangle + \tfrac45\lvert01\rangle, ∣ψa,q2⟩=12∣10⟩+32∣11⟩\lvert\psi_{a,q_2}\rangle = \tfrac12\lvert10\rangle + \tfrac{\sqrt3}{2}\lvert11\rangle. He said Szegedy will not be computed in the exam, so just know the idea: square-root the transition probabilities and put them on ∣q,q′⟩\lvert q, q'\rangle.
  • Steps 2–4 below copy the slide's numbers (which follow the row version).

📝 Instructor's annotation: under each ket he labeled the pair, e.g. ∣00⟩=q1,q1\lvert 00\rangle = q_1,q_1, ∣01⟩=q1,q2\lvert 01\rangle = q_1,q_2, ∣10⟩=q2,q1\lvert 10\rangle = q_2,q_1, ∣11⟩=q2,q2\lvert 11\rangle = q_2,q_2. He rewrote the formula as ∣ψinput a, curr q⟩=∑next q′∣q,q′⟩P(q′∣q,a)\lvert\psi_{\text{input } a,\ \text{curr } q}\rangle = \sum_{\text{next } q'} \lvert q,q'\rangle\sqrt{P(q'\mid q,a)} with the note "twice the size of ∣q⟩\lvert q\rangle".

🎙️ In class (Nov 10 pt 2, 1:00–4:33): "For each column they sum to one." "You're at q1q_1: the first half of the ket is fixed to 0. From q1q_1 with aa you have two choices: back to q1q_1 or to q2q_2. Take the probability and square-root it, and put it right there. Take each one, square-root, put it there. That's easy."

Step 2: Diffusion matrices

  • Πa=∣ψa,q1⟩⟨ψa,q1∣+∣ψa,q2⟩⟨ψa,q2∣\Pi_a = \lvert\psi_{a,q_1}\rangle\langle\psi_{a,q_1}\rvert + \lvert\psi_{a,q_2}\rangle\langle\psi_{a,q_2}\rvert

Πa=925∣00⟩⟨00∣+3310∣00⟩⟨01∣+3310∣01⟩⟨00∣+34∣01⟩⟨01∣+1625∣10⟩⟨10∣+410∣10⟩⟨11∣+410∣11⟩⟨10∣+14∣11⟩⟨11∣\Pi_a = \tfrac{9}{25}\lvert00\rangle\langle00\rvert + \tfrac{3\sqrt3}{10}\lvert00\rangle\langle01\rvert + \tfrac{3\sqrt3}{10}\lvert01\rangle\langle00\rvert + \tfrac34\lvert01\rangle\langle01\rvert + \tfrac{16}{25}\lvert10\rangle\langle10\rvert + \tfrac{4}{10}\lvert10\rangle\langle11\rvert + \tfrac{4}{10}\lvert11\rangle\langle10\rvert + \tfrac14\lvert11\rangle\langle11\rvert

  • Πb=∣ψb,q1⟩⟨ψb,q1∣+∣ψb,q2⟩⟨ψb,q2∣\Pi_b = \lvert\psi_{b,q_1}\rangle\langle\psi_{b,q_1}\rvert + \lvert\psi_{b,q_2}\rangle\langle\psi_{b,q_2}\rvert

Πb=1625∣00⟩⟨00∣+410∣00⟩⟨01∣+410∣01⟩⟨00∣+14∣01⟩⟨01∣+925∣10⟩⟨10∣+3310∣10⟩⟨11∣+3310∣11⟩⟨10∣+34∣11⟩⟨11∣\Pi_b = \tfrac{16}{25}\lvert00\rangle\langle00\rvert + \tfrac{4}{10}\lvert00\rangle\langle01\rvert + \tfrac{4}{10}\lvert01\rangle\langle00\rvert + \tfrac14\lvert01\rangle\langle01\rvert + \tfrac{9}{25}\lvert10\rangle\langle10\rvert + \tfrac{3\sqrt3}{10}\lvert10\rangle\langle11\rvert + \tfrac{3\sqrt3}{10}\lvert11\rangle\langle10\rvert + \tfrac34\lvert11\rangle\langle11\rvert

📝 Instructor's annotation: Πinput a=∑state q∣ψa,q⟩⟨ψa,q∣\Pi_{\text{input } a} = \sum_{\text{state } q} \lvert\psi_{a,q}\rangle\langle\psi_{a,q}\rvert

🎙️ In class (Nov 10 pt 2, 4:41–5:30): "Compute the ket, compute the bra, and then sum them. Keep it that way. You don't have to expand the term."

Step 3: Reflection matrices

  • Ra=2Πa−I\mathbf{R}_a = 2\Pi_a - \mathbf{I}

Ra=−725∣00⟩⟨00∣+6310∣00⟩⟨01∣+6310∣01⟩⟨00∣+24∣01⟩⟨01∣+725∣10⟩⟨10∣+810∣10⟩⟨11∣+810∣11⟩⟨10∣−24∣11⟩⟨11∣\mathbf{R}_a = -\tfrac{7}{25}\lvert00\rangle\langle00\rvert + \tfrac{6\sqrt3}{10}\lvert00\rangle\langle01\rvert + \tfrac{6\sqrt3}{10}\lvert01\rangle\langle00\rvert + \tfrac24\lvert01\rangle\langle01\rvert + \tfrac{7}{25}\lvert10\rangle\langle10\rvert + \tfrac{8}{10}\lvert10\rangle\langle11\rvert + \tfrac{8}{10}\lvert11\rangle\langle10\rvert - \tfrac24\lvert11\rangle\langle11\rvert

  • Rb=2Πb−I\mathbf{R}_b = 2\Pi_b - \mathbf{I}

Rb=725∣00⟩⟨00∣+810∣00⟩⟨01∣+810∣01⟩⟨00∣−24∣01⟩⟨01∣−725∣10⟩⟨10∣+6310∣10⟩⟨11∣+6310∣11⟩⟨10∣+24∣11⟩⟨11∣\mathbf{R}_b = \tfrac{7}{25}\lvert00\rangle\langle00\rvert + \tfrac{8}{10}\lvert00\rangle\langle01\rvert + \tfrac{8}{10}\lvert01\rangle\langle00\rvert - \tfrac24\lvert01\rangle\langle01\rvert - \tfrac{7}{25}\lvert10\rangle\langle10\rvert + \tfrac{6\sqrt3}{10}\lvert10\rangle\langle11\rvert + \tfrac{6\sqrt3}{10}\lvert11\rangle\langle10\rvert + \tfrac24\lvert11\rangle\langle11\rvert

📝 Instructor's annotation: Rinput a=2Πa−I\mathbf{R}_{\text{input } a} = 2\Pi_a - \mathbf{I}

Step 4: Transition (walk) operators

  • Ua=SWAP(Ra)\mathbf{U}_a = \mathrm{SWAP}(\mathbf{R}_a): every ∣i⟩⟨j∣\lvert i\rangle\langle j\rvert becomes ∣j⟩⟨i∣\lvert j\rangle\langle i\rvert

Ua=−725∣00⟩⟨00∣+6310∣01⟩⟨00∣+6310∣00⟩⟨01∣+24∣01⟩⟨01∣+725∣10⟩⟨10∣+810∣11⟩⟨10∣+810∣10⟩⟨11∣−24∣11⟩⟨11∣\mathbf{U}_a = -\tfrac{7}{25}\lvert00\rangle\langle00\rvert + \tfrac{6\sqrt3}{10}\lvert01\rangle\langle00\rvert + \tfrac{6\sqrt3}{10}\lvert00\rangle\langle01\rvert + \tfrac24\lvert01\rangle\langle01\rvert + \tfrac{7}{25}\lvert10\rangle\langle10\rvert + \tfrac{8}{10}\lvert11\rangle\langle10\rvert + \tfrac{8}{10}\lvert10\rangle\langle11\rvert - \tfrac24\lvert11\rangle\langle11\rvert

Ub=725∣00⟩⟨00∣+810∣01⟩⟨00∣+810∣00⟩⟨01∣−24∣01⟩⟨01∣−725∣10⟩⟨10∣+6310∣11⟩⟨10∣+6310∣10⟩⟨11∣+24∣11⟩⟨11∣\mathbf{U}_b = \tfrac{7}{25}\lvert00\rangle\langle00\rvert + \tfrac{8}{10}\lvert01\rangle\langle00\rvert + \tfrac{8}{10}\lvert00\rangle\langle01\rvert - \tfrac24\lvert01\rangle\langle01\rvert - \tfrac{7}{25}\lvert10\rangle\langle10\rvert + \tfrac{6\sqrt3}{10}\lvert11\rangle\langle10\rvert + \tfrac{6\sqrt3}{10}\lvert10\rangle\langle11\rvert + \tfrac24\lvert11\rangle\langle11\rvert

📝 Instructor's annotation: Uinput a=SWAP Ra\mathbf{U}_{\text{input } a} = \mathrm{SWAP}\ \mathbf{R}_a

🎙️ In class (Nov 10 pt 2, 5:48 and 8:26), exam hint: "Are you going to make me compute that by hand? No. I'm asking why questions instead, like: why do we need a reflection? What does it mean to do a state transition by reflection? You just have to understand the concept." And: "I'm not going to make you compute Ua\mathbf{U}_a. No actual computation at this point."

From Paths to Quantum Lattice

  • In each quantum walk, all next states are explored in parallel. This gradually produces a quantum lattice that enumerates all possible paths in its structure
  • Because of quantum nature, we cannot assign a definite probability to unobserved paths
  • A path gets a probability only when it is observed with measurement
  • We run a simulation to observe the state in each quantum walk
  • Figure 6 (Quantum lattice): start ss, then layers Ua1,Ua2,Ua3,…,UaN\mathbf{U}_{a_1}, \mathbf{U}_{a_2}, \mathbf{U}_{a_3}, \dots, \mathbf{U}_{a_N} fully connected between states
  • Figure 7 (QFA circuit): registers ∣s⟩\lvert s\rangle, ∣+⟩\lvert+\rangle (LL qubits each), then NN registers ∣0⟩\lvert 0\rangle. After each Uak\mathbf{U}_{a_k}, a CNOT copies the state into the kk-th ∣0⟩\lvert 0\rangle register, which is measured as q(k)q^{(k)}

📝 Instructor's annotation: the lattice start is ∣s⟩⊗∣+⟩⊗L\lvert s\rangle \otimes \lvert +\rangle^{\otimes L}, with a green arrow showing time direction. Under the circuit he wrote the measured outputs as ⟨Z(1)⟩⊗⋯⊗⟨Z(N)⟩\langle Z^{(1)}\rangle \otimes \dots \otimes \langle Z^{(N)}\rangle (expectation on Z for each step).

🎙️ In class (Nov 10 pt 2, 6:48–8:15): "As you apply each quantum operator, you also mirror it with the CNOT, and you can measure the expectation for each step. That's how you get the most probable state sequence." This is the quantum Viterbi algorithm: classical Viterbi for an HMM is O(N2)O(N^2), and the quantum version is O(N)O(N).

❓ Why does a quantum walk create a lattice? (Exercise 7.1 Q6.) Each Ua\mathbf{U}_a maps a state to a superposition of every possible next state. Applying NN of them spreads amplitude over every path at once, like a lattice (grid) of all routes. Nothing is "chosen" until you measure.

💡 Analogy: pouring water into a pachinko board. The water goes down every channel at once, and you only see "which hole" when you look at the bottom.

Quantum Finite-State Automaton in PennyLane

no_states = 2
markov = { 'a': [ (0, 0, 9/25), (0, 1, 16/25), (1, 1, 3/4), (1, 0, 1/4) ],
           'b': [ (0, 0, 16/25), (0, 1, 9/25), (1, 1, 1/4), (1, 0, 3/4) ] }
input_seq = ['a', 'a', 'b', 'a', 'b', 'b']
 
no_qubits_per_state = int(np.ceil(np.log2(no_states)))
state_qubits = list(range(0, no_qubits_per_state))
trans_qubits = list(range(no_qubits_per_state,
                          no_qubits_per_state * (len(input_seq) + 1)))
 
dev = qml.device('default.qubit', wires = state_qubits + trans_qubits)
 
def markov_to_unitary(markov, no_states):
    unitary_tbl = {}
    for symbol in markov:
        mat = np.zeros((no_states, no_states), dtype=np.complex128)
        for (i, j, prob) in markov[symbol]:
            mat[j, i] = prob
        unitary_tbl[symbol] = 2 * mat - np.eye(no_states)
    return unitary_tbl

Quantum Finite-State Automaton in PennyLane (cont'd)

@qml.qnode(dev, shots=1000)
def evolution_circuit():
    unitary_tbl = markov_to_unitary(markov, 2)
    for i, symbol in enumerate(input_seq):
        qml.QubitUnitary(unitary_tbl[symbol], wires=state_qubits)
        for j in range(no_qubits_per_state):
            qml.CNOT(wires=[j, (i + 1) * no_qubits_per_state + j])
    return qml.counts(wires=trans_qubits)
 
evolution_circuit()
# Expected result:
#   State transitions : Counts
# { '001010'          : 150,
#   '001101'          : 425,
#   '010010'          : 150,
#   '010101'          : 12.5,
#   '101010'          : 12.5,
#   '101101'          : 50,
#   '110010'          : 150,
#   '110101'          : 50     }
  • Each output bit-string is one state path q(1)…q(6)q^{(1)} \dots q^{(6)}; the count shows how likely that path is
  • The 2 * mat - np.eye(...) line is the "2Π−I2\Pi - \mathbf{I}" reflection idea

Exercise 7.1: Quantum Finite-State Automaton

  1. Convert this PFA (Figure 8: 4 states q1..q4q_1..q_4, each edge labeled with 0 (p) and 1 (p)) to Markov matrices and an equivalent QFA via Szegedy's Algorithm
  2. Discuss the differences between deterministic FSA and probabilistic FSA
  3. What are the key differences between probabilistic FSA and quantum FSA?
  4. Explain why we cannot directly use the Markov matrices P\mathbf{P} of PFA as a quantum operator U\mathbf{U} of QFA
  5. In Szegedy's Algorithm, what are the roles of the diffusion matrix Πa\Pi_a and the reflection matrix Ra\mathbf{R}_a?
  6. Explain why quantum walks create a quantum lattice
  • Short answer guide (the "why" questions are the exam style):
    • Q2: DFA uses a transition function (one next state, one path per input). PFA uses a conditional probability (many next states, many paths, each with a probability)
    • Q3: PFA keeps probabilities (real, non-negative, sum to 1) and follows one path at a time when simulated. QFA keeps amplitudes (complex, squared magnitudes sum to 1), evolves all paths in superposition with unitary operators, paths can interfere, and probabilities appear only on measurement
    • Q4: P\mathbf{P} is column-stochastic, not unitary (does not preserve the L2-norm and is generally not reversible)
    • Q5: Πa\Pi_a = projector onto the subspace of legal transitions for symbol aa (it defines the mirror). Ra\mathbf{R}_a = reflection about that subspace, a unitary that performs the move
    • Q6: see the "Why" box above

2. Quantum System {Exam Q6}

Final Q6 — Hamiltonian Matrix (slides 19–23)

  • "Manually compute the Hamiltonian matrix of a single-qubit quantum operator."
  • You will be given a 2×2 matrix (maybe not Hermitian) and asked to convert it into its Hamiltonian, exactly like the slide 22–23 example.
  • One of only two computation questions on the final. Use the step-by-step recipe below.
  • "My heart isn't made of wood. You would have one qubit", so no 4×4 (Nov 10).
  • See Final - Instructor Hints

Simulation of System Dynamics {Exam Q6}

  • Simulation = a representation of a system's trajectory (path of actions) by means of a model
  • In deterministic simulation, the trajectory is dictated by a deterministic model, so there is only one next state given the current state and input stimulus
  • In stochastic simulation, each state transition is dictated by a probability distribution given the current state and input stimulus
  • In quantum simulation, each state transition is dictated by a quantum operator, resulting in a state lattice
  • Challenge: quantum simulation is computationally expensive due to iterative matrix multiplications
  • Solution: we can reduce the quantum walk operator U\mathbf{U} into a special form called the Hamiltonian H^\hat{\mathbf{H}}, so that matrix multiplication becomes simple addition

U2U1≈[cis⁡(−H^1+H^2n)]n\mathbf{U}_2\mathbf{U}_1 \approx \left[\operatorname{cis}\left(-\frac{\hat{\mathbf{H}}_1 + \hat{\mathbf{H}}_2}{n}\right)\right]^n

  • Figure 9 (Trotter–Suzuki decomposition): the product [b11b12b21b22]×[a11a12a21a22]\begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22}\end{bmatrix} \times \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22}\end{bmatrix} becomes a sum [a11′a12′a21′a22′]+[b11′b12′b21′b22′]\begin{bmatrix} a'_{11} & a'_{12} \\ a'_{21} & a'_{22}\end{bmatrix} + \begin{bmatrix} b'_{11} & b'_{12} \\ b'_{21} & b'_{22}\end{bmatrix} of the two Hamiltonians

🎙️ In class (Nov 10 pt 2, 9:37–12:09): "What if you want to apply this quantum operator 10,000 times? In the simulator you'd do matrix multiplication 10,000 times. That's time-consuming. Can we speed it up?" Recall QPE needs U1,U2,U4,…,U2n\mathbf{U}^1, \mathbf{U}^2, \mathbf{U}^4, \dots, \mathbf{U}^{2^n} ("rotate the electric fan many times"). "Can we convert it to some form, multiply by 10,000, and convert it back? Yes. This step is called the Hamiltonian matrix."

🎙️ In class (Nov 3, 29:41–31:40): "We can transform any quantum algorithm into its energy form. H is called the Hamiltonian of U. We can do that by hand as well, which means I'm going to make you do it." For UN\mathbf{U}^N you just multiply NN into the Hamiltonian: UN=cis⁡(−NH^)\mathbf{U}^N = \operatorname{cis}(-N\hat{\mathbf{H}}).

❓ Why does the Hamiltonian turn multiplication into addition? Same reason as eaeb=ea+be^{a}e^{b} = e^{a+b} for numbers. If U=cis⁡(−H^)\mathbf{U} = \operatorname{cis}(-\hat{\mathbf{H}}), then UN=cis⁡(−NH^)\mathbf{U}^N = \operatorname{cis}(-N\hat{\mathbf{H}}). One scalar multiplication replaces NN matrix multiplications. For two different operators it works only approximately, because matrices don't commute (that is what Trotter–Suzuki fixes).

💡 Analogy: logarithm tables before calculators. To multiply big numbers, convert them to logs, add, then convert back. The Hamiltonian is the "log" of a quantum operator.

Quantum System and Hamiltonian {Exam Q6}

  • A quantum system is a QFA that describes the system dynamics via time evolution on the Hilbert space (complex vectors)
  • Time evolution: (q(0),a1…aN)⊢∗(q(N),ε)(q^{(0)}, a_1\dots a_N) \vdash^* (q^{(N)}, \varepsilon)

∣q(N)⟩=UN⋯U1∣q(0)⟩\lvert q^{(N)}\rangle = \mathbf{U}_N \cdots \mathbf{U}_1 \lvert q^{(0)}\rangle

  • For a QFA with a large set of states, each Ua\mathbf{U}_a becomes very large, which makes sequential multiplication intractable
  • Imitating Ψ(t)=cis⁡(−ωt)\Psi(t) = \operatorname{cis}(-\omega t), we can rewrite

U=cis⁡(−H^)=e−iH^\boxed{\mathbf{U} = \operatorname{cis}(-\hat{\mathbf{H}}) = e^{-i\hat{\mathbf{H}}}}

  • We call H^\hat{\mathbf{H}} the Hamiltonian of U\mathbf{U}
  • Time evolution can then be rewritten as

∣q(N)⟩=cis⁡(−H^N)⋯cis⁡(−H^1)∣q(0)⟩\lvert q^{(N)}\rangle = \operatorname{cis}(-\hat{\mathbf{H}}_N) \cdots \operatorname{cis}(-\hat{\mathbf{H}}_1) \lvert q^{(0)}\rangle

  • Recall that matrix multiplication is non-commutative: AB≠BA\mathbf{AB} \neq \mathbf{BA}
  • Therefore, if U1≠…≠UN\mathbf{U}_1 \neq \dots \neq \mathbf{U}_N, then

UN⋯U1≠cis⁡(−(H^1+⋯+H^N))\mathbf{U}_N \cdots \mathbf{U}_1 \neq \operatorname{cis}\left(-(\hat{\mathbf{H}}_1 + \dots + \hat{\mathbf{H}}_N)\right)

  • because UN⋯U1≠U1⋯UN\mathbf{U}_N \cdots \mathbf{U}_1 \neq \mathbf{U}_1 \cdots \mathbf{U}_N
  • Later, we can still estimate the product from the Hamiltonians

📝 Instructor's annotation:

  • Under "We call H^\hat{\mathbf{H}} the Hamiltonian of U\mathbf{U}" he added: "where U\mathbf{U} is Hermitian (U∗=U\mathbf{U}^* = \mathbf{U})"
  • On the "Therefore" line he added "If U1≠…≠UN\mathbf{U}_1 \neq \dots \neq \mathbf{U}_N then"

🎙️ In class (Nov 10 pt 2, 17:08–17:56): "We can convert only some quantum operators to this form, not all. The condition is that the operator must be Hermitian, U∗=U\mathbf{U}^* = \mathbf{U}. What if it's not Hermitian? We can still do it, but it's going to be an approximation."

🎙️ In class (Nov 10 pt 2, 18:25–19:38): "You're so tempted to add them, but can we? Matrix multiplication is non-commutative. If H^1…H^N\hat{\mathbf{H}}_1 \dots \hat{\mathbf{H}}_N are not the same, you can't just add them. You have to make sure each U\mathbf{U} is actually the same one."

❓ Why can we add the exponents only when the operators are the same (or commute)? eAeB=eA+Be^{\mathbf{A}}e^{\mathbf{B}} = e^{\mathbf{A}+\mathbf{B}} holds only if AB=BA\mathbf{AB} = \mathbf{BA}. A matrix always commutes with itself, so UN=cis⁡(−NH^)\mathbf{U}^N = \operatorname{cis}(-N\hat{\mathbf{H}}) is exact. For different operators the error is governed by the commutator [A,B][\mathbf{A},\mathbf{B}] (slides 25–26).

❓ Why "cis⁡(−ωt)\operatorname{cis}(-\omega t)"? A single wave with angular frequency ω\omega evolves as e−iωte^{-i\omega t}. A quantum operator is "many waves at once": each eigenvector rotates with its own frequency. H^\hat{\mathbf{H}} is the matrix of those frequencies (energies). That's why he calls it the "energy form".

Conversion to Hamiltonian by Pauli Decomposition {Exam Q6}

  • Step 1: if a quantum operator U\mathbf{U} is Hermitian, let U′=U\mathbf{U}' = \mathbf{U}. Otherwise, we have to approximate its Hermitian:

U′=12(U+U∗)\boxed{\mathbf{U}' = \frac{1}{2}\left(\mathbf{U} + \mathbf{U}^*\right)}

  • Step 2: enumerate all 4n4^n possible Pauli axes from {I,X,Y,Z}\{\mathbf{I}, \mathbf{X}, \mathbf{Y}, \mathbf{Z}\}, where nn is the number of qubits. E.g. a two-qubit operator has 42=164^2 = 16 Pauli axes:
    • I⊗I, I⊗X, I⊗Y, I⊗Z, …, Z⊗Z\mathbf{I}\otimes\mathbf{I},\ \mathbf{I}\otimes\mathbf{X},\ \mathbf{I}\otimes\mathbf{Y},\ \mathbf{I}\otimes\mathbf{Z},\ \dots,\ \mathbf{Z}\otimes\mathbf{Z}
  • Tip: (⨂k=1NAk)(⨂k=1NBk)=⨂k=1NAkBk\left(\bigotimes_{k=1}^{N}\mathbf{A}_k\right)\left(\bigotimes_{k=1}^{N}\mathbf{B}_k\right) = \bigotimes_{k=1}^{N}\mathbf{A}_k\mathbf{B}_k
  • Step 3: compute the coefficient ckc_k for each Pauli axis Pk\mathbf{P}_k:

ck=tr⁡(U′Pk)\boxed{c_k = \operatorname{tr}(\mathbf{U}'\mathbf{P}_k)}

  • Step 4: the Hamiltonian of U\mathbf{U} is an LCU (linear combination of unitaries):

H^=∑k=04n−1ckPk\boxed{\hat{\mathbf{H}} = \sum_{k=0}^{4^n - 1} c_k \mathbf{P}_k}

  • These steps can be computed by qml.pauli_decompose(mat, wire_order=...), where the wire order specifies the input wires

📝 Instructor's annotation: he corrected the slide typo "Hermition" → Hermitian, and circled "appproximate" (typo, should be approximate).

🎙️ In class (Nov 10 pt 2, 22:46–24:52): "First you need to check whether A is Hermitian. Do you still remember how? The diagonal is real; across the diagonal is conjugate." If not, "just add U\mathbf{U} and U∗\mathbf{U}^* and average. We can guarantee the output will be Hermitian."

🎙️ In class (Nov 10 pt 2, 23:12), exam hint: "Why do I mention that? Because I'm going to make you do it in the exam. You'll be given a matrix like this and then convert it into its Hamiltonian. I'm telling you what's going to show up in the final."

🎙️ In class (Nov 10 pt 2, 28:58): count qubits from the size: 2×22\times2 → 1 qubit, 4×44\times4 → 2 qubits, 8×88\times8 → 3 qubits (2n×2n2^n \times 2^n).

🎙️ In class (Nov 10 pt 2, 32:02): "If you look at the source code of PennyLane, you'll see the same method."

❓ Why make it Hermitian first? The Pauli matrices I,X,Y,Z\mathbf{I},\mathbf{X},\mathbf{Y},\mathbf{Z} are all Hermitian, and any real combination of them is Hermitian. So a real Pauli LCU can only represent a Hermitian matrix. 12(U+U∗)\frac12(\mathbf{U}+\mathbf{U}^*) is the closest Hermitian matrix to U\mathbf{U} (it keeps the "Hermitian half" and throws away the anti-Hermitian half 12(U−U∗)\frac12(\mathbf{U}-\mathbf{U}^*)). That's why it's only an approximation when U\mathbf{U} isn't Hermitian.

❓ Why does the trace give the coefficient? The Pauli matrices are orthogonal under the trace inner product: tr⁡(PjPk)=2n\operatorname{tr}(\mathbf{P}_j\mathbf{P}_k) = 2^n if j=kj=k, else 00. So multiplying by Pk\mathbf{P}_k and taking the trace filters out every component except the Pk\mathbf{P}_k one, the same way ⟨ek∣v⟩\langle e_k|v\rangle picks the kk-th coordinate of a vector.

❓ Why a "linear combination of unitaries"? Each Pauli string is a unitary that is easy to run on hardware. Writing H^\hat{\mathbf{H}} as a sum of them lets us later simulate cis⁡(−H^)\operatorname{cis}(-\hat{\mathbf{H}}) piece by piece (trotterization) or block-encode it (qubitization).

💡 Analogy: a sound equalizer. Any sound (your matrix) can be split into 4 "bands" (I, X, Y, Z). The trace is the meter that reads how loud each band is. The Hamiltonian is the list of slider positions.

Related

Conversion to Hamiltonian by Pauli Decomposition (cont'd) {Exam Q6}

Example: Compute the Hamiltonian of A\mathbf{A} (slides 22–23)

A=[12+i3−i4]\mathbf{A} = \begin{bmatrix} 1 & 2+i \\ 3-i & 4 \end{bmatrix}

  • Step 1: convert A\mathbf{A} into its Hermitian matrix
    • Check: diagonal 1,41, 4 is real ✓. Off-diagonal 2+i2+i vs 3−i3-i are not conjugates ✗, so not Hermitian
    • A∗=[13+i2−i4]\mathbf{A}^* = \begin{bmatrix} 1 & 3+i \\ 2-i & 4 \end{bmatrix} (transpose, then conjugate)

A′=12(A+A∗)=[15/2+i5/2−i4]\mathbf{A}' = \frac12(\mathbf{A}+\mathbf{A}^*) = \begin{bmatrix} 1 & 5/2+i \\ 5/2-i & 4 \end{bmatrix}

  • Step 2: enumerate all Pauli axes (n=1n = 1 → 41=44^1 = 4 axes)

I=[1001]X=[0110]Y=[0−ii0]Z=[100−1]\mathbf{I} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \quad \mathbf{X} = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} \quad \mathbf{Y} = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} \quad \mathbf{Z} = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}

  • Step 3: compute each coefficient (you only need the diagonal of A′P\mathbf{A}'\mathbf{P}: row 1 · column 1 + row 2 · column 2)
    • cI=tr⁡(A′I)=1+4=5c_{\mathbf{I}} = \operatorname{tr}(\mathbf{A}'\mathbf{I}) = 1 + 4 = 5
    • cX=tr⁡(A′X)=(5/2+i)+(5/2−i)=5c_{\mathbf{X}} = \operatorname{tr}(\mathbf{A}'\mathbf{X}) = (5/2+i) + (5/2-i) = 5
    • cY=tr⁡(A′Y)c_{\mathbf{Y}} = \operatorname{tr}(\mathbf{A}'\mathbf{Y}): row 1 · col 1 =(5/2+i)(i)=−1+5i2= (5/2+i)(i) = -1 + \tfrac{5i}{2}, and row 2 · col 2 =(5/2−i)(−i)=−5i2+i2=−1−5i2= (5/2-i)(-i) = -\tfrac{5i}{2} + i^2 = -1 - \tfrac{5i}{2}
      • cY=−1+5i2−1−5i2=−2c_{\mathbf{Y}} = -1 + \tfrac{5i}{2} - 1 - \tfrac{5i}{2} = \mathbf{-2}
      • ⚠️ The slide prints "−1+5i/2+1−5i/2=0-1 + 5i/2 + 1 - 5i/2 = 0". That is a sign slip: (−i)(−i)=i2=−1(-i)(-i) = i^2 = -1, not +1+1. Verified with numpy: tr⁡(A′Y)=−2\operatorname{tr}(\mathbf{A}'\mathbf{Y}) = -2. Don't copy the 0
    • cZ=tr⁡(A′Z)=1−4=−3c_{\mathbf{Z}} = \operatorname{tr}(\mathbf{A}'\mathbf{Z}) = 1 - 4 = -3
  • Step 4: the Hamiltonian of A\mathbf{A}
    • As printed on slide 23 (with cY=0c_{\mathbf{Y}}=0): H^=5I+5X+0Y−3Z=[5−3555+3]=[2558]\hat{\mathbf{H}} = 5\mathbf{I} + 5\mathbf{X} + 0\mathbf{Y} - 3\mathbf{Z} = \begin{bmatrix} 5-3 & 5 \\ 5 & 5+3 \end{bmatrix} = \begin{bmatrix} 2 & 5 \\ 5 & 8 \end{bmatrix}
    • Corrected (with cY=−2c_{\mathbf{Y}} = -2):

H^=5I+5X−2Y−3Z=[5−35+2i5−2i5+3]=[25+2i5−2i8]\hat{\mathbf{H}} = 5\mathbf{I} + 5\mathbf{X} - 2\mathbf{Y} - 3\mathbf{Z} = \begin{bmatrix} 5-3 & 5+2i \\ 5-2i & 5+3 \end{bmatrix} = \begin{bmatrix} 2 & 5+2i \\ 5-2i & 8 \end{bmatrix}

  • Sanity check: the result is Hermitian (real diagonal, conjugate off-diagonal) ✓, and it equals exactly 2A′2\mathbf{A}' (see the normalization note below) ✓

📝 Instructor's annotation (slide 22): his "trick" is colour highlighting. For each ckc_k he highlighted row 1 of A′\mathbf{A}' with column 1 of P\mathbf{P} (yellow) and row 2 of A′\mathbf{A}' with column 2 of P\mathbf{P} (green). Then he wrote the two dot products as yellow + green: cI=1+4c_{\mathbf{I}} = \boxed{1}+\boxed{4}, cX=5/2+i+5/2−ic_{\mathbf{X}} = \boxed{5/2+i}+\boxed{5/2-i}, cY=−1+5i/2+1−5i/2c_{\mathbf{Y}} = \boxed{-1+5i/2}+\boxed{1-5i/2}, cZ=1−4c_{\mathbf{Z}} = \boxed{1}-\boxed{4}.

🎙️ In class (Nov 10 pt 2, 29:40–31:14), the trick: "Instead of doing the actual multiplication, let me show you my trick. You don't have to compute the full matrix multiplication. Look at the row and the column and dot them. First row first column, second row second column. That's how you extract the trace."

🎙️ In class (Nov 10 pt 2, 43:43): "Your Hamiltonian: look at that, each element may be larger than one, and it's okay, because it's the argument of cis. These are phases."

🎙️ In class (Nov 10 pt 2, 44:17): "Once you have extracted the Hamiltonian, that's all for the final."

Step-by-step recipe for Final Q6 (single qubit) — Method A (the slide method)

  • Step 0: Read the size. 2×22\times2 → n=1n = 1 qubit → 4 Pauli axes I,X,Y,Z\mathbf{I},\mathbf{X},\mathbf{Y},\mathbf{Z}
  • Step 1: Hermitian check (write it out, it earns marks)
    • Diagonal entries real?
    • Mirror entries conjugate (u21=u12‾u_{21} = \overline{u_{12}})?
    • If both are yes: U′=U\mathbf{U}' = \mathbf{U}, and write "U is Hermitian, so the Hamiltonian is exact"
    • If not: U∗=U‾T\mathbf{U}^* = \overline{\mathbf{U}}^{\mathsf T} (swap off-diagonals, then flip every ii sign), and U′=12(U+U∗)\mathbf{U}' = \tfrac12(\mathbf{U}+\mathbf{U}^*). Write "U is not Hermitian, so this is an approximation"
    • Shortcut for U=[abcd]\mathbf{U} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}:

U′=[Re⁡ab+cˉ2c+bˉ2Re⁡d]\mathbf{U}' = \begin{bmatrix} \operatorname{Re} a & \tfrac{b + \bar c}{2} \\ \tfrac{c + \bar b}{2} & \operatorname{Re} d \end{bmatrix}

  • Step 2: list the Pauli axes (copy I, X, Y, Z from above)
  • Step 3: coefficients via the diagonal-only trick. Let U′=[pqqˉr]\mathbf{U}' = \begin{bmatrix} p & q \\ \bar q & r \end{bmatrix} (p,rp, r real):

cI=p+rcX=q+qˉ=2Re⁡qcY=i(q−qˉ)=−2Im⁡qcZ=p−r\boxed{c_{\mathbf{I}} = p + r \qquad c_{\mathbf{X}} = q + \bar q = 2\operatorname{Re} q \qquad c_{\mathbf{Y}} = i(q - \bar q) = -2\operatorname{Im} q \qquad c_{\mathbf{Z}} = p - r}

  • Where these come from: tr⁡(U′X)=u12′+u21′\operatorname{tr}(\mathbf{U}'\mathbf{X}) = u'_{12} + u'_{21}, tr⁡(U′Y)=i u12′−i u21′\operatorname{tr}(\mathbf{U}'\mathbf{Y}) = i\,u'_{12} - i\,u'_{21}, tr⁡(U′Z)=u11′−u22′\operatorname{tr}(\mathbf{U}'\mathbf{Z}) = u'_{11} - u'_{22}
  • Check: all four ckc_k must be real. If you get an ii left over, you made an arithmetic slip (most often in cYc_{\mathbf{Y}})
  • Extra shortcut (verified): ck=Re⁡tr⁡(UPk)c_k = \operatorname{Re}\operatorname{tr}(\mathbf{U}\mathbf{P}_k), so you can use the original U\mathbf{U} and keep the real part
  • Step 4: assemble. H^=cII+cXX+cYY+cZZ\hat{\mathbf{H}} = c_{\mathbf{I}}\mathbf{I} + c_{\mathbf{X}}\mathbf{X} + c_{\mathbf{Y}}\mathbf{Y} + c_{\mathbf{Z}}\mathbf{Z}, then write it as a matrix:

H^=[cI+cZcX−i cYcX+i cYcI−cZ]\boxed{\hat{\mathbf{H}} = \begin{bmatrix} c_{\mathbf{I}} + c_{\mathbf{Z}} & c_{\mathbf{X}} - i\,c_{\mathbf{Y}} \\ c_{\mathbf{X}} + i\,c_{\mathbf{Y}} & c_{\mathbf{I}} - c_{\mathbf{Z}} \end{bmatrix}}

  • Step 5: verify. H^\hat{\mathbf{H}} must be Hermitian (real diagonal, conjugate off-diagonal). With the slide formula it must equal 2U′2\mathbf{U}' for one qubit. If it doesn't, recheck cYc_{\mathbf{Y}}

Normalization: what the slide formula gives vs what PennyLane gives

  • Pauli axes satisfy tr⁡(PjPk)=2nδjk\operatorname{tr}(\mathbf{P}_j\mathbf{P}_k) = 2^n\delta_{jk}. So the textbook decomposition is ck=12ntr⁡(U′Pk)c_k = \frac{1}{2^n}\operatorname{tr}(\mathbf{U}'\mathbf{P}_k), and then ∑kckPk=U′\sum_k c_k\mathbf{P}_k = \mathbf{U}' exactly. This is what qml.pauli_decompose returns.
  • The slide formula ck=tr⁡(U′Pk)c_k = \operatorname{tr}(\mathbf{U}'\mathbf{P}_k) (no 12n\frac{1}{2^n}) gives H^=2nU′\hat{\mathbf{H}} = 2^n\mathbf{U}', i.e. 2U′2\mathbf{U}' for one qubit.
  • Example A, normalized: H^=2.5I+2.5X−Y−1.5Z=A′=[15/2+i5/2−i4]\hat{\mathbf{H}} = 2.5\mathbf{I} + 2.5\mathbf{X} - \mathbf{Y} - 1.5\mathbf{Z} = \mathbf{A}' = \begin{bmatrix} 1 & 5/2+i \\ 5/2-i & 4\end{bmatrix}
  • For the exam: follow the slide formula (it's what he demonstrated and grades from). Optionally add one line: "with PennyLane's 1/2n1/2^n normalization, H^=U′\hat{\mathbf{H}} = \mathbf{U}'."

Deeper: the "true" Hamiltonian H^=ilog⁡U\hat{\mathbf{H}} = i\log\mathbf{U} (Method B: eigen-decomposition)

  • The definition U=cis⁡(−H^)\mathbf{U} = \operatorname{cis}(-\hat{\mathbf{H}}) literally means log⁡U=−iH^\log\mathbf{U} = -i\hat{\mathbf{H}}. Slide 28 writes exactly this: "If log⁡U1=−iH^1\log\mathbf{U}_1 = -i\hat{\mathbf{H}}_1…"
  • The Pauli-decomposition recipe above gives the Pauli LCU of the Hermitian part of U\mathbf{U}. It is what the slides call "the Hamiltonian" and what Q6 asks for. In general cis⁡(−H^Pauli)≠U\operatorname{cis}(-\hat{\mathbf{H}}_{\text{Pauli}}) \neq \mathbf{U}. For example, Pauli decomposition of X\mathbf{X} gives 2X2\mathbf{X} (or X\mathbf{X} normalized), but cis⁡(−X)=cos⁡1 I−isin⁡1 X≠X\operatorname{cis}(-\mathbf{X}) = \cos 1\,\mathbf{I} - i\sin 1\,\mathbf{X} \neq \mathbf{X}
  • If a question explicitly asks for H^\hat{\mathbf{H}} such that e−iH^t=Ue^{-i\hat{\mathbf{H}}t} = \mathbf{U} (the physics meaning), use this method. It also works as a cross-check and helps you answer "why" questions
  • Recipe (single qubit, U\mathbf{U} unitary):
  • B1. Check unitary: U∗U=I\mathbf{U}^*\mathbf{U} = \mathbf{I}. A true Hamiltonian exists only for unitary U\mathbf{U}, and then the eigenvalues satisfy ∣λk∣=1|\lambda_k| = 1
  • B2. Eigen-decompose: solve det⁡(U−λI)=0\det(\mathbf{U} - \lambda\mathbf{I}) = 0, find orthonormal eigenvectors, and write U=∑kλk∣vk⟩⟨vk∣\mathbf{U} = \sum_k \lambda_k \lvert v_k\rangle\langle v_k\rvert
  • B3. Logarithm of each eigenvalue: λk=eiφk\lambda_k = e^{i\varphi_k}, so φk=arg⁡λk\varphi_k = \arg\lambda_k
  • B4. Branch choice: arg⁡\arg is only defined up to 2π2\pi. Use the principal branch φk∈(−π,π]\varphi_k \in (-\pi, \pi] unless told otherwise. Any φk+2πm\varphi_k + 2\pi m gives another valid Hamiltonian (Hamiltonians are not unique)
  • B5. Time tt: if U=e−iH^t\mathbf{U} = e^{-i\hat{\mathbf{H}}t} for evolution time tt (units with ℏ=1\hbar = 1; the slides use t=1t = 1), then

H^=itlog⁡U=∑k(−φkt)∣vk⟩⟨vk∣\boxed{\hat{\mathbf{H}} = \frac{i}{t}\log\mathbf{U} = \sum_k \left(-\frac{\varphi_k}{t}\right)\lvert v_k\rangle\langle v_k\rvert}

  • B6. Check Hermitian: the eigenvalues −φk/t-\varphi_k/t are real and the eigenvectors are orthonormal, so H^∗=H^\hat{\mathbf{H}}^* = \hat{\mathbf{H}} ✓. Then check e−iH^t=Ue^{-i\hat{\mathbf{H}}t} = \mathbf{U} by plugging eigenvalues back in
  • B7. (Optional) Pauli-decompose this H^\hat{\mathbf{H}} (normalized ck=12tr⁡(H^Pk)c_k = \tfrac12\operatorname{tr}(\hat{\mathbf{H}}\mathbf{P}_k)) to write it as an LCU

Worked example (Method B): U=X\mathbf{U} = \mathbf{X}, t=1t = 1

  • Unitary ✓ (also Hermitian)
  • Eigen-pairs: λ=+1\lambda = +1 with ∣+⟩\lvert+\rangle, λ=−1\lambda = -1 with ∣−⟩\lvert-\rangle
  • Logs: φ+=arg⁡(1)=0\varphi_+ = \arg(1) = 0, φ−=arg⁡(−1)=π\varphi_- = \arg(-1) = \pi (principal branch)
  • H^=−0⋅∣+⟩⟨+∣−π∣−⟩⟨−∣=−π⋅12[1−1−11]=[−π/2π/2π/2−π/2]=−π2I+π2X\hat{\mathbf{H}} = -0\cdot\lvert+\rangle\langle+\rvert - \pi\lvert-\rangle\langle-\rvert = -\pi\cdot\tfrac12\begin{bmatrix}1 & -1\\ -1 & 1\end{bmatrix} = \begin{bmatrix} -\pi/2 & \pi/2 \\ \pi/2 & -\pi/2 \end{bmatrix} = -\tfrac{\pi}{2}\mathbf{I} + \tfrac{\pi}{2}\mathbf{X}
  • Check: e−iH^=eiπ/2 e−iπ2X=i(cos⁡π2I−isin⁡π2X)=i(−iX)=Xe^{-i\hat{\mathbf{H}}} = e^{i\pi/2}\,e^{-i\frac{\pi}{2}\mathbf{X}} = i\left(\cos\tfrac{\pi}{2}\mathbf{I} - i\sin\tfrac{\pi}{2}\mathbf{X}\right) = i(-i\mathbf{X}) = \mathbf{X} ✓ (verified with scipy expm)
  • Other branch (φ−=−π\varphi_- = -\pi): H^=π2(I−X)\hat{\mathbf{H}} = \tfrac{\pi}{2}(\mathbf{I} - \mathbf{X}), which also gives e−iH^=Xe^{-i\hat{\mathbf{H}}} = \mathbf{X} ✓. The two differ only by a global phase term (πI\pi\mathbf{I} shift) in the I\mathbf{I} coefficient
  • General rule (verified for X, Y, Z, Hadamard): any Hermitian unitary U\mathbf{U} (eigenvalues ±1\pm1) has H^=π2(I−U)\boxed{\hat{\mathbf{H}} = \tfrac{\pi}{2}(\mathbf{I} - \mathbf{U})}

Worked example (Method B): phase gate S=[100i]\mathbf{S} = \begin{bmatrix}1&0\\0&i\end{bmatrix}

  • Already diagonal: λ0=1\lambda_0 = 1 (φ=0\varphi = 0), λ1=i\lambda_1 = i (φ=π/2\varphi = \pi/2)
  • H^=[000−π/2]=−π4I+π4Z\hat{\mathbf{H}} = \begin{bmatrix}0 & 0\\0 & -\pi/2\end{bmatrix} = -\tfrac{\pi}{4}\mathbf{I} + \tfrac{\pi}{4}\mathbf{Z} (verified)
  • Same pattern for T\mathbf{T}: H^=diag⁡(0,−π/4)=−π8I+π8Z\hat{\mathbf{H}} = \operatorname{diag}(0, -\pi/4) = -\tfrac{\pi}{8}\mathbf{I} + \tfrac{\pi}{8}\mathbf{Z} (verified)

Worked example (Method B): rotation with time, U=RX(π/2)\mathbf{U} = \mathrm{RX}(\pi/2) produced by evolving for t=2t = 2

  • RX(π/2)=e−iπ4X\mathrm{RX}(\pi/2) = e^{-i\frac{\pi}{4}\mathbf{X}}; eigenvalues e∓iπ/4e^{\mp i\pi/4} on ∣±⟩\lvert\pm\rangle, so φ±=∓π/4\varphi_\pm = \mp\pi/4
  • H^=12(π4∣+⟩⟨+∣−π4∣−⟩⟨−∣)=π8X\hat{\mathbf{H}} = \frac{1}{2}\left(\tfrac{\pi}{4}\lvert+\rangle\langle+\rvert - \tfrac{\pi}{4}\lvert-\rangle\langle-\rvert\right) = \tfrac{\pi}{8}\mathbf{X} (verified)
  • Units: H^\hat{\mathbf{H}} is "phase per unit time" (an angular frequency / energy with ℏ=1\hbar = 1). Doubling tt halves H^\hat{\mathbf{H}}
  • Link to simulation: UN=e−iNH^t\mathbf{U}^N = e^{-iN\hat{\mathbf{H}}t}, e.g. X3=cis⁡ ⁣(−3⋅π2(I−X))\mathbf{X}^3 = \operatorname{cis}\!\left(-3\cdot\tfrac{\pi}{2}(\mathbf{I}-\mathbf{X})\right) ✓ (verified)

❓ Why can the Hamiltonian have entries bigger than 1? U\mathbf{U} is unitary, so its entries are at most 1 in size. H^\hat{\mathbf{H}} holds angles/frequencies (arguments of cis), which can be any real number. That's why [25+2i5−2i8]\begin{bmatrix}2 & 5+2i\\5-2i & 8\end{bmatrix} is fine (Nov 10, 43:43).

❓ Why must H^\hat{\mathbf{H}} be Hermitian? Hermitian means real eigenvalues (real energies/phases). Then e−iH^e^{-i\hat{\mathbf{H}}} has eigenvalues e−i⋅reale^{-i\cdot\text{real}} on the unit circle, so it is unitary (probability-preserving). A non-Hermitian H^\hat{\mathbf{H}} would make amplitudes grow or shrink.

❓ Why is the Hamiltonian not unique? eiφ=ei(φ+2π)e^{i\varphi} = e^{i(\varphi + 2\pi)}, so each eigenvalue's logarithm has infinitely many branches. Every branch choice gives a valid H^\hat{\mathbf{H}}. The principal branch is the usual convention.

Exercise 7.2: Hamiltonian Matrix

  • Convert the following matrices to Hamiltonians. Note that some of them are not Hermitian.
    1. [1001]\begin{bmatrix}1&0\\0&1\end{bmatrix}
    2. [0110]\begin{bmatrix}0&1\\1&0\end{bmatrix}
    3. [0−ii0]\begin{bmatrix}0&-i\\i&0\end{bmatrix}
    4. [100−1]\begin{bmatrix}1&0\\0&-1\end{bmatrix}
    5. [34i−5i6]\begin{bmatrix}3&4i\\-5i&6\end{bmatrix}
    6. I⊗X=[0100100000010010]\mathbf{I}\otimes\mathbf{X} = \begin{bmatrix}0&1&0&0\\1&0&0&0\\0&0&0&1\\0&0&1&0\end{bmatrix}
    7. CNOT=[1000010000010010]\mathrm{CNOT} = \begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&0&1\\0&0&1&0\end{bmatrix}
    8. X⊗Y\mathbf{X}\otimes\mathbf{Y}
    9. X⊗Y⊗Z\mathbf{X}\otimes\mathbf{Y}\otimes\mathbf{Z}
    10. [cis⁡(−θ2)00cis⁡θ2]\begin{bmatrix}\operatorname{cis}(-\frac{\theta}{2}) & 0\\ 0 & \operatorname{cis}\frac{\theta}{2}\end{bmatrix} for any θ\theta

📝 Instructor's annotation: he wrote "End" with a big slash on this slide. In class he stopped the computational material here: "that's all for the final" (Nov 10, 44:17).

  • Worked solutions (slide formula ck=tr⁡(U′Pk)c_k = \operatorname{tr}(\mathbf{U}'\mathbf{P}_k); normalized ÷2n\div 2^n in brackets; all checked with numpy):
    1. I\mathbf{I}: Hermitian ✓. cI=2c_{\mathbf{I}} = 2, others 0 → H^=2I\hat{\mathbf{H}} = 2\mathbf{I} [I\mathbf{I}]
    2. X\mathbf{X}: Hermitian ✓. cX=2c_{\mathbf{X}} = 2 → H^=2X\hat{\mathbf{H}} = 2\mathbf{X} [X\mathbf{X}]
    3. Y\mathbf{Y}: Hermitian ✓. cY=tr⁡(Y2)=2c_{\mathbf{Y}} = \operatorname{tr}(\mathbf{Y}^2) = 2 → H^=2Y\hat{\mathbf{H}} = 2\mathbf{Y} [Y\mathbf{Y}]
    4. Z\mathbf{Z}: Hermitian ✓. cZ=2c_{\mathbf{Z}} = 2 → H^=2Z\hat{\mathbf{H}} = 2\mathbf{Z} [Z\mathbf{Z}]
    5. [34i−5i6]\begin{bmatrix}3&4i\\-5i&6\end{bmatrix}: diagonal real ✓, but 4i4i vs −5i-5i are not conjugates ✗
      • U∗=[35i−4i6]\mathbf{U}^* = \begin{bmatrix}3&5i\\-4i&6\end{bmatrix}, U′=[392i−92i6]\mathbf{U}' = \begin{bmatrix}3 & \tfrac92 i\\ -\tfrac92 i & 6\end{bmatrix}
      • cI=3+6=9c_{\mathbf{I}} = 3+6 = 9
      • cX=92i−92i=0c_{\mathbf{X}} = \tfrac92 i - \tfrac92 i = 0
      • cY=(92i)(i)+(−92i)(−i)=−92−92=−9c_{\mathbf{Y}} = (\tfrac92 i)(i) + (-\tfrac92 i)(-i) = -\tfrac92 - \tfrac92 = -9
      • cZ=3−6=−3c_{\mathbf{Z}} = 3 - 6 = -3
      • H^=9I−9Y−3Z=[69i−9i12]\hat{\mathbf{H}} = 9\mathbf{I} - 9\mathbf{Y} - 3\mathbf{Z} = \begin{bmatrix}6 & 9i\\-9i & 12\end{bmatrix} [4.5I−4.5Y−1.5Z=U′4.5\mathbf{I} - 4.5\mathbf{Y} - 1.5\mathbf{Z} = \mathbf{U}']
    6. I⊗X\mathbf{I}\otimes\mathbf{X} (2 qubits, 16 axes): only cIX=tr⁡((I⊗X)2)=4c_{\mathbf{IX}} = \operatorname{tr}((\mathbf{I}\otimes\mathbf{X})^2) = 4 → H^=4 I⊗X\hat{\mathbf{H}} = 4\,\mathbf{I}\otimes\mathbf{X} [I⊗X\mathbf{I}\otimes\mathbf{X}]
    7. CNOT: Hermitian ✓. CNOT=12(II+IX+ZI−ZX)\mathrm{CNOT} = \tfrac12(\mathbf{II} + \mathbf{IX} + \mathbf{ZI} - \mathbf{ZX}), so cII=cIX=cZI=2c_{\mathbf{II}} = c_{\mathbf{IX}} = c_{\mathbf{ZI}} = 2, cZX=−2c_{\mathbf{ZX}} = -2 → H^=2(II+IX+ZI−ZX)\hat{\mathbf{H}} = 2(\mathbf{II} + \mathbf{IX} + \mathbf{ZI} - \mathbf{ZX}) [12(… )\tfrac12(\dots)]
    8. X⊗Y\mathbf{X}\otimes\mathbf{Y}: Hermitian ✓. cXY=4c_{\mathbf{XY}} = 4 → 4 X⊗Y4\,\mathbf{X}\otimes\mathbf{Y} [X⊗Y\mathbf{X}\otimes\mathbf{Y}]
    9. X⊗Y⊗Z\mathbf{X}\otimes\mathbf{Y}\otimes\mathbf{Z} (8×88\times8, 43=644^3 = 64 axes, only one nonzero): cXYZ=8c_{\mathbf{XYZ}} = 8 → 8 X⊗Y⊗Z8\,\mathbf{X}\otimes\mathbf{Y}\otimes\mathbf{Z} [X⊗Y⊗Z\mathbf{X}\otimes\mathbf{Y}\otimes\mathbf{Z}]
    10. RZ(θ)=diag⁡(e−iθ/2,eiθ/2)\mathrm{RZ}(\theta) = \operatorname{diag}(e^{-i\theta/2}, e^{i\theta/2}): not Hermitian (unless θ=0 mod 2π\theta = 0 \bmod 2\pi)
      • U′=diag⁡(cos⁡θ2,cos⁡θ2)=cos⁡θ2 I\mathbf{U}' = \operatorname{diag}(\cos\tfrac\theta2, \cos\tfrac\theta2) = \cos\tfrac\theta2\,\mathbf{I}
      • cI=2cos⁡θ2c_{\mathbf{I}} = 2\cos\tfrac\theta2, cX=cY=cZ=0c_{\mathbf{X}} = c_{\mathbf{Y}} = c_{\mathbf{Z}} = 0 → H^=2cos⁡θ2 I\hat{\mathbf{H}} = 2\cos\tfrac\theta2\,\mathbf{I}
      • ⚠️ The Hermitian approximation threw away all the rotation information (the sin⁡\sin part sits in the anti-Hermitian half). The true Hamiltonian (Method B) is H^=θ2Z\hat{\mathbf{H}} = \tfrac{\theta}{2}\mathbf{Z} (principal branch, ∣θ∣<2π|\theta| < 2\pi; verified). This is a good "why is non-Hermitian only an approximation" example
  • Patterns to remember:
    • For any Pauli string P\mathbf{P} on nn qubits, the slide formula gives H^=2nP\hat{\mathbf{H}} = 2^n\mathbf{P}, because P2=I\mathbf{P}^2 = \mathbf{I} and tr⁡(I2n)=2n\operatorname{tr}(\mathbf{I}_{2^n}) = 2^n
    • A tensor product of Paulis is itself one Pauli axis, so only one coefficient is nonzero (use the Tip (⊗Ak)(⊗Bk)=⊗AkBk(\otimes\mathbf{A}_k)(\otimes\mathbf{B}_k) = \otimes\mathbf{A}_k\mathbf{B}_k)

🎙️ In class (Nov 10 pt 2, 34:58–42:29), multi-qubit: enumerate the Pauli axes as tensor products, 4n4^n of them (2 qubits → 16, 3 qubits → 64). cII=tr⁡(U′(I⊗I))c_{\mathbf{II}} = \operatorname{tr}(\mathbf{U}'(\mathbf{I}\otimes\mathbf{I})), cIX=tr⁡(U′(I⊗X))c_{\mathbf{IX}} = \operatorname{tr}(\mathbf{U}'(\mathbf{I}\otimes\mathbf{X})), … , cZZc_{\mathbf{ZZ}}. Tensor product recap: [abcd]⊗B=[aBbBcBdB]\begin{bmatrix}a&b\\c&d\end{bmatrix}\otimes\mathbf{B} = \begin{bmatrix}a\mathbf{B}&b\mathbf{B}\\c\mathbf{B}&d\mathbf{B}\end{bmatrix}. "It's exponential, 4n4^n. My heart isn't made of wood. You would have one qubit. Not 20. 4204^{20}, you don't have enough time even for your lifetime."

Commutator

  • The commutator of two matrices A\mathbf{A} and B\mathbf{B} is their positional discrepancy:

[A,B]=AB−BA\boxed{[\mathbf{A}, \mathbf{B}] = \mathbf{AB} - \mathbf{BA}}

  • A\mathbf{A} and B\mathbf{B} are commutative if and only if [A,B]=0[\mathbf{A},\mathbf{B}] = 0 (no discrepancy)
  • Repetitive commutator: apply ss pairs of B\mathbf{B} and then rr pairs of A\mathbf{A} on matrix C\mathbf{C}:

[ArBsC]=[A,[…,[A,⏟r pairs[B,[…,[B,C]]]⏟s pairs]]]where r+s>0[\mathbf{A}^r\mathbf{B}^s\mathbf{C}] = \underbrace{[\mathbf{A}, [\dots, [\mathbf{A},}_{r\text{ pairs}} \underbrace{[\mathbf{B}, [\dots, [\mathbf{B}, \mathbf{C}]]]}_{s\text{ pairs}}]]] \quad\text{where } r + s > 0

  • Example: both operands are non-commutative

[1234][5678]=[19224350][5678][1234]=[23343146]\begin{bmatrix}1&2\\3&4\end{bmatrix}\begin{bmatrix}5&6\\7&8\end{bmatrix} = \begin{bmatrix}19&22\\43&50\end{bmatrix} \qquad \begin{bmatrix}5&6\\7&8\end{bmatrix}\begin{bmatrix}1&2\\3&4\end{bmatrix} = \begin{bmatrix}23&34\\31&46\end{bmatrix}

  • Their positional discrepancy:

[[1234],[5678]]=[−4−12124]\left[\begin{bmatrix}1&2\\3&4\end{bmatrix}, \begin{bmatrix}5&6\\7&8\end{bmatrix}\right] = \begin{bmatrix}-4&-12\\12&4\end{bmatrix}

  • If [A,B]=0[\mathbf{A},\mathbf{B}] = 0, then AB=BA\mathbf{AB} = \mathbf{BA}

💡 Analogy: putting on socks then shoes ≠ shoes then socks. The commutator measures "how different the result is when you swap the order".

Baker–Campbell–Hausdorff Expansion

  • Swapping the order of applying A\mathbf{A} and B\mathbf{B} also gives different results
  • Denote one combination of applying A\mathbf{A} and B\mathbf{B} by

Δ(A,B,g)=[Ar1Bs1[…[ArK−1BsK−1[ArKBsKB]]]]r1! s1!⋯rK! sK!\Delta(\mathbf{A},\mathbf{B},g) = \frac{[\mathbf{A}^{r_1}\mathbf{B}^{s_1}[\dots[\mathbf{A}^{r_{K-1}}\mathbf{B}^{s_{K-1}}[\mathbf{A}^{r_K}\mathbf{B}^{s_K}\mathbf{B}]]]]}{r_1!\,s_1!\cdots r_K!\,s_K!}

  • where g=(r1,s1,…,rK,sK)g = (r_1, s_1, \dots, r_K, s_K) represents one combination of applying ∑krk\sum_k r_k times of A\mathbf{A} and ∑ksk\sum_k s_k times of B\mathbf{B}, with each rk+sk>0r_k + s_k > 0
  • Baker–Campbell–Hausdorff expansion: the commutator is the foundation for approximating

log⁡(exp⁡A exp⁡B)=A+B+∑K=1∞(−1)K−1K∑g∈GKΔ(A,B,g)∑g\log(\exp\mathbf{A}\,\exp\mathbf{B}) = \mathbf{A} + \mathbf{B} + \sum_{K=1}^{\infty}\frac{(-1)^{K-1}}{K}\sum_{g\in G_K}\frac{\Delta(\mathbf{A},\mathbf{B},g)}{\sum g}

  • where GKG_K is the set of all possible tuples g=(r1,s1,…,rK,sK)g = (r_1, s_1, \dots, r_K, s_K) with each rk+sk>0r_k + s_k > 0
  • In practice we set a limit for the granularity KK. The more granularity, the closer the approximation
  • Leading terms (standard result, for intuition): log⁡(eAeB)=A+B+12[A,B]+…\log(e^{\mathbf{A}}e^{\mathbf{B}}) = \mathbf{A} + \mathbf{B} + \tfrac12[\mathbf{A},\mathbf{B}] + \dots

🎙️ In class (Nov 10 pt 2, 44:28): "Let's forget this math. If you're interested you can take a look, but that's deep math. We're not looking at that." (Skipped.)

❓ Why does BCH matter? It says exactly how wrong "just add the Hamiltonians" is. The error starts with 12[A,B]\tfrac12[\mathbf{A},\mathbf{B}], so if the operators commute, the error is zero.

Exercise 7.3: Commutator

  1. Show that [A,B][\mathbf{A},\mathbf{B}] is an additive inverse of [B,A][\mathbf{B},\mathbf{A}]
    • [A,B]=AB−BA=−(BA−AB)=−[B,A][\mathbf{A},\mathbf{B}] = \mathbf{AB}-\mathbf{BA} = -(\mathbf{BA}-\mathbf{AB}) = -[\mathbf{B},\mathbf{A}]
  2. Show that if A\mathbf{A} is Hermitian, then [A,A∗]=0[\mathbf{A},\mathbf{A}^*] = 0
    • A∗=A\mathbf{A}^* = \mathbf{A} ⇒ [A,A]=AA−AA=0[\mathbf{A},\mathbf{A}] = \mathbf{AA}-\mathbf{AA} = 0
  3. Let A\mathbf{A} and B\mathbf{B} be non-Hermitian matrices. Discuss why [A,B][\mathbf{A},\mathbf{B}] reflects positional discrepancy between A\mathbf{A} and B\mathbf{B}
  4. Suppose two non-Hermitian matrices A\mathbf{A} and B\mathbf{B} are converted to their Hamiltonians H^A\hat{\mathbf{H}}_A and H^B\hat{\mathbf{H}}_B. Explain why [A,B]≠0[\mathbf{A},\mathbf{B}] \neq 0
  5. Let A\mathbf{A} and B\mathbf{B} be non-Hermitian matrices with approximate Hamiltonians H^A\hat{\mathbf{H}}_A and H^B\hat{\mathbf{H}}_B. Show that

log⁡(AB)=−i(H^A+H^B)+E\log(\mathbf{AB}) = -i(\hat{\mathbf{H}}_A + \hat{\mathbf{H}}_B) + \mathbf{E}

  • where E\mathbf{E} is an error-term matrix

Trotter–Suzuki Decomposition

  • If log⁡U1=−iH^1\log\mathbf{U}_1 = -i\hat{\mathbf{H}}_1 and log⁡U2=−iH^2\log\mathbf{U}_2 = -i\hat{\mathbf{H}}_2, then

log⁡(U2U1)=−i(H^1+H^2)+E∴U2U1=exp⁡[−i(H^1+H^2)+E]\log(\mathbf{U}_2\mathbf{U}_1) = -i(\hat{\mathbf{H}}_1 + \hat{\mathbf{H}}_2) + \mathbf{E} \quad\therefore\quad \mathbf{U}_2\mathbf{U}_1 = \exp\left[-i(\hat{\mathbf{H}}_1 + \hat{\mathbf{H}}_2) + \mathbf{E}\right]

  • where E\mathbf{E} is the error term in the Baker–Campbell–Hausdorff expansion
  • Trotter–Suzuki decomposition (a.k.a. trotterization): we can approximate

U2U1≈[cis⁡(−H^1+H^2n)]n+O(1/n)\boxed{\mathbf{U}_2\mathbf{U}_1 \approx \left[\operatorname{cis}\left(-\frac{\hat{\mathbf{H}}_1 + \hat{\mathbf{H}}_2}{n}\right)\right]^n + O(1/n)}

  • Note that the error term O(1/n)O(1/n) depends on the chosen number nn
  • Proof:

U2U1=lim⁡n→∞(exp⁡−iH^1n exp⁡−iH^2n)n\mathbf{U}_2\mathbf{U}_1 = \lim_{n\to\infty}\left(\exp\frac{-i\hat{\mathbf{H}}_1}{n}\,\exp\frac{-i\hat{\mathbf{H}}_2}{n}\right)^n

  • Since ex=1+x+O(1/n2)e^x = 1 + x + O(1/n^2) for small xx, we obtain the analogy

U2U1=lim⁡n→∞(I−iH^1n+O(1/n2))n×(I−iH^2n+O(1/n2))n\mathbf{U}_2\mathbf{U}_1 = \lim_{n\to\infty}\left(\mathbf{I} - \frac{i\hat{\mathbf{H}}_1}{n} + O(1/n^2)\right)^n \times \left(\mathbf{I} - \frac{i\hat{\mathbf{H}}_2}{n} + O(1/n^2)\right)^n

  • because the Hamiltonians are divided by a very large number nn

🎙️ In class (Nov 10 pt 2, 15:12): "This is called Trotter–Suzuki decomposition. That's a big word. In the textbook we usually call it trotterization. Not terrorization. Trotterization." (A good line for the video.)

🎙️ In class (Nov 10 pt 2, 49:05): the error is OO of the reciprocal of nn. "Reciprocal is a noun, the verb is reciprocate. For example, you take good care of your girlfriend, but she never reciprocates. That hurts, right? I learned this word the hard way."

Trotter–Suzuki Decomposition (cont'd)

  • Expand the right-hand side:

U2U1=lim⁡n→∞[(I−iH^1n)(I−iH^2n)]n+O(1/n)\mathbf{U}_2\mathbf{U}_1 = \lim_{n\to\infty}\left[\left(\mathbf{I} - \frac{i\hat{\mathbf{H}}_1}{n}\right)\left(\mathbf{I} - \frac{i\hat{\mathbf{H}}_2}{n}\right)\right]^n + O(1/n)

=lim⁡n→∞[I−i(H^1+H^2)n+H^1H^2n2]n+O(1/n)= \lim_{n\to\infty}\left[\mathbf{I} - \frac{i(\hat{\mathbf{H}}_1 + \hat{\mathbf{H}}_2)}{n} + \frac{\hat{\mathbf{H}}_1\hat{\mathbf{H}}_2}{n^2}\right]^n + O(1/n)

=lim⁡n→∞[I−i(H^1+H^2)n]n+O(1/n)= \lim_{n\to\infty}\left[\mathbf{I} - \frac{i(\hat{\mathbf{H}}_1 + \hat{\mathbf{H}}_2)}{n}\right]^n + O(1/n)

=lim⁡n→∞[exp⁡−i(H^1+H^2)n]n+O(1/n)= \lim_{n\to\infty}\left[\exp\frac{-i(\hat{\mathbf{H}}_1 + \hat{\mathbf{H}}_2)}{n}\right]^n + O(1/n)

  • Generalization: if there is only one unitary operator U=cis⁡(−H^)\mathbf{U} = \operatorname{cis}(-\hat{\mathbf{H}}) in the time evolution of NN timesteps, ∣ψ(N)⟩=UN∣ψ(0)⟩\lvert\psi^{(N)}\rangle = \mathbf{U}^N\lvert\psi^{(0)}\rangle, we can generalize Trotter–Suzuki into

UN≈[cis⁡(−NH^n)]n+O(1/n)\boxed{\mathbf{U}^N \approx \left[\operatorname{cis}\left(-\frac{N\hat{\mathbf{H}}}{n}\right)\right]^n + O(1/n)}

  • This formula is useful when the length of the time evolution is predefined, because we can precompute UN\mathbf{U}^N in advance

🎙️ In class (Nov 10 pt 2, 20:48–22:19): he jumped to this slide first: "This is the point of the Hamiltonian. If you've got UN\mathbf{U}^N where NN is very large, you don't need the actual matrix multiplication. Multiply NN into the Hamiltonian, divide by nn, then take the power nn. Instead of computing U10,000\mathbf{U}^{10{,}000}, multiply 10,000 into the Hamiltonian."

🎙️ In class (Nov 10 pt 2, 51:01–53:48): small nn is the degree of granularity (same idea as in QPE). "nn is supposed to be small, like 2 or 4, because the thing inside cis is a matrix, and you have to multiply it nn times. Use small nn to minimize the number of matrix multiplications." Trade-off: "If nn is too large it takes ages. If it's too small, the approximation may not be accurate." Trotterization is used in QPE, which makes QPE "almost practical", and when QPE becomes practical "you can crack RSA".

❓ Why does the error shrink like 1/n1/n? Slicing into nn small steps makes each step's cross term H^1H^2/n2\hat{\mathbf{H}}_1\hat{\mathbf{H}}_2/n^2 tiny. Over nn steps these add up to n⋅O(1/n2)=O(1/n)n \cdot O(1/n^2) = O(1/n). More slices means more accuracy, but also more multiplications.

❓ Why does accuracy get worse for large NN? (Exercise 7.4 Q1.) The argument NH^/nN\hat{\mathbf{H}}/n is no longer "small" when N≫nN \gg n, so the approximation ex≈1+xe^x \approx 1 + x breaks. That's the motivation for qubitization.

💡 Analogy: walking diagonally across Siam Paragon's grid of shops. You can't walk "east and north at the same time", but if you alternate tiny east steps and tiny north steps, it looks like a straight diagonal. Smaller steps make a straighter line, but take more steps.

Trotter–Suzuki Decomposition in PennyLane

mat = np.zeros((4, 4), dtype=np.complex128)            # Markov matrix
mat[0,0] = -7/25;                  mat[1,0] = 6 * np.sqrt(3) / 10
mat[2,1] = 6 * np.sqrt(3) / 10;    mat[1,1] = 2/4
mat[2,2] = 7/25;                   mat[3,2] = 8/10
mat[2,3] = 8/10;                   mat[1,3] = -2/4
 
dev = qml.device('default.qubit', wires=[0,1])
 
def make_hamiltonian(opr):
    hermitian = 0.5 * (opr + opr.T.conj())             # Enforce Hermitian matrix
    hamiltonian = qml.pauli_decompose(hermitian, wire_order=[0,1])
    return hamiltonian
 
@qml.qnode(dev, shots=1000)
def evolution_circuit():
    hmlt = make_hamiltonian(mat)
    qml.TrotterProduct(hmlt, time=10.0, n=20)          # Run for 10 steps with
                                                       # granularity degree n = 100
    return qml.counts(wires=[0,1])
 
evolution_circuit()
# Expect result: {'00': 600, '01': 125, '10': 250, '11': 25}
# These are probable final states after 10 steps of time evolution
  • make_hamiltonian is exactly Steps 1–4: 0.5 * (opr + opr.T.conj()) is 12(U+U∗)\tfrac12(\mathbf{U}+\mathbf{U}^*), and qml.pauli_decompose does Steps 2–4 (with the 1/2n1/2^n normalization)
  • time=10.0 is NN (timesteps) and n=20 is the granularity (the code comment says 100, but the code uses 20)

Qubitization Algorithm

  • Limitation: Trotter–Suzuki can approximate UN\mathbf{U}^N, but the accuracy drops for a large number of timesteps
  • Qubitization: any non-unitary Hermitian matrix A\mathbf{A} can be converted to a unitary one U\mathbf{U} via block encoding:

U=BLOCK(A)=[A⋅⋅⋅]\mathbf{U} = \mathrm{BLOCK}(\mathbf{A}) = \begin{bmatrix}\mathbf{A} & \cdot\\ \cdot & \cdot\end{bmatrix}

  • We can estimate UN∣ψ⟩\mathbf{U}^N\lvert\psi\rangle by rotating U\mathbf{U} many times with QPE and measuring the distribution of destination states
  • Step 1: since A\mathbf{A} is Hermitian, perform Pauli decomposition on it to obtain the LCU A=∑kckPk\mathbf{A} = \sum_k c_k\mathbf{P}_k, where each Pk\mathbf{P}_k is the kk-th Pauli axis
  • Step 2: construct the preparation operator PREP(A)\mathrm{PREP}(\mathbf{A}) that maps

∣0⟩⊗M⊗∣ψ⟩↦∑k=0K−1∣BM(k),ψ⟩∣ck∣Z\lvert 0\rangle^{\otimes M}\otimes\lvert\psi\rangle \mapsto \sum_{k=0}^{K-1}\lvert\mathbb{B}_M(k), \psi\rangle\sqrt{\frac{|c_k|}{Z}}

  • where the normalizing constant is Z=∑k=1K∣ck∣Z = \sum_{k=1}^{K}|c_k|

🎙️ In class (Nov 10 pt 2, 54:47): "This is an extension of trotterization. We call it qubitization: a better approximation of UN\mathbf{U}^N with better accuracy, but it's a little more complicated. I'm not going to include it in the final. If you're interested, read the book (PDF on Google Classroom)."

Qubitization Algorithm (cont'd)

  • Step 3: construct the selection operator SEL(A)\mathrm{SEL}(\mathbf{A}) that maps ∣BM(k),ψ⟩↦∣BM(k)⟩⊗Pk∣ψ⟩\lvert\mathbb{B}_M(k), \psi\rangle \mapsto \lvert\mathbb{B}_M(k)\rangle\otimes\mathbf{P}_k\lvert\psi\rangle
  • Step 4: construct the block encoder

BLOCK(A)=PREP∗(A) SEL(A) PREP(A)\mathrm{BLOCK}(\mathbf{A}) = \mathrm{PREP}^*(\mathbf{A})\,\mathrm{SEL}(\mathbf{A})\,\mathrm{PREP}(\mathbf{A})

  • and apply it to ∣0,ψ⟩\lvert 0,\psi\rangle with phase kickback:

BLOCK(A)∣0,ψ⟩=λZ∣0,ψ⟩+∣0,ψ⟩⊥1−(λ/Z)2\mathrm{BLOCK}(\mathbf{A})\lvert 0,\psi\rangle = \frac{\lambda}{Z}\lvert 0,\psi\rangle + \lvert 0,\psi\rangle^{\perp}\sqrt{1 - (\lambda/Z)^2}

  • where ∣v⟩⊥\lvert v\rangle^\perp is perpendicular to ∣v⟩\lvert v\rangle
  • Step 5: apply QPE to measure the distribution of destination states: P(q(2M))=QPE∣0,ψ⟩P(q^{(2^M)}) = \mathrm{QPE}\lvert 0,\psi\rangle
  • Step 6: deduce the phase of the Hamiltonian H^\hat{\mathbf{H}} by θ=2πr∗/2M\theta = 2\pi r^*/2^M, where r∗=arg⁡max⁡rP(r)r^* = \arg\max_r P(r)
  • Step 7: approximate UN∣ψ⟩≈cis⁡(−iNθ)∣ψ⟩\mathbf{U}^N\lvert\psi\rangle \approx \operatorname{cis}(-iN\theta)\lvert\psi\rangle, and the eigenvalue of A\mathbf{A} is λ=Zcos⁡θ\lambda = Z\cos\theta

Qubitization Algorithm (cont'd): Circuit

  • Figure 10: qubitization algorithm. Registers: MM control qubits ∣0⟩\lvert 0\rangle and an LL-qubit ∣ψ⟩\lvert\psi\rangle
  • PREP(A)\mathrm{PREP}(\mathbf{A}) → SEL(A)\mathrm{SEL}(\mathbf{A}) (controlled P1,P2,P3,P4\mathbf{P}_1, \mathbf{P}_2, \mathbf{P}_3, \mathbf{P}_4 for control patterns 00, 01, 10, 11) → PREP∗(A)\mathrm{PREP}^*(\mathbf{A}) → QPE → measure
  • PREP + SEL + PREP* together form the block encoder BLOCK(A)\mathrm{BLOCK}(\mathbf{A}). Each Pk\mathbf{P}_k is the kk-th Pauli axis of A\mathbf{A}

Proof via Jacobi–Anger Expansion

  • The Jacobi–Anger expansion explains why we can deduce the eigenvalue λ\lambda from the estimated phase θ\theta:

cis⁡θ↦cis⁡(cos⁡θ)=cis⁡λZ\operatorname{cis}\theta \mapsto \operatorname{cis}(\cos\theta) = \operatorname{cis}\frac{\lambda}{Z}

  • Jacobi–Anger expansion:

cis⁡(zcos⁡θ)=∑k=−∞∞ikJk(z)(cis⁡θ)k\operatorname{cis}(z\cos\theta) = \sum_{k=-\infty}^{\infty} i^k J_k(z)(\operatorname{cis}\theta)^k

  • where Jn(z)J_n(z) is the Bessel function of order nn applied to zz:

Jk(z)=1π∫0πcos⁡(kt−zsin⁡t) dtJ_k(z) = \frac{1}{\pi}\int_0^{\pi}\cos(kt - z\sin t)\,dt

  • Because U=cis⁡(−H^)\mathbf{U} = \operatorname{cis}(-\hat{\mathbf{H}}), we can expand it with Jacobi–Anger for matrices:

UN=∑k=−∞∞ikJk(N)(−H^)k\mathbf{U}^N = \sum_{k=-\infty}^{\infty} i^k J_k(N)(-\hat{\mathbf{H}})^k

  • Suppose U\mathbf{U} has an eigen-pair (λ,v)(\lambda, \mathbf{v}) and H^\hat{\mathbf{H}} has phase θ\theta:

UNv=(∑k=−∞∞ikJk(N)cis⁡(−kθ))v\mathbf{U}^N\mathbf{v} = \left(\sum_{k=-\infty}^{\infty} i^k J_k(N)\operatorname{cis}(-k\theta)\right)\mathbf{v}

λv=cis⁡(Zcos⁡θ) v∴λ=Zcos⁡θ\lambda\mathbf{v} = \operatorname{cis}(Z\cos\theta)\,\mathbf{v} \quad\therefore\quad \lambda = Z\cos\theta

  • where ZZ is the normalizing constant

Qubitization Algorithm in PennyLane

import pennylane as qml
from pennylane import numpy as np
 
# A unitary matrix
mat = np.zeros((4, 4), dtype=np.complex128)
mat[0,0] = -7/25;                  mat[1,0] = 6 * np.sqrt(3) / 10
mat[2,1] = 6 * np.sqrt(3) / 10;    mat[1,1] = 2/4
mat[2,2] = 7/25;                   mat[3,2] = 8/10
mat[2,3] = 8/10;                   mat[1,3] = -2/4
 
target_wires = ['t0','t1']                            # N = input qubits
control_wires = ['c1','c2','c3','c4']                 # 2^N wires
estimation_wires = ['e1','e2','e3','e4','e5','e6']    # Granularity
 
dev = qml.device('default.qubit', wires=target_wires + control_wires + estimation_wires)
 
def make_hamiltonian(opr):
    hermitian = 0.5 * (opr + opr.T.conj())
    hamiltonian = qml.pauli_decompose(hermitian, wire_order=target_wires)
    return hamiltonian

Qubitization Algorithm in PennyLane (cont'd)

hmlt = make_hamiltonian(mat)    # Convert a unitary matrix to a Hamiltonian
normconst = sum([abs(coeff) for coeff in hmlt.terms()[0]])    # Normalizing constant
print(qml.matrix(hmlt).real)    # This is how we print a Hamiltonian out in the matrix form
 
@qml.qnode(dev)
def evolution_circuit():
    qml.QuantumPhaseEstimation(
        qml.Qubitization(hmlt, control_wires),
        estimation_wires=estimation_wires
    )
    return qml.probs(wires=estimation_wires)
 
probs = evolution_circuit()
r = np.argmax(probs)
phase = 2 * np.pi * r / 2 ** len(estimation_wires)
eigval = np.cos(phase) * normconst
print(f'phase = {phase}')
print(f'eigenvalue = {eigval}')
# Expected result:
# phase = 1.7671
# eigenvalue = -0.4096

Exercise 7.4: Trotter–Suzuki Decomposition and Qubitization Algorithm

  1. Consider the general case of trotterization UN≈[cis⁡(−NH^n)]n+O(1/n)\mathbf{U}^N \approx \left[\operatorname{cis}\left(-\frac{N\hat{\mathbf{H}}}{n}\right)\right]^n + O(1/n). Explain why the accuracy deteriorates when the number of timesteps NN becomes large. [Hint: consider ex=1+x+O(1/n2)e^x = 1 + x + O(1/n^2) for small xx.]
  2. Consider the trotterization of U2U1≈[cis⁡(−H^1+H^2n)]n+O(1/n)\mathbf{U}_2\mathbf{U}_1 \approx \left[\operatorname{cis}\left(-\frac{\hat{\mathbf{H}}_1 + \hat{\mathbf{H}}_2}{n}\right)\right]^n + O(1/n). Discuss why the accuracy deteriorates when both matrices are non-Hermitian
  3. What is the role of block encoding in the qubitization algorithm?
  4. Explain how the qubitization algorithm addresses simulation over large timesteps NN by opting for the global phase rotation of the block encoder
  5. Discuss why we have to choose the right number of estimation wires for the QPE module. What happens when MM is large? What happens when MM is small?
  6. Compare the pros and cons of trotterization and qubitization in terms of speed, space, and programming complexity
  • Hints:
    • Q1: x=−iNH^/nx = -iN\hat{\mathbf{H}}/n is small only when N≪nN \ll n. For large NN the dropped terms are big
    • Q2: non-Hermitian → we only use the approximate Hamiltonian (Hermitian part), so there are two error sources: the Hermitian approximation plus the BCH/commutator error

3. Polynomial Functions

🎙️ In class (Nov 10 pt 2, 55:53): he flipped through this section saying "passed… passed". Not covered, not in the final. The sausage-machine idea returns in Lecture 8 (VQA).

Polynomial Functions

  • A polynomial function is a mathematical expression consisting of coefficients and exponentiated variables, e.g.

P(x)=4x3+(1+2i)x2−x+7P(x) = 4x^3 + (1+2i)x^2 - x + 7

  • The coefficients are Θ=(7,−1,1+2i,4)\Theta = (7, -1, 1+2i, 4)
  • The degree of a polynomial function is the greatest exponent: deg⁡P(x)=3\deg P(x) = 3
  • Polynomial functions are fundamental for modeling the non-linear behavior of a complex system, where each variable represents a stimulus
  • Figure 11: a polynomial function is sometimes seen as a configurable sausage machine: xx (stimulus/input) goes in, P(x)P(x) (observation/output) comes out. The parameters (adjustable settings = the coefficients) are tuned to change the type of sausage it produces

💡 Analogy: a Thai street noodle stall. The broth recipe settings (coefficients) decide what bowl (output) you get from the same noodles (input).

Quantum Signal Processing (QSP)

  • Quantum signal processing (QSP) is a technique for computing a polynomial function from an input qubit
  • Define the Z-rotation operator

RZ(θ)=[cis⁡(θ)00cis⁡(−θ)]\mathrm{RZ}(\theta) = \begin{bmatrix}\operatorname{cis}(\theta) & 0\\ 0 & \operatorname{cis}(-\theta)\end{bmatrix}

  • and a signal rotation operator

W(a)=[ai1−a2i1−a2a]\mathbf{W}(a) = \begin{bmatrix} a & i\sqrt{1-a^2}\\ i\sqrt{1-a^2} & a\end{bmatrix}

  • where θ\theta is a phase parameter and aa is a diagonal parameter
  • We can decompose a time series into a QSP operator made of several components:

QSP(Θ,a)=RZ(θ0)∏k=1DW(a) RZ(θk)\boxed{\mathrm{QSP}(\Theta, a) = \mathrm{RZ}(\theta_0)\prod_{k=1}^{D}\mathbf{W}(a)\,\mathrm{RZ}(\theta_k)}

  • where DD is the degree, Θ=(θ0,…,θD)\Theta = (\theta_0, \dots, \theta_D) is a set of phase parameters, and aa is a diagonal parameter
  • If we adjust parameters Θ\Theta and aa, we can estimate the original time series
  • In function fitting, we optimize Θ\Theta and aa to minimize the prediction loss, e.g. mean squared error (MSE)

QSP as Polynomial Function

  • Let b=i1−a2b = i\sqrt{1-a^2}. Then

W(a)RZ(θ)=[acis⁡(θ)bcis⁡(θ)bcis⁡(−θ)acis⁡(−θ)]\mathbf{W}(a)\mathrm{RZ}(\theta) = \begin{bmatrix} a\operatorname{cis}(\theta) & b\operatorname{cis}(\theta)\\ b\operatorname{cis}(-\theta) & a\operatorname{cis}(-\theta)\end{bmatrix}

  • The degree-2 polynomial is

W(a)RZ(θ1)W(a)RZ(θ2)=[a2cis⁡(θ1+θ2)+b2cis⁡(θ1−θ2)abcis⁡(θ1+θ2)+abcis⁡(θ1−θ2)abcis⁡(−θ1+θ2)+abcis⁡(−θ1−θ2)b2cis⁡(−θ1+θ2)+a2cis⁡(−θ1−θ2)]\mathbf{W}(a)\mathrm{RZ}(\theta_1)\mathbf{W}(a)\mathrm{RZ}(\theta_2) = \begin{bmatrix} a^2\operatorname{cis}(\theta_1+\theta_2) + b^2\operatorname{cis}(\theta_1-\theta_2) & ab\operatorname{cis}(\theta_1+\theta_2) + ab\operatorname{cis}(\theta_1-\theta_2)\\ ab\operatorname{cis}(-\theta_1+\theta_2) + ab\operatorname{cis}(-\theta_1-\theta_2) & b^2\operatorname{cis}(-\theta_1+\theta_2) + a^2\operatorname{cis}(-\theta_1-\theta_2)\end{bmatrix}

  • Observe that the crossing elements are the conjugate of each other
  • Generalization: QSP of degree DD has a polynomial form once we expand the multiplications:

QSP(Θ,a)=[P(a)bQ(a)bQ∗(a)P∗(a)]\mathrm{QSP}(\Theta, a) = \begin{bmatrix} P(a) & bQ(a)\\ bQ^*(a) & P^*(a)\end{bmatrix}

  • where a∈[−1,1]a \in [-1, 1] and b=i1−a2b = i\sqrt{1-a^2}
  • P(a)P(a) and Q(a)Q(a) are polynomial functions with these constraints:
    • deg⁡P(a)≤D\deg P(a) \le D and deg⁡Q(a)≤D−1\deg Q(a) \le D - 1
    • P(a)P(a) has parity D mod 2D \bmod 2, and Q(a)Q(a) has parity (D−1) mod 2(D-1) \bmod 2
    • ∣P(a)∣2+(1−a2)∣Q(a)∣2=1|P(a)|^2 + (1-a^2)|Q(a)|^2 = 1 (the slide prints (1−a)2(1-a)^2)

Polynomial Function of Unitary Operators

  • Generalized QSP (GQSP): treat the input signal as a control qubit. The result is a block encoding of poly(U)\mathrm{poly}(\mathbf{U}):

U↦[poly(U)⋅⋅⋅]\mathbf{U} \mapsto \begin{bmatrix}\mathrm{poly}(\mathbf{U}) & \cdot\\ \cdot & \cdot\end{bmatrix}

  • PennyLane: qml.GQSP(opr=U, angles=..., control=...)
  • Convert the polynomial coefficients into angles with qml.poly_to_angles(coeffs, 'GQSP')
  • Figure 12: control qubit ∣c⟩\lvert c\rangle with RZ(θ0),RZ(θ1),…,RZ(θD)\mathrm{RZ}(\theta_0), \mathrm{RZ}(\theta_1), \dots, \mathrm{RZ}(\theta_D). Between them, a U\mathbf{U} controlled on ∣0⟩\lvert 0\rangle and a U∗\mathbf{U}^* controlled on ∣1⟩\lvert 1\rangle act on ∣q1⟩…∣qM⟩\lvert q_1\rangle\dots\lvert q_M\rangle

Quantum Signal Processing in PennyLane

control_wires = ['c']
target_wires = ['t1', 't2', 't3']
dev = qml.device('default.qubit', wires=target_wires + control_wires)
 
@qml.prod        # Make this function an operator argument
def my_opr(wires):
    qml.Hadamard(wires=wires[0])
    qml.X(wires=wires[2])
    qml.CNOT(wires=[wires[0], wires[1]])
    qml.CNOT(wires=[wires[0], wires[2]])
 
@qml.qnode(dev, shots=1000)
def circuit():
    coeffs = np.array([0.1, 0.2j, 0.3])                    # 0.1 + 0.2j x + 0.3 x^2
    phases = qml.poly_to_angles(coeffs, routine='GQSP')    # Convert the coefficients to phases
    qml.GQSP(my_opr(target_wires), phases, control=control_wires)
    return qml.counts(wires=target_wires)
 
circuit()
# Expected result:
# {'000': 268, '001': 23, '011': 243, '100': 202, '110': 21, '111': 243}

Quantum Singular Value Transformation (QSVT)

  • Quantum singular value transformation (QSVT) computes a polynomial function of a Hamiltonian
  • Suppose A=cis⁡(−H^)\mathbf{A} = \operatorname{cis}(-\hat{\mathbf{H}}), where

H^=∑k=1Mλk∣vk⟩⟨vk∣\hat{\mathbf{H}} = \sum_{k=1}^{M}\lambda_k\lvert v_k\rangle\langle v_k\rvert

  • and each (λk,∣vk⟩)(\lambda_k, \lvert v_k\rangle) is an eigen-pair of A\mathbf{A}
  • QSVT transforms A↦cis⁡(−poly(H^))\mathbf{A} \mapsto \operatorname{cis}(-\mathrm{poly}(\hat{\mathbf{H}})), where poly(H^)\mathrm{poly}(\hat{\mathbf{H}}) is a polynomial function, e.g. P(H^)=4H^2+3iH^−7P(\hat{\mathbf{H}}) = 4\hat{\mathbf{H}}^2 + 3i\hat{\mathbf{H}} - 7
  • Imitating QSP, we convert H^\hat{\mathbf{H}} to a unitary operator

U=[H^1−H^21−H^2−H^]where1−H^2=∑k=1M∣vk⟩⟨vk∣1−λk2\mathbf{U} = \begin{bmatrix}\hat{\mathbf{H}} & \sqrt{1-\hat{\mathbf{H}}^2}\\ \sqrt{1-\hat{\mathbf{H}}^2} & -\hat{\mathbf{H}}\end{bmatrix} \quad\text{where}\quad \sqrt{1-\hat{\mathbf{H}}^2} = \sum_{k=1}^{M}\lvert v_k\rangle\langle v_k\rvert\sqrt{1-\lambda_k^2}

  • Now apply the block encoding to U\mathbf{U}: U↦[poly(U)⋅⋅⋅]\mathbf{U} \mapsto \begin{bmatrix}\mathrm{poly}(\mathbf{U}) & \cdot\\ \cdot & \cdot\end{bmatrix}
  • Note: this slide is the "eigen-decomposition" view of a Hamiltonian (H^=∑λk∣vk⟩⟨vk∣\hat{\mathbf{H}} = \sum\lambda_k\lvert v_k\rangle\langle v_k\rvert), the same idea as Method B in Section 2

Backbone of QSVT

  • Observe that

RZ(θk) U=[cis⁡(θk)H^cis⁡(θk)1−H^2cis⁡(−θk)1−H^2−cis⁡(−θk)H^]\mathrm{RZ}(\theta_k)\,\mathbf{U} = \begin{bmatrix}\operatorname{cis}(\theta_k)\hat{\mathbf{H}} & \operatorname{cis}(\theta_k)\sqrt{1-\hat{\mathbf{H}}^2}\\ \operatorname{cis}(-\theta_k)\sqrt{1-\hat{\mathbf{H}}^2} & -\operatorname{cis}(-\theta_k)\hat{\mathbf{H}}\end{bmatrix}

  • and RZ(θk) U∗\mathrm{RZ}(\theta_k)\,\mathbf{U}^* has the same form (the slide prints the identical matrix)
  • Therefore RZ(θk+1) U∗ RZ(θk) U=[poly(H^)⋅⋅⋅]\mathrm{RZ}(\theta_{k+1})\,\mathbf{U}^*\,\mathrm{RZ}(\theta_k)\,\mathbf{U} = \begin{bmatrix}\mathrm{poly}(\hat{\mathbf{H}}) & \cdot\\ \cdot & \cdot\end{bmatrix}
  • We compose a polynomial function by alternately multiplying RZ(θ2k)U\mathrm{RZ}(\theta_{2k})\mathbf{U} and RZ(θ2k+1)U∗\mathrm{RZ}(\theta_{2k+1})\mathbf{U}^* until arriving at θD\theta_D:

QSVT(H^∣Θ)=∏k=0⌊D/2⌋−1RZ(θ2k+1) U∗ RZ(θ2k) U=[poly(H^)⋅⋅⋅]\mathrm{QSVT}(\hat{\mathbf{H}}\mid\Theta) = \prod_{k=0}^{\lfloor D/2\rfloor - 1}\mathrm{RZ}(\theta_{2k+1})\,\mathbf{U}^*\,\mathrm{RZ}(\theta_{2k})\,\mathbf{U} = \begin{bmatrix}\mathrm{poly}(\hat{\mathbf{H}}) & \cdot\\ \cdot & \cdot\end{bmatrix}

  • where the polynomial of H^\hat{\mathbf{H}} has the coefficient set Θ=(θ0,…,θD)\Theta = (\theta_0, \dots, \theta_D)

Implementation of QSVT

  • Figure 13: QSVT circuits. Case 1: DD even: U,U∗,…,U,U∗\mathbf{U}, \mathbf{U}^*, \dots, \mathbf{U}, \mathbf{U}^*. Case 2: DD odd: the last pair is U∗,U\mathbf{U}^*, \mathbf{U}. In both cases the RZ(θk)\mathrm{RZ}(\theta_k) sit on the control qubit
  • PennyLane: qml.QSVT(opr, projectors)
  • The operator opr is constructed by qml.BlockEncode(U, wires=...)
  • The projectors are made by converting each phase θk∈Θ\theta_k \in \Theta into a projector-controlled phase gate qml.PCPhase(θ_k, dim, wires=...) that maps
    • ∣1⟩⊗M↦cis⁡(−θk)∣1⟩⊗M\lvert 1\rangle^{\otimes M} \mapsto \operatorname{cis}(-\theta_k)\lvert 1\rangle^{\otimes M}
    • ∣x⟩↦cis⁡(θk)∣x⟩\lvert x\rangle \mapsto \operatorname{cis}(\theta_k)\lvert x\rangle
  • Note that the projectors can now be generalized beyond RZ

Quantum Singular Value Transformation in PennyLane

target_wires = ['t1','t2']
dev = qml.device('default.qubit', wires=target_wires)
 
mat = np.array([ [0.7, 0.5],
                 [0.5, 0.4] ], dtype=np.complex128)
 
@qml.qnode(dev, shots=1000)
def circuit():
    coeffs = np.array([0.1, 0.2, 0.3])                # 0.1 + 0.2j x + 0.3 x^2
    block_encoding = qml.BlockEncode(mat, target_wires)
    projectors = [ qml.PCPhase(phase, dim=2, wires=target_wires)
                   for phase in coeffs ]
    qml.QSVT(block_encoding, projectors)
    return qml.counts(wires=target_wires)
 
circuit()
# Expected result:
# '00': 957, '01': 19, '10': 20, '11': 4}

Exercise 7.5: Polynomial Functions

  1. What are the differences between quantum signal processing (QSP) and quantum singular value transformation (QSVT)?
  2. In quantum signal processing, explain why we need both the Z-rotation operator RZ(θ)\mathrm{RZ}(\theta) and the signal rotation operator W(a)\mathbf{W}(a). What do they contribute to the polynomial function?
  3. Derive QSP((θ0,θ1,θ2,θ3),a)\mathrm{QSP}((\theta_0, \theta_1, \theta_2, \theta_3), a). The result should be a degree-3 polynomial function
  4. Discuss how we can apply QSVT in trotterization
  5. Show that we can eigen-decompose A\mathbf{A} into eigen-pairs (λ1,∣v1⟩),…,(λM,∣vM⟩)(\lambda_1, \lvert v_1\rangle), \dots, (\lambda_M, \lvert v_M\rangle). Show that if A=cis⁡(−H^)\mathbf{A} = \operatorname{cis}(-\hat{\mathbf{H}}), then H^=∑k=1Mλk∣vk⟩⟨vk∣\hat{\mathbf{H}} = \sum_{k=1}^{M}\lambda_k\lvert v_k\rangle\langle v_k\rvert
    • (This is the eigen-decomposition route of Method B in Section 2. Strictly, the eigenvalues of H^\hat{\mathbf{H}} are ilog⁡i\log of the eigenvalues of A\mathbf{A}, while the eigenvectors are shared.)

4. HHL Algorithm

🎙️ Not covered in class (Nov 10) and not in the final. Kept here for completeness.

Linear Equation Systems

  • A linear equation system (LES) is a collection of two or more equations involving the same set of variables:

a1,1x1+⋯+a1,NxN=b1⋯aM,1x1+⋯+aM,NxN=bMa_{1,1}x_1 + \dots + a_{1,N}x_N = b_1 \quad\cdots\quad a_{M,1}x_1 + \dots + a_{M,N}x_N = b_M

  • where each ai,ja_{i,j} is a coefficient
  • An LES can be rewritten in matrix form: Ax=b\boxed{\mathbf{Ax} = \mathbf{b}}, where A\mathbf{A} is the coefficient matrix and we want to solve for x\mathbf{x}
  • Three ways to solve an LES:
    • Matrix inverse: x=A−1b\mathbf{x} = \mathbf{A}^{-1}\mathbf{b}, but not all matrices are invertible
    • Gaussian elimination: solve by hand in O(N3)O(N^3) time
    • Eigen-decomposition: find the dominant eigenvalue λ\lambda of A\mathbf{A}, so that A−1v=v/λ\mathbf{A}^{-1}\mathbf{v} = \mathbf{v}/\lambda, A−1(Ax)=(Ax)/λ\mathbf{A}^{-1}(\mathbf{Ax}) = (\mathbf{Ax})/\lambda, ∴x=b/λ\therefore \mathbf{x} = \mathbf{b}/\lambda

Solving LES with Quantum Computing

  • For speed-up via quantum computing, we want to convert A\mathbf{A} to a Hermitian matrix and b\mathbf{b} to a quantum state
  • Hermitian embedding: build a Hermitian matrix (i.e. A=A∗\mathbf{A} = \mathbf{A}^*) by putting A\mathbf{A} in a Hermitian block:

A^=[0AA∗0]A^[0x]=[b0]\hat{\mathbf{A}} = \begin{bmatrix}0 & \mathbf{A}\\ \mathbf{A}^* & 0\end{bmatrix} \qquad \hat{\mathbf{A}}\begin{bmatrix}0\\ \mathbf{x}\end{bmatrix} = \begin{bmatrix}\mathbf{b}\\ 0\end{bmatrix}

  • Block encoding: we can also construct a polynomial block out of A\mathbf{A}:

A^=[poly(A)⋅⋅⋅]\hat{\mathbf{A}} = \begin{bmatrix}\mathrm{poly}(\mathbf{A}) & \cdot\\ \cdot & \cdot\end{bmatrix}

  • and encode b\mathbf{b} as an amplitude vector b^=∑k=02N−1bk∣BL(k)⟩\hat{\mathbf{b}} = \sum_{k=0}^{2^N-1} b_k\lvert\mathbb{B}_L(k)\rangle
  • The LES becomes A^x=b^\hat{\mathbf{A}}\mathbf{x} = \hat{\mathbf{b}}
  • Block encoding is numerically more stable than Hermitian embedding

📝 Instructor's annotation: he underlined "more stable" in green.

Harrow–Hassidim–Lloyd Algorithm (HHL)

  • The HHL algorithm solves an LES of NN equations and NN variables using QPE
  • A Hermitian matrix A^\hat{\mathbf{A}} can be rewritten with eigen-pairs (λk,∣vk⟩)(\lambda_k, \lvert v_k\rangle): A=∑k=0N−1λk∣vk⟩⟨vk∣\mathbf{A} = \sum_{k=0}^{N-1}\lambda_k\lvert v_k\rangle\langle v_k\rvert
  • Rewrite b\mathbf{b} and x\mathbf{x} in terms of the eigenvectors:

∣b⟩=1∣b∣∑k=0N−1bk∣BL(k)⟩=∑k=0N−1βk∣vk⟩∣x⟩=1∣x∣∑k=0N−1xk∣BL(k)⟩=∑k=0N−1γk∣vk⟩\lvert b\rangle = \frac{1}{|\mathbf{b}|}\sum_{k=0}^{N-1} b_k\lvert\mathbb{B}_L(k)\rangle = \sum_{k=0}^{N-1}\beta_k\lvert v_k\rangle \qquad \lvert x\rangle = \frac{1}{|\mathbf{x}|}\sum_{k=0}^{N-1} x_k\lvert\mathbb{B}_L(k)\rangle = \sum_{k=0}^{N-1}\gamma_k\lvert v_k\rangle

  • Since A^\hat{\mathbf{A}} may not be unitary, convert it with block encoding: U=BLOCK(A)\mathbf{U} = \mathrm{BLOCK}(\mathbf{A})
  • Step 1: initialize: ∣ψ1⟩=∣0⟩⊗(∑kβk∣vk⟩)⊗∣0⟩⊗L⊗∣0⟩\lvert\psi_1\rangle = \lvert 0\rangle\otimes\left(\sum_k\beta_k\lvert v_k\rangle\right)\otimes\lvert 0\rangle^{\otimes L}\otimes\lvert 0\rangle
  • Step 2: extract the eigenvalues: ∣ψ2⟩=QPE(U)1,2(3)∣ψ1⟩=(∑kβk∣0,vk⟩⊗∣λk⟩)⊗∣0⟩\lvert\psi_2\rangle = \mathrm{QPE}(\mathbf{U})^{(3)}_{1,2}\lvert\psi_1\rangle = \left(\sum_k\beta_k\lvert 0, v_k\rangle\otimes\lvert\lambda_k\rangle\right)\otimes\lvert 0\rangle

HHL Algorithm (cont'd)

  • Step 3: compute the filter flag of λk\lambda_k by a conditional rotation on the last qubit, controlled by each qubit of ∣λk⟩\lvert\lambda_k\rangle:

∣ψ3⟩=∏j=1LCY2@3,3(3)∣ψ2⟩=∑k=0N−1βk∣0,vk⟩⊗∣λk⟩⊗∣ck⟩\lvert\psi_3\rangle = \prod_{j=1}^{L}\mathrm{CY}^{(3)}_{2@3,3}\lvert\psi_2\rangle = \sum_{k=0}^{N-1}\beta_k\lvert 0, v_k\rangle\otimes\lvert\lambda_k\rangle\otimes\lvert c_k\rangle

  • where ∣ck⟩\lvert c_k\rangle is the filter flag of λk\lambda_k and CC is a normalizing constant:

∣ck⟩=1−C2λk2∣0⟩+Cλk∣1⟩\lvert c_k\rangle = \sqrt{1 - \frac{C^2}{\lambda_k^2}}\lvert 0\rangle + \frac{C}{\lambda_k}\lvert 1\rangle

  • Step 4: disentangle the eigenvalues from the input with inverse QPE: ∣ψ4⟩=QPE∗(U)1,2(3)∣ψ3⟩=∑kβk∣0,vk⟩⊗∣0⟩⊗L⊗∣ck⟩\lvert\psi_4\rangle = \mathrm{QPE}^*(\mathbf{U})^{(3)}_{1,2}\lvert\psi_3\rangle = \sum_k\beta_k\lvert 0, v_k\rangle\otimes\lvert 0\rangle^{\otimes L}\otimes\lvert c_k\rangle
  • Step 5: we want x≈∑kb/λk\mathbf{x} \approx \sum_k \mathbf{b}/\lambda_k. Measure the last qubit, c∼⟨X(ψ4@4)⟩c \sim \langle\mathbf{X}(\psi_4^{@4})\rangle, and post-select only c=1c = 1. If c=0c = 0, go back to Step 1 and resample ∣ψ4⟩\lvert\psi_4\rangle

HHL Algorithm (cont'd): Result

  • Step 6: after some iterations we obtain ∣ψ5⟩=(∑kβkλk∣0,vk⟩)⊗∣0⟩⊗L⊗∣1⟩\lvert\psi_5\rangle = \left(\sum_k\frac{\beta_k}{\lambda_k}\lvert 0, v_k\rangle\right)\otimes\lvert 0\rangle^{\otimes L}\otimes\lvert 1\rangle
  • Step 7: for the solution of the LES, measure its first LL qubits:

x≈∑k=0N−1βkλk∣vk⟩\mathbf{x} \approx \sum_{k=0}^{N-1}\frac{\beta_k}{\lambda_k}\lvert v_k\rangle

  • Time complexity of HHL: O(κ2log⁡N)\boxed{O(\kappa^2\log N)}, where NN is the number of variables and κ=λmax⁡/λmin⁡\kappa = \lambda_{\max}/\lambda_{\min} is the condition number of A\mathbf{A}
  • Figure 14: ∣b⟩\lvert b\rangle → QPE(U) → (CY rotations onto the flag qubit ∣0⟩\lvert 0\rangle, controlled by ∣λ⟩\lvert\lambda\rangle) → QPE*(U) → post-select flag =∣1⟩= \lvert 1\rangle → read ∣x⟩\lvert x\rangle

Implementation of HHL Algorithm in PennyLane

# Linear equation system:
# 2a + 3b - 4c + 5d = 70
# -3a + b + 2c + 0d = 50
#   a + 2b + 3c + d = 60
# 2a + 2b + 2c + 3d = 40
mat = np.array([ [ 2, 3, -4, 5],
                 [-3, 1, 2, 0],
                 [ 1, 2, 3, 1],
                 [ 2, 2, 2, 3] ], dtype=np.complex128)
bvec = np.array([70, 50, 60, 40], dtype=np.complex128)
 
extra_wires = ['x']
target_wires = ['t0','t1']
estimation_wires = ['e1','e2','e3','e4','e5']
check_wires = ['f']
 
dev = qml.device('default.qubit',
                 wires=extra_wires + target_wires + estimation_wires + check_wires)
 
def normalize_les(mat, bvec):
    norm_a = np.max(np.linalg.svd(mat)[1])
    norm_b = np.linalg.norm(bvec)
    return mat / norm_a, bvec / norm_b

Implementation of HHL Algorithm in PennyLane (cont'd)

@qml.qnode(dev, shots=1000)
def hhl_circuit(mat, bvec):
    mat, bvec = normalize_les(mat, bvec)                # Normalize A and b
    qml.AmplitudeEmbedding(bvec, wires=target_wires)    # Initialize the circuit with b
    qml.QuantumPhaseEstimation(                         # Extract eigenvalues with block encoding
        qml.BlockEncode(mat, wires=extra_wires + target_wires),
        estimation_wires=estimation_wires               # We need an extra qubit for block encoding
    )
    qml.ControlledSequence(                             # Compute the filter flag and the
        qml.Y(wires=check_wires),                       # inverse of eigenvalues
        control=estimation_wires
    )
    qml.adjoint(qml.QuantumPhaseEstimation)(            # Clean up the qubitization
        qml.BlockEncode(mat, wires=extra_wires + target_wires),
        estimation_wires=estimation_wires
    )
    m = qml.measure(wires=check_wires, postselect=1)    # Redo if the check flag is 0
    return qml.probs(wires=target_wires)
 
hhl_circuit(mat, bvec)
# Solution is a unit vector for each variable
# Result: [0.0, 0.40, 0.25, 0.35 ] -> a = 0, b = 0.4, c = 0.25, d = 0.35

Exercise 7.6: HHL Algorithm

  1. We learned that one extra qubit is needed for the block encoding. Compare the pros and cons of this against Hermitian embedding
  2. Suppose we have an LES Ax=b\mathbf{Ax} = \mathbf{b}, and A\mathbf{A} is eigen-decomposed to A=∑k=0N−1λk∣vk⟩⟨vk∣\mathbf{A} = \sum_{k=0}^{N-1}\lambda_k\lvert v_k\rangle\langle v_k\rvert. Explain why we use QPE in the HHL algorithm and why we can extract the eigenvalues λk\lambda_k with it
  3. Discuss why we have to disentangle the eigenvalues from the input using the inverse QPE. What will happen if we don't?
  4. Consider the filter flag in Step 3, ∣ck⟩=1−C2λk2∣0⟩+Cλk∣1⟩\lvert c_k\rangle = \sqrt{1 - \frac{C^2}{\lambda_k^2}}\lvert 0\rangle + \frac{C}{\lambda_k}\lvert 1\rangle, where CC is a normalizing constant. Explain why we post-select ck=1c_k = 1 and ignore ck=0c_k = 0

5. Conclusion

Conclusion

  • System dynamics is a math model for representing the non-linear behavior of a complex system
  • A quantum finite-state automaton represents such non-linear behavior, and its state transition is given by the quantum walk operator
  • Quantum simulation of system dynamics yields a path lattice, and we can observe its paths by measurement
  • However, quantum simulation is expensive. For short simulation, we trotterize the walk operator to estimate the final results
  • For a long simulation, trotterization is inaccurate, so we qubitize the walk operator instead
  • One application of simulation is solving a linear equation system (LES), which reduces the time complexity from classical O(N3)O(N^3) to quantum O(κ2log⁡N)O(\kappa^2\log N)

📝 Instructor's annotation: "trotterize" and "qubitize" are underlined.

Questions?

Target Learning Outcomes/1

  • Quantum Finite-State Automaton (QFA)
    1. Contrast deterministic, probabilistic, and quantum finite-state automata in terms of their state transitions and mathematical definitions
    2. Apply Szegedy's Algorithm to convert a Probabilistic Finite-State Automaton (PFA) into its quantum equivalent (QFA) by constructing the necessary diffusion and reflection matrices
    3. Implement a QFA circuit using PennyLane to simulate state transitions for a given input sequence
  • Quantum System Dynamics and Simulation
    1. Define the Hamiltonian of a quantum walk operator and explain how it simplifies complex matrix multiplications into additions
    2. Execute the conversion of a quantum operator into a Hamiltonian using the Pauli decomposition method (Linear Combination of Unitaries) ← Final Q6
    3. Evaluate the trade-offs between Trotter–Suzuki Decomposition for short-term simulations and the Qubitization Algorithm for high-accuracy, long-term simulations

Target Learning Outcomes/2

  • Polynomial Functions and Signal Processing
    1. Explain the role of Quantum Signal Processing (QSP) in computing polynomial functions through signal and rotation operators
    2. Analyze Quantum Singular Value Transformation (QSVT) as a method to transform a Hamiltonian via a polynomial function
    3. Construct quantum circuits that implement Generalized QSP (GQSP) and QSVT using block encoding and projector-controlled phase gates
  • HHL Algorithm for Linear Systems
    1. Formulate a Linear Equation System (LES) in a format suitable for quantum computation using Hermitian embedding or block encoding
    2. Illustrate the step-by-step mechanics of the Harrow–Hassidim–Lloyd (HHL) algorithm, including eigenvalue extraction via QPE, conditional rotation, and post-selection
    3. Compare the time complexity of classical Gaussian elimination against the quantum HHL algorithm