
Qusim.py – A toy multi-qubit quantum computer simulator written in Python - adamisntdead
https://github.com/adamisntdead/QuSimPy
======
ahelwer
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.

~~~
keyle
Thanks 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
I recommend the textbook Quantum Computing for Computer Scientists.

~~~
adamisntdead
I 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

------
da-bacon
Cool! My April fools day joke this year was a quantum programming language
made up entirely of "entanglement" and "superposition":
[https://github.com/dabacon/qsel](https://github.com/dabacon/qsel) The
simulator takes about 150 lines of python as well.

~~~
vtomole
Hey Dave, your lecture notes [0] helped us a lot when we were building our
simulator [1]. Thank you!

[0]:
[https://courses.cs.washington.edu/courses/cse599d/06wi/](https://courses.cs.washington.edu/courses/cse599d/06wi/)

[1]:
[https://github.com/QCHackers/qchackers/tree/master/software/...](https://github.com/QCHackers/qchackers/tree/master/software/kite/qvm)

~~~
da-bacon
That class was so many careers ago. Glad you enjoyed the notes. I wonder if I
taught it today: maybe I'd start by having students use a simulator, or maybe
trying to write a simple simulator themselves!

------
laughingman2
There is this quote by Jürgen Schmidhuber, director at the Swiss AI Lab IDSIA
, creator of LSTM Neural Nets that power many of our current machine learning
applications.

" General purpose quantum computation won’t work (my prediction of 15 years
ago is still standing). Related: The universe is deterministic, and the most
efficient program that computes its entire history is short and fast, which
means there is little room for true randomness, which is very expensive to
compute. What looks random must be pseudorandom, like the decimal expansion of
Pi, which is computable by a short program. Many physicists disagree, but
Einstein was right: no dice. There is no physical evidence to the contrary
randomness.html[[http://people.idsia.ch/~juergen/randomness.html](http://people.idsia.ch/~juergen/randomness.html)].

For example, Bell’s theorem does not contradict this. And any efficient search
in program space for the solution to a sufficiently complex problem will
create many deterministic universes like ours as a by-product. Think about
this. More here computeruniverse.html
[[http://people.idsia.ch/~juergen/computeruniverse.html](http://people.idsia.ch/~juergen/computeruniverse.html)]
and here.

"

I am out of depth with regards to quantum theory and quantum computation. If
anyone with better knowledge with regards to quantum computation can clarify
it would be great.

Is there any rationale to support Schmidhuber's argument, and has any advance
in making actual quantum computers disprove his theory?

~~~
jrochkind1
Hint: "There is no physical evidence to the contrary" isn't really a proof.

~~~
rejschaap
You are getting down-voted because you are shifting the burden of proof.

~~~
jrochkind1
It wasn't me that was shifting the burden of proof!

It was the original quote from Schmidhuber, claiming as if it were a known
fact "The universe is deterministic, and the most efficient program that
computes its entire history is short and fast", backed by the (arguable)
argument "There is no physical evidence to the contrary."

------
mentos
Is it possible that a massive array of GPUs might be more economical than a
few real quantum chips that need to be cooled to absolute zero?

~~~
adrianN
That depends on the number of qbits you want to simulate. Doing the
calculations on classical computers has an exponential slowdown as you need
2^n classical bits to store n qbits. It's pretty unlikely that you will ever
be able to simulate a quantum computer with more than a few dozen qbits.

~~~
AstralStorm
Indeed. I'd expect this to top of at about 64 qbits with smart maths. (Mostly
due to pointer limitations.) You could try to extend addressing but it'll be
even slower...

~~~
claudius
Just as a data point: Current state-of-the-art methods for Lanczos-type
methods on state vectors are around 40 spins/qubits incorporating many
symmetries and additional shortcuts one does not have in a generic "quantum
computer simulator". Without those symmetries/shortcuts, the limit is likely
closer to 30 qubits (i.e. approx. 16-64 GB per state vector), as it’s not only
necessary to store these beasts but also do operations on them.

If you don’t insist on a single dense state vector but a sparser tensor
network-based formulation, you can go to much larger systems (hundreds or
thousands of spins) but will be limited by the amount of entanglement you can
represent in your system.

------
nathanshammah
If you’re interested in quantum tech, here is my newsletter
[https://medium.com/quantum-tech](https://medium.com/quantum-tech)

You can subscribe here [http://eepurl.com/c10FJz](http://eepurl.com/c10FJz)

