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

Fix Identity.__repr__ bug #6506

Merged
merged 12 commits into from
Nov 8, 2024
Merged

Fix Identity.__repr__ bug #6506

merged 12 commits into from
Nov 8, 2024

Conversation

andrijapau
Copy link
Contributor

@andrijapau andrijapau commented Nov 4, 2024

Context:

Prior to this fix, the repr for Identity was incorrectly indexing self.wires at zero. This returned incorrect string representations.

>>> repr(qml.I([0, 1, 2, 3])
'I(0)'

This was potentially not caught as the __repr__ method was not being tested.

After this fix, the entire self.wires attribute is being processed. This returns the intended string representations of the operator,

>>> repr(qml.I([0, 1, 'a', 3])
'I([0,1,'a',3])'
>>> repr(qml.I([0])
'I(0)'
>>> repr(qml.I())
'I()'

Description of the Change:

  1. Corrected the handling of self.wires in Identity.__repr__.
  2. Added a test to test_identity.py to make sure the string representation is accurate.

Benefits: Code accuracy and clarity.

Possible Drawbacks: N/A

Fixes [sc-77328]

@andrijapau andrijapau marked this pull request as ready for review November 4, 2024 14:45
Copy link
Contributor

github-actions bot commented Nov 4, 2024

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.

@JerryChen97 JerryChen97 self-requested a review November 4, 2024 15:08
pennylane/ops/identity.py Show resolved Hide resolved
tests/ops/test_identity.py Outdated Show resolved Hide resolved
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.

Now LGTM! Let's see if CI complains anymore

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.34%. Comparing base (403c7a3) to head (9cb510c).
Report is 7 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6506   +/-   ##
=======================================
  Coverage   99.34%   99.34%           
=======================================
  Files         455      456    +1     
  Lines       43193    43258   +65     
=======================================
+ Hits        42909    42974   +65     
  Misses        284      284           

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

@andrijapau andrijapau requested a review from mudit2812 November 4, 2024 16:21
tests/ops/test_identity.py Outdated Show resolved Hide resolved
@andrijapau andrijapau requested a review from albi3ro November 8, 2024 16:55
@andrijapau andrijapau enabled auto-merge (squash) November 8, 2024 17:13
@andrijapau andrijapau disabled auto-merge November 8, 2024 17:14
@andrijapau andrijapau enabled auto-merge (squash) November 8, 2024 17:44
@andrijapau andrijapau added the merge-ready ✔️ All tests pass and the PR is ready to be merged. label Nov 8, 2024
@albi3ro albi3ro added the urgent Mark a pull request as high priority label Nov 8, 2024
@andrijapau andrijapau merged commit 03440b7 into master Nov 8, 2024
45 checks passed
@andrijapau andrijapau deleted the fix-identity-repr branch November 8, 2024 19:41
mudit2812 added a commit that referenced this pull request Nov 11, 2024
**Context:**

Prior to this fix, the `repr` for `Identity` was incorrectly indexing
`self.wires` at zero. This returned incorrect string representations.
```python
>>> repr(qml.I([0, 1, 2, 3])
'I(0)'
```
This was potentially not caught as the `__repr__` method was not being
tested.

After this fix, the entire `self.wires` attribute is being processed.
This returns the intended string representations of the operator,
```python
>>> repr(qml.I([0, 1, 'a', 3])
'I([0,1,'a',3])'
>>> repr(qml.I([0])
'I(0)'
>>> repr(qml.I())
'I()'
```

**Description of the Change:**

1. Corrected the handling of `self.wires` in `Identity.__repr__`.
2. Added a test to `test_identity.py` to make sure the string
representation is accurate.

**Benefits:** Code accuracy and clarity.

**Possible Drawbacks:** N/A

Fixes [sc-77328]

---------

Co-authored-by: Mudit Pandey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-ready ✔️ All tests pass and the PR is ready to be merged. urgent Mark a pull request as high priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants