A formalization of the Quipper quantum programming language Henri Chataing, Neil J. Ross & Peter Selinger Dalhousie University & ´ Ecole Polytechnique 2014 TYPES Meeting 1
Quantum computing is computing based on the laws of quantum physics. The standard model of quantum computing is Knill’s Qram model , in which a classical computer is connected to a quantum device. Instructions Quantum Classical Measurement results 2
The instructions for the quantum device are arranged in a quantum circuit. The gates that compose quantum circuits can be unitaries , which are reversible operations, or measurements , which are probabilistic operations. G 2 G 1 G 3 G 4 3
Quipper is a programming language for quantum computing, implemented as an embedded language within Haskell. Several non-trivial algorithms from the quantum computing literature have been implemented in Quipper. Quipper is a circuit description language. 4
Quipper’s circuit as data paradigm. H H 1 1 1 1 0 0 0 0 0 0 0 0 circuit :: [Qubit] -> Circ ([Qubit], [Qubit]) circuit qs = do y <- with_computed subcircuit $ \subcircuit -> do qc_copy subcircuit return (qs, y) 5
Quipper’s type system does not guarantee that quantum programs are physically meaningful. self_control :: Qubit -> Circ Qubit self_control q = do qnot_at q ‘controlled‘ q return q 6
Goals: ◮ Define a type-safe language, Proto-Quipper, that will serve as a basis for the development of Quipper as a stand-alone language. Chosen features for Proto-Quipper: ◮ Have a type system to enforce the physics (draw inspiration from the quantum lambda calculus ). ◮ Capture Quipper’s circuits as data paradigm. Simplifying assumption: ◮ No measurements (all circuits are therefore reversible). 7
The Proto-Quipper language: A , B ::= 1 A ⊗ B A ⊸ B ! A Type bool qubit Circ ( T , U ) T , U ::= 1 T ⊗ U QDataType qubit box T Term a , b , c ::= . . . q ( t , C , a ) unbox rev t , u ::= ∗ � t , u � QDataTerm q 8
Some basic built-in gates: ◮ HAD := unbox ( q , HAD , q ) ◮ CNOT := unbox ( � q 1 , q 2 � , CNOT , � q 1 , q 2 � ) ◮ INIT0 := unbox ( ∗ , 0 , q ) A Proto-Quipper term (not quite) for subcircuit : subcircuit := box qubit ( λ x . CNOT ( HAD x , INIT0 ∗ )) H , � q , q ′ � ) ( q , 0 9
Proto-Quipper’s operational semantics supposes a circuit constructor. The circuit constructor is assumed to be able to perform some basic operations: appending gates, reversing circuits, . . . The reduction will be defined on closures [ C , t ] consisting of a term t of the language and a circuit state C representing the circuit currently being built. 10
The operational semantics of Proto-Quipper (a selection): Spec FQ ( v ) ( T ) = t new ( FQ ( t )) = D [ C , box T ( v )] → [ C , ( t , D , vt )] [ D , a ] → [ D ′ , a ′ ] [ C , ( t , D , a )] → [ C , ( t , D ′ , a ′ )] bind ( v , u ) = b Append ( C , D , b ) = ( C ′ , b ′ ) FQ ( u ′ ) ⊆ dom ( b ′ ) [ C , ( unbox ( u , D , u ′ )) v ] → [ C ′ , b ′ ( u ′ )] 11
subcircuit := box qubit ( λ x . CNOT ( INIT0 ∗ , HAD x )) [ · , subcircuit ] [ , CNOT ( INIT0 ∗ , HAD q ))] ։ , CNOT ( INIT0 ∗ , q ))] [ H ։ H , CNOT ( q ′ , q ))] [ ։ 0 H [ , � q ′ , q � ] ։ 0 [ · , ( q , C , � q ′ , q � )] ։ 12
For each of the constants box T , unbox , and rev , we introduce a type: ◮ A box T ( T , U ) = !( T ⊸ U ) ⊸ ! Circ ( T , U ), ◮ A unbox ( T , U ) = Circ ( T , U ) ⊸ !( T ⊸ U ), and ◮ A rev ( T , U ) = Circ ( T , U ) ⊸ ! Circ ( U , T ). And a typing rule, for c ∈ { box T , unbox , rev } : ! A c ( T , U ) < : B !∆; ∅ ⊢ c : B 13
The type system of Proto-Quipper (a selection): A < : B !∆ , x : A ; ∅ ⊢ x : B ( ax c ) !∆; { q } ⊢ q : qubit ( ax q ) !∆ , x : A ; ∅ ⊢ b : B Γ , x : A ; Q ⊢ b : B ( λ 2 ) Γ; Q ⊢ λ x . b : A ⊸ B ( λ 1 ) !∆; ∅ ⊢ λ x . b : ! n +1 ( A ⊸ B ) Γ 1 , !∆; Q 1 ⊢ a : ! n A Γ 2 , !∆; Q 2 ⊢ b : ! n B ( ⊗ -i) Γ 1 , Γ 2 , !∆; Q 1 , Q 2 ⊢ � a , b � : ! n ( A ⊗ B ) Q 1 ⊢ t : T !∆; Q 2 ⊢ a : U In ( C ) = Q 1 Out ( C ) = Q 2 ( circ ) !∆; ∅ ⊢ ( t , C , a ) : ! n Circ ( T , U ) 14
Proto-Quipper is a type-safe language, It enjoys subject reduction and progress . Subject reduction : If Γ; FQ ( a ) ⊢ [ C , a ] : A , ( Q ′ | Q ′′ ) is a valid typed closure and [ C , a ] → [ C ′ , a ′ ], then Γ; FQ ( a ′ ) ⊢ [ C ′ , a ′ ] : A , ( Q ′ | Q ′′ ) is a valid typed closure. 15
References: ◮ A.S. Green, P. Lefanu Lumsdaine, N.J. Ross, P. Selinger, and B. Valiron. An introduction to quantum programming in quipper. ◮ A.S. Green, P. Lefanu Lumsdaine, N.J. Ross, P. Selinger, and B. Valiron. Quipper: A scalable quantum programming language. ◮ P. Selinger and B. Valiron. Quantum lambda calculus. 16
Recommend
More recommend