Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add noise #269

Open
quantumliang opened this issue May 31, 2024 · 0 comments
Open

how to add noise #269

quantumliang opened this issue May 31, 2024 · 0 comments

Comments

@quantumliang
Copy link

quantumliang commented May 31, 2024

 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant