示例#1
0
    def __exit__(self, exception_type, exception_value, traceback):
        super().__exit__(exception_type, exception_value, traceback)

        if not QueuingContext.recording():
            # remove the monkeypatching
            self._stack.__exit__(exception_type, exception_value, traceback)

        self._process_queue()
示例#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
    def __exit__(self, exception_type, exception_value, traceback):
        try:
            super().__exit__(exception_type, exception_value, traceback)

            if not QueuingContext.recording():
                # remove the monkeypatching
                self._stack.__exit__(exception_type, exception_value, traceback)

            self._process_queue()
        finally:
            QuantumTape._lock.release()
示例#4
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