Ejemplo n.º 1
0
    def test_rotations(self, rotation):
        """Checks the queue for the specified rotation settings."""

        op = qml.AngleEmbedding(features=[1, 1, 1], wires=range(4), rotation=rotation)
        tape = op.expand()

        for gate in tape.operations:
            assert gate.name == "R" + rotation
Ejemplo n.º 2
0
    def test_expansion(self, features):
        """Checks the queue for the default settings."""

        op = qml.AngleEmbedding(features=features, wires=range(4))
        tape = op.expand()

        assert len(tape.operations) == len(features)
        for gate in tape.operations:
            assert gate.name == "RX"
            assert gate.parameters[0] == 1
Ejemplo n.º 3
0
 def circuit2():
     qml.AngleEmbedding(features, wires=["z", "a", "k"])
     return qml.expval(qml.Identity("z"))
Ejemplo n.º 4
0
 def circuit():
     qml.AngleEmbedding(features, wires=range(3))
     return qml.expval(qml.Identity(0))
Ejemplo n.º 5
0
 def circuit(x=None):
     qml.AngleEmbedding(features=x, wires=range(5))
     return [qml.expval(qml.PauliZ(i)) for i in range(5)]
Ejemplo n.º 6
0
 def circuit(x=None):
     qml.AngleEmbedding(features=x, wires=range(4), rotation="X")
     qml.PauliX(wires=0)
     qml.AngleEmbedding(features=x, wires=range(4), rotation="X")
     return [qml.expval(qml.PauliZ(i)) for i in range(4)]
Ejemplo n.º 7
0
def circuit_template(features):
    qml.AngleEmbedding(features, range(3))
    qml.CNOT(wires=[2, 1])
    qml.CNOT(wires=[1, 0])
    return qml.expval(qml.PauliZ(0))
Ejemplo n.º 8
0
 def test_id(self):
     """Tests that the id attribute can be set."""
     template = qml.AngleEmbedding(np.array([1, 2]), wires=[0, 1], id="a")
     assert template.id == "a"
Ejemplo n.º 9
0
 def circuit(x=None):
     qml.AngleEmbedding(features=x, wires=range(1))
     return qml.expval(qml.PauliZ(0))
Ejemplo n.º 10
0
        adjoint(adjoint(my_op))()
        return qml.state()

    np.testing.assert_allclose(my_circuit(),
                               np.array([-0.995707, 0.068644 + 6.209710e-02j]),
                               atol=1e-6,
                               rtol=1e-6)


with qml.tape.JacobianTape() as tape:
    qml.PauliX(0)
    qml.Hadamard(1)

noncallable_objects = [
    qml.RX(0.2, wires=0),
    qml.AngleEmbedding(list(range(2)), wires=range(2)),
    [qml.Hadamard(1), qml.RX(-0.2, wires=1)],
    tape,
]


@pytest.mark.parametrize("obj", noncallable_objects)
def test_error_adjoint_on_noncallable(obj):
    """Test that an error is raised if qml.adjoint is applied to an object that
    is not callable, as it silently does not have any effect on those."""
    with pytest.raises(ValueError, match=f"{type(obj)} is not callable."):
        adjoint(obj)


class TestOutsideOfQueuing:
    """Test that operations and templates work with the adjoint transform when
Ejemplo n.º 11
0
def custom_basic_entangler_layers(weights, wires):
    return [
        qml.AngleEmbedding(weights, wires=wires),
        qml.broadcast(qml.CNOT, pattern="ring", wires=wires),
    ]