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
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__()
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 test_append_no_context(self): """Test that append does not fail when no context is present.""" QueuingContext.append(qml.PauliZ(0))