amazon-braket / BraketSimulator.jl

Apache License 2.0
11 stars 4 forks source link

Missing Conditional Instructions After Parsing with Quasar #47

Open contra-bit opened 1 month ago

contra-bit commented 1 month ago

Describe the bug After parsing a quantum circuit written in OpenQASM 3.0 using the BraketSimulator, the conditional instructions (specifically the if statement and the x gate) are not included in the created circuit. The output only reflects the Hadamard gate and the measurement, omitting the expected conditional operation.

To reproduce

  1. Create a quantum circuit using OpenQASM 3.0 with the following code:
    OPENQASM 3.0;
    bit[2] b;
    qubit[3] q;
    h q[1];
    b[0] = measure q[1];
    if (b[0]) {
     x q[0];
    }
  2. Parse the circuit using the BraketSimulator:
    circuit3 = BraketSimulator.Circuit("""
    OPENQASM 3.0;
    bit[2] b;
    qubit[3] q;
    h q[1];
    b[0] = measure q[1];
    if (b[0]) {
     x q[0];
    }
    """)
  3. Inspect the created circuit.

Expected behavior The expected behavior is that the created circuit should include all instructions, including the Hadamard gate, the measurement, and the conditional x gate based on the measurement result. The output should reflect all operations specified in the OpenQASM code.

Screenshots or logs The output of the created circuit is as follows: Firefox_Screenshot_2024-08-24T15-56-03 230Z

This output does not mention the x gate or the conditional instruction.

System information

Additional context This issue may affect the ability to implement conditional logic in quantum circuits using the BraketSimulator, which is crucial for many quantum algorithms. Further investigation is needed to determine if this is a limitation of the parser or the simulator's handling of conditional instructions.

kshyatt-aws commented 1 week ago

Yes, unfortunately we don't (yet) have support for this kind of operation, only for purely classical values that are known at circuit-instantiation time. This should be coming with mid-circuit measurement support.