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

Add operator IDs into the text based circuit draw function. #4749

Merged
merged 9 commits into from Oct 30, 2023

Conversation

JustinWoodring
Copy link
Contributor

@JustinWoodring JustinWoodring commented Oct 27, 2023

Context:
Per the associated issue "With the new functionality to assign "names" to gates, it might be worthwhile to have this information propagate to the printed circuit of qml.draw."

Description of the Change:
Modifies the printed text output resulting from qml.draw() to indicate the ids of operators.

def circuit(x,d):
    qml.RX(d, id="data", wires=0)
    qml.Rot(x, wires=0)
    return qml.expval(qml.PauliZ(0)) 
   
d = 0.123
x = np.array([0.863, 0.611, 0.281])
print(qml.draw(circuit)(*x,d))

Output:
0: ──RX(0.123,"data")──Rot(0.863,0.611,0.281)──┤ ⟨Z⟩

Benefits:
This allows users to see operators displayed with their ids in the printed circuit output.

Possible Drawbacks:
Too many rendered operators with ID's might consume more space causing the printed circuit to wrap more.

Related GitHub Issues:
This implements and closes #1397

@JustinWoodring JustinWoodring changed the title Add operation IDs into the text based circuit draw function. Add operator IDs into the text based circuit draw function. Oct 27, 2023
@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (970d30c) 99.64% compared to head (1bf1330) 99.64%.
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4749      +/-   ##
==========================================
- Coverage   99.64%   99.64%   -0.01%     
==========================================
  Files         380      380              
  Lines       34242    33993     -249     
==========================================
- Hits        34121    33871     -250     
- Misses        121      122       +1     
Files Coverage Δ
pennylane/drawer/draw.py 100.00% <100.00%> (ø)
pennylane/gradients/spsa_gradient.py 100.00% <ø> (ø)
pennylane/operation.py 97.27% <100.00%> (-0.02%) ⬇️
pennylane/qnode.py 100.00% <100.00%> (ø)
...nnylane/templates/subroutines/arbitrary_unitary.py 100.00% <100.00%> (ø)
pennylane/transforms/core/transform_dispatcher.py 100.00% <100.00%> (ø)

... and 41 files with indirect coverage changes

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

Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

Looks great to me 🎉 Nice to close such a backlogged issue.

No comments or concerns from my side. I'm happy to approve :)

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

🎉

updating the operator label also makes the ID appear in the MPL drawer, so I figure it wouldn't hurt to mention it's added there as well. otherwise lgtm!

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
@albi3ro albi3ro enabled auto-merge (squash) October 30, 2023 16:43
@albi3ro albi3ro merged commit 605ea73 into PennyLaneAI:master Oct 30, 2023
33 checks passed
@trbromley
Copy link
Contributor

Thanks @JustinWoodring for your contribution! 🏆

This should be released as part of v0.34 in early January. If you would like us to tag you as part of our Twitter/X marketing, feel free to optionally share your handle here.

@JustinWoodring
Copy link
Contributor Author

I don't use Twitter, but if you do similar stuff on LinkedIn, my LinkedIn is, https://www.linkedin.com/in/justin-woodring/ 😃

@trbromley
Copy link
Contributor

Thanks!

@Alex-Preciado Alex-Preciado added the hacktoberfest-accepted Hacktoberfest not merged but in a good shape label Nov 6, 2023
dwierichs added a commit that referenced this pull request May 3, 2024
…`qcut.PrepareNode` (#5613)

**Context:**
`MeasureNode` and `PrepareNode` automatically have a UUID (#2224), which
is being printed in tape text (#4749)

**Description of the Change:**
Update the docs of the `qcut` module to reflect some minor changes
,mostly in formatting/tape printing default settings.

Update the `label` method of `MeasureNode` and `PrepareNode` to not
include their `id`.

**Benefits:**
Updated docs.

Nicely printing qcut tape texts

**Possible Drawbacks:**

**Related GitHub Issues:**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Hacktoberfest not merged but in a good shape
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display id of gates when printing with qml.draw
5 participants