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

added custom return object #2808

Merged
merged 20 commits into from
Jul 27, 2022
Merged

added custom return object #2808

merged 20 commits into from
Jul 27, 2022

Conversation

puzzleshark
Copy link
Contributor

@puzzleshark puzzleshark commented Jul 13, 2022

Restores behavior of pennylane returning custom items to as it was here #1109 (comment)

In this pr, the return object is still an autograd numpy array (which we require for differentiation) with a single entry (being the custom object) and so requires .item() to unpack (see the discussion linked above).

@github-actions
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.

@codecov
Copy link

codecov bot commented Jul 13, 2022

Codecov Report

Merging #2808 (84b135f) into master (465642b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2808   +/-   ##
=======================================
  Coverage   99.63%   99.63%           
=======================================
  Files         252      252           
  Lines       20986    20989    +3     
=======================================
+ Hits        20910    20913    +3     
  Misses         76       76           
Impacted Files Coverage Δ
pennylane/_qubit_device.py 99.52% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 465642b...84b135f. Read the comment docs.

Copy link
Contributor

@antalszava antalszava 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 looking great overall @puzzleshark! 🎉 Some minor comments.

Also, don't forget to update the changelog! :)

tests/devices/test_custom_return_obj.py Outdated Show resolved Hide resolved
tests/devices/test_custom_return_obj.py Outdated Show resolved Hide resolved
tests/devices/test_custom_return_obj.py Outdated Show resolved Hide resolved
tests/devices/test_custom_return_obj.py Outdated Show resolved Hide resolved
pennylane/_qubit_device.py Outdated Show resolved Hide resolved
puzzleshark and others added 3 commits July 13, 2022 16:24
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
@cvjjm
Copy link
Contributor

cvjjm commented Jul 14, 2022

When running this test with the latest master merged in I get an additional error:

        with qml.tape.Unwrap(*tapes):
            res, jacs = execute_fn(tapes, **gradient_kwargs)

        for i, r in enumerate(res):

            if isinstance(r, np.ndarray):
                # For backwards compatibility, we flatten ragged tape outputs
                # when there is no sampling
                try:
>                   if isinstance(r[0][0], dict):
E                   TypeError: 'SpecialObject' object is not subscriptable

pennylane/interfaces/autograd.py:118: TypeError

To fix this TypeError probably needs to be added to the try block in autograd.py

cvjjm added a commit to cvjjm/pennylane that referenced this pull request Jul 14, 2022
@cvjjm cvjjm mentioned this pull request Jul 14, 2022
@rmoyard rmoyard added this to the v0.25.0 milestone Jul 15, 2022
Copy link
Contributor

@antalszava antalszava left a comment

Choose a reason for hiding this comment

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

Looking good overall @puzzleshark, thank you for looking into this! 💯

The main change to do from my side would be moving the test cases into another more relevant file.

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/interfaces/autograd.py Outdated Show resolved Hide resolved
tests/devices/test_default_qubit_autograd.py Outdated Show resolved Hide resolved
tests/devices/test_default_qubit_autograd.py Outdated Show resolved Hide resolved
tests/devices/test_default_qubit_autograd.py Outdated Show resolved Hide resolved
tests/devices/test_default_qubit_autograd.py Outdated Show resolved Hide resolved
Copy link
Contributor

@antalszava antalszava left a comment

Choose a reason for hiding this comment

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

Looks good! 🎉 Great one 🙂

@antalszava antalszava merged commit 07cc9a4 into master Jul 27, 2022
@antalszava antalszava deleted the custom-return-type branch July 27, 2022 22:57
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