
Getting Started with Quantum Computing in Python - chriotte
http://dataespresso.com/en/2018/07/22/Tutorial-Generating-random-numbers-with-a-quantum-computer-Python
======
sv12l
Tangentially, noticed some good Python libs for Quantum computing have started
appearing lately (one from google, Cirq for eg) could be a natural progression
(from scientific computing). Good to see Python is making a presence there as
well. Looks like it's going to stay relevant for a very long time.

~~~
adamisntdead
Quantum computing won't require much extra power that python can't provide,
the only heavy processing will be circuit generation which is (as far as we
can see at the moment) fine to use python for.

In the sort term though there's a big place for languages like C, C++ and Rust
for things like simulations which need to be done

~~~
Strilanc
Yes, there are two reasons that python is an ideal tool for quantum computing
libraries at the moment.

\- In the NISQ era [1], circuits have limited depth and size. It doesn't
matter so much which language (or even algorithm!) you use when N<1000.

\- Simulating a circuit is expensive, but all the heavy lifting can be
delegated to highly optimized C code. The most expensive part of Cirq's
simulation is (or soon will be) a call to `numpy.einsum` [2].

1: [https://arxiv.org/abs/1801.00862](https://arxiv.org/abs/1801.00862)

2:
[https://github.com/quantumlib/Cirq/blob/24638f234704686c4bb6...](https://github.com/quantumlib/Cirq/blob/24638f234704686c4bb6e365613259813fe58571/cirq/linalg/transformations.py#L140)

------
brian_herman
[http://ericbrown.com/you-probably-dont-need-machine-
learning...](http://ericbrown.com/you-probably-dont-need-machine-learning.htm)
s/machine\ learning/quantum\ computing/g

~~~
mindcrime
I kinda feel like this has become the new "middlebrow dismissal". It seems
superficially insightful, but doesn't actually say anything useful. Sure, many
- hell, maybe even most - people don't need (machine learning | quantum
computing | big data | a partridge in a pear tree | whatever). But plenty do.

Merely pointing out this dichotomy doesn't do anything to help people
understand when they do, or don't, need those things.

How about a comment along the lines of "Here's how to know when you need to
use quantum computing, and how to know when you shouldn't"?

~~~
throwawaymath
I agree. I find comments like that one to be incredibly stifling to
discussion. In my opinion there's a certain smugness to dismissals like this,
and I think they don't contribute much for several reasons.

First, the fact that most of us don't need quantum computers doesn't mean we
shouldn't feel inspired to learn about them. It's a thoroughly interesting
subject. I don't believe I'll live to see practical quantum computers for most
of the use cases they're hyped about now, but that didn't stop me from making
them my research focus in graduate school.

Second, in many exceptionally well-moderated forums for critical discussion
(e.g. /r/AskHistorians), there is a mandate in place that requires commenters
to _engage_ with their source material. This means it's not enough to link to
something that's ostensibly accurate; you also need to critically clarify that
material to make it accessible to other readers and contextually relevant.
When a link is posted without that engagement, you force others to click
through to decide for themselves not only _why_ it's relevant, but _why_ it's
accurate.

Finally, it's not a novel insight. There are scores of comments repeating the
same point for any number of hyped topics, from machine learning to blockchain
to JavaScript frameworks to quantum computing. It's essentially a meme. But
it's more insidious than a meme, because memes are obviously low effort and
insufficientally novel. This is a middlebrow dismissal precisely because it
appears intellectual, yet has no insightful contribution.

And this is the result: instead of discussing what might be a very interesting
Python library for quantum computing, we're litigating the appropriateness of
a dismissive top comment. What have we achieved?

------
wzeng
Another open source Python framework is Forest from Rigetti Computing.
[https://www.rigetti.com/products](https://www.rigetti.com/products)

A simple getting started post on a similar topic is here:
[https://medium.com/rigetti/how-to-write-a-quantum-program-
in...](https://medium.com/rigetti/how-to-write-a-quantum-program-in-10-lines-
of-code-for-beginners-540224ac6b45) which might be useful for comparison.

------
fancyfish
I've also had fun playing around with StrawberryFields
([https://github.com/XanaduAI/strawberryfields](https://github.com/XanaduAI/strawberryfields)),
a photonic quantum computing library which has some good visualizations with
simulators driven by NumPy and TensorFlow. Xanadu's even made Blackbird, a
language specifically for quantum.

~~~
ealhad
This is a real diamond.

------
chriotte
Hi guys! The next part in the tutorial series is out
[https://news.ycombinator.com/item?id=17637553](https://news.ycombinator.com/item?id=17637553)

------
leot
Does anyone know of a pedagogically-minded quantum computer simulator?

~~~
Strilanc
Quirk: [https://algassert.com/quirk](https://algassert.com/quirk)

\- Drag-and-drop what-you-see-is-what-you-get UI instead of script-based.
Smooths out the learning curve.

\- Supports putting state displays in the middle of the circuit, so you can
directly view normally-inaccessible information instead of inferring it from
experience or algebra.

\- Fast. It updates all displays interactively, as you edit the circuit. Very
easy to experiment, e.g. just drag a gate around seeing what it does in
different places.

~~~
leot
Thank you!

------
furqs
I have a question. Please excuse my ignorance but I thought that once the
world has a working quantum computer, the world as we know it will be
destroyed. Since a quantum computer can solve any NP hard problem in a
polynomial time, it would mean it could break any kind of crypto, any kind of
security and can brute force anything. Why hasn't that happened yet since its
2018 and we already have quantum computers?

~~~
0xbxd
That's not how quantum computers work. They ("quantum networking")
significantly increase security as you can tell whether a qubit has already
been observed (eavesdropped) or not. Also, there are proven asymmetric
cryptographic algorithms that work with quantum computers. Algorithms based on
factorization (RSA) won't be safe any more but you still need a large amount
of qubits (around 1000s - don't cite me on this please) to break them, which
has not been achieved yet.

Definitely not the end of the world.

edit:// And they can not solve any NP-complete problem in polynomial time.
That is a common misconception and not based on facts.

edit2:// Researchers working on quantum computers actually don't believe that
they will make it mainstream (partially due to their complexity like cooling
them down to near zero Kelvin) but instead be specialized systems available
via the internet for rent - or something similar. More on the side of
predicting complex systems like the weather than powering your smartphone.
Then again, who thought the PC would make it mainstream.

------
sidcool
But confused. How does this work without Quantum hardware?

~~~
detaro
simulation/emulation

~~~
max_
Related & interesting read;

Simulating physics with computers Richard P. Feynman —
[https://www.researchgate.net/publication/254705307_RICHARD_F...](https://www.researchgate.net/publication/254705307_RICHARD_FEYNMAN_SIMULATING_PHYSICS_WITH_COMPUTERS)

------
peter_retief
i cant think where i could possibly use this but it seems concise and easy to
follow, so here i go..

~~~
peter_retief
Ok, interesting, I dont really get the superposition on a logic gate though
and can't see any relation to entanglement?

------
throwaway37585
Quantum computing (under the quantum circuit model) basically consists of
repeatedly applying unitary matrices to complex vectors (the qubits). They are
like your Boolean logic gates but they must be unitary, which implies they
must be reversible:
[https://en.wikipedia.org/wiki/Quantum_logic_gate](https://en.wikipedia.org/wiki/Quantum_logic_gate).

You can think of unitary matrices as the complex analogue of rotation matrices
([https://en.wikipedia.org/wiki/Unitary_matrix](https://en.wikipedia.org/wiki/Unitary_matrix)),
so what quantum logic gates are doing is "rotating" these vectors around in a
complex space.

~~~
repsilat
In classical computing nobody thinks of programming as consisting of a series
of logic gates, though :-).

Should we expect more abstractions from quantum computing models in the
future? Quantum data structures, common quantum operations etc? Or are quantum
algorithms too different from one another, or are "the quantum parts" of most
quantum algorithms very compact? (Or do we try to keep them as compact as
possible because of hardware constraints?)

~~~
randomsearch
Great comment. Circuits are particularly unhelpful in describing quantum
algorithms because they usually indicate a fixed problem size, and they do not
provide an insight into entanglement, one of the fundamental “resources” of
QC.

We need new representations and much better abstractions to get away from the
low-level thinking we are currently promoting.

~~~
throwaway37585
> [Quantum circuits] do not provide an insight into entanglement

What do you mean? Entanglement occurs whenever the state of a system cannot be
factored into a product of the states of its components. Quantum circuits can
definitely do that. Just take a qubit, apply the Hadamard gate to it, then
CNOT it with a second qubit to get an entangled Bell state. You can see it in
action here:
[http://demonstrations.wolfram.com/GeneratingEntangledQubits/](http://demonstrations.wolfram.com/GeneratingEntangledQubits/).

Quantum circuits are also used to describe all kinds of quantum algorithms
(quantum Fourier transform, Grover’s algorithm, quantum teleportation, etc).

~~~
randomsearch
I mean, they do not illustrate when qubits have become entangled. You can't
see that. I'm sure we can do better.

~~~
throwaway37585
I’m not sure what you mean by “illustrate when qubits have become entangled”.
Can you explain?

~~~
randomsearch
Entanglement is fundamental to QC, right? So in order to be a useful
visualisation of an algorithm, a pictorial representation like a circuit
should give some intuition to aid understanding such as: which qubits can
potentially be entangled at a given stage in the circuit, etc.

~~~
throwaway37585
Why is this (or the demo I linked to earlier) not a satisfactory
representation?

[https://qph.fs.quoracdn.net/main-
qimg-1ab704621d3c845630ab6f...](https://qph.fs.quoracdn.net/main-
qimg-1ab704621d3c845630ab6fdc6d1b6259).

