Can we merge single-qubit gates with qml.transforms.single_qubit_fusion?

Hi,

I am implementing random compiling algorithm 1 to mitigate quantum noise with Pennylane. Here is the code.

rc = [
    ['I', 'I', 'I', 'I'],
    ['I', 'X', 'I', 'X'],
    ['I', 'Y', 'Z', 'Y'],
    ['I', 'Z', 'Z', 'Z'],
    ['Y', 'I', 'Y', 'X'],
    ['Y', 'Y', 'X', 'Z'],
    ['Y', 'X', 'Y', 'I'],
    ['Y', 'Z', 'X', 'Y'],
    ['X', 'I', 'X', 'X'],
    ['X', 'X', 'X', 'I'],
    ['X', 'Y', 'Y', 'Z'],
    ['X', 'Z', 'Y', 'Y'],
    ['Z', 'I', 'Z', 'I'],
    ['Z', 'X', 'Z', 'X'],
    ['Z', 'Y', 'I', 'Y'],
    ['Z', 'Z', 'I', 'Z']
]
PauliGate = {
    'X': qml.PauliX,
    'Y': qml.PauliY,
    'Z': qml.PauliZ,
    'I': qml.Identity
}
def circuit(param, obs):
    n_layer, n_qubit = param.shape[0], param.shape[1]
    for i in range(n_layer):
        for j in range(n_qubit):
            qml.RZ(param[i, j, 0], wires=j)
            qml.RY(param[i, j, 1], wires=j)
            qml.RZ(param[i, j, 2], wires=j)

        # CNOT
        for j in range(0, n_qubit, 2):
            if j+1 < n_qubit:
                index = np.random.randint(0, len(rc))
                if rc[index][0] != 'I':
                    PauliGate[rc[index][0]](wires=j)
                if rc[index][1] != 'I':
                    PauliGate[rc[index][1]](wires=j+1)
                qml.CNOT(wires=[j, j+1])
                if rc[index][2] != 'I':
                    PauliGate[rc[index][2]](wires=j)
                if rc[index][3] != 'I':
                    PauliGate[rc[index][3]](wires=j+1)

        for j in range(1, n_qubit, 2):
            if j+1 < n_qubit:
                index = np.random.randint(0, len(rc))
                if rc[index][0] != 'I':
                    PauliGate[rc[index][0]](wires=j)
                if rc[index][1] != 'I':
                    PauliGate[rc[index][1]](wires=j+1)
                qml.CNOT(wires=[j, j+1])
                if rc[index][2] != 'I':
                    PauliGate[rc[index][2]](wires=j)
                if rc[index][3] != 'I':
                    PauliGate[rc[index][3]](wires=j+1)

    return qml.expval(obs)

After randomly inserting Pauli gate before and after CNOT gate, I need to merge the inserted gate with adjacent single-qubit rotations to keep the number of gates unchanges. So I apply qml.transforms.single_qubit_fusion to the circuit.

circuit_merged = qml.transforms.single_qubit_fusion()(circuit)

Then the merged circuit is run with IBMQ device noise. However, I found the error is not well mitigated as expected. Does the function qml.transforms.single_qubit_fusion works in the way I mentioned before? Or any other suggestions for my implemention?

Thanks in advance!
Best regards,
Yang

Hello @Yang !

Thank you for your question. I do think that single_qubit_fusion is working in the way you are expecting it to. It works for rotations, Pauli gates, and Hadamards, so in this case it’s merging all of your Paulis and Rotations together into a singleqml.Rot gate on the wire where they appear. I’m not entirely sure what the entire workflow is here, but it might be that the error is coming from elsewhere. Good luck!

Cheers,

Alvaro

Hi @Alvaro_Ballon ,

Thank you for your message. I was wondering, if we have a circuit with quantum noise, would it be possible to mitigate the effect of the noise by merging all adjacent single-qubit gates into a single qml.Rot gate?

Best regards,
Yang

Hi Yang,

Actually, the answer to your question depends on the specifics of the device where you run your circuit. If your device can implement arbitrary rotations with, for example, a single pulse of light, then merging gates will help mitigate noise coming from qubit rotation.

However, comparatively speaking, the noise that you try to mitigate in this way might not be the main source of error. Most of the noise in quantum devices comes from two-qubit gates, such as the CNOTs. If you’d like to mitigate noise effectively, the best way is to find an equivalent circuit that uses as few two-qubit gates as possible.

Let me know if I understood your question properly. Hope this helps!

Alvaro

Hi @Alvaro_Ballon ,

Thank you for your explanation. That is exactly what I needed. I am going to learn more about quantum noise.

Best regards,
Yang