示例#1
0
    def test_remove_operator_multiple_queues(self, three_mock_queuing_contexts):
        """Test that remove_operator removes the operator from the queue."""

        op = qml.PauliZ(0)
        assert not three_mock_queuing_contexts[0].queue
        assert not three_mock_queuing_contexts[1].queue
        assert not three_mock_queuing_contexts[2].queue

        with three_mock_queuing_contexts[0]:
            with three_mock_queuing_contexts[1]:
                with three_mock_queuing_contexts[2]:
                    QueuingContext.append_operator(op)

                    assert len(three_mock_queuing_contexts[0].queue) == 1
                    assert op in three_mock_queuing_contexts[0].queue

                    assert len(three_mock_queuing_contexts[1].queue) == 1
                    assert op in three_mock_queuing_contexts[1].queue

                    assert len(three_mock_queuing_contexts[2].queue) == 1
                    assert op in three_mock_queuing_contexts[2].queue

                    QueuingContext.remove_operator(op)

        assert not three_mock_queuing_contexts[0].queue
        assert not three_mock_queuing_contexts[1].queue
        assert not three_mock_queuing_contexts[2].queue
示例#2
0
    def test_remove_operator(self, mock_queuing_context):
        """Test that remove_operator removes the operator from the queue."""

        op = qml.PauliZ(0)
        assert not mock_queuing_context.queue

        with mock_queuing_context:
            QueuingContext.append_operator(op)

            assert len(mock_queuing_context.queue) == 1
            assert op in mock_queuing_context.queue

            QueuingContext.remove_operator(op)

        assert not mock_queuing_context.queue
示例#3
0
    def test_remove_operator_not_in_list(self, mock_queuing_context):
        """Test that remove_operator does not fail when the operator to be removed is not in the queue."""

        op1 = qml.PauliZ(0)
        op2 = qml.PauliZ(1)
        assert not mock_queuing_context.queue

        with mock_queuing_context:
            QueuingContext.append_operator(op1)

            assert len(mock_queuing_context.queue) == 1
            assert op1 in mock_queuing_context.queue

            QueuingContext.remove_operator(op2)

        assert len(mock_queuing_context.queue) == 1
        assert op1 in mock_queuing_context.queue
示例#4
0
    def test_remove_operator_no_context(self):
        """Test that remove_operator does not fail when no context is present."""

        QueuingContext.remove_operator(qml.PauliZ(0))