def get_active_tape(): """Returns the currently recording tape. If no tape is currently recording, ``None`` is returned. **Example** >>> with qml.tape.QuantumTape(): ... qml.RX(0.2, wires="a") ... tape = qml.tape.get_active_tape() ... qml.RY(0.1, wires="b") >>> print(tape) <QuantumTape: wires=['a', 'b'], params=2> >>> print(qml.tape.get_active_tape()) None """ return QueuingContext.active_context()
def stop_recording(self): """Context manager to temporarily stop recording operations onto the tape. This is useful is scratch space is needed. **Example** >>> with qml.tape.QuantumTape() as tape: ... qml.RX(0, wires=0) ... with tape.stop_recording(): ... qml.RY(1.0, wires=1) ... qml.RZ(2, wires=1) >>> tape.operations [RX(0, wires=[0]), RZ(2, wires=[1])] """ if QueuingContext.active_context() is not self: raise QueuingError("Cannot stop recording requested tape " "as it is not currently recording.") active_contexts = QueuingContext._active_contexts QueuingContext._active_contexts = deque() yield QueuingContext._active_contexts = active_contexts