Noise simulations with shots

Hi there, I am playing around with adding noise to my quantum circuits with shots and am trying to use the decorator approach to add error sources to my quantum ansatz. Below is a simple script:

import pennylane as qml
from pennylane.transforms import insert
from functools import partial

dev = qml.device('default.mixed', wires=2, shots = 10)
    
    @partial(insert, qml.AmplitudeDamping, 0.2, position="end")
    @qml.qnode(dev, interface = 'torch')
    def circuit():
        qml.Hadamard(wires=0)
        qml.CNOT(wires=[0, 1])
        return qml.sample()
    
    samples = circuit()
    print(output)

When i run this however i get the following error:

TypeError: AmplitudeDamping.__init__() missing 2 required positional arguments: 
'gamma' and 'wires'

I believe I am providing this with the decorator and the device? Any incite would be great, many thanks!

Hi @Aaron_Thomas , I think there may be a bug here. I can replicate your issue. We’re investigating. Thank you for bringing this up!

Thank you very much for taking a look at this!

Hi @Aaron_Thomas !

Fortunately there’s an easy fix.
In your code make sure to set the arguments for partial as keyword arguments:

@partial(insert, op=qml.AmplitudeDamping, op_args=0.2, position="end")

This should make your code run.

We’ve also fixed the example in the docs so they should work as of the next release.

Thanks for opening this thread! Let me know if you run into other issues.

Hi @Aaron_Thomas. Slightly off-topic, but I want to mention that we’ll be adding noise models in the upcoming PennyLane 0.37 release at the start of July.

These noise models will allow you to control the recipe for when to insert noisy channels after target operations. You can check out the WIP example here.

2 Likes