qiboteam / qibo

A full-stack framework for quantum computing.
https://qibo.science
Apache License 2.0
294 stars 60 forks source link

Unroller duplicates gates when measuring in specific basis #1318

Closed andrea-pasquale closed 4 months ago

andrea-pasquale commented 6 months ago

When applying a measurement there is the possibility to specify in which basis we want to perform the measurement using the basis argument.

However, when such circuit is transpiled the "rotation gate" appears twice and only once it is correctly transpiled. Here is an example:

from qibo import Circuit, gates
from qibo.transpiler.unroller import NativeGates, Unroller

unroller = Unroller(native_gates=NativeGates.default())

nqubits = 2
circuit = Circuit(nqubits)
circuit.add(gates.M(i, basis=gates.X) for i in range(nqubits))

print(circuit.draw())
# which gives
# q0: ─H─M─
# q1: ─H─M─
transpiled_circuit = unroller(circuit)
print(transpiled_circuit.draw())
# which gives
# q0: ─Z─GPI2─H─M─
# q1: ─Z─GPI2─H─M─

In the transpiled circuit H appears twice, once it is compiled into natives as Z and GPI2 while the second times appears as H which will trigger an error since it is not a native gate. @Edoardo-Pedicillo I believe that this is not related to PRs that you recently open since I am using master.

Edoardo-Pedicillo commented 6 months ago

@Edoardo-Pedicillo I believe that this is not related to PRs that you recently open since I am using master.

I confirm it is not related

Simone-Bordoni commented 6 months ago

I will have a closer look in the next days, i think it should be an easy fix.