-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add example of magic state distillation (#40)
Co-authored-by: Alan Lawrence <[email protected]>
- Loading branch information
Showing
6 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- TODO: Fill this with holes once we can guess them | ||
map(X :: $, Y :: $, n :: #, f :: { X -o Y }) -> { Vec(X, n) -o Vec(Y, n) } | ||
map(_, _, _, _) = { [] => [] } | ||
map(X, Y, succ(n), f) = { cons(x,xs) => cons(f(x), map(X, Y, n, f)(xs)) } | ||
|
||
fold(X :: $ | ||
,{ X, X -o X } | ||
,{ -o X } | ||
,n :: # | ||
) -> { Vec(X, n) -o X } | ||
fold(X, f, x, 0) = { [] => x() } | ||
fold(X, f, x, succ(n)) = { cons(y, ys) => f(y, fold(X, f, x, n)(ys)) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pi :: Float | ||
pi = 3.1415926 | ||
|
||
-- Things that we need to find a way to support | ||
ext "TODO" arccos :: { Float -> Float } | ||
ext "TODO_sqrt" sqrt :: { Float -> Float } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
open import lib.functional | ||
open import lib.kernel | ||
open import lib.math | ||
|
||
or(Bit, Bit) -o Bit | ||
or(true, _) = true | ||
or(_, y) = y | ||
|
||
any(n :: #) -> { Vec(Bit, n) -o Bit } | ||
any(n) = fold(Bit, or, { => false }, n) | ||
|
||
-- Decoder for the [[5,3,1]] "perfect" error code | ||
-- TODO: Add vectorisation and fanin/out | ||
decoder(Vec(Qubit, 5)) -o Vec(Qubit, 5) | ||
decoder = { | ||
[/\]; | ||
CZ, CZ, |; | ||
|, CZ, CZ; | ||
swap, |, swap; | ||
|, swap, ..; | ||
|, |, CZ, |; | ||
|, swap, ..; | ||
swap, |, swap; | ||
H, H, H, H, H; | ||
[\/] | ||
} | ||
|
||
phi :: Float | ||
phi = arccos(1.0 / sqrt(3.0)) | ||
|
||
prepare_noisy_1(Money) -o Qubit | ||
prepare_noisy_1 = { | ||
fresh; | ||
Ry(phi); | ||
Rz(pi / 4.0) | ||
} | ||
|
||
measure_all(n :: #) -> { Vec(Qubit, n) -o Vec(Bit, n), Vec(Money, n) } | ||
measure_all(0) = { [] => [], [] } | ||
measure_all(succ(n)) = { q ,- qs => | ||
let m, b = measure(q) in | ||
let bs, ms = measure_all(n)(qs) in | ||
b ,- bs, m ,- ms | ||
} | ||
|
||
measure_syndrome(n :: #) | ||
-> { Vec(Qubit, n) | ||
-o Bit, Vec(Money, n) | ||
} | ||
measure_syndrome(n) = { | ||
measure_all(n); | ||
any(n), | | ||
} | ||
|
||
prepare_noisy(n :: #) -> { Vec(Money, n) -o Vec(Qubit, n) } | ||
prepare_noisy(n) = map(Money, Qubit, n, prepare_noisy_1) | ||
|
||
redistill_if_bad(Qubit, Bit, Vec(Money, 4)) | ||
-o Qubit, Vec(Money, 4) | ||
redistill_if_bad(q, false, ms) = q, ms | ||
redistill_if_bad(q, true, ms) = let m, _ = measure(q) in | ||
distill(cons(m, ms)) | ||
|
||
distill(Vec(Money, 5)) -o Qubit, Vec(Money, 4) | ||
distill = { | ||
prepare_noisy(5); | ||
decoder; | ||
uncons(4); | ||
|, measure_syndrome(4); | ||
redistill_if_bad | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
open import lib.kernel | ||
|
||
|
||
rus(Money, Qubit) -o Money, Qubit | ||
rus = { | ||
rus(timeout :: Nat) -> { Money, Qubit -o Money, Qubit } | ||
rus(0) = { .. } | ||
rus(succ(n)) = { | ||
fresh, ..; | ||
(H;T), ..; | ||
CX; | ||
H, ..; | ||
CX; | ||
(T;H), ..; | ||
measure, ..; | ||
rus' | ||
( m, false, q => m, q | ||
| m, true, q => rus(n)(m, q) | ||
) | ||
} | ||
|
||
rus'(Money, Bit, Qubit) -o Money, Qubit | ||
rus'(m, false, q) = m, q -- success | ||
rus'(m, true, q) = rus(m, q) -- try again |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters