This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathSimpleRUS.qs
114 lines (110 loc) · 3.91 KB
/
SimpleRUS.qs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace Microsoft.Quantum.Samples.RepeatUntilSuccess {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Preparation;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Measurement;
/// # Summary
/// Example of a Repeat-until-success algorithm implementing a circuit
/// that achieves (I + i√2X)/√3 by Paetznick & Svore. This is the smallest
/// circuit found in the referenced work and described in figure 8.
/// # References
/// - [ *Adam Paetznick, Krysta M. Svore*,
/// Quantum Information & Computation 14(15 & 16): 1277-1301 (2014)
/// ](https://arxiv.org/abs/1311.1074)
/// For circuit diagram, see file SimpleRUS.png.
///
/// # Input
/// ## inputBasis
/// Pauli basis in which to prepare input qubit
/// ## inputValue
/// Boolean value for input qubit (true maps to One, false maps to Zero)
/// ## limit
/// Integer limit to number of repeats of circuit
///
/// # Remarks
/// The program executes a circuit on a "target" qubit using an "auxiliary"
/// qubit.
/// The goal is to measure Zero for the auxiliary qubit.
/// If this succeeds, the program will have effectively applied an
/// (I + i√2X)/√3 gate on the target qubit.
/// If this fails, the program reruns the circuit up to <limit> times.
operation CreateQubitsAndApplySimpleGate(
inputValue : Bool,
inputBasis : Pauli,
limit : Int
)
: ( Bool, Result, Int ) {
use register = Qubit[2];
let (success, numIter) = ApplySimpleGate(
inputBasis, inputValue, limit, register);
let result = Measure([inputBasis], [register[1]]);
return (success, result, numIter);
}
/// # Summary
/// Apply (I + i√2X)/√3 on qubits using repeat until success algorithm.
///
/// # Input
/// ## inputBasis
/// Pauli basis in which to prepare input qubit
/// ## inputValue
/// Boolean value for input qubit (true maps to One, false maps to Zero)
/// ## limit
/// Integer limit to number of repeats of circuit
/// ## register
/// Qubit register including auxiliary and target qubits
///
/// # Output
/// Tuple of (success, numIter) where success = false if the number of
/// iterations (numIter) exceeds the input <limit>
operation ApplySimpleGate(
inputBasis : Pauli,
inputValue : Bool,
limit : Int,
register : Qubit[]
)
: (Bool, Int) {
// Initialize results to One by default.
mutable done = false;
mutable success = false;
mutable numIter = 0;
// Prepare target qubit in |0⟩ or |1⟩ state, depending on input value
if (inputValue) {
X(register[1]);
}
PreparePauliEigenstate(inputBasis, register[1]);
repeat {
// Assert valid starting states for all qubits
AssertMeasurement([PauliZ], [register[0]], Zero,
"Auxiliary qubit is not in |0⟩ state.");
AssertQubitIsInState(register[1], inputBasis, inputValue);
ApplySimpleRUSCircuit(register);
set success = MResetZ(register[0]) == Zero;
set done = success or (numIter >= limit);
set numIter = numIter + 1;
}
until (done);
return (success, numIter);
}
/// # Summary
/// Apply RUS circuit on qubit register
///
/// # Input
/// ## register
/// Qubit register including auxiliary and target qubits
operation ApplySimpleRUSCircuit(
register : Qubit[]
)
: Unit {
H(register[0]);
T(register[0]);
CNOT(register[0], register[1]);
H(register[0]);
CNOT(register[0], register[1]);
T(register[0]);
H(register[0]);
}
}