Beispiel #1
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__()
Beispiel #2
0
    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
def patch_operator():
    with contextlib.ExitStack() as stack:
        for mock in mock_operations():
            stack.enter_context(mock)
        yield