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

Fixes Wires objects as wire labels bug #6933

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Conversation

andrijapau
Copy link
Contributor

@andrijapau andrijapau commented Feb 6, 2025

Context:

Prior to this PR we had the following behaviour,

a = qml.wires.Wires("a")
b = qml.wires.Wires("b")
wires = [a,b,"c"]

>>> print(qml.wires.Wires(wires))
Wires([Wires(['a']), Wires(['b']), 'c'])

>>> print(qml.wires.Wires([0, 1, 2, 3, qml.wires.Wires([4, 5]), None]))
Wires([0, 1, 2, 3, Wires([4, 5]), None])

>>> print(qml.wires.Wires([qml.wires.Wires([(0,0), (0,1)])]))
Wires([Wires([(0, 0), (0, 1)])])

Description of the Change:

Add handling to _process that dissolves any Wires objects that survived to that point. This results in improved behaviour like,

a = qml.wires.Wires("a")
b = qml.wires.Wires("b")
wires = [a,b,"c"]

>>> print(qml.wires.Wires(wires))
Wires(['a', 'b', 'c'])

>>> print(qml.wires.Wires([0, 1, 2, 3, qml.wires.Wires([4, 5]), None]))
Wires([0, 1, 2, 3, 4, 5, None])

>>> print(qml.wires.Wires([qml.wires.Wires([(0,0), (0,1)])]))
Wires([(0, 0), (0, 1)])

Benefits:

Better visualization of wire objects.

Possible Drawbacks: Wire objects will look slightly different.

Related GitHub Issues: Fixes #6669

[sc-79749]

@andrijapau andrijapau changed the title Fix qml.wires.Wires initialization Add handling for Wires objects as wire labels Feb 7, 2025
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.59%. Comparing base (0ecf816) to head (446a27a).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6933   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files         480      480           
  Lines       45505    45514    +9     
=======================================
+ Hits        45320    45329    +9     
  Misses        185      185           

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

@andrijapau andrijapau marked this pull request as draft February 7, 2025 15:48
@andrijapau andrijapau changed the title Add handling for Wires objects as wire labels [BugFix] Add handling for Wires objects as wire labels Feb 7, 2025
@andrijapau andrijapau changed the title [BugFix] Add handling for Wires objects as wire labels Fix handling for Wires objects as wire labels Feb 7, 2025
@andrijapau andrijapau marked this pull request as ready for review February 7, 2025 15:53
@andrijapau andrijapau changed the title Fix handling for Wires objects as wire labels Fixes Wires objects as wire labels bug Feb 7, 2025
Copy link
Contributor

@JerryChen97 JerryChen97 left a comment

Choose a reason for hiding this comment

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

Can we have in test suite the third example where tuples do not get flattened out ?

Copy link
Contributor

@JerryChen97 JerryChen97 left a comment

Choose a reason for hiding this comment

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

The implementation looks good to me! Thanks for fixing this bug!

Copy link
Contributor

@PietropaoloFrisoni PietropaoloFrisoni left a comment

Choose a reason for hiding this comment

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

This looks flawless to me! 🥇

Only one question, maybe for @isaacdevlugt: since we are changing the wires visualization, should we mark this as a breaking change?

pennylane/wires.py Show resolved Hide resolved
pennylane/wires.py Outdated Show resolved Hide resolved
@andrijapau andrijapau added the do not merge ⚠️ Do not merge the pull request until this label is removed label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge ⚠️ Do not merge the pull request until this label is removed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] wires initialization issue
3 participants