-
Notifications
You must be signed in to change notification settings - Fork 588
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
Break up qubit operations file #1467
Conversation
Hello. You may have forgotten to update the changelog!
|
…lane into break_up_qubit
Codecov Report
@@ Coverage Diff @@
## master #1467 +/- ##
==========================================
- Coverage 98.31% 98.31% -0.01%
==========================================
Files 172 179 +7
Lines 12599 12652 +53
==========================================
+ Hits 12387 12439 +52
- Misses 212 213 +1
Continue to review full report at Codecov.
|
pennylane/ops/qubit/other.py
Outdated
from pennylane.operation import AnyWires, Operation | ||
|
||
|
||
class QFT(Operation): |
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.
Can anyone think of where this might fit better?
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.
QFT
actually feels more like a subroutine template rather than a regular qubit operation; maybe it could be moved there? (Otherwise, I think arithmetic
is the closest match, but even that's not quite right)
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.
Any reasoning as why it wasn't a subroutine template?
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.
Good question - calling in @trbromley for this thoughts since he wrote the QFT
🙂
pennylane/ops/qubit/matrix_ops.py
Outdated
# please move it to ``non_parametric_ops.py`` | ||
|
||
|
||
class MultiControlledX(ControlledQubitUnitary): |
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 @albi3ro, will be going for a full review. One thing before that is that it would be great to ensure that the reorganization is with respect to how the operations behave, not how they are coded. E.g., here MultiControlledX
should probably live in non_parametric_ops
rather than this file.
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.
An external contributor is editing 'MultiControlledX' to no longer inherit from 'ControlledQubitUnitary', at which point it can be moved to non-parametric ops.
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.
@albi3ro I would strongly recommend organizing the code around how the operation behaves/its category, rather than around how it is coded up 🤔
Even though MultiControlledX
is a matrix op internally, I feel like this is an implementation detail? How an operation is implemented should ideally not require it to change files.
As another example, as a new dev I would expect to find CNOT
in non_parametrized.py
. However, if it was instead in matrix_ops
(because it was implemented via the matrix directly), it would not be trivial for me to find it. Likewise, for a contributor making a change/improvement to an operation, requiring them to move its location sounds like an additional barrier, and would make the PR diff bigger!
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.
Just a few minor comments and things that'd be good to address. Otherwise it looks great!
from pennylane.utils import expand, pauli_eigs | ||
from pennylane.wires import Wires | ||
|
||
from .non_parametric_ops import PauliX, PauliY, PauliZ, Hadamard, CNOT |
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 might be good to address still, just changing it to an absolute import. 🙂
from pennylane.templates.state_preparations import BasisStatePreparation, MottonenStatePreparation | ||
|
||
|
||
class AdjointError(Exception): |
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.
Perhaps addressing this as well, moving the exception to the __init__.py
file would make sense here, and simply import it from there.
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.
Some comments left to be addressed, but looking on track overall to me!
Co-authored-by: antalszava <antalszava@gmail.com> Co-authored-by: Theodor <theodor@xanadu.ai>
I'll be making another PR in the near future where I focus on improving the operation tests. At that point I will bump up code code coverage, but for now we will be missing coverage on some lines. |
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 to me! 🎉 This will be so helpful in finding operations & observables! 😍 Thank you :)
Co-authored-by: antalszava <antalszava@gmail.com>
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 is great @albi3ro! Just added a few very minor (picky) suggestions to make it look a bit more like the rest of the files in the repo. 🙂
pennylane/ops/__init__.py
Outdated
class AdjointError(Exception): | ||
"""Exception for non-adjointable operations.""" | ||
pass |
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.
💯
Co-authored-by: Theodor <theodor@xanadu.ai>
Fixes #1454
This PR breaks
./pennylane/ops/qubit.py
into 8 different files in a./pennylane/ops/qubit/
folder.The new categories are: