def speed(nb_qbits, nb_circuits, repeat=1, depth=2, gpu=False, multicore = False): if gpu: params = cupy.pi * cupy.random.rand(depth, nb_qbits, nb_circuits) else: params = np.pi * np.random.rand(depth, nb_qbits, nb_circuits) start_time = ftime() for _ in range(repeat): mq.initQreg(nb_qbits, nb_circuits, gpu = gpu, multicore = multicore) for l in range(depth): for i in range(nb_qbits): mq.SX(i) mq.RZ(i, params[l,i]) mq.SX(i) for i in range(nb_qbits - 1): mq.CZ(i, i+1) for i in range(nb_qbits): mq.SX(i) mq.measureAll() end_time = ftime() return (end_time - start_time)/repeat
import manyq as mq import numpy as np angles = np.array([np.pi/3,np.pi/2,2*np.pi/3]) mq.initQreg(2,angles.shape[0]) mq.SX(0) mq.SX(1) mq.RZ(0,angles) mq.SX(0) mq.SX(1) mq.measureAll() shots = mq.makeShots(100) np.set_printoptions(precision=2) print(mq.Qreg.inQ,"\n") print(mq.Qreg.mQ,'\n') print(shots)
def measure_all(self): mq.measureAll() self.__txt += "measure_all()" return self
def __run_circuit__(self, nbshots=None): if not nbshots: return mq.measureAll() else: return mq.makeShots(nbshots)