Hi everyone, what exactly is the difference between below two codes. The only difference I think is that the Code 1 is working for some range of shot values but code Code 2 is working for some default values of some shots.
The Code 1 explanation says that as we increase the values of shots, we reaches close to exact values that are obtained by Code 2. I really do not understand this concept.
# Code 1
#-----------
# An array to store your results
shot_results = []
# Different numbers of shots
shot_values = [100, 1000, 10000, 100000, 1000000]
for shots in shot_values:
# CREATE A DEVICE, CREATE A QNODE, AND RUN IT
dev = qml.device('default.qubit', wires=1, shots= shots)
@qml.qnode(dev)
def circuit():
qml.RX(np.pi/4, wires=0)
qml.Hadamard(wires=0)
qml.PauliZ(wires=0)
return qml.expval(qml.PauliY(wires=0))
result= circuit()
shot_results.append(result)
# Code 1
#-----------
dev = qml.device('default.qubit', wires=1)
@qml.qnode(dev)
def circuit():
# IMPLEMENT THE CIRCUIT IN THE PICTURE AND MEASURE PAULI Y
qml.RX(np.pi/4, wires=0)
qml.Hadamard(wires=0)
qml.PauliZ(wires=0)
return qml.expval(qml.PauliY(wires=0))
print(circuit())