Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into swernli/unimplemented…
Browse files Browse the repository at this point in the history
…-attr
  • Loading branch information
swernli committed Nov 7, 2023
2 parents e34ae3a + e3b1c76 commit c46e5a8
Show file tree
Hide file tree
Showing 57 changed files with 2,978 additions and 687 deletions.
19 changes: 17 additions & 2 deletions .ado/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ jobs:
python build.py --wasm --npm --vscode
displayName: Build VSCode Extension
# TODO: When the VSCode Extension is ready for publishing, remove the `--pre-release` flag for 'stable' BUILD_TYPE
- script: |
vsce package --pre-release
condition: and(succeeded(), eq(variables['BUILD_TYPE'], 'dev'))
displayName: Pack pre-release VSCode Extension
workingDirectory: '$(System.DefaultWorkingDirectory)/vscode'
- script: |
vsce package
condition: and(succeeded(), ne(variables['BUILD_TYPE'], 'dev'))
displayName: Pack VSCode Extension
workingDirectory: '$(System.DefaultWorkingDirectory)/vscode'
Expand Down Expand Up @@ -294,11 +300,20 @@ jobs:
npm install -g @vscode/vsce
displayName: Install Prereqs for VSCode Ext Publishing
# TODO: When the VSCode Extension is ready for publishing, remove the `--pre-release` flag for 'stable' BUILD_TYPE
- script: |
VSIX_RPATH=../VSIX
VSIX_FNAME=`ls $VSIX_RPATH`
vsce publish --pre-release --packagePath $VSIX_RPATH/$VSIX_FNAME 2>&1 > pub.log
condition: and(succeeded(), eq(variables['BUILD_TYPE'], 'dev'))
displayName: Publish pre-release VSCode Extension
env:
VSCE_PAT: $(PAT)
- script: |
VSIX_RPATH=../VSIX
VSIX_FNAME=`ls $VSIX_RPATH`
vsce publish --packagePath $VSIX_RPATH/$VSIX_FNAME 2>&1 > pub.log
condition: and(succeeded(), ne(variables['BUILD_TYPE'], 'dev'))
displayName: Publish VSCode Extension
env:
VSCE_PAT: $(PAT)
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: CI Build and Test

on:
push:
branches: [main]
pull_request:
branches: [main]
merge_group:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/devskim.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: DevSkim

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
merge_group:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions compiler/qsc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ indoc = { workspace = true }

[lib]
bench = false
doctest = false

[[bin]]
name = "qsc"
Expand Down
3 changes: 3 additions & 0 deletions compiler/qsc_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ indenter = { workspace = true }
miette = { workspace = true }
num-bigint = { workspace = true }
qsc_data_structures = { path = "../qsc_data_structures" }

[lib]
doctest = false
3 changes: 3 additions & 0 deletions compiler/qsc_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ qsc_hir = { path = "../qsc_hir" }
expect-test = { workspace = true }
indoc = { workspace = true }
qsc_passes = { path = "../qsc_passes" }

[lib]
doctest = false
3 changes: 3 additions & 0 deletions compiler/qsc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ repository.workspace = true

[dependencies]
miette = { workspace = true }

[lib]
doctest = false
3 changes: 3 additions & 0 deletions compiler/qsc_eval/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ expect-test = { workspace = true }
indoc = { workspace = true }
qsc_frontend = { path = "../qsc_frontend" }
qsc_passes = { path = "../qsc_passes" }

[lib]
doctest = false
32 changes: 25 additions & 7 deletions compiler/qsc_eval/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,21 @@ pub(crate) fn call(
"__quantum__qis__cx__body" => two_qubit_gate(|ctl, q| sim.cx(ctl, q), arg, arg_span),
"__quantum__qis__cy__body" => two_qubit_gate(|ctl, q| sim.cy(ctl, q), arg, arg_span),
"__quantum__qis__cz__body" => two_qubit_gate(|ctl, q| sim.cz(ctl, q), arg, arg_span),
"__quantum__qis__rx__body" => Ok(one_qubit_rotation(|theta, q| sim.rx(theta, q), arg)),
"__quantum__qis__rx__body" => {
one_qubit_rotation(|theta, q| sim.rx(theta, q), arg, arg_span)
}
"__quantum__qis__rxx__body" => {
two_qubit_rotation(|theta, q0, q1| sim.rxx(theta, q0, q1), arg, arg_span)
}
"__quantum__qis__ry__body" => Ok(one_qubit_rotation(|theta, q| sim.ry(theta, q), arg)),
"__quantum__qis__ry__body" => {
one_qubit_rotation(|theta, q| sim.ry(theta, q), arg, arg_span)
}
"__quantum__qis__ryy__body" => {
two_qubit_rotation(|theta, q0, q1| sim.ryy(theta, q0, q1), arg, arg_span)
}
"__quantum__qis__rz__body" => Ok(one_qubit_rotation(|theta, q| sim.rz(theta, q), arg)),
"__quantum__qis__rz__body" => {
one_qubit_rotation(|theta, q| sim.rz(theta, q), arg, arg_span)
}
"__quantum__qis__rzz__body" => {
two_qubit_rotation(|theta, q0, q1| sim.rzz(theta, q0, q1), arg, arg_span)
}
Expand Down Expand Up @@ -155,10 +161,19 @@ fn two_qubit_gate(
}
}

