Docsity

Quantum Programming Languages in the Classically Controlled Quantum Computing Model, Lecture notes of Programming Languages

Toggle sidebar
bg1
CS231 (Spring 2022)
Quantum Programming Languages
WILLIAM MCINROY, Harvard University, USA
We provide a brief survey into the quantum computational model of “classically controlled quantum
circuits”, a generalization of the quantum circuit model of quantum computation, and quantum
programming languages (QPLs) within this paradigm. Specifically, we focus on the categorical
semantics of QPLs in the classically controlled quantum computing model, and particularly those
semantics related to the teleportation protocol.
Additional Key Words and Phrases: Quantum Computing, Category Theory,Programming Languages
1 INTRODUCTION
There are many different models of quantum computation, one of the more popular being
quantum circuits, used for instance in the open source framework
Qiskit
[Aleksandrowicz
et al
.
2019]. However, one problem with the quantum circuit paradigm for programming
is the lack of classical control, or the modification of the quantum circuit based on classical
computation. Of course, classical control can be simulated in the quantum circuit paradigm,
for instance by the introduction of a quantum oracle of a classical function, but these often
require an unwieldy number of gates and ancillary qubits to perform the computation [Fu
et al. 2020].
Here, we study classically controlled quantum computing (CCQC), a paradigm arising from
the teleportation protocol [Bennett et al
.
1993], the QRAM machine [Knill 1996], and the
logic-gate teleportation protocol [Gottesman and Chuang 1999], the later of which is shown
to be a primitive for CCQC. In CCQC, the flow (any branchings) of the computation is
handled by a classical computer, while processing without branches can be done either
classically or quantumly. In comparison, quantum circuits do not describe control flow
whereas quantum turing machines [Benioff 1982] quantumly describe control flow as well.
It is widely thought that CCQC is the most practical paradigm for a real-life quantum
computer [Knill 1996].
We are interested in studying quantum programming languages (QPLs) for CCQC, as such
languages aim to provide both a useful syntax for conversion of theoretical quantum algo-
rithms to runnable code, confirm that a described program is well-formed (does not violate
classical or quantum laws) through type-checking, and potentially an easier conversion of
classical algorithms to the quantum domain.
An interpretation of programming languages is the compilation of syntax (code) to se-
mantics (a process of quantum and classical gates). A typical framework for studying the
semantics of a programming language is within the context of category theory. The first
formal treatment of CCQC in relation to QPLs is the language
QPL
[Selinger 2004], al-
though
QPL
is notably low-level, the syntax captures only the primitives of bits, qubits, and
primitve operations between the two, but lacks the typical abstractions found in classical
programming languages. Within [Selinger and Valiron 2009], a quantum simply-typed
λ
-calculus is developed, allowing for some such abstractions, but specified no matching
categorical semantics to compile this syntax to. These semantics were finally uncovered in
full within [Malherbe et al
.
2013], eventually leading to the
Quipper
family of languages [Fu
et al. 2020,2022a,b;Green et al. 2013].
We will not attempt to survey all of the categorical semantic conditions covered in
[Malherbe et al
.
2013;Selinger and Valiron 2009], instead we will focus on an example of
the semantics necessary for the teleportation protocol, as in [Abramsky and Coecke 2004].
pf3
pf4
pf5

Partial preview of the text

Download Quantum Programming Languages in the Classically Controlled Quantum Computing Model and more Lecture notes Programming Languages in PDF only on Docsity!

CS231 (Spring 2022)

Quantum Programming Languages

WILLIAM MCINROY, Harvard University, USA

We provide a brief survey into the quantum computational model of “classically controlled quantum circuits”, a generalization of the quantum circuit model of quantum computation, and quantum programming languages (QPLs) within this paradigm. Specifically, we focus on the categorical semantics of QPLs in the classically controlled quantum computing model, and particularly those semantics related to the teleportation protocol.

Additional Key Words and Phrases: Quantum Computing, Category Theory, Programming Languages

1 INTRODUCTION

There are many different models of quantum computation, one of the more popular being quantum circuits, used for instance in the open source framework Qiskit [Aleksandrowicz et al. 2019]. However, one problem with the quantum circuit paradigm for programming is the lack of classical control, or the modification of the quantum circuit based on classical computation. Of course, classical control can be simulated in the quantum circuit paradigm, for instance by the introduction of a quantum oracle of a classical function, but these often require an unwieldy number of gates and ancillary qubits to perform the computation [Fu et al. 2020]. Here, we study classically controlled quantum computing (CCQC), a paradigm arising from the teleportation protocol [Bennett et al. 1993], the QRAM machine [Knill 1996], and the logic-gate teleportation protocol [Gottesman and Chuang 1999], the later of which is shown to be a primitive for CCQC. In CCQC, the flow (any branchings) of the computation is handled by a classical computer, while processing without branches can be done either classically or quantumly. In comparison, quantum circuits do not describe control flow whereas quantum turing machines [Benioff 1982] quantumly describe control flow as well. It is widely thought that CCQC is the most practical paradigm for a real-life quantum computer [Knill 1996]. We are interested in studying quantum programming languages (QPLs) for CCQC, as such languages aim to provide both a useful syntax for conversion of theoretical quantum algo- rithms to runnable code, confirm that a described program is well-formed (does not violate classical or quantum laws) through type-checking, and potentially an easier conversion of classical algorithms to the quantum domain. An interpretation of programming languages is the compilation of syntax (code) to se- mantics (a process of quantum and classical gates). A typical framework for studying the semantics of a programming language is within the context of category theory. The first formal treatment of CCQC in relation to QPLs is the language QPL [Selinger 2004], al- though QPL is notably low-level, the syntax captures only the primitives of bits, qubits, and primitve operations between the two, but lacks the typical abstractions found in classical programming languages. Within [Selinger and Valiron 2009], a quantum simply-typed λ -calculus is developed, allowing for some such abstractions, but specified no matching categorical semantics to compile this syntax to. These semantics were finally uncovered in full within [Malherbe et al. 2013], eventually leading to the Quipper family of languages [Fu et al. 2020, 2022a,b; Green et al. 2013]. We will not attempt to survey all of the categorical semantic conditions covered in [Malherbe et al. 2013; Selinger and Valiron 2009], instead we will focus on an example of the semantics necessary for the teleportation protocol, as in [Abramsky and Coecke 2004].

2 William McInroy

2 TELEPORTATION PROTOCOLS

We now summarize the teleportation protocol [Bennett et al. 1993] to motivate classically controlled quantum computing, and to eventually express the necessary primitives of a QPL. Typically, this protocols is presented with Alice and Bob characters. Here, we have instead described them in a manner to illustrate their relation to QPLs. The teleportation protocol considers of three qubits, say on registers A, B, C, with the qubit in register A having arbitrary state | ψ ⟩A and both other registers set to | 0 ⟩. The goal of the protocol is to terminate computation with the B-register qubit in the state A naive solution, based on the assumption we can reproduce the state | ψ ⟩A many times, is to measure | ψ ⟩A in the computation basis many times, store the results of the measurements, and prep the B-register to an approximation of | ψ ⟩, then perform whichever measurements we would like on | ψ ⟩A. However, the teleportation protocol does not assume that | ψ ⟩ may be reproduced many times, and requires only one iteration. It also importantly does not violate the no-cloning principle of a map | ψ ⟩A ⊗ | 0 ⟩B ̸→ | ψ ⟩A ⊗ | ψ ⟩B. Instead, the teleportation protocol makes use of classical control.

Definition 2.1 (Teleportation Protocol). The teleportation protocol on 1 -qubit consists of the steps (0) Start in the state | ψ ⟩A ⊗ | 00 ⟩BC. (1) Prepare the BC-registers into a Bell state √^12 (| 00 ⟩BC + | 11 ⟩BC ). (2) Measure the AC-registers in the Bell basis,

|b 00 ⟩ =

(| 00 ⟩AC + | 11 ⟩AC ), |b 01 ⟩ =

(| 00 ⟩AC − | 11 ⟩AC ),

|b 10 ⟩ =

(| 01 ⟩AC + | 10 ⟩AC ), |b 11 ⟩ =

(| 01 ⟩AC − | 10 ⟩AC ),

while classically storing the measurement outcome o corresponding to |bo ⟩. (3) Based on the outcome o, apply one of the following operators to the B-register,

U 00 =

U 01 =

U 10 =

U 11 =

(4) Now the B-register has state | ψ ⟩B. This protocol may be repeated for teleportation of multiple qubits.

End of Definition 2. We won’t prove why it is the case that the teleportation protocol is capable of both measuring | ψ ⟩A while producing | ψ ⟩B 1. Instead, the takeaway of this example is that an adjustment of the quantum circuit dependent on classical control flow is convenient in algorithms, but the fundamental differences of the two computing domains require programming languages to distinguish the domains.

(^1) A measurement of bo places the state Uo | ψ ⟩ in the B-register, which is undone by another application of Uo. This may be checked by the expansion of the joint ABC-qubit state in the computational basis.

4 William McInroy

4 PRIMITIVES FROM TELEPORTATION

We now specify a fragment of a λ -calculus syntax to implement the teleportation protocol of Section 2, typical quantum circuit operations (for our cases, we’ll assume arbitrary unitaries and computational base measurements), typical classical operations, and notably we must take care to not violate any quantum (or classical principles). This λ -calculus fragment is distilled from the work of [Selinger 2004; Selinger and Valiron 2009], and its categorical semantics are analyzed in line with [Abramsky and Coecke 2004].

4.1 Data Types The teleportation protocol (Definition 2.1) on arbitrary qubits clearly requires any QPL implementing the protocol to have the types of bit and qubit (henceforth abbreviated qbit), as well as arbitrary combinations and functions between these types. In abstract syntax terms,

Types T := bit | qbit | T 1 × T 2 | T 1 + T 2. (4.1) To this end, we recall that qbit may be thought of a density matrix over C ⊗ C , and by analogy classical bits may be thought of as a pair of two matrices over C , i.e. 0 7 → (id, 0) and 1 7 → (0, id). We can then encode all of the types of Equation 4.1 within the category VectC of (finite dimensional) C -vector spaces and C -linear maps. Precisely, we may represent a type as a list of (positive, power of 2) natural numbers n 1 ,... , nm rorresponding to the vector space ⊗i≤m C n^1 ×n^1. Then bit = (1, 1) and qbit = ( 2 ). Then if T 1 = (n 1 ,... nm) and T 2 = (n′ 1 ,... , n′ m′ ), we define T 1 + T 2 = (n 1 ,... , nm, n′ 1 ,... , n′ m′ ) and T 1 × T 2 = (n 1 n′ 1 ,... , n 1 n′ m′ ,... nmn′ m′ ). As every ni is said to be a power of two, then we obtain a natural interpretation of a list ( 2 d) as a qudits. Then concatenated lists may be interpreted as collections of (unentangled) bits and qdits, and we seem to have captured the “ground” types necessary for our QPL. However, we have not yet discussed types T 1 → T 2 nor the important concept of dual vector spaces, which will represent the primitive quantum and classical operations as well as measurements. To this end, we note that there is additional structure than ⊗ used to correspond lists on VectC , namely the presence of dual-vector spaces 2 and the identification {maps V 1 → V 2 } ≃ V 1 ∗ ⊗ V 2. Thus we may incorporate to our types of Equation 4.1 the type forming operation T 1 → T 2 with categorical semantics of T 1 → T 2 = V 1 ∗ ⊗ V 2 ,

Types T := bit | qbit | T 1 × T 2 | T 1 + T 2 | T 1 → T 2. (4.2) So we have specified the types of our QPL necessary for the teleportation protocol. But we still haven’t specified the primitive computations of our QPL, and we cannot inherit these from VectC as there are many non-unitary or measurement morphisms, and thus non-unitary allowable terms in the syntax.

4.2 Primitive Computations To remedy the issues described at the end of Section 4.1, we now describe a modified typing category ℭ constructed from VectC to match the categorical semantics necessary for a QPL capable of performing the teleportation protocol. Firstly, before specifying ℭ, we recall the primitives we would like to define syntactically.

(^2) General categories with these properties are known as ∗-autonomous and compact closed categories.

Quantum Programming Languages 5

Computations f := f 1 + f 2 | f 1 × f 2 | (x : qbit) U · x → qbit | (x : qbit) meas x → bit + bit | (x : bit) init x → qbit | (x : bit) flip x → bit | (x : bit + bit) merge x → bit | (x : bit) copy x → bit + bit.

These computations simply express the types of computations we expect to be able to do with a CCQC. Now, we are prepared to define ℭ. The objects are the C -vector spaces of the form

⊗i≤m C^2

di (^) × 2 di and

⊗i≤m C^2

di (^) × 2 di^ ∗ ⊗

⊗i≤m′ C^2

d′ i (^) × 2 d′ i^  , (4.4)

for m, di, m′, d′ i natural numbers. Note that these are all of the vector spaces that are constructible from the lists considered by Equation 4.2. We will now define the generating set of morphisms of ℭ on single qbits, qdits, and bits, subject to the axioms of quantum mechanics. We note that the remaining generated morphisms of ℭ due to concatenation of lists generating these objects can be generated in a similar manner (via ⊗ or ∗^ on the morphisms themselves). We also use the shorthand Td^ = T × T × · · · × T and d · T = T + · · · + T for d repetitions of each type (and note qbitd^ = qdit). (i) The generating set of ℭ(qbitd, qbitd) are giveny conjugations of 2d-unitary maps,

