question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warn/raise in case shot noise and caching are enabled at the same time?

See original GitHub issue

Feature details

When default.qubit with shots != None but also cache=1 is used then the same (noisy) result is returned again and again when a QNode is called. It is hard to imagine a case where this is what a user wants.

Either they want a QNode to return a noisy result that is different each time it is called (they can get this by setting cache=0), or they want only a single noisy result, in which case caching doesn’t provide any benefit.

I think it would be nice to raise an exception or at least a warning when a user makes a device with shot noise and caching enabled.

Alternatively the the device could go back to state caching, as it used to be in ancient times… This would give a speed benefit because the circuit would not need to be re-evaluated when the same shot-noisy QNode is called several times.

Implementation

To demonstrate the ā€œproblemā€ consider this sample program:

import pennylane as qml
from pennylane import numpy as np

shots=76

dev = qml.device(
    'default.qubit',
    wires=2,
    shots=shots,
    cache=1,
)

np.random.seed(87)
params = np.random.randn(2, 2, 3)
observable_as_array = np.array([[ 1. +0.j,  0. +0.j,  0. +0.j,  0. +0.j],
                                [ 0. +0.j,  0.4+0.j, 21.6+0.j,  0. +0.j],
                                [ 0. +0.j, 21.6+0.j, -0.4+0.j,  0. +0.j],
                                [ 0. +0.j,  0. +0.j,  0. +0.j, -1. +0.j]])

@qml.qnode(dev, diff_method='parameter-shift')
def circuit(params):
    qml.templates.layers.StronglyEntanglingLayers(params, wires=range(dev.num_wires))
    return qml.expval(qml.Hermitian(observable_as_array, wires=range(dev.num_wires)))

for _ in range(10):
    print(circuit(params))

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
cvjjmcommented, Mar 29, 2022

Yes, that is entirely correct.

1reaction
josh146commented, Mar 29, 2022

Good points @trbromley, this is a good reason to support the same tape multiple times šŸ¤”

but I don’t think qml.execute supports a differerent shot value for each input tape?

It doesn’t atm, but this is something I would like to add - allow shots to be metadata on tape objects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shot noise - Wikipedia
Shot noise or Poisson noise is a type of noise which can be modeled by a Poisson process. Photon noise simulation. Number of...
Read more >
1 Shot Noise - Physics 123/253
In order to ā€œseeā€ Shot Noise, the carriers must be constrained to flow past in one direction only. The carrier entering the ā€œobservationā€...
Read more >
Release 1.3 Brain-Score Team
The results of this method are cached by default (according to the ... At the same time, new brain data can quickly be...
Read more >
Theoretical Way to Overcome Photon Shot Noise Limits
The paper points to a way to overcome what is considered to be a fundamental limit - photon shot noise. The authors also...
Read more >
Two-Stage Interference Cancellation for Device-to ... - NCBI
Wireless device-to-device (D2D) caching networks are studied, in which n nodes are distributed uniformly at random over the network area.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found