Saturday, September 10, 2011

Trivial quantum computing with QCF

Here is the same trivial quantum computing example I did in QCL in QCF running on Octave.

Again, I start with a two-qubit register psi, initialized to zero. I perform the Hadamard on it to create an equal superposition of states. Then I measure it, getting a different result each time I try it.

Note the two different quantum state notations used. Vector notation is used be default in QCF as it makes computation simpler. But as a human, I prefer binary ket notation, so I go from binary ket to vector notation using bin2vec(), and vector to binary ket notation using pretty().

Also measurement in QCF does not collapse the wavefunction explicitly (although you could do psi=measure(psi) to be more realistic about the measurement process collapsing the waveform).

octave-3.2.3:132> addpath("/pathtoqcf/qcf")
octave-3.4.0:133> psi=bin2vec("00")
psi =

1
0
0
0

octave-3.4.0:134> pretty(psi)
ans = 1|00>
octave-3.4.0:135> psi=hadamard(2)*psi
psi =

0.50000
0.50000
0.50000
0.50000

octave-3.4.0:136> pretty(psi)
ans = 0.5|00> + 0.5|01> + 0.5|10> + 0.5|11>
octave-3.4.0:137> pretty(measure(psi))
ans = 1|10>
octave-3.4.0:138> pretty(measure(psi))
ans = 1|01>
octave-3.4.0:139> pretty(measure(psi))
ans = 1|11>
octave-3.4.0:140> pretty(measure(psi))
ans = 1|01>




No comments: