Skip to content

Commit

Permalink
fixup Franklin step
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Apr 10, 2024
1 parent 5e89ef5 commit caf7e69
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 76 deletions.
2 changes: 1 addition & 1 deletion code_evaluation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function evaluate_codes_decoders_setups(codes,decoders,setups;
#Threads.@spawn begin
#@show (c, d, s, Threads.threadid())
done_samples = 0
@withprogress name="$(c) $(d) $(s)" for iᵉ in reverse(eachindex(errors)) # reverse to get the smaller tasks first, to populate the progress bar
@withprogress name="$(instancenameof(c)) $(skipredundantsuffix(d)) $(skipredundantsuffix(s))" for iᵉ in reverse(eachindex(errors)) # reverse to get the smaller tasks first, to populate the progress bar
e = errors[iᵉ]
decoder = isnothing(decoder) ? d(c) : decoder
setup = s(e)
Expand Down
41 changes: 23 additions & 18 deletions code_figures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function make_decoder_figure(phys_errors, results;
linestyles=[:solid, :dash, :dot, :dashdot, :dashdotdot, Linestyle([0.5, 1.0, 1.5, 2.5])],
markers=['', '', '', '', '', ''],
single_error=false,
colorlabels=[], linestylelabels=[], markerlabels=[],
codelabels=[], decoderlabels=[], setuplabels=[],
)
minlim = minimum(phys_errors)
#minlim = min(minimum(phys_errors),minimum(skipzeronan(results)))
Expand All @@ -15,46 +15,51 @@ function make_decoder_figure(phys_errors, results;
fresults = copy(results)
fresults[results.==0] .= NaN

f = Figure(size=(1200,400))
a = Axis(f[1:3,1:3],
f = Figure(size=(1000,400))
a = Axis(f[1:7,1:3],
xscale=log10, yscale=log10,
limits=(minlim,maxlim,minlim,maxlim),
aspect=DataAspect(),
xlabel="physical error rate",
ylabel="logical error rate",
title=title)

singlecode = size(results,3) == 1
plotcolor(iᶜ,iᵈ) = singlecode ? colors[iᵈ] : colors[iᶜ]
decoderlegendcolor(iᵈ) = singlecode ? colors[iᵈ] : :gray

b = lines!(a, [minlim,maxlim],[minlim,maxlim], color=:black)
for (iᶜ,iᵈ,iˢ) in Iterators.product(axes.((fresults,), (3,4,5))...)
if single_error
scatter!(a, phys_errors, max.(fresults[:,1,iᶜ,iᵈ,iˢ],fresults[:,2,iᶜ,iᵈ,iˢ]), marker=markers[iˢ], color=colors[iᶜ], linestyle=linestyles[iᵈ])
lines!( a, phys_errors, max.(fresults[:,1,iᶜ,iᵈ,iˢ],fresults[:,2,iᶜ,iᵈ,iˢ]), marker=markers[iˢ], color=colors[iᶜ], linestyle=linestyles[iᵈ])
scatter!(a, phys_errors, max.(fresults[:,1,iᶜ,iᵈ,iˢ],fresults[:,2,iᶜ,iᵈ,iˢ]), marker=markers[iˢ], color=plotcolor(iᶜ,iᵈ), linestyle=linestyles[iᵈ])
lines!( a, phys_errors, max.(fresults[:,1,iᶜ,iᵈ,iˢ],fresults[:,2,iᶜ,iᵈ,iˢ]), marker=markers[iˢ], color=plotcolor(iᶜ,iᵈ), linestyle=linestyles[iᵈ])
else
scatter!(a, phys_errors, fresults[:,1,iᶜ,iᵈ,iˢ], marker=:+, color=colors[iᶜ], linestyle=linestyles[iᵈ])
scatter!(a, phys_errors, fresults[:,2,iᶜ,iᵈ,iˢ], marker=:x, color=colors[iᶜ], linestyle=linestyles[iᵈ])
lines!( a, phys_errors, fresults[:,1,iᶜ,iᵈ,iˢ], marker=:+, color=colors[iᶜ], linestyle=linestyles[iᵈ])
lines!( a, phys_errors, fresults[:,2,iᶜ,iᵈ,iˢ], marker=:x, color=colors[iᶜ], linestyle=linestyles[iᵈ])
scatter!(a, phys_errors, fresults[:,1,iᶜ,iᵈ,iˢ], marker=:+, color=plotcolor(iᶜ,iᵈ), linestyle=linestyles[iᵈ])
scatter!(a, phys_errors, fresults[:,2,iᶜ,iᵈ,iˢ], marker=:x, color=plotcolor(iᶜ,iᵈ), linestyle=linestyles[iᵈ])
lines!( a, phys_errors, fresults[:,1,iᶜ,iᵈ,iˢ], marker=:+, color=plotcolor(iᶜ,iᵈ), linestyle=linestyles[iᵈ])
lines!( a, phys_errors, fresults[:,2,iᶜ,iᵈ,iˢ], marker=:x, color=plotcolor(iᶜ,iᵈ), linestyle=linestyles[iᵈ])
end
end
ca = []
for (iᶜ,label) in enumerate(colorlabels)
push!(ca, lines!(a, [NaN], [NaN], color=colors[iᶜ], label=label))
for (iᶜ,label) in enumerate(codelabels)
push!(ca, lines!(a, [NaN], [NaN], color=plotcolor(iᶜ,1), label=label))
end
Legend(f[1,4],ca,colorlabels, "Code", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
Legend(f[1:2,4],ca,codelabels, "Code", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
la = []
for (iᵈ,label) in enumerate(linestylelabels)
push!(la, lines!(a, [NaN], [NaN], linestyle=linestyles[iᵈ], color=:gray, label=label))
for (iᵈ,label) in enumerate(decoderlabels)
push!(la, lines!(a, [NaN], [NaN], linestyle=linestyles[iᵈ], color=decoderlegendcolor(iᵈ), label=label))
end
Legend(f[2,4],la,linestylelabels, "Decoder", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
Legend(f[3:6,4],la,decoderlabels, "Decoder", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=1)
ma = []
if single_error
for (iˢ,label) in enumerate(markerlabels)
for (iˢ,label) in enumerate(setuplabels)
push!(ma, scatter!(a, [NaN], [NaN], marker=markers[iˢ], color=:gray, label=label))
end
Legend(f[3,4],ma,markerlabels, "Circuit Type", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
Legend(f[7,4],ma,setuplabels, "Circuit Type", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
else
push!(ma, scatter!(a, [NaN], [NaN], marker=:+, color=:gray, label="X"))
push!(ma, scatter!(a, [NaN], [NaN], marker=:x, color=:gray, label="Z"))
Legend(f[3,4],ma,["X", "Z"], "Logical Error", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
Legend(f[7,4],ma,["X", "Z"], "Logical Error", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
end
f
end
46 changes: 46 additions & 0 deletions code_helpers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function instancenameof(x)
t = typeof(x)
str = string(nameof(t))*"("
nf = nfields(x)
nb = sizeof(x)
if nf != 0 || nb == 0
for i in 1:nf
f = fieldname(t, i)
str *= string(getfield(x, i))
if i < nf
str *= ", "
end
end
end
str *= ")"
return str
end

function skipredundantsuffix(x)
x = string(x)
xs = split(x, "(")
xs = [chopsuffix(chopsuffix(x, "Decoder"), "ECCSetup") for x in xs]
return join(xs, "(")
end

struct KWFun
f
kwargs
end

function (f::KWFun)(c)
f.f(c; f.kwargs...)
end

function skipredundantsuffix(x::KWFun)
f = skipredundantsuffix(x.f)
return "$f($(join(["$k=$v" for (k,v) in pairs(x.kwargs)], ", ")))"
end

function Base.string(x::KWFun)
f = string(x.f)
return "$f(_;$(join(["$k=$v" for (k,v) in pairs(x.kwargs)], ", ")))"
end

typename(t) = nameof(t)
typename(t::KWFun) = nameof(t.f)
31 changes: 8 additions & 23 deletions code_metadata.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
using QuantumClifford
using QuantumClifford.ECC
using PyQDecoders
using LDPCDecoders
import PyQDecoders
import LDPCDecoders

logrange(eᵐⁱⁿ, eᵐᵃˣ, steps) = exp.(range(log(eᵐⁱⁿ), log(eᵐᵃˣ), length=steps))
const eᵐⁱⁿ = 0.00001
const eᵐᵃˣ = 0.3
const steps = 20

include("code_helpers.jl")
include("hodgepodge/hodgepodge_codes.jl")

struct KWFun
f
kwargs
end

function (f::KWFun)(c)
f.f(c; f.kwargs...)
end

function skipredundantsuffix(x::KWFun)
f = skipredundantsuffix(x.f)
return "$f($(join(["$k=$v" for (k,v) in pairs(x.kwargs)], ", ")))"
end

function Base.string(x::KWFun)
f = string(x.f)
return "$f(_;$(join(["$k=$v" for (k,v) in pairs(x.kwargs)], ", ")))"
end

const code_metadata = Dict(
Gottesman => Dict(
:family => [(3,),(4,),(5,),(6,)],
Expand Down Expand Up @@ -89,8 +71,11 @@ const code_metadata = Dict(
Hodgepodge.NithinCode => Dict(
:family => [()],
:decoders => [TableDecoder,
KWFun(PyBeliefPropDecoder, (;bpmethod=:productsum)),
KWFun(PyBeliefPropOSDecoder, (;bpmethod=:productsum)),
BeliefPropDecoder,
BitFlipDecoder,
KWFun(PyBeliefPropOSDecoder, (;bpmethod=:productsum, osdmethod=:zeroorder)),
KWFun(PyBeliefPropOSDecoder, (;bpmethod=:productsum, osdmethod=:exhaustive, osdorder=5)),
KWFun(PyBeliefPropOSDecoder, (;bpmethod=:productsum, osdmethod=:combinationsweep, osdorder=10)),
],
:setups => [CommutationCheckECCSetup],
:ecczoo => "",
Expand Down
Binary file modified codes/Cleve8/totalsummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified codes/Gottesman/totalsummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified codes/NithinCode/totalsummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified codes/Perfect5/totalsummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified codes/Shor9/totalsummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified codes/Steane7/totalsummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified codes/Surface/totalsummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified codes/Toric/totalsummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified codes/results.sqlite
Binary file not shown.
33 changes: 3 additions & 30 deletions generate_codes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,6 @@ global_logger(TerminalLogger(right_justify=120))

##

function instancenameof(x)
t = typeof(x)
str = string(nameof(t))*"("
nf = nfields(x)
nb = sizeof(x)
if nf != 0 || nb == 0
for i in 1:nf
f = fieldname(t, i)
str *= string(getfield(x, i))
if i < nf
str *= ", "
end
end
end
str *= ")"
return str
end

function skipredundantsuffix(x)
x = string(x)
xs = split(x, "(")
xs = [chopsuffix(chopsuffix(x, "Decoder"), "ECCSetup") for x in xs]
return join(xs, "(")
end

##

include("code_metadata.jl")

include("code_markdown.jl")
Expand Down Expand Up @@ -97,9 +70,9 @@ function prep_figures(code_metada)
# Plotting summary fig
f = make_decoder_figure(e, r;
title="$(codeentryname)",
colorlabels=instancenameof.(codes),
linestylelabels=skipredundantsuffix.(decoders),
markerlabels=skipredundantsuffix.(setups),
codelabels=instancenameof.(codes),
decoderlabels=skipredundantsuffix.(decoders),
setuplabels=skipredundantsuffix.(setups),
single_error
)
save("codes/$(codeentryname)/totalsummary.png", f)
Expand Down
48 changes: 48 additions & 0 deletions scratch.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import LDPCDecoders
using Test

function test_bpropdecoder()
H = LDPCDecoders.parity_check_matrix(1000,10,9);
decoder = LDPCDecoders.BeliefPropagationDecoder(H, 0.01, 100);
count = 0
for _ in 1:1000
error = rand(1000) .< 0.01;
syndrome = (H * error) .% 2;
guess, success = LDPCDecoders.decode!(decoder, syndrome);
count += error == guess
end
return 1-count/1000
end

function test_bitflipdecoder()
H = LDPCDecoders.parity_check_matrix(1000,10,9);
decoder = LDPCDecoders.BitFlipDecoder(H, 0.01, 100);
count = 0
for _ in 1:1000
error = rand(1000) .< 0.01;
syndrome = (H * error) .% 2;
guess, success = LDPCDecoders.decode!(decoder, syndrome);
count += error == guess
end
return 1-count/1000
end

function test_bpropdecoder_old()
H = LDPCDecoders.parity_check_matrix(1000,10,9);
decoder = LDPCDecoders.BeliefPropagationDecoder(H, 0.01, 100);
count = 0
for _ in 1:1000
error = rand(1000) .< 0.01;
syndrome = (H * error) .% 2;
LDPCDecoders.reset!(decoder)
LDPCDecoders.syndrome_decode!(decoder, decoder.scratch, syndrome)
count += error == decoder.scratch.err
end
return 1-count/1000
end

##

@test test_bitflipdecoder()
@test test_bpropdecoder() < 0.001
@test test_bpropdecoder_old() < 0.001
6 changes: 2 additions & 4 deletions utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ using QuantumClifford.ECC

include("code_metadata.jl")

#typename(t) = string(t.name.name)

function hfun_allcodes()
io = IOBuffer()
for (codeentry, metadata) in pairs(code_metadata)
codeentry = nameof(codeentry)
decoders = nameof.(metadata[:decoders])
setups = nameof.(metadata[:setups])
decoders = unique(skipredundantsuffix.(typename.(metadata[:decoders])))
setups = skipredundantsuffix.(typename.(metadata[:setups]))
description = Markdown.html(Markdown.parse(get(metadata, :description, "")))
write(io, render(mt"""
<div class="card">
Expand Down

0 comments on commit caf7e69

Please sign in to comment.