Skip to content

Playground Profile Selection #2642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion source/npm/qsharp/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
QSharpDebugService,
debugServiceProtocol,
} from "./debug-service/debug-service.js";
import { callAndTransformExceptions } from "./diagnostics.js";
import {
ILanguageService,
ILanguageServiceWorker,
Expand Down Expand Up @@ -156,6 +157,23 @@ export function getLanguageServiceWorker(
return createProxy(worker, wasmModule, languageServiceProtocol);
}

/// Extracts the target profile from a Q# source file's entry point.
/// Scans the provided source code for an EntryPoint argument specifying
/// a profile and returns the corresponding TargetProfile value, if found.
/// Returns undefined if no profile is specified or if the profile is not recognized.
export async function getTargetProfileFromEntryPoint(
fileName: string,
source: string,
): Promise<wasm.TargetProfile | undefined> {
await instantiateWasm();
return callAndTransformExceptions(
async () =>
wasm.get_target_profile_from_entry_point(fileName, source) as
| wasm.TargetProfile
| undefined,
);
}

export { StepResultId } from "../lib/web/qsc_wasm.js";
export type {
IBreakpointSpan,
Expand Down Expand Up @@ -186,7 +204,6 @@ export type {
} from "./language-service/language-service.js";
export { default as openqasm_samples } from "./openqasm-samples.generated.js";
export type { ProjectLoader } from "./project.js";
export { getTargetProfileFromEntryPoint } from "./project.js";
export { default as samples } from "./samples.generated.js";
export type { CircuitGroup as CircuitData } from "./data-structures/circuit.js";
export * as utils from "./utils.js";
Expand Down
5 changes: 1 addition & 4 deletions source/npm/qsharp/src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ export class Compiler implements ICompiler {
}

async getRir(program: ProgramConfig): Promise<string[]> {
const config = toWasmProgramConfig(
program,
program.profile || "adaptive_ri",
);
const config = toWasmProgramConfig(program, "adaptive_ri");
return callAndTransformExceptions(async () => this.wasm.get_rir(config));
}

Expand Down
12 changes: 0 additions & 12 deletions source/npm/qsharp/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,3 @@ export class ProjectLoader {
);
}
}

export async function getTargetProfileFromEntryPoint(
fileName: string,
source: string,
): Promise<wasm.TargetProfile | undefined> {
return callAndTransformExceptions(
async () =>
wasm.get_target_profile_from_entry_point(fileName, source) as
| wasm.TargetProfile
| undefined,
);
}
5 changes: 5 additions & 0 deletions source/playground/src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
log,
ProgramConfig,
LanguageServiceDiagnosticEvent,
getTargetProfileFromEntryPoint,
} from "qsharp-lang";
import { Exercise, getExerciseSources } from "qsharp-lang/katas-md";
import { codeToCompressedBase64, lsRangeToMonacoRange } from "./utils.js";
Expand Down Expand Up @@ -128,6 +129,9 @@ export function Editor(props: {
const config = {
sources: [["code", code]] as [string, string][],
languageFeatures: [],
profile:
(await getTargetProfileFromEntryPoint("main.qs", code)) ||
"adaptive_rif", // Default to adaptive_rif for qir and rir generation
};

if (props.activeTab === "ast-tab") {
Expand Down Expand Up @@ -182,6 +186,7 @@ export function Editor(props: {
const config = {
sources: [["code", code]],
languageFeatures: [],
profile: await getTargetProfileFromEntryPoint("main.qs", code),
} as ProgramConfig;

try {
Expand Down
Loading