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

[Frontend] Corrected output of PyTree when using qml.counts() #1219

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

abhamra
Copy link

@abhamra abhamra commented Oct 19, 2024

Context: When using qml.counts() in the output of a quantum circuit with qjit, the output pytree is modified to replace the output pytree element related to qml.counts with tree_structure(("keys", "counts")). Previously, this operation was buggy and didn't work well with nested return statements, more complex patterns, etc. This PR aims to fix this problem.

Description of the Change: We add a replace_child_tree(tree, index, subtree) method as suggested here, which recursively traverses the PyTreeDefs and correctly updates based on this traversal and a num_counts variable which stores the number of qml.counts() calls within a potentially complex return expression.

Benefits: This function should handle more complex, nested cases robustly.

Possible Drawbacks: More computationally intensive than the prior version.

Related GitHub Issues: This closes #1016.

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] Incorrect output pytree when using qml.counts() in specific output patterns
1 participant