Add new task to the Measurements kata: set qubit to |0⟩ state (#32)
This commit is contained in:
Родитель
5b2ad4420c
Коммит
cf7fdf09e6
|
@ -32,7 +32,20 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.2. |+⟩ or |-⟩ ?
|
||||
// Task 1.2. Set qubit to |0⟩ state
|
||||
operation InitializeQubit_Reference (q : Qubit) : ()
|
||||
{
|
||||
body
|
||||
{
|
||||
if (M(q) == One) {
|
||||
X(q);
|
||||
}
|
||||
// Note: this can be accomplished using Reset library operation.
|
||||
// Reset(q);
|
||||
}
|
||||
}
|
||||
|
||||
// Task 1.3. |+⟩ or |-⟩ ?
|
||||
// Input: a qubit which is guaranteed to be in |+⟩ or |-⟩ state
|
||||
// (|+⟩ = (|0⟩ + |1⟩) / sqrt(2), |-⟩ = (|0⟩ - |1⟩) / sqrt(2)).
|
||||
// Output: true if qubit was in |+⟩ state, or false if it was in |-⟩ state.
|
||||
|
@ -47,7 +60,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.3. |A⟩ or |B⟩ ?
|
||||
// Task 1.4. |A⟩ or |B⟩ ?
|
||||
// Inputs:
|
||||
// 1) angle alpha, in radians, represented as Double
|
||||
// 2) a qubit which is guaranteed to be in |A⟩ or |B⟩ state
|
||||
|
@ -67,7 +80,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.4. |00⟩ or |11⟩ ?
|
||||
// Task 1.5. |00⟩ or |11⟩ ?
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be in |00⟩ or |11⟩ state.
|
||||
// Output: 0 if qubits were in |00⟩ state,
|
||||
// 1 if they were in |11⟩ state.
|
||||
|
@ -86,7 +99,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.5. Distinguish four basis states
|
||||
// Task 1.6. Distinguish four basis states
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be
|
||||
// in one of the four basis states (|00⟩, |01⟩, |10⟩ or |11⟩).
|
||||
// Output: 0 if qubits were in |00⟩ state,
|
||||
|
@ -111,7 +124,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.6. Distinguish two basis states given by bit strings
|
||||
// Task 1.7. Distinguish two basis states given by bit strings
|
||||
// Inputs:
|
||||
// 1) N qubits (stored in an array) which are guaranteed to be
|
||||
// in one of the two basis states described by the given bit strings.
|
||||
|
@ -152,7 +165,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.7. |0...0⟩ state or W state ?
|
||||
// Task 1.8. |0...0⟩ state or W state ?
|
||||
// Input: N qubits (stored in an array) which are guaranteed to be
|
||||
// either in |0...0⟩ state
|
||||
// or in W state (https://en.wikipedia.org/wiki/W_state).
|
||||
|
@ -181,8 +194,8 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.8. GHZ state or W state ?
|
||||
// Input: N qubits (stored in an array) which are guaranteed to be
|
||||
// Task 1.9. GHZ state or W state ?
|
||||
// Input: N >= 2 qubits (stored in an array) which are guaranteed to be
|
||||
// either in GHZ state (https://en.wikipedia.org/wiki/Greenberger%E2%80%93Horne%E2%80%93Zeilinger_state)
|
||||
// or in W state (https://en.wikipedia.org/wiki/W_state).
|
||||
// Output: 0 if qubits were in GHZ state,
|
||||
|
@ -212,7 +225,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.9. Distinguish four Bell states
|
||||
// Task 1.10. Distinguish four Bell states
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be in one of the four Bell states:
|
||||
// |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2)
|
||||
// |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2)
|
||||
|
@ -243,7 +256,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.10*. Distinguish four orthogonal 2-qubit states
|
||||
// Task 1.11*. Distinguish four orthogonal 2-qubit states
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be in one of the four orthogonal states:
|
||||
// |S0⟩ = (|00⟩ + |01⟩ + |10⟩ + |11⟩) / 2
|
||||
// |S1⟩ = (|00⟩ - |01⟩ + |10⟩ - |11⟩) / 2
|
||||
|
@ -267,7 +280,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.11**. Distinguish four orthogonal 2-qubit states, part two
|
||||
// Task 1.12**. Distinguish four orthogonal 2-qubit states, part two
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be in one of the four orthogonal states:
|
||||
// |S0⟩ = ( |00⟩ - |01⟩ - |10⟩ - |11⟩) / 2
|
||||
// |S1⟩ = (-|00⟩ + |01⟩ - |10⟩ - |11⟩) / 2
|
||||
|
@ -353,7 +366,7 @@ namespace Quantum.Kata.Measurements
|
|||
// - can never give 0 or 1 answer incorrectly (i.e., identify |0⟩ as 1 or |+⟩ as 0).
|
||||
// - must give inconclusive (-1) answer at most 80% of the times.
|
||||
// - must correctly identify |0⟩ state as 0 at least 10% of the times.
|
||||
// - must correctly identify |1⟩ state as 1 at least 10% of the times.
|
||||
// - must correctly identify |+⟩ state as 1 at least 10% of the times.
|
||||
//
|
||||
// The state of the qubit at the end of the operation does not matter.
|
||||
// You are allowed to use ancilla qubit(s).
|
||||
|
|
|
@ -42,7 +42,18 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.2. |+⟩ or |-⟩ ?
|
||||
// Task 1.2. Set qubit to |0⟩ state
|
||||
// Input: a qubit in an arbitrary state.
|
||||
// Goal: change the state of the qubit to |0⟩.
|
||||
operation InitializeQubit (q : Qubit) : ()
|
||||
{
|
||||
body
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
// Task 1.3. |+⟩ or |-⟩ ?
|
||||
// Input: a qubit which is guaranteed to be in |+⟩ or |-⟩ state
|
||||
// (|+⟩ = (|0⟩ + |1⟩) / sqrt(2), |-⟩ = (|0⟩ - |1⟩) / sqrt(2)).
|
||||
// Output: true if qubit was in |+⟩ state, or false if it was in |-⟩ state.
|
||||
|
@ -56,7 +67,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.3. |A⟩ or |B⟩ ?
|
||||
// Task 1.4. |A⟩ or |B⟩ ?
|
||||
// Inputs:
|
||||
// 1) angle alpha, in radians, represented as Double
|
||||
// 2) a qubit which is guaranteed to be in |A⟩ or |B⟩ state
|
||||
|
@ -73,7 +84,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.4. |00⟩ or |11⟩ ?
|
||||
// Task 1.5. |00⟩ or |11⟩ ?
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be in |00⟩ or |11⟩ state.
|
||||
// Output: 0 if qubits were in |00⟩ state,
|
||||
// 1 if they were in |11⟩ state.
|
||||
|
@ -87,7 +98,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.5. Distinguish four basis states
|
||||
// Task 1.6. Distinguish four basis states
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be
|
||||
// in one of the four basis states (|00⟩, |01⟩, |10⟩ or |11⟩).
|
||||
// Output: 0 if qubits were in |00⟩ state,
|
||||
|
@ -107,7 +118,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.6. Distinguish two basis states given by bit strings
|
||||
// Task 1.7. Distinguish two basis states given by bit strings
|
||||
// Inputs:
|
||||
// 1) N qubits (stored in an array) which are guaranteed to be
|
||||
// in one of the two basis states described by the given bit strings.
|
||||
|
@ -130,7 +141,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.7. |0...0⟩ state or W state ?
|
||||
// Task 1.8. |0...0⟩ state or W state ?
|
||||
// Input: N qubits (stored in an array) which are guaranteed to be
|
||||
// either in |0...0⟩ state
|
||||
// or in W state (https://en.wikipedia.org/wiki/W_state).
|
||||
|
@ -146,7 +157,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.8. GHZ state or W state ?
|
||||
// Task 1.9. GHZ state or W state ?
|
||||
// Input: N >= 2 qubits (stored in an array) which are guaranteed to be
|
||||
// either in GHZ state (https://en.wikipedia.org/wiki/Greenberger%E2%80%93Horne%E2%80%93Zeilinger_state)
|
||||
// or in W state (https://en.wikipedia.org/wiki/W_state).
|
||||
|
@ -162,7 +173,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.9. Distinguish four Bell states
|
||||
// Task 1.10. Distinguish four Bell states
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be in one of the four Bell states:
|
||||
// |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2)
|
||||
// |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2)
|
||||
|
@ -184,7 +195,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.10*. Distinguish four orthogonal 2-qubit states
|
||||
// Task 1.11*. Distinguish four orthogonal 2-qubit states
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be in one of the four orthogonal states:
|
||||
// |S0⟩ = (|00⟩ + |01⟩ + |10⟩ + |11⟩) / 2
|
||||
// |S1⟩ = (|00⟩ - |01⟩ + |10⟩ - |11⟩) / 2
|
||||
|
@ -204,7 +215,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// Task 1.11**. Distinguish four orthogonal 2-qubit states, part two
|
||||
// Task 1.12**. Distinguish four orthogonal 2-qubit states, part two
|
||||
// Input: two qubits (stored in an array) which are guaranteed to be in one of the four orthogonal states:
|
||||
// |S0⟩ = ( |00⟩ - |01⟩ - |10⟩ - |11⟩) / 2
|
||||
// |S1⟩ = (-|00⟩ + |01⟩ - |10⟩ - |11⟩) / 2
|
||||
|
|
|
@ -74,6 +74,27 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation T102_InitializeQubit_Test () : ()
|
||||
{
|
||||
body
|
||||
{
|
||||
using (qs = Qubit[1])
|
||||
{
|
||||
for (i in 0..36) {
|
||||
let alpha = 2.0 * PI() * ToDouble(i) / 36.0;
|
||||
Ry(2.0 * alpha, qs[0]);
|
||||
|
||||
// Test Task 1
|
||||
InitializeQubit(qs[0]);
|
||||
|
||||
// Confirm that the state is |0⟩.
|
||||
AssertAllZero(qs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------
|
||||
operation StatePrep_IsQubitPlus (q : Qubit, state : Int) : () {
|
||||
body {
|
||||
|
@ -88,7 +109,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
operation T102_IsQubitPlus_Test () : ()
|
||||
operation T103_IsQubitPlus_Test () : ()
|
||||
{
|
||||
body
|
||||
{
|
||||
|
@ -112,7 +133,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
operation T103_IsQubitA_Test () : ()
|
||||
operation T104_IsQubitA_Test () : ()
|
||||
{
|
||||
body
|
||||
{
|
||||
|
@ -180,7 +201,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
operation T104_ZeroZeroOrOneOne_Test () : () {
|
||||
operation T105_ZeroZeroOrOneOne_Test () : () {
|
||||
body {
|
||||
DistinguishStates_MultiQubit(2, 2, StatePrep_ZeroZeroOrOneOne, ZeroZeroOrOneOne);
|
||||
}
|
||||
|
@ -200,7 +221,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
operation T105_BasisStateMeasurement_Test () : () {
|
||||
operation T106_BasisStateMeasurement_Test () : () {
|
||||
body {
|
||||
DistinguishStates_MultiQubit(2, 4, StatePrep_BasisStateMeasurement, BasisStateMeasurement);
|
||||
}
|
||||
|
@ -227,7 +248,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
operation T106_TwoBitstringsMeasurement_Test () : () {
|
||||
operation T107_TwoBitstringsMeasurement_Test () : () {
|
||||
body {
|
||||
for (i in 1..1) {
|
||||
let b1 = [false; true];
|
||||
|
@ -287,7 +308,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
operation T107_AllZerosOrWState_Test () : () {
|
||||
operation T108_AllZerosOrWState_Test () : () {
|
||||
body {
|
||||
for (i in 2..6) {
|
||||
DistinguishStates_MultiQubit(i, 2, StatePrep_AllZerosOrWState, AllZerosOrWState);
|
||||
|
@ -320,7 +341,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
operation T108_GHZOrWState_Test () : () {
|
||||
operation T109_GHZOrWState_Test () : () {
|
||||
body {
|
||||
for (i in 2..6) {
|
||||
DistinguishStates_MultiQubit(i, 2, StatePrep_GHZOrWState, GHZOrWState);
|
||||
|
@ -348,7 +369,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
operation T109_BellState_Test () : () {
|
||||
operation T110_BellState_Test () : () {
|
||||
body {
|
||||
DistinguishStates_MultiQubit(2, 4, StatePrep_BellState, BellState);
|
||||
}
|
||||
|
@ -389,13 +410,13 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
|
||||
operation T110_TwoQubitState_Test () : () {
|
||||
operation T111_TwoQubitState_Test () : () {
|
||||
body {
|
||||
DistinguishStates_MultiQubit(2, 4, StatePrep_TwoQubitState, TwoQubitState);
|
||||
}
|
||||
}
|
||||
|
||||
operation T111_TwoQubitStatePartTwo_Test () : () {
|
||||
operation T112_TwoQubitStatePartTwo_Test () : () {
|
||||
body {
|
||||
DistinguishStates_MultiQubit(2, 4, StatePrep_TwoQubitStatePartTwo, TwoQubitStatePartTwo);
|
||||
}
|
||||
|
@ -413,7 +434,7 @@ namespace Quantum.Kata.Measurements
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// "Framework" operation for testing multi-qubit tasks for distinguishing states of an array of qubits
|
||||
// with Int return. Framework tests against a threshold parameter for the fraction of runs that must succeed.
|
||||
|
|
Загрузка…
Ссылка в новой задаче