5 ms·
For the uninitiated - to simulate a basic quantum computer, all you need is the following: * A product state vector, which is a vector of size 2^n filled with
by ahelwer 9y ago
For the uninitiated - to simulate a basic quantum computer, all you need is the following:
* A product state vector, which is a vector of size 2^n filled with complex numbers where n is the number of qbits you're using. You derive the product state from a series of individual qbits by taking their tensor product; this exponential term is why simulating quantum computers takes exponential space.
* A set of common quantum logic gates, which are (2^n)x(2^n) matrices you multiply against the product state vector to derive the new product state vector; these matrices must be unitary (their conjugate-transpose is their inverse) (edited, see [0]) and therefore reversible (quantum computers are reversible computers). The full (2^n)x(2^n) matrices are derived by taking the tensor products of several 2x2 and 4x4 matrices.
* The measurement logic, where you calculate how the product state collapses by taking the square of the absolute value of each entry in the product state (these entries are called amplitudes).
This project is an implementation of those three things in Python. There is nothing special about the above mathematical constructs save that they match the observed semantics of a quantum system. This is good! Quantum computing is accessible to anyone who has taken a basic undergraduate course in linear algebra.
[0] I previously believed all quantum operators were their own inverses (Unitary and Hermitian) but apparently that is not the case; see comments below.
- adamisntdead 9y agoThat's pretty much it! There obviously is loads of optimizations that can be done, but it obscures the pretty standard linear algebra that is used to represent and calculate the states of the quantum computer! A well-written version using OpenCL and written in rust is also available: http://github.com/qcgpu/qcgpu-rust http://github.com/qcgpu/qcgpu-rust if you are interested! Always looking for feedback
- ahelwer 9y agoI've wondered - is it a common memory optimization tactic to store the individual qbit values until they become entangled and the product state cannot be factored? Or is entanglement common enough that it wouldn't be worth the overhead?
- adamisntdead 9y agoIt depends! If you use a lot of scratch qubits, it can be useful to use sparse vectors, but if you are going to be doing a lot of superpositions / entangling many qubits, this isn't as effective, and performance suffers a lot. Libraries such as libquantum (written in C) use sparse state vectors, whereas the QCGPU library uses dense state vectors (as it is being stored on the GPU, it doesn't really impact the performance of the computer it's being simulated on). I benchmarked it, and the rust one was way faster for everything, apart from the initialization of registers and the application of some controlled gates
- sytelus 9y agoThis is awesome. Over time I have came across too many posts claiming to explain QCs to hackers and they go on pages and pages without distilling this simple little thing. It would be great if you can also implement something like Shore's algo with your simulator.
- adamisntdead 9y agoYou can, but it would be very slow! This implementation gets really really slow around 15/16 qubits. I am currently working on implementing shors algorithm into my main, simulation library. I already have grovers algorithm! https://qcgpu.github.io/qcgpu-rust/book/algorithms/grover.html https://qcgpu.github.io/qcgpu-rust/book/algorithms/grover.ht...
- AstralStorm 9y agoMight it be caused by the use of slow matrix operation algorithms rather than the size?
- thethirdone 9y ago> these matrices must be their own inverse (in mathematical terms, Unitary and Hermitian). The full (2^n)x(2^n) matrices are derived by taking the tensor products of several 2x2 and 4x4 matrices. Gates don't have to be Hermitian right? Like NOT^(1/2) is not Hermitian.
- adamisntdead 9y agoYep, observables in quantum mechanics are represented by hermitian matrices
- ahelwer 9y agoOh wow, am I wrong? I thought all quantum operators were their own inverses, which since they're all unitary means they must be hermitian.
- andrepd 9y ago>these matrices must be their own inverse (in mathematical terms, Unitary and Hermitian) Not necessarily. The only requirement on quantum operators is that they must be unitary. Only observables have to be Hermitian (so they have real eigenvalues).
- ahelwer 9y agoThanks for the correction! I thought all quantum operators were their own inverse, but I guess I was wrong.
- comnetxr 9y agoNeither unitary or hermitian means that operators are there own inverse. Unitary here means that the inverse is the same as the complex transpose - which means that there is an inverse and it is easy to find. This is important as quantum circuits must be composed of unitaries, i.e. the circuit is reversable. Hermitian operators have no particular special property with respect to inverses.
- andrepd 9y agoQuantum gates are unitary because of conservation of probability (the out state must be remain normalized to 1). If it's also hermitian (equal to conjugate transpose) then it's its own inverse.
- keyle 9y agoThanks for the description but that made very little sense to a 'regular' developer like me. Any chance you could break it down and bring it down to my level?
- ahelwer 9y agoI recommend the textbook Quantum Computing for Computer Scientists.
- adamisntdead 9y agoI would also have to recommend "Quantum Mechanics, The Theoretical Minimum" by Leonard Susskind, if you wish to go a little bit further into general quantum mechanics
- adamisntdead 9y agoYou should check out these videos, one of them might give you an understanding! - https://www.youtube.com/watch?v=JhHMJCUmq28 https://www.youtube.com/watch?v=JhHMJCUmq28 | Quantum Computers Explained - https://www.youtube.com/watch?v=IrbJYsep45E https://www.youtube.com/watch?v=IrbJYsep45E | The Mathematics of Quantum Computers - https://www.youtube.com/watch?v=wUwZZaI5u0c https://www.youtube.com/watch?v=wUwZZaI5u0c | Hacking at Quantum Speed with Shor's Algorithm - https://www.youtube.com/playlist?list=PL1826E60FD05B44E4 https://www.youtube.com/playlist?list=PL1826E60FD05B44E4 | A series by the author of the standard textbook These are videos I particularly like!
- Deestan 9y agoThis sounds snide, but please believe me my intention is to be helpful. Have you considered instead raising your level? The relevant topic, as stated in the comment, is linear algebra.
- perl4ever 9y agoMy experience with linear algebra is that it's possible to get an excellent grade in class, without learning anything, provided the tests are multiple choice...
- Moodles 9y agoI'm no expert, but SMBC covers quantum computers quite well too :-) https://www.smbc-comics.com/comic/the-talk-3 https://www.smbc-comics.com/comic/the-talk-3
- alemhnan 9y agoThe red button was a nice touch. I genuinely laughed.
- lorenzorhoades 9y agoAfter reading that article, you pretty much become an expert. I'm going to go apply to dwave now.
- rorykoehler 9y agoThis is a great succinct explanation. I definitely understand QC's better after reading it. Thanks.