Skip to content

Commit

Permalink
Another batch of fixes for QDK 0.6 (microsoft#112)
Browse files Browse the repository at this point in the history
* Replace Primitive with Intrinsic namespace
* Replace deprecated library operations
* Update links to documentation
  • Loading branch information
tcNickolas authored May 9, 2019
1 parent ccd488a commit 3bbcac1
Show file tree
Hide file tree
Showing 33 changed files with 51 additions and 80 deletions.
4 changes: 2 additions & 2 deletions BasicGates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ You can [run the BasicGates kata as a Jupyter Notebook](https://mybinder.org/v2/

#### Q# materials

* Basic gates provided in Q# belong to the `Microsoft.Quantum.Primitive` namespace and are listed [here](https://docs.microsoft.com/qsharp/api/prelude/microsoft.quantum.primitive).
* Basic gates provided in Q# belong to the `Microsoft.Quantum.Intrinsic` namespace and are listed [here](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic).
* Using controlled and adjoint versions of gates is covered in the Q# documentation on [operation types](https://docs.microsoft.com/quantum/language/type-model#operation-and-function-types).
* Defining controlled and adjoint versions of gates is covered in the Q# documentation on [operation definitions](https://docs.microsoft.com/quantum/language/file-structure#operation-definitions).
* Defining controlled and adjoint versions of gates is covered in the Q# documentation on [operation definitions](https://docs.microsoft.com/quantum/language/file-structure#operation-declarations).
1 change: 0 additions & 1 deletion BasicGates/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Quantum.Kata.BasicGates {

open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;


//////////////////////////////////////////////////////////////////
Expand Down
12 changes: 5 additions & 7 deletions CHSHGame/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@

namespace Quantum.Kata.CHSHGame {

open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Extensions.Math;
open Microsoft.Quantum.Extensions.Convert;
open Microsoft.Quantum.Primitive;

open Microsoft.Quantum.Math;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Intrinsic;


//////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -55,7 +53,7 @@ namespace Quantum.Kata.CHSHGame {
// Measure in sign basis if bit is 1, and
// measure in computational basis if bit is 0
let basis = bit ? PauliX | PauliZ;
return BoolFromResult(Measure([basis], [qubit]));
return ResultAsBool(Measure([basis], [qubit]));
}


Expand All @@ -69,7 +67,7 @@ namespace Quantum.Kata.CHSHGame {
// Task 2.4. Bob's quantum strategy
operation BobQuantum_Reference (bit : Bool, qubit : Qubit) : Bool {
RotateBobQubit_Reference(not bit, qubit);
return BoolFromResult(M(qubit));
return ResultAsBool(M(qubit));
}


Expand Down
4 changes: 2 additions & 2 deletions CHSHGame/Tasks.qs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Quantum.Kata.CHSHGame {

open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Extensions.Math;
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Intrinsic;


//////////////////////////////////////////////////////////////////
Expand Down
11 changes: 5 additions & 6 deletions CHSHGame/Tests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ namespace Quantum.Kata.CHSHGame {

open Microsoft.Quantum.Math;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Diagnostics;


// ------------------------------------------------------
operation T11_WinCondition_Test () : Unit {
for (i in 0..1 <<< 4 - 1) {
let bits = BoolArrFromPositiveInt(i, 4);
let bits = IntAsBoolArray(i, 4);
EqualityFactB(
WinCondition(bits[0], bits[1], bits[2], bits[3]),
(bits[0] and bits[1]) == (bits[2] != bits[3]),
Expand All @@ -40,8 +41,7 @@ namespace Quantum.Kata.CHSHGame {
}
Message($"Win rate {IntAsDouble(wins) / 1000.}");

EqualityFactB(wins >= 700, true,
"Alice and Bob's classical strategy is not optimal");
Fact(wins >= 700, "Alice and Bob's classical strategy is not optimal");
}


Expand Down Expand Up @@ -94,8 +94,7 @@ namespace Quantum.Kata.CHSHGame {
op(qs[0]);
}

operation QubitToRegisterOperationA (op : (Qubit => Unit is Adj), qs : Qubit[]) : Unit
is Adj {
operation QubitToRegisterOperationA (op : (Qubit => Unit is Adj), qs : Qubit[]) : Unit is Adj {
op(qs[0]);
}

Expand Down
2 changes: 0 additions & 2 deletions DeutschJozsaAlgorithm/Tests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Quantum.Kata.DeutschJozsaAlgorithm {

open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Diagnostics;

Expand Down
3 changes: 2 additions & 1 deletion GHZGame/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Quantum.Kata.GHZGame {

open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
Expand Down Expand Up @@ -76,7 +77,7 @@ namespace Quantum.Kata.GHZGame {
if (input) {
H(qubit);
}
return BoolFromResult(M(qubit));
return ResultAsBool(M(qubit));
}


Expand Down
6 changes: 3 additions & 3 deletions GHZGame/Tasks.qs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace Quantum.Kata.GHZGame {

open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Extensions.Math;
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Extensions.Diagnostics;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Diagnostics;

//////////////////////////////////////////////////////////////////
// Welcome!
Expand Down
3 changes: 1 addition & 2 deletions GHZGame/Tests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Quantum.Kata.GHZGame {

open Microsoft.Quantum.Math;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Diagnostics;

Expand All @@ -27,7 +26,7 @@ namespace Quantum.Kata.GHZGame {
operation T11_WinCondition_Test () : Unit {
for (rst in RefereeBits()) {
for (i in 0..1 <<< 3 - 1) {
let abc = BoolArrFromPositiveInt(i, 3);
let abc = IntAsBoolArray(i, 3);
EqualityFactB(
WinCondition(rst, abc),
WinCondition_Reference(rst, abc),
Expand Down
2 changes: 0 additions & 2 deletions GroversAlgorithm/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
namespace Quantum.Kata.GroversAlgorithm {

open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;

Expand Down
9 changes: 4 additions & 5 deletions GroversAlgorithm/Tests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Quantum.Kata.GroversAlgorithm {

open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Convert;
Expand Down Expand Up @@ -53,7 +52,7 @@ namespace Quantum.Kata.GroversAlgorithm {
// ------------------------------------------------------
operation T13_Oracle_ArbitraryPattern_Test () : Unit {
for (n in 2 .. 10) {
let pattern = BoolArrFromPositiveInt(RandomIntPow2(n), n);
let pattern = IntAsBoolArray(RandomIntPow2(n), n);
let testOp = QubitArrayWrapperOperation(Oracle_ArbitraryPattern(_, _, pattern), _);
let refOp = QubitArrayWrapperOperation(Oracle_ArbitraryPattern_Reference(_, _, pattern), _);
AssertOperationsEqualReferenced(n + 1, testOp, refOp);
Expand All @@ -64,7 +63,7 @@ namespace Quantum.Kata.GroversAlgorithm {
// ------------------------------------------------------
operation T14_OracleConverter_Test () : Unit {
for (n in 2 .. 10) {
let pattern = BoolArrFromPositiveInt(RandomIntPow2(n), n);
let pattern = IntAsBoolArray(RandomIntPow2(n), n);
let markingOracle = Oracle_ArbitraryPattern_Reference(_, _, pattern);
let phaseOracleRef = OracleConverter_Reference(markingOracle);
let phaseOracleSol = OracleConverter(markingOracle);
Expand All @@ -88,7 +87,7 @@ namespace Quantum.Kata.GroversAlgorithm {
// ------------------------------------------------------
operation T23_GroverIteration_Test () : Unit {
for (n in 2 .. 10) {
let pattern = BoolArrFromPositiveInt(RandomIntPow2(n), n);
let pattern = IntAsBoolArray(RandomIntPow2(n), n);
let markingOracle = Oracle_ArbitraryPattern_Reference(_, _, pattern);
let flipOracle = OracleConverter_Reference(markingOracle);
let testOp = GroverIteration(_, flipOracle);
Expand All @@ -101,7 +100,7 @@ namespace Quantum.Kata.GroversAlgorithm {
// ------------------------------------------------------
operation T31_GroversSearch_Test () : Unit {
for (n in 2 .. 10) {
let pattern = BoolArrFromPositiveInt(RandomIntPow2(n), n);
let pattern = IntAsBoolArray(RandomIntPow2(n), n);
let markingOracle = Oracle_ArbitraryPattern_Reference(_, _, pattern);
let testOp = GroversSearch(_, markingOracle, 4);
let refOp = GroversSearch_Reference(_, markingOracle, 4);
Expand Down
2 changes: 1 addition & 1 deletion JointMeasurements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The joint measurements kata covers the usage of joint measurements, also known as parity measurements, -
measurements involving multiple qubits.

In Q# they are implemented as the [Measure](https://docs.microsoft.com/qsharp/api/prelude/microsoft.quantum.primitive.measure) operation.
In Q# they are implemented as the [Measure](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic.measure) operation.

* You can read more about measurements of multi-qubit Pauli operators in the [Q# documentation](https://docs.microsoft.com/quantum/concepts/pauli-measurements).
* A general-case implementation of CNOT gate via joint measurements is described in [this paper](https://arxiv.org/pdf/1201.5734.pdf).
3 changes: 0 additions & 3 deletions JointMeasurements/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace Quantum.Kata.JointMeasurements {

open Microsoft.Quantum.Characterization;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;


// Task 1. Single-qubit measurement
Expand Down
3 changes: 0 additions & 3 deletions JointMeasurements/Tasks.qs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
namespace Quantum.Kata.JointMeasurements {

open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;


//////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion Measurements/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Quantum.Kata.Measurements {
open Microsoft.Quantum.Arithmetic;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;


Expand Down
6 changes: 3 additions & 3 deletions PhaseEstimation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Quantum phase estimation:

* Wikipedia article on [quantum phase estimation](https://en.wikipedia.org/wiki/Quantum_phase_estimation_algorithm).
* Lectures [8](https://cs.uwaterloo.ca/~watrous/LectureNotes/CPSC519.Winter2006/08.pdf) and [9](https://cs.uwaterloo.ca/~watrous/LectureNotes/CPSC519.Winter2006/09.pdf) by John Watrous.
* [Quantum Phase Estimation](https://docs.microsoft.com/en-us/quantum/libraries/standard/algorithms) in Q# documentation.
* [Quantum Phase Estimation](https://docs.microsoft.com/quantum/libraries/standard/algorithms) in Q# documentation.

Iterative phase estimation:

* [Faster Phase Estimation](https://arxiv.org/pdf/1304.0741.pdf) paper gives an overview of several different approaches.
* [Iterative Phase Estimation](https://docs.microsoft.com/en-us/quantum/libraries/standard/characterization) in Q# documentation.
* [Iterative Phase Estimation](https://docs.microsoft.com/quantum/libraries/standard/characterization) in Q# documentation.

#### Q# materials

* [Quantum phase estimation tests](https://github.com/Microsoft/QuantumLibraries/blob/master/Canon/tests/QuantumPhaseEstimationTests.qs)
* [Quantum phase estimation tests](https://github.com/microsoft/QuantumLibraries/blob/master/Standard/tests/QuantumPhaseEstimationTests.qs)
* [Bayesian (iterative) phase estimation sample](https://github.com/Microsoft/Quantum/blob/master/Samples/src/PhaseEstimation/BayesianPhaseEstimation.qs)

1 change: 0 additions & 1 deletion PhaseEstimation/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Quantum.Kata.PhaseEstimation {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;


//////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion PhaseEstimation/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// The tasks themselves can be found in Tasks.qs file.
//////////////////////////////////////////////////////////////////////

using Microsoft.Quantum.Primitive;
using Microsoft.Quantum.Intrinsic;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
using Quantum.Kata.PhaseEstimation;
Expand Down
18 changes: 8 additions & 10 deletions PhaseEstimation/Tests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace Quantum.Kata.PhaseEstimation {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;


//////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -63,8 +61,8 @@ namespace Quantum.Kata.PhaseEstimation {
// Test state/unitary pairs which are eigenstates (so no exception should be thrown)
for ((unitary, statePrep) in [(Z, I), (Z, X),
(S, I), (S, X),
(X, H), (X, BindCA([X, H])),
(Y, BindCA([H, S])), (Y, BindCA([X, H, S]))]) {
(X, H), (X, BoundCA([X, H])),
(Y, BoundCA([H, S])), (Y, BoundCA([X, H, S]))]) {
AssertIsEigenstate(unitary, statePrep);
}
}
Expand Down Expand Up @@ -105,7 +103,7 @@ namespace Quantum.Kata.PhaseEstimation {
Test1BitPEOnOnePair(Z, I, +1);
Test1BitPEOnOnePair(Z, X, -1);
Test1BitPEOnOnePair(X, H, +1);
Test1BitPEOnOnePair(X, BindCA([X, H]), -1);
Test1BitPEOnOnePair(X, BoundCA([X, H]), -1);
}


Expand All @@ -124,13 +122,13 @@ namespace Quantum.Kata.PhaseEstimation {
Test2BitPEOnOnePair(Z, I, 0.0);
Test2BitPEOnOnePair(Z, X, 0.5);
Test2BitPEOnOnePair(S, X, 0.25);
Test2BitPEOnOnePair(BindCA([S, Z]), X, 0.75);
Test2BitPEOnOnePair(BoundCA([S, Z]), X, 0.75);

Test2BitPEOnOnePair(X, H, 0.0);
Test2BitPEOnOnePair(X, BindCA([X, H]), 0.5);
Test2BitPEOnOnePair(BindCA([H, S, H]), H, 0.0);
Test2BitPEOnOnePair(BindCA([H, S, H]), BindCA([X, H]), 0.25);
Test2BitPEOnOnePair(BindCA([H, S, Z, H]), BindCA([X, H]), 0.75);
Test2BitPEOnOnePair(X, BoundCA([X, H]), 0.5);
Test2BitPEOnOnePair(BoundCA([H, S, H]), H, 0.0);
Test2BitPEOnOnePair(BoundCA([H, S, H]), BoundCA([X, H]), 0.25);
Test2BitPEOnOnePair(BoundCA([H, S, Z, H]), BoundCA([X, H]), 0.75);
}


Expand Down
2 changes: 1 addition & 1 deletion QEC_BitFlipCode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ This kata covers the simplest of the quantum error-correction (QEC) codes - the

This code is a quantum equivalent of the classical [repetition code](https://en.wikipedia.org/wiki/Repetition_code), adjusted to take into account the impossibility of simply cloning the quantum state.

* This code is described in [the error correction article](https://docs.microsoft.com/quantum/libraries/error-correction) in the Q# documentation.
* This code is described in [the error correction article](https://docs.microsoft.com/quantum/libraries/standard/error-correction) in the Q# documentation.
* Another description can be found in [the Wikipedia article](https://en.wikipedia.org/wiki/Quantum_error_correction#The_bit_flip_code).
* An introduction to QEC can be found in ["Quantum Error Correction for Beginners"](https://arxiv.org/pdf/0905.2794.pdf), see section IV for more information on the 3-qubit code.
2 changes: 1 addition & 1 deletion QEC_BitFlipCode/Tests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ namespace Quantum.Kata.QEC_BitFlipCode {

for (idxError in 0 .. Length(errors) - 1) {
let θ = RandomReal(12);
let statePrep = BindCA([H, Rz(θ, _)]);
let statePrep = BoundCA([H, Rz(θ, _)]);
mutable errorStr = "no error";
if (idxError > 0) {
set errorStr = $"error on qubit {idxError}";
Expand Down
2 changes: 0 additions & 2 deletions SimonsAlgorithm/Tests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Quantum.Kata.SimonsAlgorithm {

open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Diagnostics;


Expand Down
2 changes: 0 additions & 2 deletions SolveSATWithGrover/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace Quantum.Kata.GroversAlgorithm {
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;


//////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion SolveSATWithGrover/Tests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Quantum.Kata.GroversAlgorithm {
using ((qs, target) = (Qubit[N], Qubit())) {
for (k in 0 .. size - 1) {
// Prepare k-th bit vector
let binary = BoolArrFromPositiveInt(k, N);
let binary = IntAsBoolArray(k, N);

//Message($"{k}/{N} = {binary}");
// binary is little-endian notation, so the second vector tried has qubit 0 in state 1 and the rest in state 0
Expand Down
1 change: 0 additions & 1 deletion SuperdenseCoding/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Quantum.Kata.SuperdenseCoding {

open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;


// Task 1. Entangled pair
Expand Down
1 change: 0 additions & 1 deletion SuperdenseCoding/Tests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Quantum.Kata.SuperdenseCoding {

open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Diagnostics;


Expand Down
3 changes: 2 additions & 1 deletion Superposition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ The superposition kata covers the following topics:

You can [run the Superposition kata as a Jupyter Notebook](https://mybinder.org/v2/gh/Microsoft/QuantumKatas/master?filepath=Superposition%2FSuperposition.ipynb)!

It is recommended to complete the [BasicGates kata](./../BasicGates/) before this one to get familiar with the basic gates used in quantum computing. The list of basic gates available in Q# can be found at [Microsoft.Quantum.Primitive](https://docs.microsoft.com/qsharp/api/prelude/microsoft.quantum.primitive).
It is recommended to complete the [BasicGates kata](./../BasicGates/) before this one to get familiar with the basic gates used in quantum computing.
The list of basic gates available in Q# can be found at [Microsoft.Quantum.Intrinsic](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic).

You can find detailed coverage of Bell states and their creation [here](https://blogs.msdn.microsoft.com/uk_faculty_connection/2018/02/06/a-beginners-guide-to-quantum-computing-and-q/).

Expand Down
Loading

0 comments on commit 3bbcac1

Please sign in to comment.