After using the simulator, I am very impressed! From what I can tell, it has everything necessary to be universal. I will likely be using this quite a bit.
To test drive it, I implemented a simple 3-qubit Fourier transform and applied it to a set of random initial states, then compared the result to the well known 3-qubit unitary DFT (dft
) applied to the same set of states. The code I ran is below, and the results agreed.
There are a few quirks, but they are relatively minor. For example, several design constraints led me (for the sake of simplicity) to make the circuit "upside down" and invert the initial register tensor product rather than bit-swap at the end.
This made me interested in attempting to build out a simulation of Shor's algorithm based on this library.
>> circ=fourier_3bit
circ =
3×6 string array
"I" "I" "." "I" "." "H"
"I" "." "" "H" "S" "I"
"H" "S" "T" "I" "I" "I"
>> dft=fourier_3bit_mtx
dft =
0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i 0.3536 + 0.0000i
0.3536 + 0.0000i 0.2500 + 0.2500i 0.0000 + 0.3536i -0.2500 + 0.2500i -0.3536 + 0.0000i -0.2500 - 0.2500i 0.0000 - 0.3536i 0.2500 - 0.2500i
0.3536 + 0.0000i 0.0000 + 0.3536i -0.3536 + 0.0000i 0.0000 - 0.3536i 0.3536 + 0.0000i 0.0000 + 0.3536i -0.3536 + 0.0000i 0.0000 - 0.3536i
0.3536 + 0.0000i -0.2500 + 0.2500i 0.0000 - 0.3536i 0.2500 + 0.2500i -0.3536 + 0.0000i 0.2500 - 0.2500i 0.0000 + 0.3536i -0.2500 - 0.2500i
0.3536 + 0.0000i -0.3536 + 0.0000i 0.3536 + 0.0000i -0.3536 + 0.0000i 0.3536 + 0.0000i -0.3536 + 0.0000i 0.3536 + 0.0000i -0.3536 + 0.0000i
0.3536 + 0.0000i -0.2500 - 0.2500i 0.0000 + 0.3536i 0.2500 - 0.2500i -0.3536 + 0.0000i 0.2500 + 0.2500i 0.0000 - 0.3536i -0.2500 + 0.2500i
0.3536 + 0.0000i 0.0000 - 0.3536i -0.3536 + 0.0000i 0.0000 + 0.3536i 0.3536 + 0.0000i 0.0000 - 0.3536i -0.3536 + 0.0000i 0.0000 + 0.3536i
0.3536 + 0.0000i 0.2500 - 0.2500i 0.0000 - 0.3536i -0.2500 - 0.2500i -0.3536 + 0.0000i -0.2500 + 0.2500i 0.0000 + 0.3536i 0.2500 + 0.2500i
>> regs=initializeRegisters(v1,v2,v3)
regs =
0.0000 - 0.2804i
-0.2349 + 0.0000i
0.0000 + 0.5541i
0.4643 + 0.0000i
0.2029 + 0.0000i
0.0000 - 0.1700i
-0.4009 + 0.0000i
0.0000 + 0.3359i
>> regs_rev=initializeRegisters(v3,v2,v1)
regs_rev =
0.0000 - 0.2804i
0.2029 + 0.0000i
0.0000 + 0.5541i
-0.4009 + 0.0000i
-0.2349 + 0.0000i
0.0000 - 0.1700i
0.4643 + 0.0000i
0.0000 + 0.3359i
>> dft*regs
ans =
0.0111 + 0.1555i
-0.4009 + 0.2265i
0.3923 - 0.5422i
0.3405 - 0.3100i
-0.1511 + 0.0381i
-0.1343 - 0.1412i
0.0346 - 0.0478i
-0.0921 - 0.1717i
>> quantumComputer(circ,[1 2 3],regs_rev)
ans =
0.0111 + 0.1555i
-0.4009 + 0.2265i
0.3923 - 0.5422i
0.3405 - 0.3100i
-0.1511 + 0.0381i
-0.1343 - 0.1412i
0.0346 - 0.0478i
-0.0921 - 0.1717i
