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

Dynamic one shot does not work with ZNE #929

Open
dime10 opened this issue Jul 12, 2024 · 1 comment
Open

Dynamic one shot does not work with ZNE #929

dime10 opened this issue Jul 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@dime10
Copy link
Collaborator

dime10 commented Jul 12, 2024

import jax.numpy as jnp
import pennylane as qml
from catalyst import *

@qml.qnode(dev, mcm_method="one-shot")
def circuit():
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    qml.Hadamard(wires=0)
    return qml.expval(qml.PauliY(0))


@qjit
def mitigated_circuit():
    s = jax.numpy.array([1, 2])
    return mitigate_with_zne(circuit, scale_factors=s)()
  File "catalyst/frontend/catalyst/jax_primitives.py", line 739, in _zne_lowering
    _func_lowering(ctx, *args, call_jaxpr=jaxpr.eqns[0].params["call_jaxpr"], fn=fn, call=False)
                                          ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'call_jaxpr'
@dime10 dime10 added the bug Something isn't working label Jul 12, 2024
@dime10
Copy link
Collaborator Author

dime10 commented Jul 15, 2024

Briefly looked into this issue, and the root cause is that the ZNE wrapper only works directly on QNodes, but the dynamic_one_shot transform replaces a QNode with a classical function that invokes a QNode, thus breaking the ZNE assumption.

I think a solution to this problem might be to rewrite ZNE to be part of the QNode transform program, that way it would be properly propagated by the dynamic_one_shot method. Haven't verified if this would actually work though.

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

1 participant