peter selinger- semantics of a quantum programming language
TRANSCRIPT
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
1/36
Semantics of a Quantum Programming Language
Peter Selinger
Dalhousie University
Halifax, Canada
1
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
2/36
Why Quantum Programming Languages?
For certain problems, quantum algorithms have anexponential speedup over best known classical algorithms.
Most research in quantum computing has focused onalgorithms and complexity theory.
Quantum algorithms are traditionally described in terms ofhardware: quantum circuits or quantum Turing machines.
Want compositionality. Also, how do quantum featuresinteract with other language features such as structured
data, recursion, i/o, higher-order.
2
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
3/36
Part I: Quantum Computation
3
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
4/36
The QRAM abstract machine [Knill96]
Classical device:
master
(general purpose)
Quantum device:
slave
control
results
General-purpose classical computer controls a specialquantum hardware device
Quantum device provides a bank of individually addressablequbits.
Left-to-right: instructions.
Right-to-left: results.4
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
5/36
Linear Algebra Review
Scalars C, column vectors u Cn, matrices A Cnm.
Adjoint A = (aji)ij, trace tr A = iaii, norm
A2 = ij |aij|2. Unitary matrix S Cnn if SS = I.
Change of basis: B = SAS
tr B = tr A, B = A.
Hermitian matrix A Cnn: if A = A.Hermitian positive: uAu 0 for all u Cn.Diagonalization: A = SDS, S unitary, D real diagonal.
Tensor product A B, e.g.
0 1
1 0
B =
0 B
B 0
.
5
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
6/36
Quantum computation: States
state of one qubit: |0
+ |1
(superposition of |0
and |1
).
state of two qubits: |00 + |01 +|10 + |11.
independent: (a|0 + b|1) (c|0 + d|1) =ac|00 + ad|01 + bc|10 + bd|11.
otherwise entangled.
6
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
7/36
Lexicographic convention
Identify the basis states |00, |01, |10, |11 with the standardbasis vectors
1
0
0
0
,
0
1
0
0
,
0
0
1
0
,
0
0
0
1
,
in the lexicographic order.
Note: we use column vectors for states.
= |00 + |01 +|10 + |11.
7
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
8/36
Quantum computation: Operations
unitary transformation
measurement
8
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
9/36
Some standard unitary gates
Unary: Binary:
N =
0 11 0
, Nc =
I 00 N
,
H = 12
1 1
1
1, Hc =
I 0
0 H,
V =
1 0
0 i
, Vc =
I 0
0 V
,
W =
1 0
0
i
, Wc =
I 0
0 W
, X =
1 0 0 0
0 0 1 0
0 1 0 0
0 0 0 1
.
9
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
10/36
Measurement
|0 + |1
||20
||21
|0 |1
10
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
11/36
Two Measurements|00 + |01 +|10 + |11
||2+||2
0
||2+||2
1
|00 + |01
||2
||2+||20 ||2
||2+||21
|10 + |11
||2
||2+||20 ||2
||2+||21
|00 |01 |10 |11
Note: Normalization convention.
11
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
12/36
Pure vs. mixed states
A mixed state is a (classical) probability distribution on
quantum states.
Ad hoc notation:
1
2
+
1
2
Note: A mixed state is a description of our knowledge of a
state. An actual closed quantum system is always in a (possiblyunknown) pure state.
12
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
13/36
Density matrices (von Neumann)
Represent the pure state v =
C2 by the matrix
vv
=
C2
2.
Represent the mixed state 1 {v1} + . . . + n {vn} by
1v1v1 + . . . + nvnv
n.
This representation is not one-to-one, e.g.
1
2
1
0
+
1
2
0
1
=
1
2
1 0
0 0
+
1
2
0 0
0 1
=
.5 0
0 .5
1
2
12
1
1
+
1
2
12
1
1
=
1
2
.5 .5
.5 .5
+
1
2
.5 .5
.5 .5
=
.5 0
0 .5
But these two mixed states are indistinguishable.
13
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
14/36
Quantum operations on density matrices
Unitary:
v
Uv vv
UvvU A
UAU
Measurement:
||20
||21
0
0
0
1
0
0 0
0 00
a bc d
a
0
d
1
a 00 0
0 00 d
14
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
15/36
A complete partial order of density matrices
Let Dn = {A Cnn | A is positive hermitian and tr A 1}.
Definition. We write A B if B A is positive.
Theorem. The density matrices form a complete partial order
under
.
A A A B and B A
A = B
A
B and B
C A C every increasing sequence A1 A2 . . . has a least upper
bound
15
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
16/36
Part II: The Flow Chart Language
16
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
17/36
Earlier Quantum Programming Languages
Knill (1996): conventions for writing pseudo-code
Omer (1998): scratch space management, user definedoperators
Sanders and Zuliani (2000): specification language,
stepwise refinement
Bettelli, Calarco, and Serafini (2001): based on C++
Imperative languages, run-time checks and errors, no formal
semantics.
17
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
18/36
A simple classical flow chart
input b, c : bit
branch b
0 1b, c : bit
b, c : bit
b, c : bit
b := c
b, c : bit
c := 0
b, c : bit
b, c : bitoutput b, c : bit
18
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
19/36
Classical flow chart, with boolean variables expanded
00 01 10 11
00 01 10 11
( branch b )
( b := c )
( c := 0 )
( merge )
input b, c : bit
output b, c : bit
19
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
20/36
Classical flow chart, with boolean variables expanded
00 01 10 11
00 01 10 11
A B C D
A B 0 0
0 0 C D
C 0 0 D
C 0 D 0
B D 0A + C
( branch b )
( b := c )
( c := 0 )
( merge )
input b, c : bit
output b, c : bit
19-a
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
21/36
A simple classical flow chart
input b, c : bit
branch b
0 1b, c : bit
b, c : bit
b, c : bit
b := c
b, c : bit
c := 0
b, c : bit
b, c : bitoutput b, c : bit
20
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
22/36
A simple classical flow chart
input b, c : bit
branch b
0 1 b, c : bit = (0,0,C,D)
b, c : bit = (A,B,C,D)
b, c : bit = (A,B,0,0)
b := c
b, c : bit = (C,0,0,D)
c := 0
b, c : bit = (C,0,D,0)
b, c : bit = (A + C,B,D,0)output b, c : bit
20-a
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
23/36
Summary of classical flow chart componentsAllocate bit:
= A
new bit b := 0
b : bit, = (A, 0)
Discard bit:
b : bit, = (A, B)
discard b
= A + B
Assignment:
b : bit, = (A, B)
b := 0
b : bit, = (A + B, 0)
b : bit, = (A, B)
b := 1
b : bit, = (0, A + B)
Branching:
branch b
0b : bit, = (A, 0) 1b : bit, = (0, B)
b : bit, = (A, B)
Merge: Initial:
= A = B
= A + B
= 0
Permutation:
b1, . . . , bn : bit = A0, . . . , A2n1
permute
b(1), . . . , b(n) : bit = A2(0), . . . , A2(2n1)
21
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
24/36
A simple quantum flow chart
input p, q : qbit
measure p
0
p,q : qbit1
p,q : qbit
p,q : qbit
q = Np,q : qbit
p = Np,q : qbit
p,q : qbit
output p, q : qbit
22
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
25/36
A simple quantum flow chart
input p, q : qbit
measure p
0
p,q : qbit =
A 0
0 0
1
p,q : qbit =
0 0
0 D
p,q : qbit =
A B
C D
q = N
p,q : qbit =
NAN 0
0 0
p = Np,q : qbit =
D 0
0 0
p,q : qbit =
NAN + D 00 0
output p, q : qbit
22-a
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
26/36
Summary of quantum flow chart components
Allocate qbit:
= A
new qbit q := 0
q : qbit, = A 00 0
Discard qbit:
q : qbit, =
A BC D
discard q
= A + D
Unitary transformation:
q : qbit, = A
q = S
q : qbit, = (S I)A(S I)
Measurement:
measure q
0q : qbit, =
A 00 0
1q : qbit, =
0 00 D
q : qbit, =
A BC D
Merge: Initial:
= A = B
= A + B
= 0
Permutation:
q1
, . . . , qn
: qbit = (aij
)ij
permute
q(1), . . . , q(n) : qbit = (a2(i),2(j))ij
23
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
27/36
Combining classical data with quantum data
Consider typing contexts of the form
b1 : bit, . . . , bn : bit, q1 : qbit, . . . , qm : qbit.
Definition. A state for the above typing context is a 2n-tuple
(A0, . . . , A2n1) of density matrices, each of dimension 2m
2m.
tr (A0, . . . , A2n1) :=
i tr Ai,
(A0
, . . . , A2
n1
)
:= (A0
, . . . , A2
n1
),
S(A0, . . . , A2n1)S := (SA0S, . . . , SA2n1S),
|(A0, . . . , A2n1)|2 :=
i |Ai|
2.
24
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
28/36
Summary of language features:
our language is functional (no side effects) and staticallytyped (no run-time errors).
it combines quantum and classical features (the compilercan separate them again).
it has high-level features (such as loops, recursion, andstructured data types) [not shown in this talk]
there is a compositional denotational semantics.
25
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
29/36
The denotation of a quantum flow chart
The denotation of a flow chart is a function which maps
(tuples of) matrices to (tuples of) matrices.
Example: the denotation of the quantum flow chart from
previous slide is the function
F
A B
C D
=
NAN + D 0
0 0
.
Question: Which functions can occur?
26
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
30/36
Superoperators
1) linear
2) positive: A positive F(A) positive
3) trace non-increasing: A positive tr F(A) tr(A)4) completely positive: F idn positive for all n
Theorem: The above conditions are necessary and sufficient.
27
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
31/36
The category Q of superoperators
Objects: signatures = n1, . . . , nk
Morphisms: f : is a superoperatorf : Cn1n1 . . . Cnknk
Cm1m1 . . . Cmkmk
Structure:
symmetric monoidal category (horiz.+vert. composition) coproducts (merge, initial)
CPO-enriched (fixpoints, recursion) traced monoidal (loops)
28
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
32/36
Structural and denotational equivalence
Definition. An elementary quantum flow chart category is a
symmetric monoidal category with traced finite coproducts,
such that A () is a traced monoidal functor for every objectA, together with a distinguished object qbit and morphisms
: I I qbit and : qbit I I, such that = id.Definition. Two quantum flow charts X, Y are structurally
equivalent if for every elementary quantum flow chart categoryC and every interpretation of basic operator symbols,
[[X]] = [[Y]].
We say X and Y are denotationally equivalent if [[X]] = [[Y]] for the
canonical interpretation in the category Q of signatures and
superoperators.
29
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
33/36
Higher-order quantum computation
Consider functions of higher-order types such as(qbit bit) qbit etc.
Quantum data is subject to linearity constraints. Need to
avoid terms that lead to runtime errors such aslet q = new qbit() in (x.H(x, x))q.
Bits are always duplicable, qubits are never duplicable.
What about functions?
Considerq:qbit p.p : qbit
qbit
q:qbit p.q : qbit qbitBoth closures have type qbit qbit, but only the first oneis duplicable.
30
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
34/36
Linear type system [Selinger,Valiron04]
Types: A, B ::= !A A B 1 A B.
Subtyping: !A
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
35/36
Example: quantum teleportation / dense coding
It is possible to write a function
TPPair : 1 (qbit bit bit) (bit bit qbit)such that for any application
(f, g) = TPPair(),
one obtains a pair of functions (f, g) with the properties:
f : qbit bit bitg : bit
bit
qbit
f g = idbitbitg f = idqbit
Thus, are the types qbit and bit bit isomorphic?
Answer: No, because each such pair f, g can only be used once.
Thus we have a single-use type isomorphism. This is a
curious phenomenon.
32
-
8/3/2019 Peter Selinger- Semantics of a Quantum Programming Language
36/36
Overview of some recent research
Quantum process calculi. Lalire-Jorrand (2004),Gay-Nagarajan (2004), Adao-Mateus (2005)
Higher-order quantum computation. Van Tonder (2003,2004), Selinger-Valiron (2004), Altenkirch-Grattage (2004)
Categorical quantum computation. Abramsky-Coecke(2004), Selinger (2005)
Measurement based quantum computation.Danos-DHondt-Kashefi-Panangaden (2004, 2005)
Quantum specification. Zuliani (2001-2004),DHondt-Panangaden (2004), Tafliovich (2004)
Quantum coherent spaces. Girard (2003), Selinger(2004)
33