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

Break up qubit operations file #1467

Merged
merged 45 commits into from
Jul 29, 2021
Merged

Break up qubit operations file #1467

merged 45 commits into from
Jul 29, 2021

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Jul 21, 2021

Fixes #1454

This PR breaks ./pennylane/ops/qubit.py into 8 different files in a ./pennylane/ops/qubit/ folder.

The new categories are:

  • non parametric ops
  • parametric ops
  • qchem ops
  • state preparations
  • observables
  • arithmetic ops
  • arbitrary ops: things like Qubit Unitary
  • other: currently just QFT. couldn't figure out where to put it

@albi3ro albi3ro added code quality 🎓 Discussion and improvements to code quality WIP 🚧 Work-in-progress labels Jul 21, 2021
@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov
Copy link

codecov bot commented Jul 21, 2021

Codecov Report

Merging #1467 (5826ed5) into master (69800c4) will decrease coverage by 0.00%.
The diff coverage is 98.65%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
pennylane/ops/qubit/non_parametric_ops.py 96.78% <96.78%> (ø)
pennylane/ops/qubit/matrix_ops.py 97.11% <97.11%> (ø)
pennylane/ops/qubit/parametric_ops.py 99.78% <99.78%> (ø)
pennylane/ops/__init__.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/__init__.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/arithmetic_ops.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/observables.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/qchem_ops.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/state_preparation.py 100.00% <100.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69800c4...5826ed5. Read the comment docs.

@albi3ro albi3ro removed the WIP 🚧 Work-in-progress label Jul 21, 2021
from pennylane.operation import AnyWires, Operation


class QFT(Operation):
Copy link
Contributor Author

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?

Copy link
Contributor

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)

Copy link
Contributor Author

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?

Copy link
Contributor

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 🙂

@albi3ro albi3ro added the review-ready 👌 PRs which are ready for review by someone from the core team. label Jul 22, 2021
.github/CHANGELOG.md Outdated Show resolved Hide resolved
# please move it to ``non_parametric_ops.py``


class MultiControlledX(ControlledQubitUnitary):
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

@josh146 josh146 Jul 28, 2021

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!

Copy link
Contributor

@thisac thisac left a 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!

pennylane/ops/qubit/__init__.py Outdated Show resolved Hide resolved
from pennylane.utils import expand, pauli_eigs
from pennylane.wires import Wires

from .non_parametric_ops import PauliX, PauliY, PauliZ, Hadamard, CNOT
Copy link
Contributor

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):
Copy link
Contributor

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.

pennylane/ops/qubit/non_parametric_ops.py Outdated Show resolved Hide resolved
Copy link
Contributor

@antalszava antalszava left a 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!

albi3ro and others added 5 commits July 28, 2021 07:59
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Theodor <theodor@xanadu.ai>
@albi3ro
Copy link
Contributor Author

albi3ro commented Jul 28, 2021

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.

Copy link
Contributor

@antalszava antalszava left a 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 :)

pennylane/ops/qubit/__init__.py Outdated Show resolved Hide resolved
.github/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@thisac thisac left a 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. 🙂

Comment on lines 40 to 42
class AdjointError(Exception):
"""Exception for non-adjointable operations."""
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

pennylane/ops/qubit/__init__.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/arithmetic_ops.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/matrix_ops.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/non_parametric_ops.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/parametric_ops.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/qchem_ops.py Outdated Show resolved Hide resolved
Co-authored-by: Theodor <theodor@xanadu.ai>
@josh146 josh146 merged commit 5af5733 into master Jul 29, 2021
@josh146 josh146 deleted the break_up_qubit branch July 29, 2021 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality 🎓 Discussion and improvements to code quality review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Divide qubit.py into multiple shorter files
5 participants