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 consistency of QNode results processing #6568

Merged
merged 17 commits into from
Nov 21, 2024
Merged

Conversation

andrijapau
Copy link
Contributor

@andrijapau andrijapau commented Nov 11, 2024

Context:

The output of QNode execution was not consistent based on the type of the qfunc output,

@qml.qnode(qml.device('default.qubit'))
def circuit(t):
    return t([qml.expval(qml.Z(0))])
>>> circuit(tuple)
1.0
>>> circuit(list)
[1.0]

Description of the Change:

Updates how the results of the QNode execution gets "type-converted" according to the qfunc_output.

After this fix we get consistency,

@qml.qnode(qml.device('default.qubit'))
def circuit(t):
    return t([qml.expval(qml.Z(0))])
>>> circuit(tuple)
(1.0,)
>>> circuit(list)
[1.0]

Benefits: Consistency

Possible Drawbacks: Output of QNode execution may look different than people are used to. A direct example is needed to change some tests to squeeze out the new dimension that has been introduced.

Related GitHub Issue: Fixes #6540

[sc-77682]

@andrijapau andrijapau marked this pull request as ready for review November 11, 2024 20:34
Copy link
Contributor

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.

@andrijapau andrijapau requested a review from albi3ro November 19, 2024 21:24
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.

❤️

Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.45%. Comparing base (08e694f) to head (4336b4c).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6568   +/-   ##
=======================================
  Coverage   99.45%   99.45%           
=======================================
  Files         451      451           
  Lines       42293    42293           
=======================================
  Hits        42062    42062           
  Misses        231      231           

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


🚨 Try these New Features:

@JerryChen97
Copy link
Contributor

I guess we should permanently turn off the too-many-positional of codefac

@andrijapau andrijapau merged commit 76f9d7c into master Nov 21, 2024
46 checks passed
@andrijapau andrijapau deleted the fix-qfunc-processing branch November 21, 2024 14:28
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.

[BUG] Inconsistent qnode return behavior for list and tuple
3 participants