Showing posts with label memory requirements. Show all posts
Showing posts with label memory requirements. Show all posts

Tuesday, June 22, 2010

Simulating Quantum Computers

Here's a good blog post by Tucci: Best Heavy Duty Quantum Computer Simulators. He basically breaks them down into two categories: super computers and distributed grids (like BOINC). For anything heavy duty that is a simulation on a classical computer, those types of approaches are the only real solutions.

There are some approaches to help on a modern PC, although your still much more limited than the above. A quantum register is represented by 2^n complex numbers, where an operation on that register is a 2^n x 2^n matrix of complex numbers. The simple approach is just that, but as you can see, the memory requirements are large: you'll need 2^n complex numbers for the initial state of the register, the 2^n x 2^n complex matrix for the operation, and 2^n complex numbers for the output. One way to cut down the memory needed is to only do the matrix multiplication one row at a time. Doing so you need only 2^n complex numbers for the matrix instead of the entire thing. This is how the current implementation of Cove, my framework for programming quantum computers, currently works. Of course, there are much more elaborate tricks out there for improving the efficiency of quantum computers.

Another area I've been toying with for some time is to utilize more than one core on a system. The easiest approach with the current implementation of Cove would be just to spawn extra threads to do the matrix multiplication pieces. This would come at the cost of the extra 2^n complex numbers for each thread running. So there is a trade off between memory use and faster execution of the simulation. The execution time has been the bottle neck for a lot of the sets of a few handfuls of qubits I've been playing with, so this is something I'll probably get to eventually.

The previous paragraph being said, my goal has always been the creation of a usable framework for quantum computer programming. The simulation has always been something that will allow me to play with existing code, so my focus has never been on making it incredibly efficient.

Cove is setup where a user writes their code against a set of interfaces. With the current incarnation of Cove, the implementation is this simulation I've been talking about. The idea is however, that the simulation implementation could eventually be swapped out with one that runs on an actual quantum computer. In doing so a users code could switch between various implementations (actual quantum computer, my simulation, super computer, grid, etc) with only switching a reference and using statement.

Sunday, November 15, 2009

Reducing Memory Requirements in Cove

With Cove, I've never spent much time on making the simulation efficient. Instead I've been focusing my efforts on creating a usable framework. Furthermore, once we have quantum computers any work spent on efficient simulations is largely a mute point.

Not taking into account tricks for efficient simulation, any simulation of a quantum computer requires exponential memory. This is best illustrated by expressing a quantum register (a collection of qubits) as a matrix. Each cell in the matrix is the probability amplitude of the register collapsing to that state. (These are also complex numbers.) As an example, we can consider a two qubit register:

So that's why we need an exponential number of cells: 1 qubit is expressed by 2 complex numbers, 2 qubits by 4 complex numbers, 3 by 8 complex numbers, and so on.

Operations are expressed by a 2^n x 2^n matrix, when they operate on n qubits. So a controlled not operation is a 4 x 4 matrix. Simple linear algebra shows how the operation is applied, here is an example of performing a not operation:

The math dictates that the operation is that 2^n x 2^n matrix. So what happens when the not operation is applied to a 4 qubit register? In Cove I used explicit matrix expansion [1]. That means that the matrix of the operation is expanded, in this case it would be a 16 x 16 matrix. Obviously this eats up a bunch of memory and this was pretty obvious early on. So to apply an operation on a n qubit register I needed 2n + (2^n)^2 complex numbers: the 2n for the state of the register before and after, and the (2^n)^2 for expanded operation. With this I hit memory limitations with no more than a few handfuls of qubits.

This past week I reduced the memory requirements quite a bit in change set [925]. This is something I've been meaning to do since this past spring. Basically what I did was expand the operation matrix one row at a time instead of all at once. This essentially cut the memory requirements down to 3n for a n qubit matrix. So I should be able to simulate much larger systems now.

References

[1] L. Spector, Automatic Quantum Computer Programming: A Genetic Programming Approach, 1 ed. New York, NY: Springer Science and Business Media, LLC, 2004.