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

Update deprecated QNode.(q)tape property usage in tests #6625

Merged
merged 65 commits into from
Dec 18, 2024

Conversation

andrijapau
Copy link
Contributor

@andrijapau andrijapau commented Nov 21, 2024

Context:

Many tests incorrectly rely on the tape and qtape properties to access information during tests. With these properties deprecated in #6583, deprecation warnings in the affected test files have been suppressed. This PR aims to replace all instances of deprecated code with the correct code.

Description of the Change:

Tests should construct the tape dynamically using construct_tape rather than use the deprecated properties.

Benefits: Better testing and code maintainability.

Possible Drawbacks:

I’m still a bit unsure about the changes in tests/workflow/interfaces/qnode/. The lines I deleted were originally a workaround to further verify QNode interfacing. However, the primary goal of the tests in this folder isn’t to check gradient accuracy but rather to ensure proper interfacing with the QNode architecture (e.g., verifying data types and result shapes). Since the property being used should now be considered private, relying on it in tests isn’t best practice—hence the deletion.

[sc-78317]

This comment was marked as resolved.

@andrijapau andrijapau requested a review from albi3ro November 21, 2024 17:39
@andrijapau andrijapau changed the title Fix tests associated with QNode.qtape/tape property deprecation Fix tests associated with the deprecated QNode.qtape/tape property Nov 21, 2024
@andrijapau andrijapau changed the title Fix tests associated with the deprecated QNode.qtape/tape property Fix tests that use the deprecated QNode.qtape/tape property Nov 21, 2024
@andrijapau andrijapau changed the title Fix tests that use the deprecated QNode.qtape/tape property [WIP] Fix tests that use the deprecated QNode.qtape/tape property Nov 21, 2024
@andrijapau andrijapau added the WIP 🚧 Work-in-progress label Nov 21, 2024
@andrijapau andrijapau changed the title [WIP] Fix tests that use the deprecated QNode.qtape/tape property Update tests that use the deprecated QNode.qtape/tape property Dec 16, 2024
@lillian542 lillian542 self-requested a review December 17, 2024 20:47
@andrijapau andrijapau changed the title Update tests that use the deprecated QNode.qtape/tape property Update deprecated QNode.qtape/tape property usage Dec 17, 2024
@andrijapau andrijapau changed the title Update deprecated QNode.qtape/tape property usage Update deprecated QNode.qtape/tape property usage in tests Dec 17, 2024
@andrijapau andrijapau changed the title Update deprecated QNode.qtape/tape property usage in tests Update deprecated QNode.(q)tape property usage in tests Dec 17, 2024
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 very good to me!

About the deletion(s) in the tests/workflow/interfaces/qnode/ file, I might miss context here, but it seems to me that you are deleting all the code lines checking properties of the QuantumScript (such as trainable_params) that it was possible to access from the QNode using the deprecated tape/qtape property (for example as circuit.qtape.trainable_params).

Now that the tape/qtape property is deprecated, we no longer have access to such properties of the QuantumScript from the QNode interface, hence the decision to remove the associated test lines. Is that correct?

@andrijapau
Copy link
Contributor Author

@PietropaoloFrisoni,

Now that the tape/qtape property is deprecated, we no longer have access to such properties of the QuantumScript from the QNode interface, hence the decision to remove the associated test lines. Is that correct?

Indeed 🙂. I personally think that the deletion of these lines doesn't impact the overall test quality. More extensive testing of the ML interface gradient logic is being done in tests/workflow/interfaces/run and tests/workflow/interfaces/execute.

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.

@andrijapau Thanks for the clarification. I agree, this seems a totally legitimate choice to me.

I left just some personal preference in terms of names used in the tests 🚀

tests/gradients/core/test_adjoint_metric_tensor.py Outdated Show resolved Hide resolved
tests/gradients/core/test_adjoint_metric_tensor.py Outdated Show resolved Hide resolved
tests/gradients/core/test_adjoint_metric_tensor.py Outdated Show resolved Hide resolved
@andrijapau andrijapau removed the WIP 🚧 Work-in-progress label Dec 18, 2024
Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

LGTM!

@andrijapau andrijapau enabled auto-merge (squash) December 18, 2024 18:24
@andrijapau andrijapau merged commit 24f491f into master Dec 18, 2024
46 checks passed
@andrijapau andrijapau deleted the fix-tape-property-tests branch December 18, 2024 18:40
andrijapau added a commit that referenced this pull request Dec 20, 2024
**Context:**

Follow up to #6625.

For some reason, CI never complained about this property usage despite
no `qml.PennylaneDeprecationWarning` suppression occuring in these files
... weird. Created story ([sc-80957]) to track.

**Description of the Change:**

Tests should construct the tape dynamically using `construct_tape`
rather than use the deprecated properties.

**Benefits:** Better testing and code maintainability.

**Possible Drawbacks:** None

[[sc-78317](https://app.shortcut.com/xanaduai/story/78317)]

---------

Co-authored-by: Pietropaolo Frisoni <[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.

4 participants