fn one_qubit_rotation(mut gate: impl FnMut(f64, usize), arg: Value) -> Value {
fn one_qubit_rotation(
mut gate: impl FnMut(f64, usize),
arg: Value,
arg_span: PackageSpan,
) -> Result<Value, Error> {
let [x, y] = unwrap_tuple(arg);
gate(x.unwrap_double(), y.unwrap_qubit().0);
Value::unit()
let angle = x.unwrap_double();
if angle.is_nan() || angle.is_infinite() {
Err(Error::InvalidRotationAngle(angle, arg_span))
} else {
gate(angle, y.unwrap_qubit().0);
Ok(Value::unit())
}
}

fn three_qubit_gate(
Expand All @@ -181,10 +196,13 @@ fn two_qubit_rotation(
arg_span: PackageSpan,
) -> Result<Value, Error> {
let [x, y, z] = unwrap_tuple(arg);
let angle = x.unwrap_double();
if y == z {
Err(Error::QubitUniqueness(arg_span))
} else if angle.is_nan() || angle.is_infinite() {
Err(Error::InvalidRotationAngle(angle, arg_span))
} else {
gate(x.unwrap_double(), y.unwrap_qubit().0, z.unwrap_qubit().0);
gate(angle, y.unwrap_qubit().0, z.unwrap_qubit().0);
Ok(Value::unit())
}
}
Expand Down
72 changes: 72 additions & 0 deletions compiler/qsc_eval/src/intrinsic/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,3 +1173,75 @@ fn qubit_not_unique_three_qubit_error_second_third() {
&expect!["qubits in gate invocation are not unique"],
);
}

#[test]
fn single_qubit_rotation_nan_error() {
check_intrinsic_output(
"",
indoc! {"{
use q = Qubit();
Rx(Microsoft.Quantum.Math.ArcSin(2.0), q);
}"},
&expect!["invalid rotation angle: NaN"],
);
}

#[test]
fn two_qubit_rotation_nan_error() {
check_intrinsic_output(
"",
indoc! {"{
use (q1, q2) = (Qubit(), Qubit());
Rxx(Microsoft.Quantum.Math.ArcSin(2.0), q1, q2);
}"},
&expect!["invalid rotation angle: NaN"],
);
}

#[test]
fn single_qubit_rotation_inf_error() {
check_intrinsic_output(
"",
indoc! {"{
use q = Qubit();
Rx(-Microsoft.Quantum.Math.Log(0.0), q);
}"},
&expect!["invalid rotation angle: inf"],
);
}

#[test]
fn two_qubit_rotation_inf_error() {
check_intrinsic_output(
"",
indoc! {"{
use (q1, q2) = (Qubit(), Qubit());
Rxx(-Microsoft.Quantum.Math.Log(0.0), q1, q2);
}"},
&expect!["invalid rotation angle: inf"],
);
}

#[test]
fn single_qubit_rotation_neg_inf_error() {
check_intrinsic_output(
"",
indoc! {"{
use q = Qubit();
Rx(Microsoft.Quantum.Math.Log(0.0), q);
}"},
&expect!["invalid rotation angle: -inf"],
);
}

#[test]
fn two_qubit_rotation_neg_inf_error() {
check_intrinsic_output(
"",
indoc! {"{
use (q1, q2) = (Qubit(), Qubit());
Rxx(Microsoft.Quantum.Math.Log(0.0), q1, q2);
}"},
&expect!["invalid rotation angle: -inf"],
);
}
Loading

0 comments on commit c46e5a8

Please sign in to comment.