Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Move Quantikz support here
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Mar 21, 2022
1 parent d988b61 commit d4a3b76
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name = "QuantumCliffordPlots"
uuid = "4eeed724-23be-436c-a322-a8540588cc9f"
authors = ["Stefan Krastanov <[email protected]> and contributors"]
version = "0.1.1"
version = "0.1.2"

[deps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Quantikz = "b0d11df0-eea3-4d79-b4a5-421488cbf74b"
QuantumClifford = "0525e862-1e90-11e9-3e4d-1b39d7109de1"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[compat]
Makie = "0.15.3, 0.16"
QuantumClifford = "0.2.12, 0.3, 0.4"
RecipesBase = "0.7, 0.8, 1.0"
Makie = "0.16"
Quantikz = "1.1.2"
QuantumClifford = "0.4.1"
RecipesBase = "1.0"
julia = "1.6"

[extras]
Expand Down
61 changes: 61 additions & 0 deletions src/QuantumCliffordPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,65 @@ function stabilizerplot_(s; colorbar=true)
fig
end

###
# Quantikz.jl
###

import Quantikz
using QuantumClifford.Experimental.NoisyCircuits

function Quantikz.QuantikzOp(op::SparseGate)
g = op.cliff
if g==CNOT
return Quantikz.CNOT(op.indices...)
elseif g==SWAP*CNOT*SWAP
return Quantikz.CNOT(op.indices[end:-1:begin]...)
elseif g==CPHASE
return Quantikz.CPHASE(op.indices...)
elseif g==SWAP
return Quantikz.SWAP(op.indices...)
else
return Quantikz.MultiControlU([],[],op.indices) # TODO Permit skipping the string
end
end
Quantikz.QuantikzOp(op::AbstractOperation) = Quantikz.MultiControlU(affectedqubits(op))
Quantikz.QuantikzOp(op::BellMeasurement) = Quantikz.ParityMeasurement(["\\mathtt{$(string(o))}" for o in op.pauli], op.indices)
Quantikz.QuantikzOp(op::NoisyBellMeasurement) = Quantikz.QuantikzOp(op.meas)
Quantikz.QuantikzOp(op::ConditionalGate) = Quantikz.ClassicalDecision(affectedqubits(op),op.controlbit)
Quantikz.QuantikzOp(op::DecisionGate) = Quantikz.ClassicalDecision(affectedqubits(op),Quantikz.ibegin:Quantikz.iend)
Quantikz.QuantikzOp(op::DenseGate) = Quantikz.MultiControlU(affectedqubits(op))
Quantikz.QuantikzOp(op::DenseMeasurement) = Quantikz.Measurement("\\begin{array}{c}$(lstring(op.pauli))\\end{array}",affectedqubits(op),op.storagebit)
Quantikz.QuantikzOp(op::SparseMeasurement) = Quantikz.Measurement("\\begin{array}{c}$(lstring(op.pauli))\\end{array}",affectedqubits(op),op.storagebit)
Quantikz.QuantikzOp(op::NoisyGate) = Quantikz.QuantikzOp(op.gate)
Quantikz.QuantikzOp(op::VerifyOp) = Quantikz.MultiControlU("\\begin{array}{c}\\mathrm{Verify:}\\\\$(lstring(op.good_state))\\end{array}",affectedqubits(op))
function Quantikz.QuantikzOp(op::Reset) # TODO This is complicated because quantikz requires $$ for some operators but not all of them... Fix in Quantikz.jl
m,M = extrema(op.indices)
indices = sort(op.indices)
str = "\\begin{array}{c}\\\\$(lstring(op.resetto))\\end{array}"
if collect(m:M)==indices
Quantikz.Initialize("\$$str\$",affectedqubits(op))
else
Quantikz.Initialize("$str",affectedqubits(op))
end
end
Quantikz.QuantikzOp(op::NoiseOp) = Quantikz.Noise(op.indices)
Quantikz.QuantikzOp(op::NoiseOpAll) = Quantikz.NoiseAll()

function lstring(pauli::PauliOperator)
v = join(("\\mathtt{$(o)}" for o in replace(string(pauli)[3:end],"_"=>"I")),"\\\\")
end

function lstring(stab::Stabilizer)
v = join(("\\mathtt{$(replace(string(p),"_"=>"I"))}" for p in stab),"\\\\")
end

###
# image show methods
###

Base.show(io::IO, mime::MIME"image/png", circuit::AbstractVector{<:AbstractOperation}; scale=1, kw...) =
show(io, mime, [Quantikz.QuantikzOp(c) for c in circuit]; scale=scale, kw...)
Base.show(io::IO, mime::MIME"image/png", gate::T; scale=1, kw...) where T<:AbstractOperation =
show(io, mime, Quantikz.QuantikzOp(gate); scale=scale, kw...)

end
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,17 @@ using QuantumCliffordPlots
using Test

@testset "QuantumCliffordPlots.jl" begin
# Write your tests here.
# @testset "Quantikz diagrams" begin
# noise = UnbiasedUncorrelatedNoise(0.1)
# @test circuit2string([
# SparseGate(CNOT, [1,4]),
# SparseGate(CNOT, [3,2]),
# SparseGate(CPHASE, [1,2]),
# SparseGate(SWAP, [2,4]),
# SparseGate(CNOT*CNOT, [1,3]),
# NoiseOp(noise,[1,3]),
# NoiseOpAll(noise),
# NoisyGate(SparseGate(CNOT*CNOT, [2,4]),noise),
# ]) == "\\begin{quantikz}[transparent, row sep={0.8cm,between origins}]\n\\qw & \\ctrl{0} & \\qw & \\ctrl{0} & \\qw & \\gate[3,label style={yshift=0.2cm},disable auto height]{\\;\\;} & \\gate[1,style={starburst,starburst points=7,inner xsep=-2pt,inner ysep=-2pt,scale=0.5}]{} & \\gate[1,style={starburst,starburst points=7,inner xsep=-2pt,inner ysep=-2pt,scale=0.5}]{} & \\qw & \\qw\\\\\n\\qw & \\qw & \\targ{}\\vqw{0} & \\ctrl{-1} & \\swap{0} & \\linethrough & \\qw & \\gate[1,style={starburst,starburst points=7,inner xsep=-2pt,inner ysep=-2pt,scale=0.5}]{} & \\gate[3,label style={yshift=0.2cm},disable auto height]{\\;\\;} & \\qw\\\\\n\\qw & \\qw & \\ctrl{-1} & \\qw & \\qw & \\qw & \\gate[1,style={starburst,starburst points=7,inner xsep=-2pt,inner ysep=-2pt,scale=0.5}]{} & \\gate[1,style={starburst,starburst points=7,inner xsep=-2pt,inner ysep=-2pt,scale=0.5}]{} & \\linethrough & \\qw\\\\\n\\qw & \\targ{}\\vqw{-3} & \\qw & \\qw & \\swap{-2} & \\qw & \\qw & \\gate[1,style={starburst,starburst points=7,inner xsep=-2pt,inner ysep=-2pt,scale=0.5}]{} & \\qw & \\qw\n\\end{quantikz}"
# end
end

2 comments on commit d4a3b76

@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/56987

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 v0.1.2 -m "<description of version>" d4a3b7681dddfe0e0d37af3cf9b0aece781926b7
git push origin v0.1.2

Please sign in to comment.