Ejemplo n.º 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))
Ejemplo n.º 2
0
    def test_single_ex_unitary_operations(self, single_wires, ref_gates):
        """Test the correctness of the FermionicSingleExcitation template including the gate count
        and order, the wires each operation acts on and the correct use of parameters
        in the circuit."""

        sqg = 10
        cnots = 4 * (len(single_wires) - 1)
        weight = np.pi / 3
        op = qml.FermionicSingleExcitation(weight, wires=single_wires)
        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
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def circuit_template(weight):
    qml.FermionicSingleExcitation(weight, wires=[0, 1])
    return qml.expval(qml.PauliZ(0))
Ejemplo n.º 6
0
 def test_id(self):
     """Tests that the id attribute can be set."""
     template = qml.FermionicSingleExcitation(0.4, wires=[1, 0, 2], id="a")
     assert template.id == "a"
Ejemplo n.º 7
0
 def circuit(weight=weight):
     qml.FermionicSingleExcitation(weight=weight, wires=single_wires)
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 8
0
 def circuit2():
     qml.FermionicSingleExcitation(0.4, wires=["a", "z", "k"])
     return qml.expval(qml.Identity("z"))
Ejemplo n.º 9
0
 def circuit():
     qml.FermionicSingleExcitation(0.4, wires=[1, 0, 2])
     return qml.expval(qml.Identity(0))
Ejemplo n.º 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))