Exemple #1
0
def circuit_template(weights):
    qml.UCCSD(
        weights,
        wires=range(4),
        s_wires=[[0, 1]],
        d_wires=[[[0, 1], [2, 3]]],
        init_state=np.array([0, 0, 0, 1]),
    )
    return qml.expval(qml.PauliZ(0))
Exemple #2
0
 def circuit2():
     qml.UCCSD(
         weights,
         wires=["z", "a", "k", "e"],
         s_wires=[["z", "a"]],
         d_wires=[[["z", "a"], ["k", "e"]]],
         init_state=np.array([0, 1, 0, 1]),
     )
     return qml.expval(qml.Identity("z"))
Exemple #3
0
 def circuit():
     qml.UCCSD(
         weights,
         wires=range(4),
         s_wires=[[0, 1]],
         d_wires=[[[0, 1], [2, 3]]],
         init_state=np.array([0, 1, 0, 1]),
     )
     return qml.expval(qml.Identity(0))
Exemple #4
0
 def test_id(self):
     """Tests that the id attribute can be set."""
     template = qml.UCCSD(
         [0.1, 0.2],
         wires=range(4),
         s_wires=[[0, 1]],
         d_wires=[[[0, 1], [2, 3]]],
         init_state=np.array([0, 1, 0, 1]),
         id="a",
     )
     assert template.id == "a"
Exemple #5
0
    def test_uccsd_operations(self, s_wires, d_wires, weights, ref_gates):
        """Test the correctness of the UCCSD template including the gate count
        and order, the wires the operation acts on and the correct use of parameters
        in the circuit."""

        sqg = 10 * len(s_wires) + 72 * len(d_wires)

        cnots = 0
        for s_wires_ in s_wires:
            cnots += 4 * (len(s_wires_) - 1)

        for d_wires_ in d_wires:
            cnots += 16 * (len(d_wires_[0]) - 1 + len(d_wires_[1]) - 1 + 1)
        N = 6
        wires = range(N)

        ref_state = np.array([1, 1, 0, 0, 0, 0])

        op = qml.UCCSD(weights,
                       wires,
                       s_wires=s_wires,
                       d_wires=d_wires,
                       init_state=ref_state)
        raw_queue = op.expand().operations

        # hack to avoid updating the test data:
        # expand the other templates, which now
        # queue as a single operation
        queue = []
        for op in raw_queue:
            if op.name in [
                    "FermionicSingleExcitation", "FermionicDoubleExcitation"
            ]:
                queue.extend(op.expand().operations)
            else:
                queue.append(op)

        assert len(queue) == sqg + cnots + 1

        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 np.allclose(res_weight, exp_weight)
Exemple #6
0
 def circuit(weights=weights,
             wires=wires,
             s_wires=s_wires,
             d_wires=d_wires,
             init_state=init_state):
     qml.UCCSD(
         weights=weights,
         wires=wires,
         s_wires=s_wires,
         d_wires=d_wires,
         init_state=init_state,
     )
     return qml.expval(qml.PauliZ(0))