Skip to content

Commit

Permalink
Add Microsoft.Quantum.Measurement to compiler prelude (#1233)
Browse files Browse the repository at this point in the history
Closes #1193 

As suggested by @swernli, this PR adds `Microsoft.Quantum.Measurement`
to the prelude to avoid constant importing.
  • Loading branch information
eureka-cpu authored Mar 13, 2024
1 parent ce8e749 commit 5458bd0
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 62 deletions.
38 changes: 12 additions & 26 deletions compiler/qsc_codegen/src/qir_base/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ fn qubit_allocation_allows_reuse_of_unmeasured_qubits() {
check(
"",
Some(indoc! {"{
open Microsoft.Quantum.Measurement;
{ use (c, q) = (Qubit(), Qubit()); CNOT(c, q); MResetZ(q); }
{ use (c, q) = (Qubit(), Qubit()); CNOT(c, q); MResetZ(q) }
}"}),
Expand Down Expand Up @@ -604,7 +603,6 @@ fn complex_program_is_valid() {
check(
"",
Some(indoc! {"{
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Math;
operation SWAPfromExp(q1 : Qubit, q2 : Qubit) : Unit is Ctl + Adj {
Expand Down Expand Up @@ -911,7 +909,6 @@ fn qubit_ids_properly_reused() {
namespace Test {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Measurement;
// Verifies the use of the CNOT quantum gate from Q#'s Microsoft.Quantum.Intrinsic namespace.
// Expected simulation output: ([0, 0], [1, 1]).
Expand Down Expand Up @@ -1011,7 +1008,6 @@ fn custom_intrinsic_on_single_qubit() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : (Result, Result) {
use (q1, q2) = (Qubit(), Qubit());
Expand Down Expand Up @@ -1086,7 +1082,6 @@ fn multiple_custom_intrinsic_calls() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : (Result, Result) {
use (q0, q1) = (Qubit(), Qubit());
Expand Down Expand Up @@ -1173,7 +1168,6 @@ fn custom_intrinsic_on_qubit_and_double() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : Result {
use q = Qubit();
Expand Down Expand Up @@ -1244,7 +1238,6 @@ fn custom_intrinsic_on_qubit_and_bool() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : Result {
use q = Qubit();
Expand Down Expand Up @@ -1315,7 +1308,6 @@ fn custom_intrinsic_on_qubit_and_int() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : Result {
use q = Qubit();
Expand Down Expand Up @@ -1386,7 +1378,6 @@ fn custom_intrinsic_fail_on_result_arg() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : Result {
use q = Qubit();
Expand All @@ -1410,8 +1401,8 @@ fn custom_intrinsic_fail_on_result_arg() {
2,
),
span: Span {
lo: 217,
hi: 301,
lo: 177,
hi: 261,
},
},
)
Expand All @@ -1424,7 +1415,6 @@ fn custom_intrinsic_fail_on_bigint_arg() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : Result {
use q = Qubit();
Expand All @@ -1448,8 +1438,8 @@ fn custom_intrinsic_fail_on_bigint_arg() {
2,
),
span: Span {
lo: 219,
hi: 303,
lo: 179,
hi: 263,
},
},
)
Expand All @@ -1462,7 +1452,6 @@ fn custom_intrinsic_fail_on_string_arg() {
check(
indoc! {r#"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : Result {
use q = Qubit();
Expand All @@ -1486,8 +1475,8 @@ fn custom_intrinsic_fail_on_string_arg() {
2,
),
span: Span {
lo: 230,
hi: 314,
lo: 190,
hi: 274,
},
},
)
Expand All @@ -1500,7 +1489,6 @@ fn custom_intrinsic_fail_on_array_arg() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : Result {
use q = Qubit();
Expand All @@ -1524,8 +1512,8 @@ fn custom_intrinsic_fail_on_array_arg() {
2,
),
span: Span {
lo: 225,
hi: 308,
lo: 185,
hi: 268,
},
},
)
Expand All @@ -1538,7 +1526,6 @@ fn custom_intrinsic_fail_on_tuple_arg() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : Result {
use q = Qubit();
Expand All @@ -1562,8 +1549,8 @@ fn custom_intrinsic_fail_on_tuple_arg() {
2,
),
span: Span {
lo: 225,
hi: 318,
lo: 185,
hi: 278,
},
},
)
Expand All @@ -1576,7 +1563,6 @@ fn custom_intrinsic_fail_on_non_unit_return() {
check(
indoc! {"
namespace Test {
open Microsoft.Quantum.Measurement;
@EntryPoint()
operation Test() : Result {
use q = Qubit();
Expand All @@ -1598,8 +1584,8 @@ fn custom_intrinsic_fail_on_non_unit_return() {
2,
),
span: Span {
lo: 195,
hi: 265,
lo: 155,
hi: 225,
},
},
)
Expand Down
5 changes: 0 additions & 5 deletions compiler/qsc_eval/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3410,8 +3410,6 @@ fn lambda_operation_empty_closure() {
check_expr(
"
namespace A {
open Microsoft.Quantum.Measurement;
operation Foo(op : Qubit => ()) : Result {
use q = Qubit();
op(q);
Expand All @@ -3431,7 +3429,6 @@ fn lambda_operation_closure() {
check_expr(
"
namespace A {
open Microsoft.Quantum.Measurement;
operation Foo(op : () => Result) : Result { op() }
operation Bar() : Result {
use q = Qubit();
Expand All @@ -3450,7 +3447,6 @@ fn lambda_operation_controlled() {
check_expr(
"
namespace A {
open Microsoft.Quantum.Measurement;
operation Foo(op : Qubit => Unit is Adj + Ctl, q : Qubit) : Unit is Adj + Ctl { op(q) }
operation Bar() : Result[] {
mutable output = [];
Expand Down Expand Up @@ -3478,7 +3474,6 @@ fn lambda_operation_controlled_controlled() {
check_expr(
"
namespace A {
open Microsoft.Quantum.Measurement;
operation Foo(op : Qubit => Unit is Adj + Ctl, q : Qubit) : Unit is Adj + Ctl { op(q) }
operation Bar() : Result[] {
mutable output = [];
Expand Down
1 change: 1 addition & 0 deletions compiler/qsc_frontend/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const PRELUDE: &[&str] = &[
"Microsoft.Quantum.Canon",
"Microsoft.Quantum.Core",
"Microsoft.Quantum.Intrinsic",
"Microsoft.Quantum.Measurement",
];

// All AST Path nodes get mapped
Expand Down
13 changes: 0 additions & 13 deletions library/src/tests/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fn check_maj() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use q = Qubit[3];
mutable r = [];
Expand Down Expand Up @@ -107,7 +106,6 @@ fn check_inc_by_le_general() {
test_expression(
{
"{ // General cases for IncByLE
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use x1 = Qubit[10];
use y1 = Qubit[10];
Expand Down Expand Up @@ -173,7 +171,6 @@ fn check_ripple_carry_ttk_inc_by_le_general() {
test_expression(
{
"{ // General cases for RippleCarryTTKIncByLE
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use x1 = Qubit[10];
Expand Down Expand Up @@ -279,7 +276,6 @@ fn check_ripple_carry_cg_inc_by_le_general() {
test_expression(
{
"{ // General cases for RippleCarryCGIncByLE
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use x1 = Qubit[10];
Expand Down Expand Up @@ -436,7 +432,6 @@ fn check_inc_by_le_using_add_le_general() {
test_expression(
{
"{ // General cases for IncByLEUsingAddLE
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use x1 = Qubit[10];
Expand All @@ -463,7 +458,6 @@ fn check_inc_by_i_general() {
test_expression(
{
"{ // General cases for IncByI
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use y0 = Qubit[1];
Expand Down Expand Up @@ -519,7 +513,6 @@ fn check_ripple_carry_cg_inc_by_i_general() {
test_expression(
{
"{ // General cases for IncByIUsingIncByLE
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use y0 = Qubit[10];
Expand Down Expand Up @@ -556,7 +549,6 @@ fn check_inc_by_l_general() {
test_expression(
{
"{ // General cases for IncByL
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use y0 = Qubit[1];
Expand Down Expand Up @@ -612,7 +604,6 @@ fn check_ripple_carry_cg_inc_by_l_general() {
test_expression(
{
"{ // Branching cases for IncByLUsingIncByLE
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use y0 = Qubit[10];
Expand Down Expand Up @@ -691,7 +682,6 @@ fn check_add_le_general() {
test_expression(
{
"{ // General cases for AddLE
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use x1 = Qubit[10];
Expand Down Expand Up @@ -761,7 +751,6 @@ fn check_ripple_carry_cg_add_le_general() {
test_expression(
{
"{ // General cases for RippleCarryAddLE
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use x1 = Qubit[10];
Expand Down Expand Up @@ -829,7 +818,6 @@ fn check_lookahead_dkrs_add_le_general() {
test_expression(
{
"{ // General cases for LookAheadDKRSAddLE
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Unstable.Arithmetic;
use x1 = Qubit[10];
Expand Down Expand Up @@ -965,7 +953,6 @@ fn check_apply_if_less_l_non_x_action() {
test_expression(
"{
open Microsoft.Quantum.Unstable.Arithmetic;
open Microsoft.Quantum.Measurement;
use input = Qubit[10];
use output1 = Qubit[10];
use output2 = Qubit[10];
Expand Down
8 changes: 0 additions & 8 deletions library/src/tests/canon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ fn check_apply_p() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
use q = Qubit[3];
ApplyP(PauliX, q[0]);
H(q[1]); ApplyP(PauliY, q[1]);
Expand All @@ -194,7 +193,6 @@ fn check_apply_pauli() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
use q = Qubit[3];
H(q[1]);
H(q[2]); S(q[2]);
Expand All @@ -211,7 +209,6 @@ fn check_apply_pauli_from_bit_string() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
use q = Qubit[3];
ApplyPauliFromBitString(PauliX, false, [true, false, true], q);
return MResetEachZ(q);
Expand All @@ -226,7 +223,6 @@ fn check_apply_pauli_from_int() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
use q = Qubit[3];
ApplyPauliFromInt(PauliX, false, 5, q);
return MResetEachZ(q);
Expand All @@ -241,7 +237,6 @@ fn check_apply_controlled_on_int() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
use c = Qubit[3];
use t1 = Qubit();
use t2 = Qubit();
Expand All @@ -264,7 +259,6 @@ fn check_apply_controlled_on_bitstring() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
use c = Qubit[4];
use t1 = Qubit();
use t2 = Qubit();
Expand Down Expand Up @@ -323,7 +317,6 @@ fn check_swap_reverse_register() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
use q = Qubit[10];
ApplyXorInPlace(328, q);
SwapReverseRegister(q);
Expand Down Expand Up @@ -361,7 +354,6 @@ fn check_apply_xor_in_place_l() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
use q = Qubit[100];
ApplyXorInPlaceL(953L <<< 50, q);
let result = MeasureInteger(q[50...]);
Expand Down
1 change: 0 additions & 1 deletion library/src/tests/measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ fn check_measure_integer() {
test_expression(
{
"{
open Microsoft.Quantum.Measurement;
use q = Qubit[16];
ApplyXorInPlace(45967, q);
let result = MeasureInteger(q);
Expand Down
Loading

0 comments on commit 5458bd0

Please sign in to comment.