what is the number of shots? when I use a default.qubit device. Is the number of shots affects the performance of the circuit.
When you submit a job to a quantum hardware device, the device will execute the submitted circuit, and then perform measurements on each wire — on a qubit device, the output will be a list of '0’s and '1’s.
The more samples, or shots, we take, the better the estimate of the output statistic.
In PennyLane, you specify how many shots you want to use to estimate these statistics when you create your device:
dev = qml.device("qiskit.ibmq", backend="ibmq_rome", wires=5, shots=1000) @qml.qnode(dev) def circuit(x): qml.RX(x, wires=0) return qml.expval(qml.PauliZ(0))
When we execute this circuit, we will get the expectation value of the Z observable using 1000 shots:
>>> circuit(0.54) 0.32543 >>> circuit(0.54) 0.33764
The output has some level of stochasticity — repeated evaluations will give slightly varying output.
When using simulators, we also have the option of calculating the exact statistics. The simulator will compute the wavefunction of the circuit prior to measurement, and calculate the exact result:
dev = qml.device("default.qubit", wires=5, analytic=True)
This is the result you would expect if you increase the number of shots on a sampling device \rightarrow\infty. Here, repeated circuit evaluation will always return the same, exact, result.
So to answer your question: on devices that sample, such as hardware devices or simulators with
analytic=False, increasing the number of shots increases the accuracy of the output.
Some simulators, however, can compute these statistics exactly, so are not affected by changing the number of shots.
Hope that helps!
Thanks a lot for your explanation.
Can I use another gate to measure expectation values instead of Z gate?
Hi, @ZainabAli, definitely! A list of available observables is available here: https://pennylane.readthedocs.io/en/stable/introduction/operations.html#qubit-observables