예제 #1
0
            def queue(self):
                QueuingContext.append(self, owns=tuple(self.obs))

                for o in self.obs:
                    try:
                        QueuingContext.update_info(o, owner=self)
                    except AttributeError:
                        pass

                return self
예제 #2
0
    def __enter__(self):
        if not QueuingContext.recording():
            # if the tape is the first active queuing context
            # monkeypatch the operations to support the new queuing context
            with contextlib.ExitStack() as stack:
                for mock in mock_operations():
                    stack.enter_context(mock)
                self._stack = stack.pop_all()

        QueuingContext.append(self)
        return super().__enter__()
예제 #3
0
파일: tape.py 프로젝트: mo0-pi/pennylane
    def __enter__(self):
        QuantumTape._lock.acquire()
        try:
            if not QueuingContext.recording():
                # if the tape is the first active queuing context
                # monkeypatch the operations to support the new queuing context
                with contextlib.ExitStack() as stack:
                    for mock in mock_operations():
                        stack.enter_context(mock)
                    self._stack = stack.pop_all()

            QueuingContext.append(self)
            return super().__enter__()
        except Exception as _:
            QuantumTape._lock.release()
            raise
예제 #4
0
    def test_append_no_context(self):
        """Test that append does not fail when no context is present."""

        QueuingContext.append(qml.PauliZ(0))