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][] = [];