1
$\begingroup$

I have tried to program universal quantum computer simulator in MatLab. Please find a code here:

https://www.mathworks.com/matlabcentral/fileexchange/73035-quantum-computer-simulator

Can be this code used as a good simulator of quantum computer? Thanks for answer.

$\endgroup$
  • 1
    $\begingroup$ Hi Martin. This might be interesting and useful for many, but I'm afraid as it stands this is not a question, and therefore off-topic here. If you can rephrase this as a question (which you may then self-answer) that could make it fit for the site $\endgroup$ – glS Nov 6 at 14:41
  • $\begingroup$ Ok, thanks. Tried to rephase as a request/question. $\endgroup$ – Martin Vesely Nov 6 at 14:44
  • 1
    $\begingroup$ that's still off-topic imo. Asking for somebody to "test and post opinion about my code" is way too broad. If you want to post about some code you developed, you may rephrase the question as something along the lines of "What are the available matlab packages to simulate quantum computers?", which you can then self-answer with your code (and preferably some word describing it). $\endgroup$ – glS Nov 6 at 14:48
  • 3
    $\begingroup$ @MartinVesely Please don't be discouraged by the SE format. As glS said the SE format requires a well defined question. If you could rephrase as glS suggested, or ask a specific question about the package (e.g. "Can this Matlab package be used to accurately simulate a universal quantum computer?"), you should get good feedback. I'm personally very interested in this and happy to test/evaluate the package. $\endgroup$ – ChainedSymmetry Nov 6 at 15:18
  • $\begingroup$ Thanks for help with formulating a question. Hope now everything is right. $\endgroup$ – Martin Vesely Nov 6 at 21:33
2
$\begingroup$

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

Probability Dist

$\endgroup$
  • $\begingroup$ Thank you for taking time to test my code and suggestions you made. As I mentioned during our chat, I will try to make the simulator more general (e.g. to add SWAP gate and possibility to have a control bit below target one for controlled gates. I would be glad if you could share results of Shor algorithm simulation here. Thanks again. $\endgroup$ – Martin Vesely Nov 8 at 5:28
  • $\begingroup$ I have just implemented swap gate. If you are interested in the new version, it is available under link above. $\endgroup$ – Martin Vesely Nov 25 at 13:10
  • $\begingroup$ @MartinVesely Great! Many thanks. $\endgroup$ – ChainedSymmetry Nov 25 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.