Can my MatLab code be used as a good simulator of a quantum computer?

0

1

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.

Martin Vesely

Posted 2019-11-06T05:51:27.370

Reputation: 7 763

1Hi 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 – glS – 2019-11-06T14:41:17.363

Ok, thanks. Tried to rephase as a request/question. – Martin Vesely – 2019-11-06T14:44:24.357

1that'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). – glS – 2019-11-06T14:48:05.707

3@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. – Jonathan Trousdale – 2019-11-06T15:18:39.217

Thanks for help with formulating a question. Hope now everything is right. – Martin Vesely – 2019-11-06T21:33:12.207

@MartinVesely I spent some time getting familiar with the structure and trying implement a 3-qubit fourier transform. I'm running into some roadblocks. I opened a chat channel here to discuss.

– Jonathan Trousdale – 2019-11-07T00:27:07.940

Answers

2

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

Jonathan Trousdale

Posted 2019-11-06T05:51:27.370

Reputation: 2 714

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. – Martin Vesely – 2019-11-08T05:28:05.127

I have just implemented swap gate. If you are interested in the new version, it is available under link above. – Martin Vesely – 2019-11-25T13:10:28.123

@MartinVesely Great! Many thanks. – Jonathan Trousdale – 2019-11-25T17:57:46.210