-
Notifications
You must be signed in to change notification settings - Fork 575
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
Create qml.PauliError
#1781
Create qml.PauliError
#1781
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1781 +/- ##
==========================================
+ Coverage 98.80% 98.81% +0.01%
==========================================
Files 225 227 +2
Lines 17123 17291 +168
==========================================
+ Hits 16918 17086 +168
Misses 205 205
Continue to review full report at Codecov.
|
Hey @antalszava, you're right using the I suggest returning a dictionary containing an entry for every wire up to the maximum wire specified. Each of the operators which are specified in the For now it is only possible to specify one string of operators, one list of wires and one probability value. An extension could maybe return a list of dictionaries... I hope this points into the direction you were looking for and I'm excited about your opinion on this solution |
Hi @MoritzWillmann, I've been giving this a bit more thought and also started considering the integration with The approach that you present sounds like something I had in mind. However, this approach will also likely need significant changes to
To use the representation that you've proposed and I had in mind, we would need to change So what would likely fit the existing API best after all is to compute the dense Kraus matrices and pass those to the Let me know what you think! |
Hey @antalszava, I totally agree that any solution right now is suboptimal. I can implement it in the original way with the dense Kraus matrices and add a notice (and maybe an upper limit for wires?). I'll also check later if it's possible to use any sparse matrix representation. I think this doesn't make a whole lot of sense though because matrix density should be quite high if p is not 0 or 1. Cheers Moritz |
Hey @antalszava,
when trying to access them with
Cheers Moritz |
Hi @MoritzWillmann, yes, this is something new related to The In [2]: qml.BitFlip(0.3, wires=0)
Out[2]: BitFlip(0.3, wires=[0])
In [3]: op = qml.BitFlip(0.3, wires=0)
In [4]: op.wires
Out[4]: <Wires = [0]>
In [5]: op = qml.BitFlip.wires
In [6]: op
Out[6]: <property at 0x7f49218e3540> Even perhaps with Another avenue to go down might be to make On another note, the |
pennylane/ops/channel.py
Outdated
r"""PauliError(operators, wires, p) | ||
Arbitrary number qubit, arbitrary Pauli error channel. | ||
|
||
This Class returns a dictionary of Kraus Matrices specified in the operators string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing: it's the _kraus_matrices method that will return the matrices (in some format).
Hey @antalszava, |
Hey @antalszava, this is my final suggestion for now. Let me know what you think 🙂 |
hey @antalszava, sorry again for the large delay. I added the suggested changes. I'll start adding the tests for |
Hey @antalszava, can you take a look at the tests. I'm not 100% sure about them but I tried to cross check with Quirk as good as I can. Cheers Moritz |
Hi @MoritzWillmann, sure! I'll be taking a look and leave a note here. |
p (float): The probability of the operator being applied | ||
wires (Sequence[int] or int): The wires the channel acts on | ||
|
||
**Example:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! :)
def _kraus_matrices(cls, *params): | ||
operators, p = params[0], params[1] | ||
|
||
nq = len(operators) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nq = len(operators) | |
nq = len(self.wires) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, that's the same problem we had in the beginning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch! We don't have self
here indeed.
] | ||
|
||
@pytest.mark.parametrize("ops", diagonal_ops) | ||
def test_diagonal_kraus(self, ops, tol): | ||
"""Tests that matrices of non-diagonal unitary operations are retrieved correctly""" | ||
"""Tests that matrices of diagonal unitary operations are retrieved correctly""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @MoritzWillmann, this is amazing! 😍 Overall all looks good, my comments are minor suggestions. 👍 🙂 Thank you for coming back and adding the remaining test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you so much for this great addition @MoritzWillmann and for hanging in there throughout the process 🎉 😊
It was a pleasure 💯 |
Context: Additional channel
qml.ops.PauliError
Description of the Change: Adding error channel for arbitrary Pauli operations on arbitrary number of wires
Benefits: More flexible error channel
Possible Drawbacks: Possibly expensive, no nice interface
Related GitHub Issues: closes #1529
Note: a package called
mistune
used bym2r2
has been raising errors when running the documentation CI checks. This PR further closes #1983, to resolve this issue.cc: @antalszava