예제 #1
0
 def __init__(self, q_device: tq.QuantumDevice = None):
     super().__init__()
     self.q_device = q_device
     self.n_gate = 10
     self.gate0 = tq.CNOT()
     # self.gate1 = tq.CNOT()
     self.submodules = tq.QuantumModuleList()
     self.q_layer0 = TQAll(self.n_gate, tq.CNOT)
     for k in range(self.n_gate):
         self.submodules.append(tq.RY())
     # for k in range(self.n_gate):
     #     self.submodules.append(tq.CNOT())
     # self.gate0 = tq.RY(has_params=False, trainable=False)
     # self.gate1 = tq.RX(has_params=False, trainable=False)
     # self.gate2 = tq.RZ(has_params=False, trainable=False)
     self.gate1 = tq.RX(has_params=True, trainable=True)
     self.gate2 = tq.RZ(has_params=True, trainable=True)
     self.gate3 = tq.RY(has_params=True, trainable=True)
     # self.gate3 = tq.CNOT()
     self.gate4 = tq.RX(has_params=True, trainable=True)
     self.gate5 = tq.RZ(has_params=True, trainable=True)
     self.gate6 = tq.RY(has_params=True, trainable=True)
     self.gate7 = tq.RX()
     self.gate8 = tq.U2(has_params=True, trainable=True)
     self.gate9 = tq.TrainableUnitary(has_params=True,
                                      trainable=True,
                                      n_wires=3)
     self.gate10 = tq.MultiXCNOT(n_wires=5)
     self.gate11 = tq.MultiCNOT(n_wires=3)
예제 #2
0
        def __init__(self):
            super().__init__()
            self.n_wires = 4
            self.random_layer = tq.RandomLayer(n_ops=50,
                                               wires=list(range(self.n_wires)))

            # gates with trainable parameters
            self.rx0 = tq.RX(has_params=True, trainable=True)
            self.ry0 = tq.RY(has_params=True, trainable=True)
            self.rz0 = tq.RZ(has_params=True, trainable=True)
            self.crx0 = tq.CRX(has_params=True, trainable=True)
예제 #3
0
 def __init__(self):
     super().__init__()
     self.n_gate = 12
     self.gate0 = tq.CNOT()
     self.gate1 = tq.CNOT()
     self.submodules = tq.QuantumModuleList()
     self.q_layer0 = TQAll(self.n_gate, tq.CNOT)
     for k in range(self.n_gate):
         self.submodules.append(tq.RY())
     # for k in range(self.n_gate):
     #     self.submodules.append(tq.CNOT())
     # self.gate0 = tq.RY(has_params=False, trainable=False)
     # self.gate1 = tq.RX(has_params=False, trainable=False)
     # self.gate2 = tq.RZ(has_params=False, trainable=False)
     self.gate1 = tq.RX(has_params=True, trainable=True)
     self.gate2 = tq.RZ(has_params=True, trainable=True)
     self.gate3 = tq.RY(has_params=True, trainable=True)
     # self.gate3 = tq.CNOT()
     self.gate4 = tq.RX(has_params=True, trainable=True)
     self.gate5 = tq.RZ(has_params=True, trainable=True)
     self.gate6 = tq.RY(has_params=True, trainable=True)
예제 #4
0
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(1, 32, 3, 1)
        self.conv2 = nn.Conv2d(32, 64, 3, 1)
        self.dropout1 = nn.Dropout(0.25)
        self.dropout2 = nn.Dropout(0.5)
        self.fc1 = nn.Linear(9216, 128)
        self.fc2 = nn.Linear(128, 10)
        self.sigmoid = nn.Sigmoid()
        self.q_device0 = tq.QuantumDevice(n_wires=12)
        self.q_device0_1 = tq.QuantumDevice(n_wires=10)
        self.q_layer0 = tq.TrainableOpAll(n_gate=12, op=tq.RX)
        # self.q_layer1 = OpAll(n_gate=10, op=tq.RY)
        self.q_layer2 = tq.RX(has_params=True,
                              trainable=False,
                              init_params=-np.pi / 4)

        self.q_layer3 = tq.RZ(has_params=True, trainable=True)
        self.q_device1 = tq.QuantumDevice(n_wires=3)
        self.q_layer4 = tq.CY()
        self.q_layer5 = tq.Toffoli()
        self.q_layer6 = tq.PhaseShift(has_params=True, trainable=True)
        self.q_layer7 = tq.Rot(has_params=True, trainable=True)
        self.q_layer8 = tq.MultiRZ(has_params=True, trainable=True, n_wires=5)
        self.q_layer9 = tq.CRX(has_params=True, trainable=True)
        self.q_layer10 = tq.CRY(has_params=True, trainable=True)
        self.q_layer11 = tq.CRZ(has_params=True, trainable=True)
        self.q_layer12 = tq.CRot(
            has_params=True,
            trainable=False,
            init_params=[-np.pi / 4, np.pi / 4, np.pi / 2])
        self.q_layer13 = tq.U1(has_params=True,
                               trainable=False,
                               init_params=np.pi / 7)
        self.q_layer14 = tq.U2(has_params=True,
                               trainable=True,
                               init_params=[np.pi / 7, np.pi / 8.8])
        self.q_layer15 = tq.U3(has_params=True, trainable=True)
        self.q_layer16 = tq.QubitUnitary(has_params=True,
                                         trainable=False,
                                         init_params=[[1, 0], [0, 1]])
        self.q_test_layer = TestModule()
        self.random_layer = tq.RandomLayer(30, wires=[0, 3, 5, 7])
        # self.random_layer.static_on(wires_per_block=3)

        # self.q_test_layer.static_on(wires_per_block=4)
        self.q_device2 = tq.QuantumDevice(n_wires=3)
        self.t00 = T00()
예제 #5
0
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(1, 32, 3, 1)
        self.conv2 = nn.Conv2d(32, 64, 3, 1)
        self.dropout1 = nn.Dropout(0.25)
        self.dropout2 = nn.Dropout(0.5)
        self.fc1 = nn.Linear(9216, 128)
        self.fc2 = nn.Linear(128, 10)
        self.sigmoid = nn.Sigmoid()
        self.q_device0 = tq.QuantumDevice(n_wires=10)
        self.q_layer0 = tq.TrainableOpAll(n_gate=10, op=tq.RX)
        self.q_layer1 = tq.ClassicalInOpAll(n_gate=10, op=tq.RX)
        self.q_layer2 = tq.RX(has_params=True,
                              trainable=False,
                              init_params=-np.pi / 4)

        self.q_layer3 = tq.RZ(has_params=True, trainable=True)
        self.q_device1 = tq.QuantumDevice(n_wires=3)
        self.q_layer4 = tq.CY()
        self.q_layer5 = tq.Toffoli()
        self.q_layer6 = tq.PhaseShift(has_params=True, trainable=True)
        self.q_layer7 = tq.Rot(has_params=True, trainable=True)
        self.q_layer8 = tq.MultiRZ(has_params=True, trainable=True, n_wires=5)
        self.q_layer9 = tq.CRX(has_params=True, trainable=True)
        self.q_layer10 = tq.CRY(has_params=True, trainable=True)
        self.q_layer11 = tq.CRZ(has_params=True, trainable=True)
        self.q_layer12 = tq.CRot(
            has_params=True,
            trainable=False,
            init_params=[-np.pi / 4, np.pi / 4, np.pi / 2])
        self.q_layer13 = tq.U1(has_params=True,
                               trainable=False,
                               init_params=np.pi / 7)
        self.q_layer14 = tq.U2(has_params=True,
                               trainable=True,
                               init_params=[np.pi / 7, np.pi / 8.8])
        self.q_layer15 = tq.U3(has_params=True, trainable=True)
        self.q_layer16 = tq.QubitUnitary(has_params=True,
                                         trainable=False,
                                         init_params=[[1, 0], [0, 1]])
        self.q_layer17 = tq.MultiCNOT(n_wires=5)
        self.q_layer18 = tq.MultiXCNOT(n_wires=5)
예제 #6
0
 def __init__(self, n_wires):
     super().__init__()
     self.n_wires = n_wires
     self.gate1 = tq.RX(has_params=True, trainable=True)
     self.gate2 = tq.RY(has_params=True, trainable=True)
     self.gate3 = tq.RZ(has_params=True, trainable=True)