示例#1
0
def circuit_decomposed(weights):
    qml.BasisState(np.array([0, 0, 1, 1]), wires=[0, 1, 2, 3])
    qml.FermionicDoubleExcitation(weights[0][4], wires1=[0, 1], wires2=[2, 3])
    qml.FermionicDoubleExcitation(weights[0][5], wires1=[2, 3], wires2=[0, 1])
    qml.FermionicSingleExcitation(weights[0][0], wires=[0, 1, 2])
    qml.FermionicSingleExcitation(weights[0][1], wires=[1, 2, 3])
    qml.FermionicSingleExcitation(weights[0][2], wires=[2, 1, 0])
    qml.FermionicSingleExcitation(weights[0][3], wires=[3, 2, 1])
    return qml.expval(qml.PauliZ(0))
示例#2
0
 def test_id(self):
     """Tests that the id attribute can be set."""
     template = qml.FermionicDoubleExcitation(0.4,
                                              wires1=[0, 2],
                                              wires2=[1, 4, 3],
                                              id="a")
     assert template.id == "a"
示例#3
0
    def test_double_ex_unitary_operations(self, wires1, wires2, ref_gates):
        """Test the correctness of the FermionicDoubleExcitation template including the gate count
        and order, the wires each operation acts on and the correct use of parameters
        in the circuit."""

        sqg = 72
        cnots = 16 * (len(wires1) - 1 + len(wires2) - 1 + 1)
        weight = np.pi / 3
        op = qml.FermionicDoubleExcitation(weight,
                                           wires1=wires1,
                                           wires2=wires2)
        queue = op.expand().operations

        assert len(queue) == sqg + cnots

        for gate in ref_gates:
            idx = gate[0]

            exp_gate = gate[1]
            res_gate = queue[idx]
            assert isinstance(res_gate, exp_gate)

            exp_wires = gate[2]
            res_wires = queue[idx].wires
            assert res_wires.tolist() == exp_wires

            exp_weight = gate[3]
            res_weight = queue[idx].parameters
            assert res_weight == exp_weight
示例#4
0
    def expand(self):

        weights = self.parameters[0]

        with qml.tape.QuantumTape() as tape:

            BasisState(self.init_state_flipped, wires=self.wires)

            for i, (w1, w2) in enumerate(self.d_wires):
                qml.FermionicDoubleExcitation(weights[len(self.s_wires) + i],
                                              wires1=w1,
                                              wires2=w2)

            for j, s_wires_ in enumerate(self.s_wires):
                qml.FermionicSingleExcitation(weights[j], wires=s_wires_)

        return tape
示例#5
0
    def expand(self):

        with qml.tape.QuantumTape() as tape:

            qml.BasisEmbedding(self.init_state_flipped, wires=self.wires)
            weights = self.parameters[0]

            for layer in range(self.k):
                for i, (w1, w2) in enumerate(self.d_wires):
                    qml.FermionicDoubleExcitation(
                        weights[layer][len(self.s_wires) + i],
                        wires1=w1,
                        wires2=w2)

                for j, s_wires_ in enumerate(self.s_wires):
                    qml.FermionicSingleExcitation(weights[layer][j],
                                                  wires=s_wires_)

        return tape
示例#6
0
def circuit_template(weight):
    qml.FermionicDoubleExcitation(weight, wires1=[0, 1], wires2=[2, 3])
    return qml.expval(qml.PauliZ(0))
示例#7
0
 def circuit(weight):
     qml.FermionicDoubleExcitation(weight=weight,
                                   wires1=wires1,
                                   wires2=wires2)
     return qml.expval(qml.PauliZ(0))
示例#8
0
 def circuit2():
     qml.FermionicDoubleExcitation(0.4,
                                   wires1=["z", "k"],
                                   wires2=["a", "s", "t"])
     return qml.expval(qml.Identity("z"))
示例#9
0
 def circuit():
     qml.FermionicDoubleExcitation(0.4, wires1=[0, 2], wires2=[1, 4, 3])
     return qml.expval(qml.Identity(0))
示例#10
0
def circuit_decomposed(weights):
    qml.BasisState(np.array([1, 0, 0, 0]), wires=range(4))
    qml.FermionicDoubleExcitation(weights[1], wires1=[0, 1], wires2=[2, 3])
    qml.FermionicSingleExcitation(weights[0], wires=[0, 1])
    return qml.expval(qml.PauliZ(0))