Exemple #1
0
    def test_apply_not_parametrized(self):
        """Tests that the proper error is raised if an Operation is applied
        that was not parametrized before."""
        operation = CirqOperation(
            lambda a, b, c:
            [cirq.X, cirq.ry(a),
             cirq.rx(b), cirq.Z,
             cirq.rz(c)])
        qubit = cirq.LineQubit(1)

        with pytest.raises(
                qml.DeviceError,
                match=
                "CirqOperation must be parametrized before it can be applied.",
        ):
            operation.apply(qubit)
Exemple #2
0
    def test_apply(self):
        """Tests that the operations in the queue are correctly applied."""

        operation = CirqOperation(
            lambda a, b, c:
            [cirq.X, cirq.ry(a),
             cirq.rx(b), cirq.Z,
             cirq.rz(c)])
        operation.parametrize(0.1, 0.2, 0.3)

        qubit = cirq.LineQubit(1)

        gate_applications = list(operation.apply(qubit))

        assert gate_applications[0] == cirq.X.on(qubit)
        assert gate_applications[1] == cirq.ry(0.1).on(qubit)
        assert gate_applications[2] == cirq.rx(0.2).on(qubit)
        assert gate_applications[3] == cirq.Z.on(qubit)
        assert gate_applications[4] == cirq.rz(0.3).on(qubit)