Skip to content

Qrack cannot return catalyst mid-circuit measurements #1627

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

Open
yorgossot opened this issue Apr 9, 2025 · 3 comments
Open

Qrack cannot return catalyst mid-circuit measurements #1627

yorgossot opened this issue Apr 9, 2025 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@yorgossot
Copy link

yorgossot commented Apr 9, 2025

The following code

import pennylane as qml
from catalyst import qjit, measure


dev = qml.device("qrack.simulator", wires=3, shots=5)

@qjit()
@qml.qnode(dev, mcm_method="one-shot")
def circuit():
    qml.X(0)
    m_res = [measure(0), measure(1)]

    return [qml.sample(m) for m in m_res]

print(circuit())

gives:

[Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], dtype=int64), Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], dtype=int64)]

It created:

  • 2 IDENTICAL arrays (as many as the elements sampled)
  • each array containing the results of ALL 3 of the qubits reversed and then stacked for every shot. i.e.
    1st shot (0, 0, 1,) 2nd shot(0, 0, 1) 3rd shot(0, 0, 1) 4th shot(0, 0, 1) 5th shot(0, 0, 1) gives
    Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], dtype=int64)

These values though are the result of some final measurement happening on all qubits at the end of the execution as resetting the qubit in state "1" gives:

import pennylane as qml
from catalyst import qjit, measure


dev = qml.device("qrack.simulator", wires=3, shots=5)

@qjit()
@qml.qnode(dev, mcm_method="one-shot")
def circuit():
    qml.X(0)
    m_res = [measure(0,True), measure(1)]

    return [qml.sample(m) for m in m_res]

print(circuit())

gives:

[Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int64), Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int64)]

tagging @josh146
related issue #1626

@josh146
Copy link
Member

josh146 commented Apr 9, 2025

Thanks or reporting this! Just so I understand, what's the relation between this issue and #1626, #1611?

@yorgossot
Copy link
Author

I am not really sure. It's likely that it is the same fix will resolve both but I thought I should post them as separate ones just in case this is not the case.

@dime10
Copy link
Contributor

dime10 commented Apr 21, 2025

The example now gives the following results for me:

[Array([1, 1, 1, 1, 1], dtype=int64), Array([0, 0, 0, 0, 0], dtype=int64)]

which looks exactly right. This is with the latest Qrack release and the Catalyst main branch, could you confirm whether this is fixed for you as well @yorgossot ? :)

@dime10 dime10 added duplicate This issue or pull request already exists bug Something isn't working labels Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants