Error when calling device()

Hi, I am having an error when calling the device:

DeviceError                               Traceback (most recent call last)
<ipython-input-41-5e0abc3e2a88> in <module>()
  4 from pennylane.plugins import default_qubit
  5 import matplotlib.pyplot as plt
----> 6 dev = qml.device('default.qubit', wires=1)
  7 
  8 # Set a random seed

/usr/local/lib/python3.6/dist-packages/pennylane/__init__.py in device(name, *args, **kwargs)
128 
129     raise DeviceError(
--> 130         "Device does not exist. Make sure the required plugin is installed."
131     )
132 

DeviceError: Device does not exist. Make sure the required plugin is installed.

How can I solve it?
Thanks in advance

1 Like

Hi @abignu,

:thinking: That’s an unusual error. The default.qubit plugin shouldn’t need any extra installation (comes pre-packaged within pennylane). My guess would be something has gone wrong with your pennylane install. Can you try the following and tell us the output?

import pennylane as qml
qml.about()

Also, can you try uninstalling and reinstalling it and let me know how that works?

Thanks,
Nathan

PS you shouldn’t need to directly import the plugin (line 4 of your code). This is handled automatically by the qml.device function.

1 Like

Hi @nathan, thanks for your reply. I was working in Google Colab. I found on another page that restarting the runtime fixes this issue. So I have already fixed it.

Thanks for your time

Agustin

1 Like

Glad you got it working :slight_smile:

Hi both, I’m having the same error on colab and have tried restarting the runtime a couple of times without success.

The output from qml.about() I get is:

Version: 0.7.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author: None
Author-email: None
License: Apache License 2.0
Location: /usr/local/lib/python3.6/dist-packages
Requires: toml, networkx, numpy, autograd, appdirs, semantic-version, scipy
Required-by: PennyLane-qiskit
Platform info:           Linux-4.14.137+-x86_64-with-Ubuntu-18.04-bionic
Python version:          3.6.9
Numpy version:           1.17.5
Scipy version:           1.4.1
Installed devices:

This is what I’m doing to install it: https://colab.research.google.com/drive/1bPipFzEuYgNPLVeJ5HXVP-kpG1o5QFmJ which I’m basing on https://pennylane.ai/install.html

Ignore me, restarted it again and it works :blush:

1 Like

I had the same problem with google collab, then I used this code snippet to restart runtime

import os

def restart_runtime():
  os.kill(os.getpid(), 9)
restart_runtime()

Calling qml.about() should have the following output

Name: PennyLane
Version: 0.8.1
Summary: PennyLane is a Python quantum machine learning library 
by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author: None
Author-email: None
License: Apache License 2.0
Location: /usr/local/lib/python3.6/dist-packages
Requires: appdirs, networkx, scipy, semantic-version, numpy, toml, 
autograd
Required-by: 
Platform info:           Linux-4.14.137+-x86_64-with-Ubuntu-18.04-bionic
Python version:          3.6.9
Numpy version:           1.17.5
Scipy version:           1.4.1
Installed devices:
- default.gaussian (PennyLane-0.8.1)
- default.qubit (PennyLane-0.8.1)
- default.tensor (PennyLane-0.8.1)
- default.tensor.tf (PennyLane-0.8.1)

If you’re working manually in a colab notebook, it should also be sufficient (and probably safer?) to restart the runtime via the available menu commands (i.e., no need to script it in python)

Thank you so much!
I faced a similar issue while working in Kaggle.
Resolved after restarting the runtime environment with your code snippet.
Only restarting the session didn’t quite help earlier.
Thank you once again

Very helpful.
I had the similar output for qml.about() earlier but resolved after restarting the environment.

Thank you for posting this query

Hi, I am having an issue in loading the device default.tensor.tf on Pennylane 0.11.0.

dev = qml.device('default.tensor.tf', wires=4)

This gives the following error:

ImportError: default.tensor device requires TensorNetwork>=0.3

This is the complete error message:

ModuleNotFoundError                       Traceback (most recent call last)
C:\ProgramData\Anaconda3\envs\tf-gpu\lib\site- 
packages\pennylane\beta\devices\default_tensor.py in <module>
 26 try:
---> 27     import tensornetwork as tn
  28 ModuleNotFoundError: No module named 'tensornetwork'

During handling of the above exception, another exception occurred:

 ImportError                               Traceback (most recent call last)
<ipython-input-3-385680400a10> in <module>
----> 1 dev = qml.device('default.tensor.tf', wires=4)

C:\ProgramData\Anaconda3\envs\tf-gpu\lib\site- 
packages\pennylane\__init__.py in device(name, *args, **kwargs)
182 
183         # loads the plugin device class
--> 184         plugin_device_class = plugin_devices[name].load()
185 
186         if Version(version()) not in 
Spec(plugin_device_class.pennylane_requires):

C:\ProgramData\Anaconda3\envs\tf-gpu\lib\site- 
packages\pkg_resources\__init__.py in load(self, require, *args, 
**kwargs)
2448         if require:
2449             self.require(*args, **kwargs)
-> 2450         return self.resolve()
2451 
2452     def resolve(self):

C:\ProgramData\Anaconda3\envs\tf-gpu\lib\site-packages\pkg_resources\__init__.py in resolve(self)
2454         Resolve the entry point from its module and attrs.
2455         """
-> 2456         module = __import__(self.module_name, fromlist=['__name__'], level=0)
2457         try:
2458             return functools.reduce(getattr, self.attrs, module)

C:\ProgramData\Anaconda3\envs\tf-gpu\lib\site-packages\pennylane\beta\devices\__init__.py in <module>
 17 .. currentmodule:: pennylane.beta.devices
 18 """
---> 19 from .default_tensor import DefaultTensor
 20 from .default_tensor_tf import DefaultTensorTF

C:\ProgramData\Anaconda3\envs\tf-gpu\lib\site-packages\pennylane\beta\devices\default_tensor.py in <module>
 31         raise ImportError("default.tensor device requires TensorNetwork>=0.3")
 32 except ImportError as e:
---> 33     raise ImportError("default.tensor device requires TensorNetwork>=0.3")
 34 
 35 

ImportError: default.tensor device requires TensorNetwork>=0.3

The error persists even after upgrading my tensorflow version to 2.3.0

import tensorflow as tf
print(tf.__version__)
2.3.0

How to resolve this?

HI @Vineesha! You will need to install TensorNetwork in order to use this device. You can do this via pip:

pip install tensornetwork==0.3
1 Like

It works! Thank you :smiley:

1 Like

DeviceError: Device does not exist. Make sure the required plugin is installed.

Please reply solution. Error is same

Hi @Amandeep, what device are you using?

  • If you want to use a device from an external plugin, the plugin will need to be separately installed using pip before the device is available.

  • If you are using PennyLane with Google Colab, you will need to restart the runtime (RuntimeRestart Runtime) before any PennyLane devices are available.

device=qiskit.aer and i am not using google colab.

device=qiskit.aer and i am not using google colab.

To access the qiskit.aer device, you will need to install the PennyLane-Qiskit plugin, if you haven’t already:

pip install pennylane-qiskit

If you have installed the plugin already, then it could be something to do with your system configuration - could you post the output of qml.about()?

1 Like

Name: PennyLane
Version: 0.11.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author: None
Author-email: None
License: Apache License 2.0
Location: c:\users\hp\anaconda3\lib\site-packages
Requires: numpy, appdirs, scipy, autograd, toml, semantic-version, networkx
Required-by:
Platform info: Windows-10-10.0.19041-SP0
Python version: 3.8.3
Numpy version: 1.18.5
Scipy version: 1.5.0
Installed devices:

  • default.gaussian (PennyLane-0.11.0)
  • default.qubit (PennyLane-0.11.0)
  • default.qubit.autograd (PennyLane-0.11.0)
  • default.qubit.tf (PennyLane-0.11.0)
  • default.tensor (PennyLane-0.11.0)
  • default.tensor.tf (PennyLane-0.11.0)

@Amandeep it looks like the PennyLane-Qiskit plugin is not installed. You can install it using pip:

pip install pennylane-qiskit
1 Like