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

remove _qfunc_output from tape #4651

Merged
merged 5 commits into from
Oct 6, 2023
Merged

remove _qfunc_output from tape #4651

merged 5 commits into from
Oct 6, 2023

Conversation

timmysilv
Copy link
Contributor

@timmysilv timmysilv commented Oct 5, 2023

Context:
_qfunc_output is a pain to keep track of, and we only need it for QNode handling. QNode._qfunc_output still exists, but tape._qfunc_output does not.

Description of the Change:

  • Remove tape._qfunc_output
  • update qnode.construct to not use make_qscript so it can get the tape result shape
  • remove squeezing logic from param_shift_cv (the only other place that used tape._qfunc_output) because it doesn't accept parameter broadcasting, shot vectors, or multiple measurements, so it really never needs it
  • if I saw a transform creating a QuantumTape explicitly, I changed it to create type(tape) so QuantumScript in = QuantumScript out
  • qfunc_transform is the only other place that needed the qfunc output, so I added some handling there that's quite similar to qnode, but slightly different. see in-line comment

Benefits:
everyone hates tape._qfunc_output so this should bring peace of mind. less work, one less private attribute being used publicly.

Possible Drawbacks:
Maybe harder to see the output shape of a tape? tape.measurements should mostly make it clear.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2023

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.

@timmysilv
Copy link
Contributor Author

[sc-36827]

@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (da79370) 99.63% compared to head (0191794) 99.63%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4651      +/-   ##
==========================================
- Coverage   99.63%   99.63%   -0.01%     
==========================================
  Files         376      376              
  Lines       33666    33647      -19     
==========================================
- Hits        33542    33523      -19     
  Misses        124      124              
Files Coverage Δ
pennylane/_device.py 99.40% <ø> (-0.01%) ⬇️
pennylane/gradients/parameter_shift_cv.py 99.60% <ø> (-0.01%) ⬇️
pennylane/ops/functions/map_wires.py 100.00% <ø> (ø)
pennylane/optimize/adaptive.py 100.00% <100.00%> (ø)
pennylane/optimize/riemannian_gradient.py 100.00% <100.00%> (ø)
pennylane/qnode.py 100.00% <100.00%> (ø)
pennylane/tape/qscript.py 100.00% <100.00%> (ø)
pennylane/tape/tape.py 98.55% <ø> (-0.03%) ⬇️
pennylane/transforms/compile.py 100.00% <100.00%> (ø)
...ennylane/transforms/convert_to_numpy_parameters.py 100.00% <ø> (ø)
... and 12 more

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

@timmysilv timmysilv marked this pull request as ready for review October 6, 2023 13:32
@timmysilv timmysilv requested a review from a team October 6, 2023 13:32
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.

🎉

My only comment is about a changelog. Maybe just an "Improvement"? Something like _qfunc_output is pruned from QuantumScript?

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.

Looks good to me once @albi3ro 's comment is addressed! 🚀

@timmysilv timmysilv enabled auto-merge (squash) October 6, 2023 19:44
@timmysilv timmysilv merged commit 751400d into master Oct 6, 2023
39 checks passed
@timmysilv timmysilv deleted the remove-qfunc-output branch October 6, 2023 20:47
PietropaoloFrisoni added a commit that referenced this pull request Aug 28, 2024
#6153)

**Context:** In #4651, `tape._qfunc_output` was removed. As a
consequence, for `qml.pattern_matching_optimization`, the original
quantum function output (used to re-create the quantum function output
of the new tape) was removed. Since in the optimization process of
`qml.pattern_matching_optimization` the measurements of the original
tape are not involved, the measurements of the tape coming out from the
optimization process correspond to an empty list, causing information on
such a variable to be lost in the optimization process.

**Description of the Change:** We simply store the original measurements
and assign them to the new (optimized) tape, similarly to the original
approach (see #2032).

**Benefits:** Measurements are preserved in the optimization process.

**Possible Drawbacks:** I can think of none since measurements should
not be involved in the optimization process.

**Related GitHub Issues:** #6088

**Related Shortcut Stories** [sc-71174]

---------

Co-authored-by: Christina Lee <christina@xanadu.ai>
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.

3 participants