Adding gate noise¶

In this notebook, we show how an example of noise model where the gates are perfect, but are followed by a user-defined noisy channel.

Hardware model with depolarizing gate noise¶

Here, the noisy channel will be a depolarizing channel (whether one-qbit or two-qbit).

In [1]:
import numpy as np
from itertools import product
from qat.lang.AQASM import Program, H, PH, CNOT, SWAP, RX
from qat.hardware.default import DefaultGatesSpecification, HardwareModel
from qat.quops import QuantumChannelKraus

prog = Program()
reg = prog.qalloc(2)
prog.apply(H, reg[0])
prog.apply(CNOT, reg)
prog.apply(RX(0.3), reg[0])
prog.apply(RX(0.5), reg[1])
circ = prog.to_circ()

circ.display()

gates_spec = DefaultGatesSpecification()

# instantiating a noise model representing a depolarizing noise
# with probability 5%
prob = 0.05
Xmat = np.array([[0, 1], [1, 0]])
Ymat = np.array([[0, -1j], [1j, 0]])
Zmat = np.array([[1, 0], [0, -1]])
kraus_ops = [np.sqrt(1-prob)*np.identity(2),
             np.sqrt(prob/3)*Xmat, np.sqrt(prob/3)*Ymat, np.sqrt(prob/3)*Zmat]
noise = QuantumChannelKraus(kraus_ops)

# two-qbit version
noise2 = QuantumChannelKraus([np.kron(K1, K2) for K1, K2 in product(noise.kraus_operators, 
                                                                    noise.kraus_operators)])
# for each gate, we specify the noise
# note that the values in this dictionary are lambda functions
# with as many arguments as the gate's number of arguments
gates_noise = {"H": lambda: noise,
               "CNOT": lambda: noise2,
               "RX": lambda _: noise}

hw_model = HardwareModel(gates_spec, gates_noise, idle_noise=None)
No description has been provided for this image