-
Notifications
You must be signed in to change notification settings - Fork 586
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
Add a QutritChannel operation #5649
Comments
Hi @trbromley , I want to tackle this issue as part of unitaryhack. |
Nice @Tarun-Kumar07! Let us know how we can help as you get started. Regarding assigning, we typically don't assign the issue until a resolving PR has fixed it. We don't want to discourage other attempts at the bounty, and it's also encouraged if contributors want to optionally work together. |
No problem, thanks @trbromley |
I'm a bit puzzled by the existing Currently, At some point I thought "Ok, but then one can just add the checks that the matrices are # check the dimension of all Kraus matrices are valid
if any(K.ndim != 2 for K in K_list):
raise ValueError(
"Dimension of all Kraus matrices must be (2**num_wires, 2**num_wires)."
) show that it is intended to accept Kraus operators in higher dimensions. So, is it preferable to:
For instance, for now, nothing prevents to instantiate On an unrelated topic, I wanted to test a similar code of yours to see how import pennylane as qml
import numpy as np
kraus_X = [
np.array([
[0., 1.],
[1., 0.]
])
]
dev = qml.device("default.qubit")
@qml.qnode(dev)
def f():
#qml.QubitChannel(kraus_X, 0)
qml.X(wires=0)
return qml.expval(qml.PauliZ(wires=0))
f() Running it with
Did I misunderstand something? Sorry for the long comment! |
Hi @trbromley , I have a doubt. @pytest.mark.parametrize("angle", np.linspace(0, 2 * np.pi, 7))
def test_grad_depolarizing(self, angle):
"""Test that analytical gradient is computed correctly for different states. Channel
grad recipes are independent of channel parameter"""
dev = qml.device("default.qutrit", wires=1)
prob = pnp.array(0.5, requires_grad=True)
@qml.qnode(dev, diff_method="parameter-shift")
def circuit(p):
qml.TRX(angle, wires=0, subspace=(0, 1))
qml.TRX(angle, wires=0, subspace=(1, 2))
qml.QutritDepolarizingChannel(p, wires=0)
return qml.expval(qml.GellMann(0, 3) + qml.GellMann(0, 8))
expected_errorless = (
(np.sqrt(3) - 3) * (1 - np.cos(2 * angle)) / 24
- 2 / np.sqrt(3) * np.sin(angle / 2) ** 4
+ (np.sqrt(1 / 3) + 1) * np.cos(angle / 2) ** 2
)
assert np.allclose(circuit(prob), ((prob - (1 / 9)) / (8 / 9)) * expected_errorless)
gradient = np.squeeze(qml.grad(circuit)(prob))
assert np.allclose(gradient, circuit(1) - circuit(0))
assert np.allclose(gradient, -(9 / 8) * expected_errorless) When I add
|
@tnemoz, I think the below behaviour is wrong
Reason being for QubitChannel kraus matrices should be if any(K.shape[0] != 2 for K in K_list): because the condition right now if any(K.ndim != 2 for K in K_list): will return |
@Tarun-Kumar07 I totally agree, I just wanted a confirmation that this wasn't intentional before going on! |
Hi @Tarun-Kumar07 , this is expected. @tnemoz , this is the same reason why you are unable to use |
I think that either 1 or 3 are reasonable solutions. While I do agree that it is generally better practice to use a parent class for cases like this with a lot of duplicate code, With that in mind, I would leave it to your discretion to choose either option 1 or 3 as I think that in this specific situation they're both valid. |
Hello, I went with approach 1 and I'm at the testing stage but I'm having some trouble with the differentiation part. I tried following a method similar to
I get the following error when I run this
But this is a line that was originally in |
Hi everyone! It's great to see some engagement around this bounty 🤩 I just to clarify how things work in case of multiple contribution attempts for this bounty:
So far, @Tarun-Kumar07 has opened a PR and we'll be taking a look at that soon. Thanks! |
Hi @MashAliK . |
**Context:** The goal of this PR is to create a qutrit counterpart to the QubitChannel, enabling noise to be defined using a set of 3×3 Kraus operators. **Description of the Change:** - Implement `QutritChannel` similar to `QubitChannel` **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** Fixes #5649 --------- Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai> Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com> Co-authored-by: Christina Lee <chrissie.c.l@gmail.com>
Hi @trbromley and @mudit2812 , |
Awesome job @Tarun-Kumar07! Congratulations on completing this bounty 🚀 |
@Tarun-Kumar07, would you optionally like to be tagged in any of our announcements around unitaryHACK or the upcoming PennyLane 0.37 release at the start of July? This would be on LinkedIn and Twitter, so if you would like, please share your username(s). |
Hey @trbromley , I would love that :).
|
Feature details
Version 0.36 of PennyLane includes a
"default.qutrit.mixed"
device that is capable of simulating qutrit systems in the mixed-state setting. This unlocks the ability to simulate qutrit-based noise, and we would like to add more qutrit noise channels to complement our existing range of qutrit operators.This objective of this issue is to provide a qutrit analogue of$(3\times 3)$ -dimensional Kraus operators.
QubitChannel
, which would allow noise to be specified via a collection ofImplementation
It should be possible to execute the following code:
This can be done by following these instructions:
Implement a
qml.QutritChannel
operation inpennylane/ops/channel.py
, which defines the qutrit equivalent of theqml.QubitChannel
operation. This operation should:wires
andid
(optional string representation of the operator).compute_kraus_matrices
, which is astaticmethod
that returns the Kraus matrices in a list, and_flatten
functions (just like inqml.QubitChannel
).Add unit and integration tests:
QNode
that applies theqml.QutritChannel
operation is correct.QNode
s that apply theqml.QutritChannel
operation can be differentiated using theparameter-shift
,finite-diff
, andbackprop
differentiation methods and that the computed gradients/jacobians are correct.default.qutrit
anddefault.qutrit.mixed
devices.A successful PR must include:
Check out our development guide for more information, and don't hesitate to reach out to us if you need assistance.
How important would you say this feature is?
1: Not important. Would be nice to have.
Additional information
Existing work is underway to support specific qutrit channels in PRs #5502 and #5503.
The text was updated successfully, but these errors were encountered: