Skip to content

Commit

Permalink
Merge a9c5a2d into e19947a
Browse files Browse the repository at this point in the history
  • Loading branch information
idavis committed May 1, 2024
2 parents e19947a + a9c5a2d commit fed14e2
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion compiler/qsc/src/codegen/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ mod adaptive_profile {
}
}

mod quantinuum_profile {
mod adaptive_ri_profile {
use expect_test::expect;
use qsc_data_structures::{language_features::LanguageFeatures, target::TargetCapabilityFlags};
use qsc_frontend::compile::SourceMap;
Expand Down
8 changes: 4 additions & 4 deletions compiler/qsc/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use qsc_data_structures::target::TargetCapabilityFlags;
pub enum Profile {
Unrestricted,
Base,
Quantinuum,
AdaptiveRI,
}

impl Profile {
Expand All @@ -18,7 +18,7 @@ impl Profile {
match self {
Self::Unrestricted => "Unrestricted",
Self::Base => "Base",
Self::Quantinuum => "Quantinuum",
Self::AdaptiveRI => "Adaptive_RI",
}
}
}
Expand All @@ -28,7 +28,7 @@ impl From<Profile> for TargetCapabilityFlags {
match value {
Profile::Unrestricted => Self::all(),
Profile::Base => Self::empty(),
Profile::Quantinuum => Self::Adaptive | Self::IntegerComputations | Self::QubitReset,
Profile::AdaptiveRI => Self::Adaptive | Self::QubitReset | Self::IntegerComputations,
}
}
}
Expand All @@ -38,7 +38,7 @@ impl FromStr for Profile {

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Quantinuum" | "quantinuum" => Ok(Self::Quantinuum),
"Adaptive_RI" | "adaptive_ri" => Ok(Self::AdaptiveRI),
"Base" | "base" => Ok(Self::Base),
"Unrestricted" | "unrestricted" => Ok(Self::Unrestricted),
_ => Err(()),
Expand Down
2 changes: 1 addition & 1 deletion language_service/src/state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ async fn rca_errors_are_reported_when_compilation_succeeds() {
let mut updater = new_updater(&errors);

updater.update_configuration(WorkspaceConfigurationUpdate {
target_profile: Some(Profile::Quantinuum),
target_profile: Some(Profile::AdaptiveRI),
package_type: Some(PackageType::Lib),
});

Expand Down
4 changes: 2 additions & 2 deletions npm/qsharp/src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class Compiler implements ICompiler {
return this.wasm.get_ast(
code,
languageFeatures ?? [],
profile ?? "quantinuum",
profile ?? "adaptive_ri",
);
}

Expand All @@ -225,7 +225,7 @@ export class Compiler implements ICompiler {
return this.wasm.get_hir(
code,
languageFeatures ?? [],
profile ?? "quantinuum",
profile ?? "adaptive_ri",
);
}

Expand Down
5 changes: 3 additions & 2 deletions pip/qsharp/_native.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class TargetProfile:
This option maps to the Base Profile as defined by the QIR specification.
"""

Quantinuum: ClassVar[Any]
Adaptive_RI: ClassVar[Any]
"""
Target supports Quantinuum profile.
Target supports the Adaptive profile with integer computation and qubit
reset capabilities.
This profile includes all of the required Adaptive Profile
capabilities, as well as the optional integer computation and qubit
Expand Down
6 changes: 3 additions & 3 deletions pip/qsharp/_qsharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def __init__(
language_features: Optional[List[str]],
manifest: Optional[str],
):
if target_profile == TargetProfile.Quantinuum:
self._config = {"targetProfile": "quantinuum"}
warn("The Quantinuum target profile is a preview feature.")
if target_profile == TargetProfile.Adaptive_RI:
self._config = {"targetProfile": "adaptive_ri"}
warn("The Adaptive_RI target profile is a preview feature.")
warn("Functionality may be incomplete or incorrect.")
elif target_profile == TargetProfile.Base:
self._config = {"targetProfile": "base"}
Expand Down
7 changes: 4 additions & 3 deletions pip/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn _native(py: Python, m: &PyModule) -> PyResult<()> {
// This ordering must match the _native.pyi file.
#[derive(Clone, Copy)]
#[pyclass(unsendable)]
#[allow(non_camel_case_types)]
/// A Q# target profile.
///
/// A target profile describes the capabilities of the hardware or simulator
Expand All @@ -56,12 +57,12 @@ pub(crate) enum TargetProfile {
///
/// This option maps to the Base Profile as defined by the QIR specification.
Base,
/// Target supports Quantinuum profile.
/// Target supports the Adaptive profile with integer computation and qubit reset capabilities.
///
/// This profile includes all of the required Adaptive Profile
/// capabilities, as well as the optional integer computation and qubit
/// reset capabilities, as defined by the QIR specification.
Quantinuum,
Adaptive_RI,
/// Target supports the full set of capabilities required to run any Q# program.
///
/// This option maps to the Full Profile as defined by the QIR specification.
Expand Down Expand Up @@ -114,7 +115,7 @@ impl Interpreter {
list_directory: Option<PyObject>,
) -> PyResult<Self> {
let target = match target {
TargetProfile::Quantinuum => Profile::Quantinuum,
TargetProfile::Adaptive_RI => Profile::AdaptiveRI,
TargetProfile::Base => Profile::Base,
TargetProfile::Unrestricted => Profile::Unrestricted,
};
Expand Down
12 changes: 6 additions & 6 deletions pip/tests/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_entry_expr_circuit() -> None:

# this is by design
def test_callables_failing_profile_validation_are_still_registered() -> None:
e = Interpreter(TargetProfile.Quantinuum)
e = Interpreter(TargetProfile.Adaptive_RI)
with pytest.raises(Exception) as excinfo:
e.interpret(
"operation Foo() : Double { use q = Qubit(); mutable x = 1.0; if MResetZ(q) == One { set x = 2.0; } x }"
Expand All @@ -287,7 +287,7 @@ def test_callables_failing_profile_validation_are_still_registered() -> None:

# this is by design
def test_once_rca_validation_fails_following_calls_also_fail() -> None:
e = Interpreter(TargetProfile.Quantinuum)
e = Interpreter(TargetProfile.Adaptive_RI)
with pytest.raises(Exception) as excinfo:
e.interpret(
"operation Foo() : Double { use q = Qubit(); mutable x = 1.0; if MResetZ(q) == One { set x = 2.0; } x }"
Expand All @@ -299,7 +299,7 @@ def test_once_rca_validation_fails_following_calls_also_fail() -> None:


def test_adaptive_errors_are_raised_when_interpreting() -> None:
e = Interpreter(TargetProfile.Quantinuum)
e = Interpreter(TargetProfile.Adaptive_RI)
with pytest.raises(Exception) as excinfo:
e.interpret(
"operation Foo() : Double { use q = Qubit(); mutable x = 1.0; if MResetZ(q) == One { set x = 2.0; } x }"
Expand All @@ -308,14 +308,14 @@ def test_adaptive_errors_are_raised_when_interpreting() -> None:


def test_adaptive_errors_are_raised_from_entry_expr() -> None:
e = Interpreter(TargetProfile.Quantinuum)
e = Interpreter(TargetProfile.Adaptive_RI)
e.interpret("use q = Qubit();")
with pytest.raises(Exception) as excinfo:
e.run("{mutable x = 1.0; if MResetZ(q) == One { set x = 2.0; }}")
assert "Qsc.CapabilitiesCk.UseOfDynamicDouble" in str(excinfo)


def test_quantinuum_qir_can_be_generated() -> None:
def test_adaptive_ri_qir_can_be_generated() -> None:
adaptive_input = """
namespace Test {
open Microsoft.Quantum.Math;
Expand All @@ -333,7 +333,7 @@ def test_quantinuum_qir_can_be_generated() -> None:
}
}
"""
e = Interpreter(TargetProfile.Quantinuum)
e = Interpreter(TargetProfile.Adaptive_RI)
e.interpret(adaptive_input)
qir = e.qir("Test.Main()")
assert qir == dedent(
Expand Down
2 changes: 1 addition & 1 deletion playground/src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export function Editor(props: {
<span>Profile</span>
<select value={profile} onChange={profileChanged}>
<option value="unrestricted">Unrestricted</option>
<option value="quantinuum">Quantinuum</option>
<option value="adaptive_ri">Adaptive RI</option>
<option value="base">Base</option>
</select>
</>
Expand Down
4 changes: 2 additions & 2 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@
"enum": [
"unrestricted",
"base",
"quantinuum"
"adaptive_ri"
],
"enumDescriptions": [
"The set of all capabilities required to run any Q# program.",
"The minimal set of capabilities required to run a quantum program. This option maps to the Base Profile as defined by the QIR specification.",
"The Quantinuum target profile includes all of the required Adaptive Profile capabilities, as well as the optional integer computation and qubit reset capabilities, as defined by the QIR specification."
"The Adaptive_RI target profile includes all of the required Adaptive Profile capabilities, as well as the optional integer computation and qubit reset capabilities, as defined by the QIR specification."
],
"description": "Setting the target profile allows the Q# extension to generate programs that are compatible with a specific target. The target is the hardware or simulator which will be used to run the Q# program. The target profile is a description of a target's capabilities."
},
Expand Down
6 changes: 3 additions & 3 deletions vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getTarget(): TargetProfile {
.get<TargetProfile>("targetProfile", "unrestricted");
switch (target) {
case "base":
case "quantinuum":
case "adaptive_ri":
case "unrestricted":
return target;
default:
Expand All @@ -32,8 +32,8 @@ export function getTargetFriendlyName(targetProfile?: string) {
switch (targetProfile) {
case "base":
return "Q#: QIR base";
case "quantinuum":
return "Q#: QIR Quantinuum";
case "adaptive_ri":
return "Q#: QIR Adaptive RI";
case "unrestricted":
return "Q#: unrestricted";
default:
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ async function updateLanguageServiceProfile(languageService: ILanguageService) {

switch (targetProfile) {
case "base":
case "quantinuum":
case "adaptive_ri":
case "unrestricted":
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/qirGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getQirForActiveWindow(): Promise<string> {
const targetProfile = getTarget();
const enablePreviewQirGen = getEnablePreviewQirGen();
if (targetProfile !== "base") {
const allowed = targetProfile === "quantinuum" && enablePreviewQirGen;
const allowed = targetProfile === "adaptive_ri" && enablePreviewQirGen;
if (!allowed) {
const result = await vscode.window.showWarningMessage(
"Submitting to Azure is only supported when targeting the QIR base profile.",
Expand Down
12 changes: 6 additions & 6 deletions vscode/src/statusbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,20 @@ function registerTargetProfileCommand() {

const targetProfiles = [
{ configName: "base", uiText: "Q#: QIR base" },
{ configName: "quantinuum", uiText: "Q#: QIR Quantinuum" },
{ configName: "adaptive_ri", uiText: "Q#: QIR Adaptive RI" },
{ configName: "unrestricted", uiText: "Q#: unrestricted" },
];

function getTargetProfiles(): {
configName: string;
uiText: string;
}[] {
const allow_quantinuum = getEnableAdaptiveProfile();
if (allow_quantinuum) {
const allow_adaptive_ri = getEnableAdaptiveProfile();
if (allow_adaptive_ri) {
return targetProfiles;
} else {
return targetProfiles.filter(
(profile) => profile.configName !== "quantinuum",
(profile) => profile.configName !== "adaptive_ri",
);
}
}
Expand All @@ -123,8 +123,8 @@ function getTargetProfileSetting(uiText: string): TargetProfile {
switch (uiText) {
case "Q#: QIR base":
return "base";
case "Q#: QIR Quantinuum":
return "quantinuum";
case "Q#: QIR Adaptive RI":
return "adaptive_ri";
case "Q#: unrestricted":
return "unrestricted";
default:
Expand Down
2 changes: 1 addition & 1 deletion wasm/src/language_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ serializable_type! {
pub manifest: Option<String>,
},
r#"export interface INotebookMetadata {
targetProfile?: "base" | "quantinuum" | "unrestricted";
targetProfile?: "base" | "adaptive_ri" | "unrestricted";
languageFeatures?: "v2-preview-syntax"[];
manifest?: string;
}"#,
Expand Down
2 changes: 1 addition & 1 deletion wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,5 +478,5 @@ pub fn generate_docs() -> Vec<IDocFile> {

#[wasm_bindgen(typescript_custom_section)]
const TARGET_PROFILE: &'static str = r#"
export type TargetProfile = "base" | "quantinuum" |"unrestricted";
export type TargetProfile = "base" | "adaptive_ri" |"unrestricted";
"#;

0 comments on commit fed14e2

Please sign in to comment.