Open
Description
class QLayer_input(tq.QuantumModule):
def __init__(self):
super().__init__()
self.n_wires = 4
self.encoder = tq.GeneralEncoder(
[ {'input_idx': [0], 'func': 'rx', 'wires': [0]},
{'input_idx': [1], 'func': 'rx', 'wires': [1]},
{'input_idx': [2], 'func': 'rx', 'wires': [2]},
{'input_idx': [3], 'func': 'rx', 'wires': [3]},
])
self.rx0 = tq.RX(has_params=True, trainable=True)
self.rx1 = tq.RX(has_params=True, trainable=True)
self.rx2 = tq.RX(has_params=True, trainable=True)
self.rx3 = tq.RX(has_params=True, trainable=True)
self.measure = tq.MeasureAll(tq.PauliZ)
def forward(self, x):
qdev = tq.QuantumDevice(n_wires=self.n_wires, bsz=x.shape[0], device=x.device)
self.encoder(qdev, x)
self.rx0(qdev, wires=0)
self.rx1(qdev, wires=1)
self.rx2(qdev, wires=2)
self.rx3(qdev, wires=3)
for k in range(self.n_wires):
if k==self.n_wires-1:
tqf.cnot(qdev, wires=[k, 0])
else:
tqf.cnot(qdev, wires=[k, k+1])
`return(self.measure(qdev))`
this is a simple QNN, I want to know how to add noise in it? Are there any examples?
Metadata
Metadata
Assignees
Labels
No labels