1

I would like to get familiar with quantum computing basics.

A good way to get familiar with it would be writing very basic virtual quantum computer machines. From what I can understand of it, the, effort of implementing a single qubit cannot simply be duplicated to implement a two qubit system. But I don't know how I would implement a single qubit either.

How do I implement a qubit? How do I implement a set of qubits?

Pico
  • 593
  • 1
  • 5
  • 15

4 Answers4

1

Example Code

If you want to start from something simple but working, you can play around with this basic quantum circuit simulator on jsfiddle (about ~2k lines, but most of that is UI stuff [drawing and clicking] and maths stuff [defining complex numbers and matrices]).

State

The state of a quantum computer is a set of complex weights, called amplitudes. There's one amplitude for each possible classical state. In the case of qubits, the classical states are just the various states a normal bit can be in.

For example, if you have three bits, then you need a complex weight for the 000, 001, 010, 011, 100, 101, 110, and 111 states.

var threeQubitState = new Complex[8];

The amplitudes must satisfy a constraint: if you add up their squared magnitudes, the result is 1. Classical states correspond to one amplitude having magnitude 1 while the others are all 0:

threeQubitState[3] = 1; // the system is 100% in the 011 state

Operations

Operations on quantum states let you redistribute the amplitude by flowing it between the classical states, but the flows you choose must preserve the squared-magnitudes-add-up-to-1 property in all cases. More technically, the operation must correspond to some unitary matrix.

var myOperation = state => new[] {
    (state[1] + state[0])/sqrt(2),
    (state[1] - state[0])/sqrt(2),
    state[2],
    state[3],
    state[4],
    state[5],
    state[6],
    state[7]
};
var myNewState = myOperation(threeQubitState);

... and those are the basics. The state is a list of complex numbers with unit 2-norm, the operations are unitary matrices, and the probability of measuring a state is just its squared amplitude.

Etc

Other things you probably need to consider:

  • What kinds of operations do you want to include?
  • A 1-qubit operation is a 2x2 matrix and a 3-qubit operation is an 8x8 matrix. How do you convert a 1-qubit operation into an 8x8 matrix when applying it to a single qubit in a 3-qubit state? (Use the Kronecker Product.)
  • What kinds of tricks can you use to speed up the simulation? For example, if only a few states are non-zero, or if the qubits are not entangled, there's no need to do a full matrix multiplication.
  • How does the user tell the simulation what to do? How can you represent what's going on for the user? There's an awful lot of numbers flowing around...
Craig Gidney
  • 17,763
  • 5
  • 68
  • 136
0

The article that @Qwertie cites is a very good introduction. If you want to implement these on your computer, you can play with the libquantum simulator, which implements sophisticated quantum operations in a C library. You can look at this example to see what using the code is like.

Rick
  • 1,784
  • 3
  • 15
  • 25
0

The information is actually stored in the interaction between different Qbits, so no implementing 1 Qbit will not translate to using multiple. I'd think another way you could play around is to use existing languages like QCL or google QCP http://qcplayground.withgoogle.com/#/home to play around

0

I don't actually know the answer, but an interesting place to start reading about qubits is this article. It doesn't describe in detail how entangled qubits work, but it hints at the complexity involved:

If this is how complicated things can get with only two qubits, how complicated will it get for 3 or 4, or 100? It turns out that the state of an N-qubit quantum computer can only be completely defined when plotted as a point in a space with (4^N-1) dimensions. That means we need 4^N good old fashion classical numbers to simulate it.

Note that this is the maximum space complexity, which for example is about 1 billion numbers (2^30=4^15) for 15 qubits. It says nothing about the time complexity of a simulation.

Qwertie
  • 16,354
  • 20
  • 105
  • 148