Exemple #1
0
    def test_parametrize(self):
        """Tests that parametrize yields the correct queue of operations."""

        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)

        assert operation.parametrized_cirq_gates[0] == cirq.X
        assert operation.parametrized_cirq_gates[1] == cirq.ry(0.1)
        assert operation.parametrized_cirq_gates[2] == cirq.rx(0.2)
        assert operation.parametrized_cirq_gates[3] == cirq.Z
        assert operation.parametrized_cirq_gates[4] == cirq.rz(0.3)
Exemple #2
0
    def test_inv_error(self):
        """Test that inv raises an error if the CirqOperation was already parametrized."""

        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)

        with pytest.raises(
                qml.DeviceError,
                match=
                "CirqOperation can't be inverted after it was parametrized",
        ):
            operation.inv()
Exemple #3
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)