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