Several small improvements in presentation (#53)
* Add detailed hint to the first task in Measurements * Add explanations to several solutions in JointMeasurements and marked task complexity
This commit is contained in:
Родитель
e1b283e82d
Коммит
2341a1f62d
|
@ -31,25 +31,32 @@ namespace Quantum.Kata.JointMeasurements {
|
|||
|
||||
// Task 3. |0000⟩ + |1111⟩ or |0011⟩ + |1100⟩ ?
|
||||
operation GHZOrGHZWithX_Reference (qs : Qubit[]) : Int {
|
||||
// Considering only the two middle qubits of the array, their parity for the first state is 0,
|
||||
// so the first state belongs to the +1 eigenspace of operator Z ⊗ Z on these qubits;
|
||||
// their parity for the second state is 1, so the second state belongs to the -1 eigenspace.
|
||||
return Measure([PauliZ, PauliZ], qs[1 .. 2]) == Zero ? 0 | 1;
|
||||
}
|
||||
|
||||
|
||||
// Task 4. |0..0⟩ + |1..1⟩ or W state ?
|
||||
operation GHZOrWState_Reference (qs : Qubit[]) : Int {
|
||||
// Since the number of qubits in qs is even, the parity of both |0..0⟩ and |1..1⟩ basis states is 0,
|
||||
// so both of them belong to the +1 eigenspace of operator Z ⊗ Z ⊗ ... ⊗ Z.
|
||||
// All basis vectors in W state have parity 1 and belong to the -1 eigenspace of this operator.
|
||||
return MeasureAllZ(qs) == Zero ? 0 | 1;
|
||||
}
|
||||
|
||||
|
||||
// Task 5. Parity measurement in different basis
|
||||
// Task 5*. Parity measurement in different basis
|
||||
operation DifferentBasis_Reference (qs : Qubit[]) : Int {
|
||||
// The first state is a superposition of |++⟩ and |--⟩,
|
||||
// the second one - of |+-⟩ and |-+⟩
|
||||
// The first state is a superposition of the states |++⟩ and |--⟩,
|
||||
// which belong to the +1 eigenspace of the operator X ⊗ X;
|
||||
// the second one is a superposition of |+-⟩ and |-+⟩, which belong to the -1 eigenspace.
|
||||
return Measure([PauliX, PauliX], qs) == Zero ? 0 | 1;
|
||||
}
|
||||
|
||||
|
||||
// Task 6. Controlled X gate with |0⟩ target
|
||||
// Task 6*. Controlled X gate with |0⟩ target
|
||||
operation ControlledX_Reference (qs : Qubit[]) : Unit {
|
||||
H(qs[1]);
|
||||
if (Measure([PauliZ, PauliZ], qs) == One) {
|
||||
|
@ -58,7 +65,7 @@ namespace Quantum.Kata.JointMeasurements {
|
|||
}
|
||||
|
||||
|
||||
// Task 7*. Controlled X gate with arbitrary target
|
||||
// Task 7**. Controlled X gate with arbitrary target
|
||||
operation ControlledX_General_Reference (qs : Qubit[]) : Unit {
|
||||
|
||||
body (...) {
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace Quantum.Kata.JointMeasurements {
|
|||
}
|
||||
|
||||
|
||||
// Task 5. Parity measurement in different basis
|
||||
// Task 5*. Parity measurement in different basis
|
||||
// Input: Two qubits (stored in an array) which are guaranteed to be
|
||||
// either in superposition α|00⟩ + β|01⟩ + β|10⟩ + α|11⟩
|
||||
// or in superposition α|00⟩ - β|01⟩ + β|10⟩ - α|11⟩.
|
||||
|
@ -92,10 +92,10 @@ namespace Quantum.Kata.JointMeasurements {
|
|||
}
|
||||
|
||||
|
||||
// Task 6. Controlled X gate with |0⟩ target
|
||||
// Task 6*. Controlled X gate with |0⟩ target
|
||||
// Input: Two unentangled qubits (stored in an array of length 2).
|
||||
// The first qubit will be in state |ψ⟩ = α |0⟩ + β |1⟩, the second - in state |0⟩
|
||||
// (this can be written as two-qubit state (α|0⟩ + β|1⟩) ⊕ |0⟩).
|
||||
// (this can be written as two-qubit state (α|0⟩ + β|1⟩) ⊗ |0⟩).
|
||||
// Goal: Change the two-qubit state to α |00⟩ + β |11⟩ using only single-qubit gates and joint measurements.
|
||||
// Do not use two-qubit gates.
|
||||
// You do not need to allocate extra qubits.
|
||||
|
@ -104,7 +104,7 @@ namespace Quantum.Kata.JointMeasurements {
|
|||
}
|
||||
|
||||
|
||||
// Task 7*. Controlled X gate with arbitrary target
|
||||
// Task 7**. Controlled X gate with arbitrary target
|
||||
// Input: Two qubits (stored in an array of length 2) in an arbitrary
|
||||
// two-qubit state α|00⟩ + β|01⟩ + γ|10⟩ + δ|11⟩.
|
||||
// Goal: Change the two-qubit state to α|00⟩ + β|01⟩ + δ|10⟩ + γ|11⟩ using only single-qubit gates and joint measurements.
|
||||
|
|
|
@ -35,7 +35,14 @@ namespace Quantum.Kata.Measurements {
|
|||
// Output: true if qubit was in |1⟩ state, or false if it was in |0⟩ state.
|
||||
// The state of the qubit at the end of the operation does not matter.
|
||||
operation IsQubitOne (q : Qubit) : Bool {
|
||||
// ...
|
||||
// The operation M will measure a qubit in the Z basis (|0⟩ and |1⟩ basis)
|
||||
// and return Zero if the observed state was |0⟩ or One if the state was |1⟩.
|
||||
// To answer the question, you need to perform the measurement and check whether the result
|
||||
// equals One - either directly or using library function IsResultOne.
|
||||
//
|
||||
// Replace the returned expression with (M(q) == One)
|
||||
// Then rebuild the project and rerun the tests - T101_IsQubitOne_Test should now pass!
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -357,8 +357,8 @@ namespace Quantum.Kata.Superposition {
|
|||
WState_PowerOfTwo_Reference(qs);
|
||||
} else {
|
||||
// allocate extra qubits
|
||||
using (ans = Qubit[P - N]) {
|
||||
let all_qubits = qs + ans;
|
||||
using (anc = Qubit[P - N]) {
|
||||
let all_qubits = qs + anc;
|
||||
|
||||
repeat {
|
||||
// prepare state W_P on original + ancilla qubits
|
||||
|
@ -367,12 +367,12 @@ namespace Quantum.Kata.Superposition {
|
|||
// measure ancilla qubits; if all of the results are Zero, we get the right state on main qubits
|
||||
mutable allZeros = true;
|
||||
for (i in 0 .. (P - N) - 1) {
|
||||
set allZeros = allZeros && IsResultZero(M(ans[i]));
|
||||
set allZeros = allZeros && IsResultZero(M(anc[i]));
|
||||
}
|
||||
}
|
||||
until (allZeros)
|
||||
fixup {
|
||||
ResetAll(ans);
|
||||
ResetAll(anc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче