Documentation

CslibFrontier.Computability.Circuit.Quantum.PathNetwork

The acceptance gap of a circuit as a tensor contraction #

The acceptance gap of a list of gate codes (Cslib.Quantum.acceptGap) is the contraction of an explicit Boolean tensor network (Cslib.Quantum.PathNetwork.network) built from the circuit and a mirror copy of it (Cslib.Quantum.PathNetwork.contraction_network). More generally, for a list S of measured qubits, the network computes the projected gap Cslib.Quantum.onesGap S of the event that every qubit of S reads 1; acceptance is the case S = [0]. This is the form in which the contraction algorithm of [OAI26k], Theorem D.1, simulates quantum circuits exactly.

Occurrences. The qubits of a gate code are its target and then its controls (Cslib.Quantum.PathNetwork.qubits). Listing them gate by gate numbers the occurrences 0, …, N - 1 of qubits in gates (Cslib.Quantum.PathNetwork.occurrences); gate i owns the occurrences from base gs i on. The last occurrence of qubit j before position p (Cslib.Quantum.PathNetwork.lastOcc) is where the value of j entering position p was written.

The network. It has two copies, c = 0 and c = 1, of the circuit. In copy c, occurrence u has the segment c N + u, with an out edge 2 (c N + u) and a link edge 2 (c N + u) + 1, so there are 4 N edges.

So every edge joins a row to a column, every vertex has at most six ports, and untouched qubits cost nothing. The gate tables are bounded tables for the degree bound six (Cslib.Circuits.Frontier.ExplicitTensorNetwork.boundedTable). With neg = -1, an assignment of nonzero weight is a pair of paths of the path sum (Cslib.Quantum.pathRun) ending in the same register with every measured qubit equal to one, and its weight is the product of their signs, so the contraction is onesGap S (Cslib.Quantum.PathNetwork.contraction_network). The network is defined for any value neg of the Hadamard sign, so that over ℕ it can carry 2 ^ P - 1, which is -1 modulo 2 ^ P (Cslib.Quantum.PathNetwork.contraction_network_mod).

Main definitions #

Main results #

References #

Occurrences #

The qubits of a gate code: its target, then its controls.

The occurrences of qubits in a list of gate codes, gate by gate.

The number of the first occurrence of gate i.

The last occurrence of the qubit j before position p in the occurrence list qs.

Tensors and vertices #

def Cslib.Quantum.PathNetwork.gateEntry {R : Type u_1} [Zero R] [One R] (neg : R) (g : GateCode) (ins outs : List Bool) :
R

The tensor of the gate code g at the bits ins entering and outs leaving its qubits. For the Hadamard gate it is neg when the target enters and leaves as one, and 1 otherwise; for a classical gate it is 1 when the outputs are the gate applied to the inputs, and 0 otherwise.

The port at which a gate with first occurrence b reads the qubit j in copy c: the link edge of the last earlier occurrence of j, or none when the gate reads j from the input.

The ports of gate i in copy c: the out edges of its occurrences, then its input ports.

The bit entering qubit j of gate i in copy c at the table position idx: the input bit of j, or the bit of its input port.

def Cslib.Quantum.PathNetwork.gateVertex {R : Type u_1} [Zero R] [One R] (neg : R) (X : List Bool) (gs : List GateCode) (c i : ℕ) :

The vertex of gate i in copy c, for the input register X.

The table on two ports that requires both bits to be one.

def Cslib.Quantum.PathNetwork.glueVertex {R : Type u_1} [Zero R] [One R] (S : List ℕ) (gs : List GateCode) (w : ℕ) :

The glue vertex of occurrence w, for the list S of measured qubits: when w is the last occurrence of its qubit, it joins the link edges of w in the two copies, requiring equal bits, and both bits one for a qubit of S.

The scalar vertex: it requires the input bit of every qubit of S that no gate touches to be one.

The network of a circuit with the measured qubits S, the input register X and the Hadamard sign neg, with its number of rows: the gate vertices of the two copies, the glue vertices and the scalar vertex, then the segment vertices.

Runs along the occurrences #

Last occurrences #

theorem Cslib.Quantum.PathNetwork.lastOcc_succ (qs : List ℕ) (j p : ℕ) :
lastOcc qs j (p + 1) = if qs.getD p 0 = j then some p else lastOcc qs j p
theorem Cslib.Quantum.PathNetwork.lastOcc_eq_some {qs : List ℕ} {j p w : ℕ} (h : lastOcc qs j p = some w) :
w < p ∧ qs.getD w 0 = j ∧ ∀ (w' : ℕ), w < w' → w' < p → qs.getD w' 0 ≠ j

The last occurrence of j before p is an occurrence of j before p, and no later occurrence before p is one of j.

theorem Cslib.Quantum.PathNetwork.lastOcc_eq_none {qs : List ℕ} {j p : ℕ} :
lastOcc qs j p = none ↔ ∀ w < p, qs.getD w 0 ≠ j

There is no occurrence of j before p exactly when no position before p holds j.

Occurrences of gates #

theorem Cslib.Quantum.PathNetwork.base_succ {gs : List GateCode} {i : ℕ} (hi : i < gs.length) :
base gs (i + 1) = base gs i + (qubits (gs.getD i default)).length
theorem Cslib.Quantum.PathNetwork.getD_occurrences {gs : List GateCode} {i k : ℕ} (hi : i < gs.length) (hk : k < (qubits (gs.getD i default)).length) :
(occurrences gs).getD (base gs i + k) 0 = (qubits (gs.getD i default)).getD k 0

The occurrence k of gate i is its qubit k.

Registers along the occurrences #

Entries of the vertices #

A gate vertex has at most twice as many ports as its gate has qubits.

The final registers #

The contraction #

A well-formed gate code has at most three qubits.

theorem Cslib.Quantum.PathNetwork.contraction_network {R : Type u_1} [CommRing R] (S : List ℕ) (X : List Bool) (gs : List GateCode) (hgs : ∀ g ∈ gs, GateCode.WellFormed X.length g) :
(network (-1) S X gs).2.contraction = ↑(onesGap S gs X)

The contraction of the network is the projected gap. With -1 as the Hadamard sign, over any commutative ring, the contraction of the network of well-formed gate codes with the measured qubits S on the input register X is onesGap S gs X; for S = [0] it is the acceptance gap Cslib.Quantum.acceptGap.

Residues of the contraction over ℕ #

theorem Cslib.Quantum.PathNetwork.network_mapTables {R : Type u_1} {R' : Type u_2} [CommSemiring R] [CommSemiring R'] (ψ : R →+* R') (neg : R) (S : List ℕ) (X : List Bool) (gs : List GateCode) :
Circuits.Frontier.ExplicitTensorNetwork.mapTables (⇑ψ) (network neg S X gs).2 = (network (ψ neg) S X gs).2

Mapping the tables maps the Hadamard sign.

theorem Cslib.Quantum.PathNetwork.contraction_network_mod (S : List ℕ) (X : List Bool) (gs : List GateCode) (hgs : ∀ g ∈ gs, GateCode.WellFormed X.length g) {P : ℕ} (hP : hadamardCount gs < P) :
(network (2 ^ P - 1) S X gs).2.contraction % 2 ^ P = (onesGap S gs X).toNat

The residue of the contraction over ℕ is the projected gap. With 2 ^ P - 1, which is -1 modulo 2 ^ P, as the Hadamard sign, and P larger than the number of Hadamard gates, the contraction of the network of well-formed gate codes with the measured qubits S on the input register X, reduced modulo 2 ^ P, is the projected gap.

Sizes #

Every gate has at least one and at most three occurrences.

@[simp]
theorem Cslib.Quantum.PathNetwork.fst_network {R : Type u_1} [Zero R] [One R] (neg : R) (S : List ℕ) (X : List Bool) (gs : List GateCode) :
(network neg S X gs).1 = 2 * gs.length + (occurrences gs).length + 1
@[simp]
theorem Cslib.Quantum.PathNetwork.numEdges_network {R : Type u_1} [Zero R] [One R] (neg : R) (S : List ℕ) (X : List Bool) (gs : List GateCode) :
(network neg S X gs).2.numEdges = 2 * (2 * (occurrences gs).length)

Four edges per occurrence.

@[simp]
theorem Cslib.Quantum.PathNetwork.length_vertices_network {R : Type u_1} [Zero R] [One R] (neg : R) (S : List ℕ) (X : List Bool) (gs : List GateCode) :
(network neg S X gs).2.vertices.length = 2 * gs.length + 3 * (occurrences gs).length + 1
theorem Cslib.Quantum.PathNetwork.maxDegree_network_le {R : Type u_1} [Zero R] [One R] (neg : R) (S : List ℕ) (X : List Bool) {gs : List GateCode} (hgs : ∀ g ∈ gs, (qubits g).length ≤ 3) :
(network neg S X gs).2.maxDegree ≤ 6

Degree at most six: a gate vertex has at most two ports per qubit, and the other vertices at most two ports.

theorem Cslib.Quantum.PathNetwork.length_table_network {R : Type u_1} [Zero R] [One R] (neg : R) (S : List ℕ) (X : List Bool) {gs : List GateCode} (hgs : ∀ g ∈ gs, (qubits g).length ≤ 3) (v : List ℕ × List R) :
v ∈ (network neg S X gs).2.vertices → v.2.length = 2 ^ v.1.length

Full tables: every table lists 2 ^ (number of ports) entries.

The bipartition #

theorem Cslib.Quantum.PathNetwork.lastOcc_eq_some_of {qs : List ℕ} {j p w : ℕ} (hw : w < p) (hwj : qs.getD w 0 = j) (hnext : ∀ (w' : ℕ), w < w' → w' < p → qs.getD w' 0 ≠ j) :
lastOcc qs j p = some w

The converse of lastOcc_eq_some.

theorem Cslib.Quantum.PathNetwork.base_mono (gs : List GateCode) {i i' : ℕ} (h : i ≤ i') :
base gs i ≤ base gs i'
theorem Cslib.Quantum.PathNetwork.exists_base_le_lt {gs : List GateCode} {p : ℕ} (hp : p < (occurrences gs).length) :
∃ i < gs.length, base gs i ≤ p ∧ p < base gs (i + 1)

The gate of an occurrence: every occurrence lies in one gate.

theorem Cslib.Quantum.PathNetwork.eq_of_base_le_lt {gs : List GateCode} {p i i' : ℕ} (h1 : base gs i ≤ p) (h2 : p < base gs (i + 1)) (h1' : base gs i' ≤ p) (h2' : p < base gs (i' + 1)) :
i = i'
theorem Cslib.Quantum.PathNetwork.mem_qubits_iff {gs : List GateCode} {i : ℕ} (hi : i < gs.length) (q : ℕ) :
q ∈ qubits (gs.getD i default) ↔ ∃ k < (qubits (gs.getD i default)).length, (occurrences gs).getD (base gs i + k) 0 = q

Gate i holds the qubit q exactly when one of its occurrences does.

theorem Cslib.Quantum.PathNetwork.sum_readers {gs : List GateCode} (hnd : ∀ g ∈ gs, (qubits g).Nodup) {u : ℕ} (hu : u < (occurrences gs).length) :
((List.map (fun (i : ℕ) => if (occurrences gs).getD u 0 ∈ qubits (gs.getD i default) ∧ lastOcc (occurrences gs) ((occurrences gs).getD u 0) (base gs i) = some u then 1 else 0) (List.range gs.length)).sum + if lastOcc (occurrences gs) ((occurrences gs).getD u 0) (occurrences gs).length = some u then 1 else 0) = 1

The reader of a link edge. Let u be an occurrence of the qubit q. If u is the last occurrence of q, no gate reads q from u; otherwise exactly one gate does, the gate of the next occurrence of q.

A gate whose qubits are distinct has distinct ports: the out edges are distinct and even, and the input ports are distinct and odd, since distinct qubits have distinct last occurrences.

theorem Cslib.Quantum.PathNetwork.isRowsFirstBipartite_network {R : Type u_1} [Zero R] [One R] (neg : R) (S : List ℕ) (X : List Bool) {gs : List GateCode} (hnd : ∀ g ∈ gs, (qubits g).Nodup) :

The network is rows-first bipartite with the gate, glue and scalar vertices as rows, when the qubits of every gate are distinct.