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

Set operations and tests added #5983

Merged
merged 41 commits into from
Jul 26, 2024
Merged

Set operations and tests added #5983

merged 41 commits into from
Jul 26, 2024

Conversation

austingmhuang
Copy link
Contributor

@austingmhuang austingmhuang commented Jul 10, 2024

Context:
Set operations are useful for Wires and Registers and would be a welcome addition/feature in the PennyLane ecosystem

Description of the Change:
This PR implements the 4 set operations for Wires and you can access them with their respective operators (| & - ^) as well as comprehensive tests.

Benefits:
Nice syntactic sugar

Possible Drawbacks:

Related GitHub Issues:
[sc-67925]

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.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.

pennylane/wires.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.65%. Comparing base (b7675ca) to head (d21786c).
Report is 302 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5983      +/-   ##
==========================================
- Coverage   99.66%   99.65%   -0.01%     
==========================================
  Files         428      430       +2     
  Lines       41182    41193      +11     
==========================================
+ Hits        41042    41052      +10     
- Misses        140      141       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@isaacdevlugt isaacdevlugt left a comment

Choose a reason for hiding this comment

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

Thanks @austingmhuang! would it also be possible to have union, difference, intersection and symmetric_difference methods? E.g.,

    def union(self, other):
        new_wires = set(self.labels) | set(other.labels)
        return Wires(list(new_wires))

    def __or__(self, other):
        return self.union(other)

I know it's a bit more to add and have tests for, but this would be nice.

Other than that, looks great!

pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
@trbromley
Copy link
Contributor

Thanks @austingmhuang! would it also be possible to have union, difference, intersection and symmetric_difference methods? E.g.,

    def union(self, other):
        new_wires = set(self.labels) | set(other.labels)
        return Wires(list(new_wires))

    def __or__(self, other):
        return self.union(other)

I know it's a bit more to add and have tests for, but this would be nice.

Other than that, looks great!

Yes, we're looking to add as many as possible of the typical Python set operations - though happy to discuss any that are particularly challenging.

@austingmhuang
Copy link
Contributor Author

Yes, we're looking to add as many as possible of the typical Python set operations - though happy to discuss any that are particularly challenging.

No worries I can add all the set operations, no challenge there :)

@isaacdevlugt
Copy link
Contributor

Thanks @austingmhuang! 🤗 Feel free to tag me for review again when the time comes 👍

austingmhuang and others added 6 commits July 15, 2024 11:13
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
Copy link
Contributor

@isaacdevlugt isaacdevlugt left a comment

Choose a reason for hiding this comment

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

Thanks Austin! My suggestions are minor. Just want to make the docstring code examples copy-pastable.

pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
austingmhuang and others added 10 commits July 19, 2024 11:10
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
austingmhuang and others added 5 commits July 24, 2024 11:19
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Copy link
Contributor

@soranjh soranjh left a comment

Choose a reason for hiding this comment

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

Thanks @austingmhuang, looks good to me. Left some minor comments.

pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
tests/test_wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Show resolved Hide resolved
@austingmhuang austingmhuang enabled auto-merge (squash) July 26, 2024 13:27
@austingmhuang austingmhuang merged commit 9808d0c into master Jul 26, 2024
39 checks passed
@austingmhuang austingmhuang deleted the set-based-operations branch July 26, 2024 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants