From a7ce77a555f8d4ed4e8f60f96b14784667fa5c3e Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Tue, 21 May 2024 20:17:44 -0700 Subject: [PATCH] Updated UX for VSCode QIR generation (#1548) This change updates the extension behavior for QIR code generation to give more granular error messages and guidance when possible. We used to always report an error with "Submitting to Azure" and recommend switching to Base profile. Now the message and guidance will differentiate between a few different scenarios: - Generating QIR with profile set to unrestricted will use codegen specific message and prompt for Base Profile. - Submitting to Azure target with profile set to unrestricted will recommend either Base or Adaptive_RI depending on what the target supports. - Submitting to Azure target that only supports Base profile with Adaptive_RI configured will give specific error message and recommend Base. This also fixes a minor bug with a missing await that could cause an error message to crop up even if the user clicked "Set" to take the recommended change. --- vscode/src/azure/commands.ts | 6 ++-- vscode/src/azure/providerProperties.ts | 4 +++ vscode/src/qirGeneration.ts | 39 ++++++++++++++++++++------ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/vscode/src/azure/commands.ts b/vscode/src/azure/commands.ts index 9568c3db8d..b620004f3c 100644 --- a/vscode/src/azure/commands.ts +++ b/vscode/src/azure/commands.ts @@ -20,7 +20,7 @@ import { } from "./workspaceActions"; import { QuantumUris } from "./networkRequests"; import { getQirForActiveWindow } from "../qirGeneration"; -import { targetSupportQir } from "./providerProperties"; +import { supportsAdaptive, targetSupportQir } from "./providerProperties"; import { startRefreshCycle } from "./treeRefresher"; import { getTokenForWorkspace } from "./auth"; @@ -109,9 +109,11 @@ export async function initAzureWorkspaces(context: vscode.ExtensionContext) { const providerId = target.id.split(".")?.[0]; + const supports_adaptive = supportsAdaptive(target.id); + let qir = ""; try { - qir = await getQirForActiveWindow(); + qir = await getQirForActiveWindow(supports_adaptive); } catch (e: any) { if (e?.name === "QirGenerationError") { vscode.window.showErrorMessage(e.message); diff --git a/vscode/src/azure/providerProperties.ts b/vscode/src/azure/providerProperties.ts index e887ca8902..eafa1d3fc3 100644 --- a/vscode/src/azure/providerProperties.ts +++ b/vscode/src/azure/providerProperties.ts @@ -44,3 +44,7 @@ export function shouldExcludeTarget(target: string) { export function shouldExcludeProvider(provider: string) { return excludeProviders.includes(provider); } + +export function supportsAdaptive(target: string) { + return target.startsWith("quantinuum"); +} diff --git a/vscode/src/qirGeneration.ts b/vscode/src/qirGeneration.ts index 78c90d928d..c2d09df9b7 100644 --- a/vscode/src/qirGeneration.ts +++ b/vscode/src/qirGeneration.ts @@ -21,7 +21,9 @@ export class QirGenerationError extends Error { } } -export async function getQirForActiveWindow(): Promise { +export async function getQirForActiveWindow( + supports_adaptive?: boolean, // should be true or false when submitting to Azure, undefined when generating QIR +): Promise { let result = ""; const editor = vscode.window.activeTextEditor; @@ -31,25 +33,46 @@ export async function getQirForActiveWindow(): Promise { ); } - // Check that the current target is base or adaptive_ri profile, and current doc has no errors. const targetProfile = getTarget(); - if (targetProfile === "unrestricted") { + const is_unrestricted = targetProfile === "unrestricted"; + const is_base = targetProfile === "base"; + + // We differentiate between submission to Azure and on-demand QIR codegen by checking + // whether a boolean value was passed for `supports_adaptive`. On-demand codegen does not + // have a target, so support for adaptive is unknown. + let error_msg = + supports_adaptive === undefined + ? "Generating QIR " + : "Submitting to Azure "; + if (is_unrestricted) { + error_msg += "is not supported when using the unrestricted profile."; + } else if (!is_base && supports_adaptive === false) { + error_msg += + "using the Adaptive_RI profile is not supported for targets that can only accept Base profile QIR."; + } + + // Check that the current target is base or adaptive_ri profile, and current doc has no errors. + if (is_unrestricted || (!is_base && supports_adaptive === false)) { const result = await vscode.window.showWarningMessage( - "Submitting to Azure is only supported when targeting the QIR base or adaptive_ri profile.", + // if supports_adaptive is undefined, use the generic codegen message + error_msg, { modal: true }, { - title: "Set the QIR target profile to Base and continue", + title: + "Set the QIR target profile to " + + (supports_adaptive ? "Adaptive_RI" : "Base") + + " to continue", action: "set", }, { title: "Cancel", action: "cancel", isCloseAffordance: true }, ); if (result?.action !== "set") { throw new QirGenerationError( - "Submitting to Azure is not supported when using the unrestricted profile. " + - "Please update the QIR target via the status bar selector or extension settings.", + error_msg + + " Please update the QIR target via the status bar selector or extension settings.", ); } else { - setTarget("base"); + await setTarget(supports_adaptive ? "adaptive_ri" : "base"); } } let sources: [string, string][] = [];