From 7f803e17147f8f96348de2460d79d1aeffd3a623 Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Sun, 2 Jun 2024 21:18:59 -0400 Subject: [PATCH] support for drawing circuits with quantikz (#18) --- Project.toml | 9 ++++- ext/BPGatesQuantikzExt/BPGatesQuantikzExt.jl | 37 ++++++++++++++++++++ test/Project.toml | 1 + test/runtests.jl | 1 + test/test_quantikz.jl | 8 +++++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 ext/BPGatesQuantikzExt/BPGatesQuantikzExt.jl create mode 100644 test/test_quantikz.jl diff --git a/Project.toml b/Project.toml index b43c053..95f251f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,13 +1,20 @@ name = "BPGates" uuid = "2c1a90cd-bec4-4415-ae35-245016909a8f" authors = ["Shu Ge ", "Stefan Krastanov "] -version = "1.0.2" +version = "1.1.0" [deps] QuantumClifford = "0525e862-1e90-11e9-3e4d-1b39d7109de1" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +[weakdeps] +Quantikz = "b0d11df0-eea3-4d79-b4a5-421488cbf74b" + +[extensions] +BPGatesQuantikzExt = "Quantikz" + [compat] +Quantikz = "1.3.1" QuantumClifford = "0.8, 0.9" Random = "1" julia = "1.9" \ No newline at end of file diff --git a/ext/BPGatesQuantikzExt/BPGatesQuantikzExt.jl b/ext/BPGatesQuantikzExt/BPGatesQuantikzExt.jl new file mode 100644 index 0000000..881cbc2 --- /dev/null +++ b/ext/BPGatesQuantikzExt/BPGatesQuantikzExt.jl @@ -0,0 +1,37 @@ +module BPGatesQuantikzExt + +import Quantikz +using BPGates + + +function small_vert_matrix(numbers, suffix="") + return "{\\tiny\\begin{matrix}"*join(numbers, "\\\\")*"\\end{matrix}}"*suffix +end +function small_tuples(list_of_tuples) + return "{\\tiny\\begin{matrix}"*join(join.(list_of_tuples), "\\\\")*"\\end{matrix}}" +end + +Quantikz.QuantikzOp(op::BellSinglePermutation) = Quantikz.U(small_vert_matrix(BPGates.one_perm_tuple[op.pidx], "\\ \\mathcal{C}_1^*"), op.sidx) +Quantikz.QuantikzOp(op::BellDoublePermutation) = Quantikz.MultiControlU( + small_vert_matrix(BPGates.double_perm_tuple[op.pidx][1:4])*"\\ "* + small_vert_matrix(BPGates.double_perm_tuple[op.pidx][5:8])*"\\ "* + small_vert_matrix(BPGates.double_perm_tuple[op.pidx][9:12])*"\\ "* + small_vert_matrix(BPGates.double_perm_tuple[op.pidx][13:16], "\\ \\mathcal{C}_2^*"), + [op.sidx1, op.sidx2]) +Quantikz.QuantikzOp(op::BellPauliPermutation) = Quantikz.U(["I", "X", "Z", "Y"][op.pidx], op.sidx) +Quantikz.QuantikzOp(op::BellMeasure) = Quantikz.Measurement(small_tuples([BPGates.int_to_bit(phase, Val(2)) for phase in 1:4 if BPGates.measure_tuple[phase][op.midx]]),op.sidx) +Quantikz.QuantikzOp(op::BellGate) = Quantikz.MultiControlU("BP_{$(op.pauli1),$(op.pauli2),$(op.double),$(op.single1),$(op.single2)}",[op.idx1, op.idx2]) +Quantikz.QuantikzOp(op::CNOTPerm) = Quantikz.MultiControlU( + small_vert_matrix(BPGates.good_perm_tuple[op.single1])*"\\ "* + small_vert_matrix(BPGates.good_perm_tuple[op.single2])*"\\ X", + op.idx1, [op.idx2]) +Quantikz.QuantikzOp(op::GoodSingleQubitPerm) = Quantikz.U(small_vert_matrix(BPGates.good_perm_tuple[op.single]), op.idx) + +Quantikz.QuantikzOp(op::PauliNoiseOp) = Quantikz.Noise([op.idx]) + +Quantikz.QuantikzOp(op::PauliNoiseBellGate) = Quantikz.QuantikzOp(op.g) +Quantikz.QuantikzOp(op::NoisyBellMeasure) = Quantikz.QuantikzOp(op.m) +Quantikz.QuantikzOp(op::NoisyBellMeasureNoisyReset) = Quantikz.QuantikzOp(op.m) + + +end diff --git a/test/Project.toml b/test/Project.toml index 6141ea2..ccf8fc1 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -6,6 +6,7 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Quantikz = "b0d11df0-eea3-4d79-b4a5-421488cbf74b" QuantumClifford = "0525e862-1e90-11e9-3e4d-1b39d7109de1" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" diff --git a/test/runtests.jl b/test/runtests.jl index e4b2366..6080dde 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,6 +24,7 @@ end println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREADS = $(Sys.CPU_THREADS)`...") @doset "quantumclifford" +@doset "quantikz" get(ENV,"JET_TEST","")=="true" && @doset "jet" @doset "doctests" diff --git a/test/test_quantikz.jl b/test/test_quantikz.jl new file mode 100644 index 0000000..3a18b90 --- /dev/null +++ b/test/test_quantikz.jl @@ -0,0 +1,8 @@ +using BPGates +using Quantikz +using Test + +@testset "Quantikz" begin + quantikz_circ = Quantikz.QuantikzOp.([BellSinglePermutation(2,2), BellDoublePermutation(1,2,3), BellPauliPermutation(4,1), BellMeasure(3,1), BellGate(1,1,1,1,1,1,2), CNOTPerm(1,2,3,4), GoodSingleQubitPerm(1,2), PauliNoiseOp(1,0.0,0.0,0.0), PauliNoiseBellGate(CNOTPerm(1,2,3,4),0.0,0.0,0.0), NoisyBellMeasure(BellMeasure(1,2),0.0), NoisyBellMeasureNoisyReset(BellMeasure(1,2),0.0,0.0,0.0,0.0)]) + img = Quantikz.circuit2image(quantikz_circ) +end