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

[BUG] pattern_matching_optimization eliminates all measurements #6088

Closed
1 task done
albi3ro opened this issue Aug 12, 2024 · 5 comments
Closed
1 task done

[BUG] pattern_matching_optimization eliminates all measurements #6088

albi3ro opened this issue Aug 12, 2024 · 5 comments
Labels
bug 🐛 Something isn't working

Comments

@albi3ro
Copy link
Contributor

albi3ro commented Aug 12, 2024

Expected behavior

I expect pattern_matching_optimization to preserve the user's measurements.

Actual behavior

The are all eliminated and the function simply returns a tuple

Additional information

No response

Source code

from functools import partial

ops = [qml.S(0), qml.S(0), qml.Z(0)]
pattern = qml.tape.QuantumTape(ops)

@partial(qml.transforms.pattern_matching_optimization, pattern_tapes = [pattern])
@qml.qnode(device=qml.device('default.qubit'))
def circuit():
    qml.S(wires=0)
    qml.Z(0)
    qml.S(wires=1)
    qml.CZ(wires=[0, 1])
    qml.S(wires=1)
    qml.S(wires=2)
    qml.CZ(wires=[1, 2])
    qml.S(wires=2)
    return qml.expval(qml.X(0))

circuit()

Tracebacks

No response

System information

PL master. But this issue has been around for at least a year.

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@albi3ro albi3ro added the bug 🐛 Something isn't working label Aug 12, 2024
@tonmoy-b
Copy link
Contributor

Hi, if no one's working on this right now maybe I can be assigned to it. Thanks.

@isaacdevlugt
Copy link
Contributor

Hey @tonmoy-b! Thanks for your interest in fixing this 💪. We see this bug as possibly straightforward to fix, but (of course 😅) it might be more complicated. Feel free to work on this and we can assist where possible. If it ends up being too demanding of a fix, we'll reassess 🙂.

Make sure to read our contributing guidelines before getting started!

https://docs.pennylane.ai/en/stable/development/guide/contributing.html

@Alex-Preciado
Copy link
Contributor

Hi @tonmoy-b 👋🏼 ,

Thank you for volunteering to work on this issue 💪🏼! I wanted to check in and see if you’ve had a chance to make any progress. We’re in the middle of our feature freeze, with the release of PennyLane v0.38 coming up next week, so it’s crucial that we complete this fix by Friday.

If you haven’t had time, no worries, please just let us know as soon as possible so we can decide if we need to take over to ensure the deadline is met—If that’s the case, we’ll be happy to find another good first issue for you to work on 😎.

Thank you again for your contribution!!

@tonmoy-b
Copy link
Contributor

Hi @tonmoy-b 👋🏼 ,

Thank you for volunteering to work on this issue 💪🏼! I wanted to check in and see if you’ve had a chance to make any progress. We’re in the middle of our feature freeze, with the release of PennyLane v0.38 coming up next week, so it’s crucial that we complete this fix by Friday.

If you haven’t had time, no worries, please just let us know as soon as possible so we can decide if we need to take over to ensure the deadline is met—If that’s the case, we’ll be happy to find another good first issue for you to work on 😎.

Thank you again for your contribution!!

Hi @Alex-Preciado, I haven't been able to put in much time on this yet. Kindly assign it to someone else so there's no delay. I will take up another task. Thanks

@Alex-Preciado
Copy link
Contributor

Hi @tonmoy-b, thanks for letting me know! No worries at all—we’ve gone ahead and reassigned this to a member of our team to ensure we stay on track. We regularly have new good first issues, so feel free to let us know if you would like to take on another task when you’re ready. Thanks again for your help! 🚀

PietropaoloFrisoni added a commit that referenced this issue 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
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants