Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot adjust #17

Merged
merged 10 commits into from
Dec 19, 2024
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[default.extend-words]
ket = "ket"
braket = "braket"

[type.ipynb]
# It detects false possitives in the base64 encoded images inside notebooks
Expand Down
14 changes: 10 additions & 4 deletions _2.markdown_generation_pass/code_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,28 @@ can be generated with [`QuantumClifford.naive_encoding_circuit`](https://quantum

![the encoding circuit of the {{:codetypename}}{{.}} instance of this code family](./{{{:codetypename}}}{{{.}}}_encoding.png)

<!-- TODO: Make QASM download for naive encoding circuit -->

#### Naive Syndrome Extraction Circuit

@@small
can be generated with [`QuantumClifford.naive_syndrome_circuit`](https://quantumsavory.github.io/QuantumClifford.jl/dev/ECC_API/#QuantumClifford.ECC.naive_syndrome_circuit)
@@

![the naive syndrome extraction circuit of the {{:codetypename}}{{.}} instance of this code family](./{{{:codetypename}}}{{{.}}}_encoding.png)
![the naive syndrome extraction circuit of the {{:codetypename}}{{.}} instance of this code family](./{{{:codetypename}}}{{{.}}}_naive_syndrome.png)

<!-- TODO: Make QASM download for naive syndrome circuit -->

#### Shor Syndrome Extraction Circuit

@@small
can be generated with [`QuantumClifford.shor_syndrome_circuit`](https://quantumsavory.github.io/QuantumClifford.jl/dev/ECC_API/#QuantumClifford.ECC.shor_syndrome_circuit)
@@

![the Shor syndrome extraction circuit of the {{:codetypename}}{{.}} instance of this code family](./{{{:codetypename}}}{{{.}}}_shor.png)
<!-- ![the Shor syndrome extraction circuit of the {{:codetypename}}{{.}} instance of this code family](./{{{:codetypename}}}{{{.}}}_shor_syndrome.png) -->
<!-- TODO: make the above work reliably and uncomment it -->

<!-- TODO: Make QASM download for Shor syndrome circuit -->

~~~
</details>
Expand All @@ -73,5 +80,4 @@ can be generated with [`QuantumClifford.shor_syndrome_circuit`](https://quantums

## Performance of Specific Decoders

TODO

TODO
50 changes: 28 additions & 22 deletions _2.markdown_generation_pass/figures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module CodeFigures

using Makie, CairoMakie
using Quantikz
using QuantumClifford: stab_to_gf2
using QuantumClifford.ECC: TableDecoder, stabilizerplot_axis, parity_checks, iscss, parity_checks_z, parity_checks_x
using QuantumClifford: stab_to_gf2, stabilizerplot_axis
using QuantumClifford.ECC: TableDecoder, parity_checks, iscss, parity_checks_z, parity_checks_x, code_n, naive_encoding_circuit, naive_syndrome_circuit, shor_syndrome_circuit

include("../_0.helpers_and_metadata/helpers.jl")
include("../_0.helpers_and_metadata/db_helpers.jl")
Expand All @@ -28,14 +28,20 @@ function make_decoder_figure(phys_errors, results;
fresults = copy(results)
fresults[results.==0] .= NaN

f = Figure(size=(1000,400))
a = Axis(f[1:7,1:3],
f = Figure(size=(1000,600))
a = Axis(f[1:7,1:6],
xscale=log10, yscale=log10,
limits=(minlim,maxlim,minlim,maxlim),
aspect=DataAspect(),
xlabel="physical error rate",
ylabel="logical error rate",
title=title)
title=title,
titlesize=25,
xlabelsize=20,
ylabelsize=20,
xticklabelsize=15,
yticklabelsize=15,
)

singlecode = size(results,3) == 1
plotcolor(iᶜ,iᵈ) = singlecode ? colors[iᵈ] : colors[iᶜ]
Expand All @@ -44,41 +50,41 @@ function make_decoder_figure(phys_errors, results;
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=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ᵈ])
scatter!(a, phys_errors, max.(fresults[:,1,iᶜ,iᵈ,iˢ],fresults[:,2,iᶜ,iᵈ,iˢ]), marker=markers[iˢ], color=plotcolor(iᶜ,iᵈ), markersize=10)
lines!( a, phys_errors, max.(fresults[:,1,iᶜ,iᵈ,iˢ],fresults[:,2,iᶜ,iᵈ,iˢ]), color=plotcolor(iᶜ,iᵈ), linestyle=linestyles[iᵈ], linewidth=3)
else
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ᵈ])
scatter!(a, phys_errors, fresults[:,1,iᶜ,iᵈ,iˢ], marker=:+, color=plotcolor(iᶜ,iᵈ), markersize=10)
scatter!(a, phys_errors, fresults[:,2,iᶜ,iᵈ,iˢ], marker=:x, color=plotcolor(iᶜ,iᵈ), markersize=10)
lines!( a, phys_errors, fresults[:,1,iᶜ,iᵈ,iˢ], color=plotcolor(iᶜ,iᵈ), linestyle=linestyles[iᵈ], linewidth=3)
lines!( a, phys_errors, fresults[:,2,iᶜ,iᵈ,iˢ], color=plotcolor(iᶜ,iᵈ), linestyle=linestyles[iᵈ], linewidth=3)
end
end
ca = []
for (iᶜ,label) in enumerate(codelabels)
push!(ca, lines!(a, [NaN], [NaN], color=plotcolor(iᶜ,1), label=label))
end
Legend(f[1:2,4],ca,codelabels, "Code", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
Legend(f[1:2,7],ca,codelabels, "Code", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2, titlesize=25, labelsize=20)
la = []
for (iᵈ,label) in enumerate(decoderlabels)
push!(la, lines!(a, [NaN], [NaN], linestyle=linestyles[iᵈ], color=decoderlegendcolor(iᵈ), label=label))
end
Legend(f[3:6,4],la,decoderlabels, "Decoder", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=1)
Legend(f[3:6,7],la,decoderlabels, "Decoder", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=1, titlesize=25, labelsize=20)
ma = []
if single_error
for (iˢ,label) in enumerate(setuplabels)
push!(ma, scatter!(a, [NaN], [NaN], marker=markers[iˢ], color=:gray, label=label))
end
Legend(f[7,4],ma,setuplabels, "Circuit Type", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
Legend(f[7,7],ma,setuplabels, "Circuit Type", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2, titlesize=25, labelsize=20)
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[7,4],ma,["X", "Z"], "Logical Error", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2)
Legend(f[7,7],ma,["X", "Z"], "Logical Error", framevisible = false, halign=:left, titlehalign=:left, valign=:top, nbanks=2, titlesize=25, labelsize=20)
end
f
end

function prep_figures(code_metadata)
for (codetype, metadata) in code_metadata
Threads.@threads :greedy for (codetype, metadata) in code_metadata
codetypename = typenameof(codetype)
@info "Plotting figures for $(codetypename) ..."
codes = [codetype(instance_args...) for instance_args in metadata[:family]]
Expand All @@ -90,7 +96,7 @@ function prep_figures(code_metadata)

single_error = length(decoders)>1 || decoders==[TableDecoder]

# Plotting summary fig
# Plotting benchmarking summary fig
f = make_decoder_figure(e, r;
title="$(codetypename)",
codelabels=instancenameof.(codes),
Expand Down Expand Up @@ -139,20 +145,20 @@ function prep_figures(code_metadata)
colgap!(f.layout, 1, Relative(0.15))
save("codes/$(codetypename)/$(instancenameof(c)).png", f)
# Plotting circuits
continue # skip circuit plots
if nqubits(c) <= 15
if code_n(c) <= 10
try
savecircuit(naive_encoding_circuit(c), "codes/$(codetypename)/$(c)_encoding.png")
savecircuit(naive_encoding_circuit(c), "codes/$(codetypename)/$(instancenameof(c))_encoding.png")
catch
@error "$(c) failed to plot `naive_encoding_circuit`"
end
try
savecircuit(naive_syndrome_circuit(c)[1], "codes/$(codetypename)/$(c)_naive_syndrome.png")
savecircuit(naive_syndrome_circuit(c)[1], "codes/$(codetypename)/$(instancenameof(c))_naive_syndrome.png")
catch
@error "$(c) failed to plot `naive_syndrome_circuit`"
end
try
savecircuit(vcat(shor_syndrome_circuit(c)[1:2]...), "codes/$(codetypename)/$(c)_naive_syndrome.png")
error("shor syndrome circuit plotting is problematic, fix it") #TODO
savecircuit(vcat(shor_syndrome_circuit(c)[1:2]...), "codes/$(codetypename)/$(instancenameof(c))_shor_syndrome.png")
catch
@error "$(c) failed to plot `shor_syndrome_circuit`"
end
Expand Down
1 change: 1 addition & 0 deletions _2.markdown_generation_pass/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using Mustache

function make_markdown_page(codetypename, metadata)
family_strs = ["($(join(string.(s),", ")))" for s in metadata[:family]] # otherwise there is an annoying trailing comma
@debug family_strs
rendered = render_from_file(joinpath((@__DIR__), "code_template.md"), (;codetypename, metadata..., family_strs))
write(joinpath((@__DIR__), "../codes/$codetypename/index.md"), rendered)
end
Expand Down
10 changes: 6 additions & 4 deletions wiki_database_passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using Logging
using TerminalLoggers
using ProgressLogging

export run_evaluations, prep_everything, code_metadata

global_logger(TerminalLogger(right_justify=120))

include("_0.helpers_and_metadata/helpers.jl")
Expand Down Expand Up @@ -46,8 +48,8 @@ function prep_folders(code_metadata)
end
end

function prep_everything(code_metada)
prep_folders(code_metada)
prep_figures(code_metada)
prep_markdown(code_metada)
function prep_everything(code_metadata; plot=true, markdown=true)
prep_folders(code_metadata)
plot && prep_figures(code_metadata)
markdown && prep_markdown(code_metadata)
end
Loading