How to write a high-performance quantum computing simulator in just a few lines of code

Photo by Vlada Karpovich from Pexels

High-performance, really?

   ┌─────────┐         ┌─────────┐                      ┌─────────┐
0: ┤ RX(π/3) ├────■────┤ RY(π/5) ├────────────────■─────┤ RX(π/7) ├
├─────────┤┌───┴───┐└─────────┘┌─────────┐ │ └────┬────┘
1: ┤ RX(π/3) ├┤ RX(3) ├─────■─────┤ RY(π/5) ├─────┼──────────┼─────
├─────────┤└───────┘ ┌───┴───┐ ├─────────┤┌────┴────┐ │
2: ┤ RX(π/3) ├──────────┤ RX(3) ├─┤ RY(π/5) ├┤ RX(π/7) ├─────■─────
└─────────┘ └───────┘ └─────────┘└─────────┘

moara vs qasm-simulator

Circuits of how much depth can be executed in under 500ms. Left: qasm-simulator. Right: moara running qiskit circuits.

moara vs qvm

Circuits of how much depth can be executed in under 500ms. Left: qvm. Right: moara running quil

moara vs qsim

Circuits of how much depth can be executed in under 500ms. Left: qsim. Right: moara running cirq
Circuits of how much depth can be executed in under 200ms. Left: qsim. Right: moara
Circuits of how much depth can be executed in under 50ms.

How it was designed

  R = [ a b ]
[ c d ]
[ a b 0 0 0 0 0 0 ]
┌───┐ [ c d 0 0 0 0 0 0 ]
0: ┤ R ├ [ 0 0 a b 0 0 0 0 ]
└───┘ [ 0 0 c d 0 0 0 0 ]
1: ───── => [ 0 0 0 0 a b 0 0 ]
[ 0 0 0 0 c d 0 0 ]
2: ───── [ 0 0 0 0 0 0 a b ]
[ 0 0 0 0 0 0 c d ]
[ a 0 b 0 0 0 0 0 ]
0: ───── [ 0 a 0 b 0 0 0 0 ]
┌───┐ [ c 0 d 0 0 0 0 0 ]
1: ┤ R ├ => [ 0 c 0 d 0 0 0 0 ]
└───┘ [ 0 0 0 0 a 0 b 0 ]
2: ───── [ 0 0 0 0 0 a 0 b ]
[ 0 0 0 0 c 0 d 0 ]
[ 0 0 0 0 0 c 0 d ]
[ a 0 0 0 b 0 0 0 ]
0: ───── [ 0 a 0 0 0 b 0 0 ]
[ 0 0 a 0 0 0 b 0 ]
1: ───── => [ 0 0 0 a 0 0 0 b ]
┌───┐ [ c 0 0 0 d 0 0 0 ]
2: ┤ R ├ [ 0 c 0 0 0 d 0 0 ]
└───┘ [ 0 0 c 0 0 0 d 0 ]
[ 0 0 0 c 0 0 0 d ]
               [ 1 0 0 0 0 0 0 0 ]
┌───┐ [ 0 1 0 0 0 0 0 0 ]
0: ┤ R ├ [ 0 0 a b 0 0 0 0 ]
└─┬─┘ [ 0 0 c d 0 0 0 0 ]
1: ──■── => [ 0 0 0 0 1 0 0 0 ]
[ 0 0 0 0 0 1 0 0 ]
2: ───── [ 0 0 0 0 0 0 a b ]
[ 0 0 0 0 0 0 c d ]

[ 1 0 0 0 0 0 0 0 ]
┌───┐ [ 0 1 0 0 0 0 0 0 ]
0: ┤ R ├ [ 0 0 1 0 0 0 0 0 ]
└─┬─┘ => [ 0 0 0 1 0 0 0 0 ]
1: ──┼── [ 0 0 0 0 a b 0 0 ]
│ [ 0 0 0 0 c d 0 0 ]
2: ──■── [ 0 0 0 0 0 0 a b ]
[ 0 0 0 0 0 0 c d ]

[ 1 0 0 0 0 0 0 0 ]
[ 0 a 0 b 0 0 0 0 ]
0: ──■── [ 0 0 1 0 0 0 0 0 ]
┌─┴─┐ [ 0 c 0 d 0 0 0 0 ]
1: ┤ R ├ => [ 0 0 0 0 1 0 0 0 ]
└───┘ [ 0 0 0 0 0 a 0 b ]
2: ───── [ 0 0 0 0 0 0 1 0 ]
[ 0 0 0 0 0 c 0 d ]

Finishing up

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store