catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

[linux x86-64] Invalid wire is valid measurement.

Open erick-xanadu opened this issue 2 years ago • 2 comments

Issue description

Test case:

from catalyst import qjit, measure
import pennylane as qml

@qjit
@qml.qnode(qml.device("lightning.qubit", wires=2))
def circuit(x: int):
    return measure(x)
circuit(0)
circuit(1)
circuit(2)
  • Expected behavior: An assertion should trigger for circuit(2)

  • Actual behavior: No assertion is triggered.

  • Reproduces how often: Always (on x86 - linux)

erick-xanadu avatar Aug 10 '23 18:08 erick-xanadu

@erick-xanadu this applies to operators as well:

dev = qml.device("lightning.qubit", wires=4)

@qjit
@qml.qnode(dev)
def circuit(n):
    print("Tracing occurring")

    def loop_fn(i):
        qml.RX(i, wires=i)

    for_loop(0, n, 1)(loop_fn)()

    def loop_fn(i):
        qml.CNOT(wires=[i, jnp.mod(i+1, n)])
    
    for_loop(0, n, 1)(loop_fn)()
    return qml.expval(qml.PauliZ(0))

This works with any wire number as input, even though the device only has 4 wires:

>>> circuit(7)
array(0.22259496)

josh146 avatar Sep 26 '23 23:09 josh146

We also don't appear to check for duplicate wires in the same operation, something that could be fixed alongside this issue:

@qjit
@qml.qnode(qml.device("lightning.qubit", wires=2))
def f(a: int, b: int):
    qml.Hadamard(0)
    qml.CNOT(wires=[a, b])
    return qml.probs()
f(0, 0)  # succeeds

dime10 avatar Nov 09 '23 22:11 dime10

This issue is now fixed (I believe by #784) :)

[catalyst/runtime/lib/capi/RuntimeCAPI.cpp][Line:967][Function:__catalyst__rt__array_get_element_ptr_1d] Error in Catalyst Runtime: The qubit register does not contain the requested wire: 2

dime10 avatar Jun 24 '24 14:06 dime10