An introduction to QML, a functional quantum language

Richard Jozsa. Solutions. ▻ A high-level quantum language with a structure similar to .... The inner product of terms is defined, which to any pair of terms Γ ⊣ t,u ...
306KB taille 7 téléchargements 249 vues
An introduction to QML, a functional quantum language Jonathan Grattage

October 2007

Why a quantum language? Problems I

The Quantum Hardware Crisis

I

The Quantum Software Crisis

I

Algorithms generally presented using quantum circuit model

I

‘Coming up with good quantum algorithms is hard’ Nielson and Chuang

I

‘We need to develop quantum thinking!’ Richard Jozsa

Solutions I

A high-level quantum language with a structure similar to functional languages

I

Simplify the design of quantum algorithms: Allow formal reasoning principles Provide a more intuitive understanding

Motivation and Design Basics of Quantum Computation I

Analysed the differences between classical reversible computation and quantum computation

I

Define reversible classical computation, using the category FCC

I

Define quantum computation, using the category FQC, by analogy with FCC

The language QML I

First-order, functional, quantum language

I

“Quantum data and control”

I

Based on strict linear logic: controlled, explicit, weakening

I

Design guided by categorical semantics

I

Controlling measurement

Classical vs. Quantum

Classical Case (FCC) Finite sets Cartesian product (×) Bijections Functions Injective functions Projections

Quantum Case (FQC) Finite dimensional Hilbert spaces Tensor product (⊗) Unitary operators Superoperators Isometries Partial trace

FQC: Category of Quantum Circuits I I

Morphisms in FQC' a are characterised inductively Sequential Composition: φ ∈ FQC' a, ψ ∈ FQC' a, then φ ◦ ψ ∈ FQC' a can be constructed. _ _ _ _ 

φ   ψ _ _ _ _ I

Parallel Composition: φ ⊗ ψ : FQC' (a ⊗ b) _

_

 φ  



 ψ  _ _ I

Reordering: wire φ ∈ FQC' a where φ : [a] ' [a] is a bijection a b

??? ?

b a

FQC: Category of Quantum Circuits

I

Conditional: Given φ, ψ ∈ FQC' a, then φ|ψ ∈ FQC' (1 ⊗ a) can be constructed  Q2 • ψ

a I

φ

Rotation: rot u ∈ FQC' 1, where u is a unitary operation   λ0 λ1 κ0 κ1 with λ∗0 κ0 + λ∗1 κ1 = 0 Q2

ϕ

QML Syntax I

Types σ = Q1 | Q2 | σ ⊗ τ

I

Expressions (Variables) x, y , ...

∈ Vars

(Prob. ampl) κ, ι, ... ∈ C (Patterns) p, q ::= x | (x, y ) (Terms) t, u ::= x | x ~y | () | (t, u) | let p = t in u | if t then u else u 0 | if ◦ t then u else u 0 | qfalse | qtrue | 0 | κ × t | t + u I

EPR State =

√1 2

× (qfalse, qfalse) +

√1 2

× (qtrue, qtrue)

Control of Weakening

I

Projection Function π1 ∈ (Q2 , Q2 ) → Q2 π1 (x, y ) = x

Q2



Q2

Q2

φπ1

I

Diagonal Function δ ∈ Q2 → (Q2 , Q2 ) δ x = (x, x)



x∈Q2 0∈Q2



 

x∈Q2 x∈Q2

Control of Weakening

I

π1 ◦ δ ∈ Q2 → Q2 x∈Q2 0∈Q2

I

Quantum Case: Input = √12 × false + Output = { 12 }false +

 



φδ

Classical Case: Q2

I





x∈Q2

φπ1 Q2

√1 × true (equal superposition) 2 { 21 }true (probability distribution)

Not the identity function

More Weakening

I

