Skip to content

Commit

Permalink
Updated UX for VSCode QIR generation (#1548)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
swernli authored May 22, 2024
1 parent 93bc2e0 commit a7ce77a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
6 changes: 4 additions & 2 deletions vscode/src/azure/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions vscode/src/azure/providerProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
39 changes: 31 additions & 8 deletions vscode/src/qirGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class QirGenerationError extends Error {
}
}

export async function getQirForActiveWindow(): Promise<string> {
export async function getQirForActiveWindow(
supports_adaptive?: boolean, // should be true or false when submitting to Azure, undefined when generating QIR
): Promise<string> {
let result = "";
const editor = vscode.window.activeTextEditor;

Expand All @@ -31,25 +33,46 @@ export async function getQirForActiveWindow(): Promise<string> {
);
}

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

0 comments on commit a7ce77a

Please sign in to comment.