I have a general question about the entire codebook which I suspect is due to some backend processes. Due to the randomness of measurements, you always get a different value of expected value/probabilities and this variance is reduced as the number of shots approaches infinity. However, the examples in the codebook seem to return an analytic deterministic output.
For example, the following code snippet from I.10 will always return the same values, but if you add shots=1000
into the dev
object, which I believe is the default, then it introduces the randomness that you would expect.
dev = qml.device('default.qubit', wires=1)
@qml.qnode(dev)
def circuit():
qml.RX(np.pi/4, 0)
qml.Hadamard(0)
qml.PauliZ(0)
return qml.expval(qml.PauliY(0))
print(circuit())
Update: I have found an explanation for my question in another thread:
Since you are working with a simulator, you can calculate the exact value of the wave function without having to run different shots, just multiplying matrices. Not indicating the number of shots means that you want the analytical solution (this will not be possible with a real quantum computer)
Also note that the function qml.device()
used in the codebooks is different to the class qml.Device()
which has the default setting as shots=1000
. I got mixed up with the documentation of these two.
Though I am still curious on cases when qml.device()
cannot find analytical solutions. And why do real quantum computers not compute analytical solutions? Is it because the cases in which analytical solutions are computable are trivial, and can just be left to simulations?