U : C^2

d → C^2

d , ρ 7 → U ρ U†. (4.5)

(ii) The generating set of ℭ(qbitd, qbitd

′ ) for d ≠ d′^ is empty. (iii) The generating set of ℭ(qbitd, d · bit) is given by the 2d^ different maps corresponding to the 2d^ different measurement operators in the computational basis, and should be thought of inducing the quantum non-determinism branching. (iv) The generating set of ℭ(qbitd, d′^ · bit) for d ≠ d′^ is empty. (v) The generating set of ℭ(d · bit, qbitd

′ ) is given by the 2d^ different maps corresponding to the 2d^ different initializations of a qudit in the computational basis. (vi) The set of ℭ(d · bit, d′^ · bit) is VectC (( C^1 ×^1 )⊗^2 d, ( C^1 ×^1 )⊗^2 d

′ ). Then we obtain a semantic-syntactic correspondence (1) (i) and (ii) correspond to (x : qbit) U · x → qbit, (2) (iii) and (iv) correspond to (x : qbit) meas x → 2 · bit, (3) (v) corresponds to (x : bit) init x → qbit, (4) All C -linear maps of (vi) correspond to the purely-bit computations. We now have all of the necessary syntax and semantics to express the teleportation protocol. Notably, the protocol is of type qbit^3 → 4 · qbit^3 , where the 4 indicates the 4 possibilities due to branching caused by the measurement and quantum non-determinism.

Quantum Programming Languages 7

REFERENCES

Samson Abramsky and Bob Coecke. 2004. A categorical semantics of quantum protocols. In Proceedings of the 19th Annual IEEE Symposium on Logic in Computer Science, 2004. 415–425. https://doi.org/10.1109/LICS.2004. Gadi Aleksandrowicz, Thomas Alexander, Panagiotis Barkoutsos, Luciano Bello, Yael Ben-Haim, David Bucher, Francisco Jose Cabrera-Hernández, Jorge Carballo-Franquis, Adrian Chen, Chun-Fu Chen, and et al. 2019. Qiskit: An Open-source Framework for Quantum Computing. (Jan 2019). https://doi.org/10.5281/zenodo. Paul Benioff. 1982. Quantum mechanical Hamiltonian models of Turing machines. Journal of Statistical Physics 29 (11 1982), 515–546. https://doi.org/10.1007/BF Charles Bennett, Gilles Brassard, Claude Crépeau, Richard Jozsa, Asher Peres, and William Wootters. 1993. Teleporting an unknown quantum state via dual classical and Einstein-Podolsky-Rosen channels. Physical review letters 70 (04 1993), 1895–1899. https://doi.org/10.1103/PhysRevLett.70. Peng Fu, Kohei Kishida, Neil J. Ross, and Peter Selinger. 2020. A tutorial introduction to quantum circuit programming in dependently typed Proto-Quipper. CoRR abs/2005.08396 (2020). arXiv:2005.08396 https: //arxiv.org/abs/2005. Peng Fu, Kohei Kishida, Neil J. Ross, and Peter Selinger. 2022a. A biset-enriched categorical model for Proto- Quipper with dynamic lifting. https://doi.org/10.48550/ARXIV.2204. Peng Fu, Kohei Kishida, Neil J. Ross, and Peter Selinger. 2022b. Proto-Quipper with dynamic lifting. https: //doi.org/10.48550/ARXIV.2204. Daniel Gottesman and Isaak Chuang. 1999. Quantum Teleportation is a Universal Computational Primitive. ( 1999). Alexander Green, Peter LeFanu Lumsdaine, Neil J. Ross, Peter Selinger, and Benoît Valiron. 2013. Quipper: a Scalable Quantum Programming Language. In Proceedings of the 34th Annual ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2013, Seattle (ACM SIGPLAN Notices, Vol. 48(6)). 333–342. https://doi.org/10.1145/2499370. E Knill. 1996. Conventions for quantum pseudocode. (6 1996). https://doi.org/10.2172/ Octavio Malherbe, Philip Scott, and Peter Selinger. 2013. Presheaf Models of Quantum Computation: An Outline. (02 2013). https://doi.org/10.1007/978-3-642-38164-5_ Peter Selinger. 2004. Towards a Quantum Programming Language. Mathematical. Structures in Comp. Sci. 14, 4 (aug 2004), 527–586. https://doi.org/10.1017/S Peter Selinger and Benoît Valiron. 2009. Quantum Lambda Calculus. Cambridge University Press, 135–172. https://doi.org/10.1017/CBO9781139193313.