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
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
def circuit2(): qml.AngleEmbedding(features, wires=["z", "a", "k"]) return qml.expval(qml.Identity("z"))
def circuit(): qml.AngleEmbedding(features, wires=range(3)) return qml.expval(qml.Identity(0))
def circuit(x=None): qml.AngleEmbedding(features=x, wires=range(5)) return [qml.expval(qml.PauliZ(i)) for i in range(5)]
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)]
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))
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"
def circuit(x=None): qml.AngleEmbedding(features=x, wires=range(1)) return qml.expval(qml.PauliZ(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
def custom_basic_entangler_layers(weights, wires): return [ qml.AngleEmbedding(weights, wires=wires), qml.broadcast(qml.CNOT, pattern="ring", wires=wires), ]