Alternative device options for noisy circuit

Hi all, I’m working on a project that requires support for noisy operations, and I am wondering if there are any faster device options that default.mixed. In particular, I am wondering if there are any third party or community plugins that are faster than default.mixed and support qml.BitFlip and qml.PhaseFlip operations.

Hi @justin6626 ,

Currently default.mixed is our general recommended device for noisy operations. It is slower because it needs to work with density matrices, which takes more memory and time.

If you want to simulate Clifford circuits you could try our DefaultClifford device. Check the section on Error Channels in this device’s documentation to learn how to use them with this device.

And since you asked about errors … here’s a preview to what’s coming!

We’ll be adding PennyLane noise models in the upcoming 0.37 release in about 3 weeks. These noise models will allow you to control the recipe for when to insert noisy channels after target operations. You can check out the (Work In Progress) example here.

Let us know if you have any additional questions!

1 Like

My apologies for the delay, thank you very much for getting back to me on this! I am wondering also how efficient it would be, comparatively speaking, to use a qiskit.aer Pennylane device instantiated with a NoiseModel object.

Hi @justin6626 , it’s hard to say at the moment how efficient that will be. It may be better, or worse, or worse now but improved later. For now, just adding this feature this is an important step to give people flexibility in doing different kinds of simulations.
I hope you can try it out and let us know how we can improve it in future releases!

Thanks again for getting back to me! I am trying it out now, but I get an error when I attempt to instantiate a device with qiskit.aer.

Here are the specs of my installation:

Name: PennyLane
Version: 0.36.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /N/u/justsing/Quartz/.local/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Cirq, Pennylane-Pyquest, PennyLane-qiskit, pennylane-qulacs, PennyLane-Rigetti, PennyLane_Lightning, PennyLane_Lightning_GPU

Platform info:           Linux-4.18.0-513.24.1.el8_9.x86_64-x86_64-with-glibc2.28
Python version:          3.11.5
Numpy version:           1.26.4
Scipy version:           1.13.1
Installed devices:
- default.clifford (PennyLane-0.36.0)
- default.gaussian (PennyLane-0.36.0)
- default.mixed (PennyLane-0.36.0)
- default.qubit (PennyLane-0.36.0)
- default.qubit.autograd (PennyLane-0.36.0)
- default.qubit.jax (PennyLane-0.36.0)
- default.qubit.legacy (PennyLane-0.36.0)
- default.qubit.tf (PennyLane-0.36.0)
- default.qubit.torch (PennyLane-0.36.0)
- default.qutrit (PennyLane-0.36.0)
- default.qutrit.mixed (PennyLane-0.36.0)
- null.qubit (PennyLane-0.36.0)
- qulacs.simulator (pennylane-qulacs-0.36.0)
- qiskit.aer (PennyLane-qiskit-0.36.0)
- qiskit.basicaer (PennyLane-qiskit-0.36.0)
- qiskit.basicsim (PennyLane-qiskit-0.36.0)
- qiskit.ibmq (PennyLane-qiskit-0.36.0)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.36.0)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.36.0)
- qiskit.remote (PennyLane-qiskit-0.36.0)
- lightning.gpu (PennyLane_Lightning_GPU-0.36.0)
- lightning.qubit (PennyLane_Lightning-0.36.0)
- cirq.mixedsimulator (PennyLane-Cirq-0.36.0)
- cirq.pasqal (PennyLane-Cirq-0.36.0)
- cirq.qsim (PennyLane-Cirq-0.36.0)
- cirq.qsimh (PennyLane-Cirq-0.36.0)
- cirq.simulator (PennyLane-Cirq-0.36.0)
- rigetti.numpy_wavefunction (PennyLane-Rigetti-0.36.0)
- rigetti.qpu (PennyLane-Rigetti-0.36.0)
- rigetti.qvm (PennyLane-Rigetti-0.36.0)
- rigetti.wavefunction (PennyLane-Rigetti-0.36.0)
- pyquest.mixed (Pennylane-Pyquest-0.1.0)
- pyquest.pure (Pennylane-Pyquest-0.1.0)

This is the code that I am using to verify the device instantiation:

import pennylane as qml
dev = qml.device('qiskit.aer', wires=2)

Here is the error that I get:

Traceback (most recent call last):
  File "/geode2/home/u040/justsing/Quartz/qml_dev_test.py", line 13, in <module>
    dev = qml.device('qiskit.aer', wires=2)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/pennylane/__init__.py", line 382, in device
    plugin_device_class = plugin_devices[name].load()
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/N/soft/rhel8/deeplearning/Python-3.11.5/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/N/soft/rhel8/deeplearning/Python-3.11.5/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/pennylane_qiskit/__init__.py", line 22, in <module>
    from .runtime_devices import IBMQCircuitRunnerDevice
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/pennylane_qiskit/runtime_devices.py", line 21, in <module>
    from qiskit_ibm_runtime import QiskitRuntimeService
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/qiskit_ibm_runtime/__init__.py", line 207, in <module>
    from .qiskit_runtime_service import QiskitRuntimeService
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/qiskit_ibm_runtime/qiskit_runtime_service.py", line 27, in <module>
    from qiskit_ibm_runtime import ibm_backend
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/qiskit_ibm_runtime/ibm_backend.py", line 44, in <module>
    from .provider_session import (
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/qiskit_ibm_runtime/provider_session.py", line 19, in <module>
    from .utils.converters import hms_to_seconds
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/qiskit_ibm_runtime/utils/__init__.py", line 29, in <module>
    from .json import RuntimeEncoder, RuntimeDecoder, to_base64_string
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/qiskit_ibm_runtime/utils/json.py", line 73, in <module>
    from qiskit_ibm_runtime.options.zne_options import ExtrapolatorType
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/qiskit_ibm_runtime/options/__init__.py", line 100, in <module>
    from .environment_options import EnvironmentOptions
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/qiskit_ibm_runtime/options/environment_options.py", line 17, in <module>
    from .utils import primitive_dataclass
  File "/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/qiskit_ibm_runtime/options/utils.py", line 23, in <module>
    from pydantic import ConfigDict, ValidationInfo, field_validator
ImportError: cannot import name 'ValidationInfo' from 'pydantic' (/N/u/justsing/Quartz/.local/lib/python3.11/site-packages/pydantic/__init__.cpython-311-x86_64-linux-gnu.so)

Any guidance that you can provide would be much appreciated.

Hi @justin6626 ,

I’m not being able to replicate your issue. I suggest updating PennyLane and PennyLane-Qiskit and restarting your kernel

python -m pip install pennylane pennylane-qiskit --upgrade

If this doesn’t work then I recommended that you create a new virtual environment to avoid any installation issues. You can create a virtual environment with Conda
and install PennyLane as follows:

  1. Install Miniconda following the instructions here.
  2. Open your terminal (mac) or command line (Windows).
  3. Create a new Conda environment with: conda create --name <name_of_your_environment> python=3.10
  4. Activate the environment with: conda activate <name_of_your_environment>
  5. Install PennyLane with: python -m pip install pennylane
  6. Install other useful packages with: python -m pip install jupyter pennylane-qiskit

Note that you will be installing 3 packages here: PennyLane, Jupyter, and PennyLane-Qiskit. Also, note that where it says <name_of_your_environment> you can choose any name that you want.

Then you can open a notebook and run your code:

import pennylane as qml
dev = qml.device('qiskit.aer', wires=2)

Let me know if this fixes your issue.

Thank you very much for getting back to me again! I believe I actually managed to resolve the issue by reinstalling pydantic at the latest version. I noticed that when pennylane-qiskit is installed using pip, it installs an outdated version of pydantic and downgrades the existing pydantic version if a more recent one is installed. That might be something to look at in the next patch.

Oh that’s interesting @justin6626 . If you try this in a new environment (created as I mentioned in my previous post) do you get the same issue?

I’m thinking that the behaviour you’re seeing is due to some conflicts with existing packages in your environment. This is why I always recommend starting from a fresh environment. But if this behaviour persists even in a new and clean environment then it’s worth investigating.

When I install everything with !pip install pennylane pennylane-qiskit in Colab it pulls the latest version of pydantic (2.7.4 at the moment) with no issues.