• Non ci sono risultati.

Introduction to Probabilistic and Quantum Programming

N/A
N/A
Protected

Academic year: 2021

Condividi "Introduction to Probabilistic and Quantum Programming"

Copied!
24
0
0

Testo completo

(1)

Introduction to Probabilistic and Quantum Programming

Part II

Ugo Dal Lago

BISS 2014, Bertinoro

(2)

Section 1

Probabilistic Programming Languages

(3)

Flipping a Coin

I Adding probabilistic behaviour to any programming language is relatively easy, at least from a purely linguistic point of view.

I The naïve solution is to endow your favourite language with a primitive that, when executed, “flips a fair coin” returning 0 or 1 with equal probability.

I In imperative programming langauges, this can take the form of a keyword rand, to be used in expressions;

I In functional programming languages, one could also use a form of binary, probabilistic sum, call it ⊕, as follows:

letrec f x = x (+) (f (x+1))

I How do we get the necessary randomness, when executing programs?

I By a source of true randomness, like physical randomness.

I By pseudorandomness (we will come to that later).

(4)

Sampling

I If incepted into a universal programming language, binary uniform choice is enough to encode sampling from any computable distribution.

I As an example, if f is defined as follows letrec f x = x (+) (f (x+1))

then f(0) produces the exponential distribution {012,114,218, . . .}.

I A real number x ∈ R is computable if there is an algorithm Ax outputting, on input n ∈ N, a rational number qn∈ Q such that |x − qn| < 21n.

I A computable distribution is one such that there is an algorithm B that, on input n, outputs the code of Apn, where pn is the probability the distribution assigns to n.

Theorem

PTMs are universal for computable distributions.

(5)

True Randomness vs. Pseudorandomness

I Having access to a source of true randomness is definitely not trivial.

I One could make use, as an example, of:

I Keyboard and mouse actions;

I External sources of randomness, like sound or movements;

I TRNGs (True Random Number Generators).

I A pseudorandom generator is a deterministic algorithm G from strings in Σ to Σ such that:

I |G(s)| > |s|;

I G(s) is somehow indistinguishable from a truly random string t of the same length.

I The point of pseudorandomness is amplification: a short truly random string is turned into a longer string which is not random, but looks so.

(6)

Programming vs. Modeling

I Probabilistic models, contrarily to probabilistic languages, are pervasive and very-well studied from decades.

I Markov Chains

I Markov Processes

I Stochastic Processes

I . . .

I A probabilistic program, however, can indeed be seen as a way to concisely specify a model, for the purpose of doing, e.g., machine learning or inference.

