Error when trying to create a strawberryfields.tf device

When I try to run the following piece of code:

dev = qml.device('strawberryfields.tf', wires=6, cutoff_dim=3)

I get the error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-a9c3d55d3613> in <module>
----> 1 dev = qml.device('strawberryfields.tf', wires=6, cutoff_dim=3)

C:\ProgramData\Anaconda3\envs\Pennylane14TF\lib\site-packages\pennylane\__init__.py in device(name, *args, **kwargs)
    251 
    252         # load device
--> 253         return plugin_device_class(*args, **options)
    254 
    255     raise DeviceError("Device does not exist. Make sure the required plugin is installed.")

C:\ProgramData\Anaconda3\envs\Pennylane14TF\lib\site-packages\pennylane_sf\tf.py in __init__(self, wires, cutoff_dim, analytic, shots, hbar)
    191 
    192     def __init__(self, wires, *, cutoff_dim, analytic=True, shots=1000, hbar=2):
--> 193         super().__init__(wires, analytic=analytic, shots=shots, hbar=hbar)
    194         self.cutoff = cutoff_dim
    195         self.params = dict()

C:\ProgramData\Anaconda3\envs\Pennylane14TF\lib\site-packages\pennylane_sf\simulator.py in __init__(self, wires, analytic, shots, hbar)
     82         self.state = None
     83         self.samples = None
---> 84         self.analytic = analytic
     85 
     86     def execution_context(self):

AttributeError: can't set attribute

This code worked fine with Pennylane v0.13.0, but in the new version of Pennylane (v0.15.1) it gives the error I reported above.
Do I need to change the parameters I pass to the qml.device function, or is it a bug?

Hey @Denis-Stanev,

The error seems to be caused by a the new logic of how shots is used to define whether a device is analytic or not (see here under " Devices do not have an analytic argument or attribute anymore.")

Are you sure you have the latest version of the StrawberryFields plugin installed? Could you post the output of qml.about() (after importing pennylane as qml)?

1 Like

I had version 0.14 of the pennylane-sf plugin installed.
I have now updated to version 0.15 and it seems to work now.
Thank you for your help.

Great, happy to hear you sorted it out!