Conflict between Packages

I’m trying to develop a qiskit noise model using pennylane-qiskit, but there seems to be some issue between the packages.

Here is the code I’m running in my juptyer notebook.

import qiskit
import pennylane as qml
import qiskit.providers.aer.noise as noise

# create a bit flip error with probability p = 0.01
p = 0.01
my_bitflip = noise.pauli_error([('X', p), ('I', 1 - p)])

# create an empty noise model
my_noise_model = noise.NoiseModel()

# attach the error to the hadamard gate 'h'
my_noise_model.add_quantum_error(my_bitflip, ['h'], [0])

dev4 = qml.device('qiskit.aer', wires=1, noise_model = my_noise_model)

The error is on the last line. Here is the specific error message. I’ve tried reinstalling the packages and fiddling with the different versions but with no luck.

ContextualVersionConflict                 Traceback (most recent call last)
Cell In[4], line 15
     12 # attach the error to the hadamard gate 'h'
     13 my_noise_model.add_quantum_error(my_bitflip, ['h'], [0])
---> 15 dev4 = qml.device('qiskit.aer', wires=1, noise_model = my_noise_model)

File /opt/anaconda3/lib/python3.9/site-packages/pennylane/__init__.py:317, in device(name, *args, **kwargs)
    314 options.update(kwargs)
    316 # loads the device class
--> 317 plugin_device_class = plugin_devices[name].load()
    319 if Version(version()) not in SimpleSpec(plugin_device_class.pennylane_requires):
    320     raise DeviceError(
    321         f"The {name} plugin requires PennyLane versions {plugin_device_class.pennylane_requires}, "
    322         f"however PennyLane version {__version__} is installed."
    323     )

File /opt/anaconda3/lib/python3.9/site-packages/pkg_resources/__init__.py:2516, in EntryPoint.load(self, require, *args, **kwargs)
   2509     warnings.warn(
   2510         "Parameters to load are deprecated.  Call .resolve and "
   2511         ".require separately.",
   2512         PkgResourcesDeprecationWarning,
   2513         stacklevel=2,
   2514     )
   2515 if require:
-> 2516     self.require(*args, **kwargs)
   2517 return self.resolve()

File /opt/anaconda3/lib/python3.9/site-packages/pkg_resources/__init__.py:2539, in EntryPoint.require(self, env, installer)
   2533 # Get the requirements for this entry point with all its extras and
   2534 # then resolve them. We have to pass `extras` along when resolving so
   2535 # that the working set knows what extras we want. Otherwise, for
   2536 # dist-info distributions, the working set will assume that the
   2537 # requirements for that extra are purely optional and skip over them.
   2538 reqs = self.dist.requires(self.extras)
-> 2539 items = working_set.resolve(reqs, env, installer, extras=self.extras)
   2540 list(map(working_set.add, items))

File /opt/anaconda3/lib/python3.9/site-packages/pkg_resources/__init__.py:827, in WorkingSet.resolve(self, requirements, env, installer, replace_conflicting, extras)
    824 if not req_extras.markers_pass(req, extras):
    825     continue
--> 827 dist = self._resolve_dist(
    828     req, best, replace_conflicting, env, installer, required_by, to_activate
    829 )
    831 # push the new requirements onto the stack
    832 new_requirements = dist.requires(req.extras)[::-1]

File /opt/anaconda3/lib/python3.9/site-packages/pkg_resources/__init__.py:873, in WorkingSet._resolve_dist(self, req, best, replace_conflicting, env, installer, required_by, to_activate)
    870 if dist not in req:
    871     # Oops, the "best" so far conflicts with a dependency
    872     dependent_req = required_by[req]
--> 873     raise VersionConflict(dist, req).with_context(dependent_req)
    874 return dist

ContextualVersionConflict: (websocket-client 0.58.0 (/opt/anaconda3/lib/python3.9/site-packages), Requirement.parse('websocket-client~=1.5.1'), {'qiskit-ibmq-provider'})

Thank you in advance for the help

Hey @lingling36109! Welcome to the forum :sunglasses:!

I’ve tried reinstalling the packages and fiddling with the different versions but with no luck.

I think it’s most likely an issue still with your package versions not being up-to-date. I’m able to run this with no issues. Here are my versions:

PennyLane             0.30.0
PennyLane-Lightning   0.30.0
PennyLane-qiskit      0.30.1
qiskit                0.43.0
qiskit-aer            0.12.0
qiskit-ibm-provider   0.6.0
qiskit-ibm-runtime    0.10.0
qiskit-ibmq-provider  0.20.2
qiskit-terra          0.24.0
websocket-client      1.5.2
websockets            11.0.3

You can check your package versions by doing python -m pip list. Does the output of that correspond with what you think your package versions should be?

Hello! Thank you for the help. I’m actually still having issues. I had to downgrade several of my packages to match your versions, but despite that I still get the ContextualVersionConflict error, although the error message is slightly different now.

---------------------------------------------------------------------------
ContextualVersionConflict                 Traceback (most recent call last)
Cell In[1], line 15
     12 # attach the error to the hadamard gate 'h'
     13 my_noise_model.add_quantum_error(my_bitflip, ['h'], [0])
---> 15 dev4 = qml.device('qiskit.aer', wires=1, noise_model = my_noise_model)

File /opt/anaconda3/lib/python3.9/site-packages/pennylane/__init__.py:317, in device(name, *args, **kwargs)
    314 options.update(kwargs)
    316 # loads the device class
--> 317 plugin_device_class = plugin_devices[name].load()
    319 if Version(version()) not in SimpleSpec(plugin_device_class.pennylane_requires):
    320     raise DeviceError(
    321         f"The {name} plugin requires PennyLane versions {plugin_device_class.pennylane_requires}, "
    322         f"however PennyLane version {__version__} is installed."
    323     )

File /opt/anaconda3/lib/python3.9/site-packages/pkg_resources/__init__.py:2516, in EntryPoint.load(self, require, *args, **kwargs)
   2509     warnings.warn(
   2510         "Parameters to load are deprecated.  Call .resolve and "
   2511         ".require separately.",
   2512         PkgResourcesDeprecationWarning,
   2513         stacklevel=2,
   2514     )
   2515 if require:
-> 2516     self.require(*args, **kwargs)
   2517 return self.resolve()

File /opt/anaconda3/lib/python3.9/site-packages/pkg_resources/__init__.py:2539, in EntryPoint.require(self, env, installer)
   2533 # Get the requirements for this entry point with all its extras and
   2534 # then resolve them. We have to pass `extras` along when resolving so
   2535 # that the working set knows what extras we want. Otherwise, for
   2536 # dist-info distributions, the working set will assume that the
   2537 # requirements for that extra are purely optional and skip over them.
   2538 reqs = self.dist.requires(self.extras)
-> 2539 items = working_set.resolve(reqs, env, installer, extras=self.extras)
   2540 list(map(working_set.add, items))

File /opt/anaconda3/lib/python3.9/site-packages/pkg_resources/__init__.py:827, in WorkingSet.resolve(self, requirements, env, installer, replace_conflicting, extras)
    824 if not req_extras.markers_pass(req, extras):
    825     continue
--> 827 dist = self._resolve_dist(
    828     req, best, replace_conflicting, env, installer, required_by, to_activate
    829 )
    831 # push the new requirements onto the stack
    832 new_requirements = dist.requires(req.extras)[::-1]

File /opt/anaconda3/lib/python3.9/site-packages/pkg_resources/__init__.py:873, in WorkingSet._resolve_dist(self, req, best, replace_conflicting, env, installer, required_by, to_activate)
    870 if dist not in req:
    871     # Oops, the "best" so far conflicts with a dependency
    872     dependent_req = required_by[req]
--> 873     raise VersionConflict(dist, req).with_context(dependent_req)
    874 return dist

ContextualVersionConflict: (websocket-client 0.58.0 (/opt/anaconda3/lib/python3.9/site-packages), Requirement.parse('websocket-client>=1.5.1'), {'qiskit-ibm-runtime', 'qiskit-ibmq-provider', 'qiskit-ibm-provider'})

Interesting. Based on your error traceback, it looks like you’re not using a virtual environment. I would suggest doing so for a couple of reasons:

  1. It’s a fresh start! Akin to turning off/on again
  2. It’s much easier to manage projects where package versions might conflict with other projects.

You can learn about setting up virtual environments here: Managing environments — conda 23.5.1.dev52 documentation

Let me know if that helps!

Ah, actually I had some difficulties running the virtual environments as well, but I actually realized what the error means. I think the problem is that my jupyter notebook is running websocket-client version 0.58.0, when the actual version installed on my computer is 1.5.2, which is unusual. And because it’s running version 0.58.0, there’s a conflict with the packages ‘qiskit-ibmq-provider’, ‘qiskit-ibm-provider’, ‘qiskit-ibm-runtime’ since they have this requirement: ‘websocket-client>=1.5.1’.

Ah, I see! Well, you can install packages inside of a Jupyter notebook as follows:

!pip install pennylane

or with conda:

!conda install pennylane

The key here is the !. Does adding !pip install websocket-client==1.5.2 at the top of your notebook help?

Thank you so much for the help, but unfortunately I’m still getting an error. Whenever I try that I get the following error:

/bin/bash: pip: command not found

What about with conda?

The same issue pops up:

/bin/bash: conda: command not found

Okay — so might just be worth it to install these packages with the correct python that your notebook is calling on.

In a terminal, can you type:

python3.9 -m pip install <package>

Then try using your notebook again? You can get rid of the !pip install commands at the start.

If this doesn’t work, I recommend getting acquainted with virtual environments :slight_smile:.

I got to run by using google colab lol. I have no idea what the issue was, but thank you so much for your time!

Nice! And my pleasure :slight_smile:. Yep, Google colab is nice for making sure that packages will function as they should :raised_hands:. Glad this is working for you now!