I A quite large research community is currently involved in this effort, mainly in the United States (for more details, see http://probabilistic-programming.org).

I Roughly, you cannot only “flip a coin”, but you can also incorporate observations about your dataset in your program.

(7)

Programming vs. Modeling

I Probabilistic models, contrarily to probabilistic languages, are pervasive and very-well studied from decades.

I Markov Chains

I Markov Processes

I Stochastic Processes

I . . .

I A probabilistic program, however, can indeed be seen as a way to concisely specify a model, for the purpose of doing, e.g., machine learning or inference.

I A quite large research community is currently involved in this effort, mainly in the United States (for more details, see http://probabilistic-programming.org).

I Roughly, you cannot only “flip a coin”, but you can also incorporate observations about your dataset in your program.

(8)

A Nice Example: FUN

(9)

A Nice Example: FUN

(10)

Section 2

Quantum Programming Languages

(11)

Quantum Data and Classical Control

Classical Control

Quantum Store

Create a New Qubit

Observe the Value of a Qubit

(12)

Quantum Data and Classical Control

Classical Control

Quantum Store

Create a New Qubit

Observe the Value of a Qubit

(13)

Quantum Data and Classical Control

Classical Control

Quantum Store

Observe the Value of a Qubit Create a New Qubit

(14)

Quantum Data and Classical Control

Classical Control

Quantum Store

Apply a Transform

Unitary

Create a New Qubit

Observe the Value of a Qubit

(15)

Imperative Quantum Programming Languages

I QCL, which has been introduced by Ömer

I Example:

qufunct set(int n,qureg q) {

int i;

for i=0 to #q-1 {

if bit(n,i) {Not(q[i]);}

} }

I Classical and quantum variables.

I The syntax is very reminiscent of the one of C.

(16)

Quantum Imperative Programming Languages

I qGCL, which has been introduced by Sanders and Zuliani.

I It is based on Dijkstra’s predicate transformers and guarded-command language, called GCL.

I Features quantum, probabilistic, and nondeterministic evolution.

I It can be seen as a generalization of pGCL, itself a probabilistic variation on GCL.

I Tafliovich, Hehner adapted predicative programming to quantum computation.

I Predicative programming is not a proper programming language, but rather a methodology for specification and verification.

(17)

Quantum Functional Programming Languages

I QPL, introduced by Selinger.

I A very simple, first-order, functional programming language.

I The first one with a proper denotational semantics, given in terms of superoperators, but also handling divergence by way of domain theory.

I A superoperator is a mathematical object by which we can describe the evolution of a quantum system in presence of measurements.

I Many papers investigated the possibility of embedding quantum programming into Haskell, arguably the most successful real-world functional programming language.

I In a way or another, they are all based on the concept of a monad.

(18)

Quantum Functional Programming Languages

I QPL, introduced by Selinger.

I A very simple, first-order, functional programming language.

I The first one with a proper denotational semantics, given in terms of superoperators, but also handling divergence by way of domain theory.

I A superoperator is a mathematical object by which we can describe the evolution of a quantum system in presence of measurements.

I Many papers investigated the possibility of embedding quantum programming into Haskell, arguably the most successful real-world functional programming language.

I In a way or another, they are all based on the concept of a monad.

(19)

QPL: an Example

(20)

Quantum Functional Programming Languages

I In a first-order fragment of Haskell, one can also model a form of quantum control, i.e., programs whose interal state is in superposition.

I This is Altenkirch and Grattage’s QML.

I Operations are programmed at a very low level: unitary transforms become programs themselves, e.g.

I Whenever you program by way of the if construct, you should be careful and check that the two branches are orthogonal in a certain sense.

(21)

Quantum Functional Programming Languages

I Most work on functional programming languages has focused on λ-calculi, which are minimalist, paradigmatic languages only including the essential features.

I Programs are seen as terms from a simple grammar M, N ::= x

|

M N

|

λx.M

|

. . .

I Computation is captured by way of rewriting

I Quantum features can be added in many different ways.

I By adding quantum variables, which are meant to model the interaction with the quantum store.

I By allowing terms to be in superposition, somehow diverging from the quantum-data-and-classical-control paradigm:

M ::= . . .

|

X

i∈I

αiMi

I The third part of this course will be entirely devoted to (probabilistic and) quantum λ-calculi.

(22)

Quantum Process Algebras

I Process algebras are calculi meant to model concurrency and interaction rather than mere computation.

I Terms of process algebras are usually of the following form;

P, Q::= 0

|

a.P

|

a.P

|

P ||Q

|

. . .

I Again, computation is modeled by a form of rewriting, e.g., a.P ||a.Q → P ||Q

I How could we incept quantum computation? Usually:

I Each process has its own set of classical and quantum (local) variables.

I Processes do not only synchronize, but can also send classical and quantum data along channels.

I Unitary transformations and measurements are done locally.

(23)

Other Programming Paradigms

I Concurrent Constraint Programming

I Measurement-Based Quantum Computation

I Hardware Description Languages

I . . .

(24)

Thank You!

Questions?

Riferimenti

Documenti correlati

therefore, the memory for the array is stack memory; it is created (allocated) when the function is called, and it is destroyed (deallocated) when the function finished

In the previous example, the problem is that after the function str_swap() returns, the address of the allocated memory is lost (it was stored in a local variable), so we cannot

Usually, declaration and definition coincide for variables The definition consists of the type keyword followed by the name of the variable, followed by the “;”

However, in many cases we must execute alternative instructions, depending on the value of certain expressions Also, sometimes we need to repeat instructions a number of times, or

the swap function does not need to return anything: so the return type is void. the array my is initialized when it

3 Write a function that given a string, substitutes all lower case characters to

scope: all objects defined after temp lifetime: duration of the program res and s[] are local variables scope: body of function main lifetime: duration of the program..

scope: all objects defined after temp lifetime: duration of the program res and s[] are local variables scope: body of function main lifetime: duration of the program..