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

Replace the type checking using property return_type with direct is… #1044

Merged
merged 15 commits into from
Jan 27, 2025

Conversation

JerryChen97
Copy link
Contributor

@JerryChen97 JerryChen97 commented Jan 22, 2025

Context:
In the deprecations of PL0.41, the property return_type of class MeasurementProcess will be deprecated very soon PennyLaneAI/pennylane#6841. Therefore, we would like to replace the use of return_type with the equivalent direct isinstance check. For individual string info use of these return types, we replace them with in-place strings.

Description of the Change:
3 files are changed with equivalents in-place:

  • pennylane_lightning/core/_adjoint_jacobian_base.py

    • Private staticmethod _get_return_type of class LightningBaseAdjointJacobian called return_type once, so replaced with equivalent isinstance
    • The private staticmethod _check_adjdiff_supported_measurements was only called by another private helper _process_jacobian_tape, therefore the two Enum type returns were replaced by strings, along with their conditional values in _process_jacobian_tape.
    • _process_jacobian_tape also called return_type once, therefore replace with equivalent isinstance.
  • pennylane_lightning/core/lightning_base.py

    • The private staticmethod _check_adjdiff_supported_measurements was identified as not used by any code inside lightning. Therefore, we deleted it directly.
  • tests/test_measurements.py

    • Two return_type usages were replaced with isinstance

Benefits:
Consistent with both v0.40 and v0.41 of PL

Possible Drawbacks:
Not aware of yet.

Related GitHub Issues:
[sc-71892]

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.

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 32.91%. Comparing base (24e429e) to head (34b1a1b).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pennylane_lightning/core/_adjoint_jacobian_base.py 14.28% 6 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (24e429e) and HEAD (34b1a1b). Click for more details.

HEAD has 40 uploads less than BASE
Flag BASE (24e429e) HEAD (34b1a1b)
46 6
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #1044       +/-   ##
===========================================
- Coverage   98.10%   32.91%   -65.20%     
===========================================
  Files         233       29      -204     
  Lines       39079     2634    -36445     
===========================================
- Hits        38339      867    -37472     
- Misses        740     1767     +1027     

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

This reverts commit d06a8cbada45a4cb0500d3d9dd134b4b6527151e.
@JerryChen97 JerryChen97 self-assigned this Jan 22, 2025
@JerryChen97 JerryChen97 added the ci:use-gpu-runner Enable usage of GPU runner for this Pull Request label Jan 22, 2025
@JerryChen97 JerryChen97 added ci:build_wheels Activate wheel building. and removed ci:use-gpu-runner Enable usage of GPU runner for this Pull Request labels Jan 22, 2025
Copy link
Contributor

@josephleekl josephleekl left a comment

Choose a reason for hiding this comment

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

Thanks @JerryChen97 ! Looks good, just have some quick questions before approving

@JerryChen97 JerryChen97 requested a review from maliasadi January 23, 2025 18:47
@JerryChen97
Copy link
Contributor Author

JerryChen97 commented Jan 23, 2025

@maliasadi @AmintorDusko As described in description of change, the lines affected here are all in-line equivalents, therefore they should be no-effect towards any other files. However, codecov patch has been all the time 0 inside the changes of pennylane_lightning/core/_adjoint_jacobian_base.py, which I believe is caused by the fact that we actually do not have a direct unit test file for it; we should add another separate unit test file against this submodule in the future.

@AmintorDusko
Copy link
Contributor

@JerryChen97, you might want to re-trigger the PR CIs with an empty commit.

@JerryChen97 JerryChen97 removed the ci:build_wheels Activate wheel building. label Jan 24, 2025
@JerryChen97
Copy link
Contributor Author

@AmintorDusko I removed ci build_wheels label and retriggered tests.

Copy link
Contributor

@AmintorDusko AmintorDusko 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! Thanks!

@JerryChen97 JerryChen97 merged commit 975bd1b into master Jan 27, 2025
68 of 70 checks passed
@JerryChen97 JerryChen97 deleted the replace-return_type-check branch January 27, 2025 18:38
josephleekl added a commit that referenced this pull request Feb 26, 2025
### Before submitting

Please complete the following checklist when submitting a PR:

- [ ] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      [`tests`](../tests) directory!

- [ ] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [ ] Ensure that the test suite passes, by running `make test`.

- [ ] Add a new entry to the `.github/CHANGELOG.md` file, summarizing
the
      change, and including a link back to the PR.

- [ ] Ensure that code is properly formatted by running `make format`. 

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**
[This PR ](#1044)
added two instances of `if tape_return_type is "state"` in
`_adjoint_jacobian_base.py` , that introduces python SyntaxWarning, e.g.
:
```
_adjoint_jacobian_base.py:197: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if tape_return_type is "state":
```
which is also observed in CI logs during testing (e.g.
[here](https://github.com/PennyLaneAI/pennylane-lightning/actions/runs/13533320431/job/37820142204#step:14:23)
)

**Description of the Change:**
This PR changes `is` to `==`.

**Benefits:**
No more syntax warning - equivalent test
[here](https://github.com/PennyLaneAI/pennylane-lightning/actions/runs/13552303713/job/37878601833?pr=1070#step:14:21)

**Possible Drawbacks:**

**Related GitHub Issues:**

[sc-85337]

---------

Co-authored-by: ringo-but-quantum <[email protected]>
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.

5 participants