Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] pennylane.DeviceError: Gate Adjoint(DepolarizingChannel) not supported on device default.mixed #6351

Open
1 task done
kilian106 opened this issue Oct 7, 2024 · 2 comments
Labels
bug 🐛 Something isn't working

Comments

@kilian106
Copy link

Expected behavior

I want to call qml.adjoint(qml.DepolarizingChannel)(0.1, wires=0) with the default.mixed device. I expect the circuit to perform the adjoint of qml.DepolarizingChannel

Actual behavior

The error pennylane.DeviceError: Gate Adjoint(DepolarizingChannel) not supported on device default.mixed is printed and the code execution is aborted.

Additional information

No response

Source code

import pennylane as qml
dev = qml.device("default.mixed", wires=1)
@qml.qnode(dev)
def circuit():
    qml.adjoint(qml.DepolarizingChannel)(0.1, wires=0)
    return qml.expval(qml.PauliZ(0))

circuit()

Tracebacks

Traceback (most recent call last):
  File "/mnt/c/Users/kil39759/Code/qsvr_v2/test.py", line 8, in <module>
    circuit()
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/workflow/qnode.py", line 1020, in __call__
    return self._impl_call(*args, **kwargs)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/workflow/qnode.py", line 1008, in _impl_call
    res = self._execution_component(args, kwargs, override_shots=override_shots)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/workflow/qnode.py", line 957, in _execution_component
    res = qml.execute(
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/workflow/execution.py", line 660, in execute
    results = inner_execute(tapes)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/workflow/execution.py", line 212, in inner_execute
    results = device.execute(transformed_tapes, execution_config=execution_config)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/devices/modifiers/single_tape_support.py", line 32, in execute
    results = batch_execute(self, circuits, execution_config)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/devices/legacy_facade.py", line 456, in execute
    results = _set_shots(dev, first_shot)(dev.batch_execute)(circuits, **kwargs)
  File "/usr/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/devices/_qubit_device.py", line 510, in batch_execute
    res = self.execute(circuit, **kwargs)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/logging/decorators.py", line 61, in wrapper_entry
    return func(*args, **kwargs)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/devices/default_mixed.py", line 771, in execute
    return super().execute(circuit, **kwargs)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/devices/_qubit_device.py", line 276, in execute
    self.check_validity(circuit.operations, circuit.observables)
  File "/home/groot/venv/lib/python3.10/site-packages/pennylane/devices/_legacy_device.py", line 1001, in check_validity
    raise qml.DeviceError(
pennylane.DeviceError: Gate Adjoint(DepolarizingChannel) not supported on device default.mixed

System information

Name: PennyLane
Version: 0.38.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: /home/groot/venv/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane_Lightning

Platform info:           Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python version:          3.10.12
Numpy version:           1.26.4
Scipy version:           1.13.1
Installed devices:
- default.clifford (PennyLane-0.38.0)
- default.gaussian (PennyLane-0.38.0)
- default.mixed (PennyLane-0.38.0)
- default.qubit (PennyLane-0.38.0)
- default.qubit.autograd (PennyLane-0.38.0)
- default.qubit.jax (PennyLane-0.38.0)
- default.qubit.legacy (PennyLane-0.38.0)
- default.qubit.tf (PennyLane-0.38.0)
- default.qubit.torch (PennyLane-0.38.0)
- default.qutrit (PennyLane-0.38.0)
- default.qutrit.mixed (PennyLane-0.38.0)
- default.tensor (PennyLane-0.38.0)
- null.qubit (PennyLane-0.38.0)
- lightning.qubit (PennyLane_Lightning-0.38.0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@kilian106 kilian106 added the bug 🐛 Something isn't working label Oct 7, 2024
@isaacdevlugt
Copy link
Contributor

Hey @kilian106! Thanks for this 🙏

This is a gap we're aware of, but it's very helpful that you requested this feature in PennyLane 🤩. We have some future plans for more noise model features and we'll put this in our roadmap 🗺️.

Just curious, is this feature blocking your work? If so, how urgent is it for you?

@kilian106
Copy link
Author

Hi Isaac, thank you for the fast response!
I want to evaluate the influence of noise on Quantum Kernel Methods. The kernel evaluation is performed on the simulator using the fidelity kernel $$k(\boldsymbol{x}_i, \boldsymbol{x}_j) = \vert \bra{0^{\otimes n}} U^\dagger(\boldsymbol{x}_i) U(\boldsymbol{x}_j) \ket{0^{\otimes n}} \vert ^2$$.
Initially, I defined my unitary like

def unitary(x): 
   qml.RZ(x, wires=0) 
   qml.DepolarizingChannel(0.1, wires=0)

and then define my circuit like

dev = qml.device("default.mixed", wires=1)
@qml.qnode(dev, interface="torch")
def circuit(x1, x2):
   unitary(x1)
   qml.adjoint(unitary)(x2)
   return qml.probs(wires=0)

However, I realized this is not what I want to do since I want to insert the original (not the adjoint) noise channel after every applied gate, in both $U$ and $U^\dagger$.
I came up with a workaround that seems to work fine, where I define the noise model using qml.NoiseModel and @partial(qml.transforms.add_noise, noise_model=noise_model).

As a summary, I am not blocked by this feature. If you are planning to implement this feature, it would be helpful for me to have the option to force qml.adjoint(qml.DepolarizingChannel)(p, wire) to apply qml.DepolarizingChannel(p, wire) instead of its adjoint.

@kilian106 kilian106 reopened this Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants