Skip to content

Commit

Permalink
support for drawing circuits with quantikz (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov authored Jun 3, 2024
1 parent 774840a commit 7f803e1
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
name = "BPGates"
uuid = "2c1a90cd-bec4-4415-ae35-245016909a8f"
authors = ["Shu Ge <[email protected]>", "Stefan Krastanov <[email protected]>"]
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"
37 changes: 37 additions & 0 deletions ext/BPGatesQuantikzExt/BPGatesQuantikzExt.jl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 8 additions & 0 deletions test/test_quantikz.jl
Original file line number Diff line number Diff line change
@@ -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

2 comments on commit 7f803e1

@Krastanov
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/108111

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.0 -m "<description of version>" 7f803e17147f8f96348de2460d79d1aeffd3a623
git push origin v1.1.0

Please sign in to comment.