public void OnOperationStartHandler(ICallable operation, IApplyData arguments) { // We don't want to process operations whose parent is a measurement gate (will mess up gate visualization) var metadata = (this.operations.Count == 0) || (!this.operations.Peek()?.IsMeasurement ?? true) ? operation.GetRuntimeMetadata(arguments) : null; // We also push on `null` operations to the stack instead of ignoring them so that we pop off the // correct element in `OnOperationEndHandler`. this.operations.Push(this.MetadataToOperation(metadata)); }