ProjectQ-Framework / ProjectQ

ProjectQ: An open source software framework for quantum computing
https://projectq.ch
Apache License 2.0
876 stars 271 forks source link

Add histogram plotting feature for simulator #362

Closed AriJordan closed 4 years ago

AriJordan commented 4 years ago

Allows users to draw a histogram plot of all possible measurement outcomes.

Typical usage:

from projectq import MainEngine
from projectq.ops import H, CNOT, Measure, All
from projectq.libs.hist import histogram
import matplotlib.pyplot as plt

eng = MainEngine()
qureg = eng.allocate_qureg(4)
H | qureg[0]
CNOT | (qureg[0], qureg[1])
CNOT | (qureg[0], qureg[2])
CNOT | (qureg[0], qureg[3])
eng.flush()

histogram(eng.backend, qureg)
plt.show()

All(Measure) | qureg