forget mentions x forget ∈ Q2 ( Q2 forget x = if x then qtrue else qtrue

I

but doesn’t use it.

I

Hence, it has to measure it

I

if always measures the conditional

I

Not, using if not ∈ Q2 ( Q2 not x = if x then qfalse else qtrue

if ◦ – Quantum control I

forget 0 ∈ Q2 ( Q2 forget 0 x = if ◦ x then qtrue else qtrue I

This program has a type error, because true 6⊥ true.

I

qnot ∈ Q2 ( Q2 qnot x = if ◦ x then qfalse else qtrue I

This program typechecks, because false ⊥ true.

I

cnot ∈ Q2 ( Q2 ( (Q2 , Q2 ) cnot c x = if ◦ c then (qtrue, qnot x) else (qfalse, x) I

Deutsch-Josza Algorithm, Quantum Teleport Algorithm, ...

Quantum Teleport Algorithm pZed ∈ Q2 ( Q2 pZed x = if ◦ x then (−1) × qtrue else qfalse had ∈ Q2 ( Q2 had x = if ◦ x then (−1) × qtrue + qfalse else qtrue + qfalse

tel ∈ Q2 ( Q2 tel x = let (a, b) = (qfalse, qfalse) + (qtrue, qtrue) (a0 , x 0 ) = cnot a x b0 = if a0 then qnot b else b 00 b = if ◦ had x 0 then pZed b 0 else b 0 00 in b

Deutsch’s Algorithm

deutsch : N2 ( N2 ( Q2 deutsch a b = let (x, y ) = if ◦ qfalse + qtrue then (qtrue, if a then qfalse + (−1) × qtrue else (−1) × qfalse + qtrue) else (qfalse, if b then (−1) × qfalse + qtrue else qfalse + (−1) × qtrue) in had x

Inner Product & ⊥

I

The inner product of terms is defined, which to any pair of terms Γ ` t, u : σ assigns ht|ui ∈ C ∪ {?}.

I

t ⊥ u holds if ht|ui = 0.

I

ht|ti = 1,

I

h0|truei = 0 = htrue|0i, h0|xi = 0 = hx|0i

I I

I

hfalse|truei = 0, htrue|falsei = 0 h0|falsei = 0 = hfalse|0i,

h(t, t 0 ) | (u, u 0 )i = ht|ui × ht 0 |u 0 i hλ × t + λ0 × t 0 | ui = λ∗ × ht|ui + λ0∗ × ht 0 |ui, ht | κ × u + κ0 × u 0 i = κ × ht|ui + κ0 × ht|u 0 i ... ht|ui =?

otherwise

Operational Semantics: QML → FQC

I

Implemented in Haskell

I

QML expressions compiled into FQC (Finite Quantum Computation) objects

I

a



b

φ h

g



I

φ = quantum circuit

I

Circuit represented as simple combinators

I

Can be directly simulated, or passed to any standard simulator

I

. . . or a real quantum computer

Example: JΓ ⊗ ∆ `a (t, u) : σ ⊗ τ KaOp I

Γ `a t : σ

∆ `a u : τ

Γ ⊗ ∆ `a (t, u) : σ ⊗ τ

⊗ intro

I

Γ⊗∆

99  9  9

φt



  I

σ

Γ

φC 

φu

44

4 4

4

τ

 

t ∈ FQCa Γ σ u ∈ FQCa ∆ τ pairaOp t u ∈ FQCa (Γ ⊗ ∆) (σ ⊗ τ ) pairaOp t u = (hC + ht + hu , gt + gu , φ)

⊗ on contexts

I

Γ, x : σ ⊗ ∆, x : σ = (Γ ⊗ ∆), x : σ Γ⊗∆ σ

 

I

99  9  9

φδ σ

99  9  9

Γ σ ∆ σ

Γ, x : σ ⊗ ∆ = (Γ ⊗ ∆), x : σ, if x ∈ / dom ∆ Γ⊗∆ σ

I

φC(Γ,∆)



99  9  9

φC(Γ,∆)

99  9  9

•⊗∆=∆ •⊗∆



Γ σ ∆

Example: JΓ ⊗ ∆ `a let (x, y ) = t in u : ρKaOp I

Γ `a t : σ ⊗ τ ∆, x : σ, y : τ `a u : ρ Γ ⊗ ∆ `a let (x, y ) = t in u : ρ

⊗ elim

I

Γ⊗∆

φC 





σ

φt  

I

99  9  9

Γ

τ

φu

99  99  9

ρ

44

4 4

4

 

t ∈ FQCa Γ (σ ⊗ τ ) u ∈ FQCa (∆ ⊗ σ ⊗ τ ) ρ letpaOp t u ∈ FQCa (Γ ⊗ ∆) ρ letpaOp t u = (hC + ht + hu , gt + gu , φ)

Denotational Semantics: QML → Q

I

Given as a translation to superoperators (Q)

I

Factored through operational semantics: QML → FQC → Q

I

Compositionality can be shown by a direct translation: QML → Q 

QML◦ Γ Nσ NNN J·K◦ NNNOp NNN N&  ◦ J·KD FQC◦ Γ σ pp ppp p p p  wppp J·K ◦ / Q Γσ

b.

/ QML Γ σ r J·KOp rrr r r r r y rr

/ FQC Γ σ J·KD LLL LLL LL J·K LL%  /QΓσ

FQC' as a unitary operation I

I I I I

I

φ ∈ FQC' a can be interpreted as JφK ∈ Q' a, by induction over the inductive definition of FQC' rotation Jrot uK = u

wires Jwire φK = f where f a b = if φ a ≡ b then 1 else 0. sequential composition Jφ ◦ ψK = JφK ◦ JψK

parallel composition Jφ ⊗ ψK = JφK ⊗ JψK, using the fact that 2a×b = 2a + 2b . conditional Jφ | ψK = JφK|JψK where φ|ψ (0, a) (0, b) = φ a b φ|ψ (1, a) (1, b) = ψ a b φ|ψ =0 Note that φ|ψ is unitary/isometric if both φ and ψ are also unitary/isometric.

Superoperators and Extensional Equality

I

Denotational semantics gives rise to equational equality; morphisms as superoperators

I

Jt ∈ QML Γ δK = (h, g , φ) ∈ FQC |Γ| |δ|

I

A morphism (h, g , φ) ∈ FQC a b is interpreted as trg ◦JφK◦ ⊗ 0h ∈ Q a b

I

a ⊗O h

JφK

(−,0h )

a

/b⊗g 

f

/b

trg

⊕ : Coproducts in QML⊕

I

Introduced by qtrue = qinl () : Q2 , qfalse = qinr () : Q2

I

Q2 = Q1 ⊕ Q1

I

case generalises if Γ`c :σ⊕τ ∆, x : σ ` t : ρ ∆, y : τ ` u : ρ Γ ⊗ ∆ ` case c of {inl x ⇒ t | inr y ⇒ u } : ρ

I

|σ ⊕ τ | = Q2 ⊗ (|σ| t |τ |)

I

What about case◦ ?

⊕elim

⊕ : case◦

I

case◦ : quantum control Γ `a c : σ ⊕ τ ∆, x : σ `◦ t : ρ ∆, y : τ `◦ u : ρ t ⊥ u Γ ⊗ ∆ `a case◦ c of {inl x ⇒ t | inr y ⇒ u} : ρ

I

Problem: Types of different size; e.g. Q1 ⊕ Q2

I

Require that |σ| = |τ |

I

Restrict ⊕ to classical types

⊕elim◦

An algebra for (pure) QML

I

A sound and complete equational theory for QML

I

Proof of completeness gives rise to a normalisation algorithm (normalisation by evaluation)

I

Focuses on the pure fragment of QML (omitting measurements)

I

I

if ◦ (λ t0 + κ t1 ) then u0 else u1 = λ (if ◦ t0 then u0 else u1 ) + κ (if ◦ t1 then u0 else u1 ) Thorsten Altenkirch (UK), Juliana K. Vizzotto (Brazil), Amr Sabry (USA)

Algebra Example: had (had x) I

How can had (had x) =obs x be verified? I

I

I

I

I

= if ◦ (if ◦ x then (qfalse − qtrue) else (qfalse + qtrue)) then (qfalse − qtrue) else (qfalse + qtrue) -- by commuting conversion for if ◦ = if ◦ x then if ◦ (qfalse − qtrue) then (qfalse − qtrue) else (qfalse + qtrue) else if ◦ (qfalse + qtrue) then (qfalse − qtrue) else (qfalse + qtrue) -- by if ◦ = if ◦ x then (qfalse − qfalse + qtrue + qtrue) else (qfalse + qfalse + qtrue − qtrue) -- by simplification and normalisation = if ◦ x then qtrue else qfalse -- by η-rule for if ◦ =x

Overview I

Introduced the functional, quantum, language QML, with quantum data and control

I

Based on strict linear logic: controlling weakening which can destroy the quantum state

I

Introduced the categories FCC and FQC

I

Gives a formal, categorical, definition of the quantum circuit model

I

An operational semantics for QML is defined: a compiler which translates programs into FQC objects (circuits)

I

I

A denotational semantics is defined in terms of isometries Q◦ and superoperators Q An algebra for pure QML that supports formal reasoning

Future directions

I

Redefine operational semantics using MBQC model

I

Implement semantics using the new Haskell Quantum IO Monad

I

Extend to higher order

I

Introduce classical types and coproduct

I

Make QML basis independent

I

Extend algebra to full language

I

Investigate more algorithms

I

Investigate (infinite?) quantum data structures

Merci pour votre attention

I

Project website: sneezy.cs.nott.ac.uk/qml

I

Contains archive of published papers, drafts, and theses related to QML

I

Email [email protected]

I

or Thorsten Altenkirch at: [email protected]