Exemplo n.º 1
0
 def test_id(self):
     """Tests that the id attribute can be set."""
     template = qml.ArbitraryStatePreparation(np.random.random(size=(2**4 -
                                                                     2)),
                                              wires=[0, 1, 2],
                                              id="a")
     assert template.id == "a"
Exemplo n.º 2
0
    def test_correct_gates_single_wire(self):
        """Test that the correct gates are applied on a single wire."""
        weights = np.array([0, 1], dtype=float)

        op = qml.ArbitraryStatePreparation(weights, wires=[0])
        queue = op.expand().operations

        assert queue[0].name == "PauliRot"

        assert queue[0].data[0] == weights[0]
        assert queue[0].data[1] == "X"
        assert queue[0].wires.labels == (0, )

        assert queue[1].name == "PauliRot"
        assert queue[1].data[0] == weights[1]
        assert queue[1].data[1] == "Y"
        assert queue[1].wires.labels == (0, )
Exemplo n.º 3
0
    def test_correct_gates_two_wires(self):
        """Test that the correct gates are applied on on two wires."""
        weights = np.array([0, 1, 2, 3, 4, 5], dtype=float)

        op = qml.ArbitraryStatePreparation(weights, wires=[0, 1])
        queue = op.expand().operations

        assert queue[0].name == "PauliRot"

        assert queue[0].data[0] == weights[0]
        assert queue[0].data[1] == "XI"
        assert queue[0].wires.labels == (0, 1)

        assert queue[1].name == "PauliRot"
        assert queue[1].data[0] == weights[1]
        assert queue[1].data[1] == "YI"
        assert queue[1].wires.labels == (0, 1)

        assert queue[2].name == "PauliRot"
        assert queue[2].data[0] == weights[2]
        assert queue[2].data[1] == "IX"
        assert queue[2].wires.labels == (0, 1)

        assert queue[3].name == "PauliRot"
        assert queue[3].data[0] == weights[3]
        assert queue[3].data[1] == "IY"
        assert queue[3].wires.labels == (0, 1)

        assert queue[4].name == "PauliRot"
        assert queue[4].data[0] == weights[4]
        assert queue[4].data[1] == "XX"
        assert queue[4].wires.labels == (0, 1)

        assert queue[5].name == "PauliRot"
        assert queue[5].data[0] == weights[5]
        assert queue[5].data[1] == "XY"
        assert queue[5].wires.labels == (0, 1)
Exemplo n.º 4
0
def circuit_template(weights):
    qml.ArbitraryStatePreparation(weights, range(2))
    return qml.expval(qml.PauliZ(0))
Exemplo n.º 5
0
 def circuit(weights):
     qml.ArbitraryStatePreparation(weights, wires=range(3))
     return qml.expval(qml.PauliZ(0))
Exemplo n.º 6
0
 def circuit2():
     qml.ArbitraryStatePreparation(weights, wires=["z", "a", "k"])
     return qml.expval(qml.Identity("z"))
Exemplo n.º 7
0
 def circuit():
     qml.ArbitraryStatePreparation(weights, wires=range(3))
     return qml.expval(qml.Identity(0))
Exemplo n.º 8
0
        def circuit(weights):
            qml.ArbitraryStatePreparation(weights, [0, 1, 2])

            return qml.expval(qml.PauliZ(0))