Towards a Monadic Approach for Margolus Parallel Quantum Celular Automaton (Working in Progress) Juliana Kaizer Vizzotto, Mirkos Martins Mestrado em Nanociˆencias, Universidades Franciscanas CEP: 97010-032 , Santa Maria -RS, Brazil {juvizzotto,mirkos}@gmail.com Abstract In this paper we revisit Margolus’ model to parallel quantum computers based on cellular automaton and propose a monadic approach to such model. Monads are a semantic framework for structuring notions of computations in purely functional programming languages. It seems the quantum cellular automaton is a specific kind of computation which can be structured as a Minda. Moreover, due to the absence of side-effects, purely functional languages with minds, like Haskell, seem a good scenario for modelling and also simulating Margalo’s’ model. We aim to investigate this model as a basis for the development of high-level quantum data structures for parallel quantum programming languages.
1. Introduction A straightforward way to describe the behaviour of a quantum computer is to build its time evolution operator U to represent the operation we want to perform during one time step. U itself would be enough for studying the behaviour of the processor, but for physical realization, it is always necessary to know the Hamiltonian H. In general, H can be directly calculated from U by signalization and matrix multiplication, but as the matrix size grows exponentially in the number of cubits, this requires a lot of work. Following classical approaches it would seem an interesting idea to divide the computer into locally interconnected subsystems and describe the behaviour of the whole system based on its smaller subsystems. However, in quantum systems when the subsystems interact the behaviour of the whole system cannot be calculated as the sum the local Hamiltonian’s. This kind of sum operator does not take care of the correct operating order of the subsys-
Antˆonio Carlos da Rocha Costa Escola de Inform´atica, Universidade Cat´olica de Pelotas CEP: 96010-000 , Pelotas-RS, Brazil
[email protected] tems. An alternative to this subject was introduced by Feynman [1] implementing deterministic serial computation. Nevertheless, in the physical world things happen everywhere at once. Motivated by the intrinsic concurrent nature in physical systems and hence by the significance of describing parallel computations within the quantum formalism to information in physics, Margolus [5] generalized this model to parallel computers. In this paper we revisit Margolus’ model to parallel quantum computers based on cellular automaton and propose a monadic approach to such model. The motivation to this work is twofold. Monads are a semantic framework for structuring notions of computations in purely functional programming languages. It seems the quantum cellular automaton is a specific kind of computation, working with sets of configurations at a time, which can be structured as a monad. Moreover, due to the absence of side-effects in a purely functional program, it is relatively easy to partition programs so that sub-programs can be executed in parallel: any computation which is needed to produce the result of the program may be run as a separate task. Hence purely functional languages with monads, like Haskell [3], seem a good scenario for modelling and also simulating Margolus’ model. Additionally, we are interested in the development of high level programming methods to describe quantum algorithms (see [7, 8]) and it appear for us that this quantum cellular automaton may be a way to find out how to work with high level quantum data structures. The paper is organized as follows. Section 2 presents Feynman’s quantum computer. In Section 3 we discuss Margalo’s model to parallel quantum computation. The concept of monads is discussed on Section 4. The proposed approach to structure the parallel quantum cellular a automaton as monads is shown in 5. Sec-
tion 6 provides an overview of Concurrent Haskell. We briefly discuss some pointers about the parallel model in Haskell we propose in Section 7. Finally, in Section 8 we conclude.
2. Feynman’s Quantum Computer In this section we briefly discuss a serial quantum processor presented by Feynman in [1]. He considered a kind of logical circuit, a series of unitary operators UF i , which sould operate in a certain order to produce the final result. Thus the overall operation of this quantum computer can be described by a unitary matrix: UF = UF k .UF (k−1) . . . UF 2 .UF 1 . The operation of a quantum computer, however is not directly guided by this unitary operator UF , but by a corresponding Hamiltonian HF . One would like the hamiltonian operator H to be given as a sum of pieces, each of which only involves the interaction of a few parts of the computer which are near to each other. Feynman noticed that if the unitary operator UF which describes one step of the desired forward evolution can be written as a sum of local pieces, then if we let H = UF + UF † be the hamiltonian operator, H will also be a sum of local (nearby) interactions. The time evolution operator U (t) = e−iHt is a sum of UF . Thus if |ni corresponds to the logical state of a computer at step n (i.e., UF |ni = |n + 1i then U (t)|ni is a superposition of configurations of the computer at various steps in the original computation. This superposition contains no configuration which aren’t legitimate logical successors or predecessors to |ni. If you make a measurement of the configuration of the computer, you will find it at some step of the desired computation. If instead you simple measure some piece of the configuration which tells you whether the computation is done or not, then when you see that it is done, you can immediately look elsewhere in the configuration to find the answer, and P be assured that it is correct. In order to write F = Fi , Feynman described a computer in which only one spot is active at a time. Margolus celular automaton model for building parallel quantum computations is a generalization of this method, only requiring the F i’s to be local. It turns out a computer where all sites are active at once, but where there is no global time. Synchronization becomes a matter of local intercommunication.
3. Margolus’ Model to Quantum Parallel Computation Margolus’ model (MM) for parallel quantum computation is based on cellular automaton. Cellular automaton consists of a set (of any dimension) of units, called cells, which change their state according to some set
of rules. On each time step, the current state of some neighborhood (a set of cells which can but not need to contain the cell itself), determines the new state of the cell. Specifically, it is considered a bit different variant of cellular automaton, called partitioning cellular automaton. Basically, the grid of cells is partitioned into disjoint blocks, and the evolution rules are given for a block, not for a single cell. A block rule gives the new state of a block based on the old state of the block, without any reference to the neighboring cells or blocks. From one time step to the next, the partitioning is changed so that the blocks of one step overlap with those of the next step. This creates interaction between blocks an turns the automaton into a dynamical system. In classical computation, in general, it is used a globally synchronized automaton, i.e., all the cells changes their values at same time. This is not a problem if we are simulating the automaton on a classical computer. However, on a quantum system, making all the qubits behave synchronously would require explicitly taking into account the connections among even the furthermost qubits. Thus, in order to accommodate parallelism in quantum mechanics MM considered asynchronous computations using only neighboring interactions. Nevertheless, the synchronization can be restored using extra variables to keep track of relative synchronization (how many more times one portion of the system has been updated than an adjacent portion). In [5], the author considered a one-dimensional cellular automaton. That is a row of cells, each containing a few bits of state. The evolution consists of two phases: first, the cells at each even-numbered position are grouped with the cells to its right, and perform a logical transformation on the state of these two cells; then the cells are regrouped so that each evennumbered cell is associated with the cell to its left, and again we update the pair. This two kind of steps produce the dynamics of the system. Since the cells are updated in pairs, it is really unnecessary for the entire system be globally synchronous. The same result can be achieved by local means. In the pairing configuration the local dynamics only depends on the contents of two cells, it makes no difference whether or not any other cells have been updated yet. Using this scheme any cell that is labeled as having been updated n times is at the same state that it would have had if the whole system had been updated synchronously n times. Moreover, two adjacent cells cannot get more that one step apart in the update-count.
0
1
2
3
0
1
0
1
2
2
3
3
0
1
2
3
Figure 1. Example of the behavior of data configurations for a one-dimension four qubit automaton.
3.1. A quantum parallel automaton In the quantum parallel automaton, possible configurations are vectors of the quantum system and the evolution from state to state is described by a Hamiltonian as described by Feynman (see Section 2). Effectively, the Hamiltonian tells the quantum automaton in what possible ways a corresponding classical automaton can behave. The quantum automaton has the same set of (basis) states and the same connections between them as the classical one, but it uses them in a quantum way: instead of being in one state at a time, it can be in a superposition of all possible states at once. Each column in the Hamiltonian tells into which basis states some basis state can evolve during one logical step. The resulting Hamiltonian can be interpreted as a relation, which tells whether a basis state is reachable from another or not. Bellow we show a simple example of the behaviour of data configuration for a one-dimension automaton with four states. As one can see on Figure 1 we ignore the counter in the example. In the first time step the cells are grouped as [0, 1] and [2, 3] and then as [0, 3] and [1, 2].
4. Monads A monad is used for formulating definitions and structuring notions of computations (possibly non-functional) in programming languages. In this context, a program, which features notions of computations, can be viewed as a function from values to computations. For instance a program with exceptions can be viewed as a function that takes a value and returns a computation that may succeed or may fail. More precisely, to understand monadic computations one can consider a value category C, as a model for functions, and build on top of that, notions of com-
putation via an operator (endofunctor ) T acting on objects of C - i.e., T maps an object B from C, viewed as the set of values of type τ , to an object T B corresponding to computations of type τ . Then a program which takes an input of type A, and after performing a certain computation returns a value of type B, can be identified with a morphism from A to T B in C [6]. A monad is represented using a type constructor for computations m and two functions: return ∈ forall a ◦ a → m a > >= ∈ forall a b ◦ m a → (a → m b) → m b The operation > >= (pronounced “bind”) specifies how to sequence computations and return specifies how to lift values to computations. Note the requirements of f orall in the definitions above. This is because T , as explained above, is an endofunctor in C. Then, m is a type constructor acting on all objects from the value category. However, sometimes we want to select some objects (sets) from C to apply the constructor T . This notion is slightly more general than monads, and it is captured by the definition of Kleisli structure. Basically, for indexed monads (as we prefer to call Kleisli structures), the function T does not need be an endofunctor on C. We can select some objects from C to apply the constructor. This is exactly the notion we need to model quantum states as yet discussed in [7, 8]. Essentially, the constructor for a quantum states can only act over the types which constitute a basis. Now, the definitions of return and > >= in Haskell should be rephrased as: return ∈ forall a ◦ F a ⇒ a → m a > >= ∈ forall a b ◦ F a, F b ⇒ m a → (a → m b) → m b That is, for all a for which F a holds we can apply the constructor m, and for all a and b for which F a and F b hold we can apply > >=. Moreover, to construe a proper monad or indexed monad, the return and > >= functions must work together according to the three monad laws [6].
5. The Parallel Quantum Celular Automaton as Indexed Monads As described in Section 3 at each time step the state of the system is given by a set of possible configurations of the quantum automaton. The Haskell’s constructor [ ] stands for lists. type QAuto a = [[a ]] The monadic functions for configurations are defined as: return ∈ Basis a ⇒ a → QAuto a return a = [[a ]] (> >=) ∈ (Basis a, Basis b) ⇒
QAuto a → (a → QAuto b) → QAuto b return just lifts values to configurations, and bind, given a Hamiltonian represented as a function a → QAuto b, and given a QAuto a, returns a QAuto b (that is, it specifies how a QAuto a can be turned in a QAuto b). We omit the definition of bind but the idea is as follows. Suppose we have a state automaton representing an entangled pair as follows: [[0, 0], [1, 1]]. Then a Hadamard gate on the first qubit would be represented as the following function: 0 7→ [[1], [0]] and 1 7→ [[0], [−1]], then the result of applying the Hadamard function the pair above would give: [[0, 0], [0, 1]].
threads to update blocks of the automaton in parallel. Additionally, it is relevant to mention that we are investigating the use of a recent extension of Haskell concurrent of Software Transactional Memory (STM) [2]. It is more ”high-level” and perhaps better suited for modeling the parallel quantum automaton. More specifically, it is an abstraction for concurrent communication. The main benefits of STM are composability and modularity. That is, using STM you can write concurrent abstractions that can be easily composed with any other abstraction built using STM, without exposing the details of how your abstraction ensures safety
6. Concurrent Haskell
In this paper we have shown an approach to structure Margolus’ model to parallel quantum computers based on celular automaton in Haskell. We hope the intended implementation in Haskell would give a highlevel environment to simulate quantum parallel algorithms. More interestingly we believe that the monadic simulation in Haskell will give good hints about the construction of high-level quantum data structures. This would be a start point for the development of a really high-level quantum parallel programming language.
Concurrent Haskell [4] is a concurrent extension to the lazy functional language Haskell that introduces two main new ingredients: i, threads, and a mechanism for thread initiation; and, ii) atomically-mutable state, to support inter-thread communication and cooperation. Firstly, the language provides a new primitive called f orkIO, which starts a thread. The type of f orkIO is: forkIO ∈ IO a → IO ThreadId . It takes an I/O action and arranges to run it concurrently with the “parent” thread. For communication between different threads, Concurrent Haskell offers a variety of concepts, all based on mutable variables (M V ar). Mutable variables are embedded in the IO monad, which guarantees that threads access M V ars only in a mutually exclusive way. This is necessary because of the non-determinism of the underlying interleaving semantics. Different schedules may lead to different interactions taking place and therefore to different results. In this context, threads can create M V ars, read values form M V ars and write values to M V ars. If a thread tries to read form an empty M V ar or write to a full M V ar, then it is suspended until the M V ar is filled or emptied (respectively) by another thread.
7. Concurrent Haskell and the Monadic Model As this paper presents a working in progress we just give some pointers about this part of the work as it is being done. The idea for modelling parallel quantum computation is to encode the monadic approach from Section 5 using M V ars to allow parallel state update. The quantum automaton would be rewritten as: type QAuto a = [[MVar a ]] and the monadic functions would be rewritten using this new schema. In this way we would have different
8. Final Discussion
References [1] R. P. Feynman. Quantum mechanical computers. Opt. News, 11, 1985. [2] T. Harris, S. Marlow, S. Peyton-Jones, and M. Herlihy. Composable memory transactions, 2005. [3] S. P. Jones. Haskell 98 Language and Libraries. Cambridge University Press, 2003. [4] S. P. Jones, A. Gordon, and S. Finne. Concurrent Haskell. In Conference Record of POPL ’96: The 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 295–308, St. Petersburg Beach, Florida, 21–24 1996. [5] N. Margolus. Parallel quantum computation. Complexity, Entropy, and the Physics of Information, VIII:273– 287, 1990. [6] E. Moggi. Computational lambda-calculus and monads. In Proceedings of the Fourth Annual Symposium on Logic in computer science, pages 14–23. IEEE Computer Society Press, IEEE Press, 1989. [7] J. K. Vizzotto, T. Altenkirch, and A. Sabry. Structuring quantum effects: Superoperators as arrows. Mathematical Structures in Computer Science, special issue on Quantum Programming Languages, 16:453–468, 2006. to appear. [8] J. K. Vizzotto, A. C. da Rocha Costa, and A. Sabry. Quantum arrows in haskell. In 4rd International Workshop on Quantum Programming Languages, 2006. to appear in ENTCS.