In [2]:
import qiskit
import qiskit.quantum_info as qiskit_quantum_info
import numpy as np
import matplotlib.pyplot as plt
In [3]:
import random
nbqubits = 2
# labels = ['0','1']
labels=['00','10','01','11']
qc = qiskit.QuantumCircuit(nbqubits)
qc.h(0)
qc.cx(0,1)
# qc.rz(random.uniform(0,2*np.pi), 0)
# qc.rx(np.pi/3,0)
# qc.rz(random.uniform(0,2*np.pi), 0)
# qc.rx(np.pi/3,0)
stateVec = qiskit_quantum_info.Statevector.from_instruction(qc)
print(stateVec.data)
probavec = stateVec.probabilities()
print(probavec)
nbshots = 10000
shots = np.random.multinomial(nbshots, probavec)
print(shots)
# plt.bar(range(2**nbqubits), probavec)
# plt.xticks(range(2**nbqubits),labels=labels)
qc.draw(output='mpl')
[0.70710678+0.j 0. +0.j 0. +0.j 0.70710678+0.j] [0.5 0. 0. 0.5] [5029 0 0 4971]
Out[3]:
In [5]:
%%time
nbqubits = 24
qc = qiskit.QuantumCircuit(nbqubits)
qc.h(0)
for n in range(nbqubits-1):
qc.cx(n,n+1)
stateVec = qiskit_quantum_info.Statevector.from_instruction(qc)
probadict = stateVec.probabilities_dict()
for k,v in probadict.items():
print(f"'{k}': {v:.2f}")
print(f"{stateVec.data.nbytes/1024/1024:.0f}MB")
qc.draw(output='mpl')
'000000000000000000000000': 0.50 '111111111111111111111111': 0.50 256MB CPU times: user 20 s, sys: 19.2 s, total: 39.3 s Wall time: 5.87 s
Out[5]: