diff --git a/Project.toml b/Project.toml index 659884f..e701e99 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Quantikz" uuid = "b0d11df0-eea3-4d79-b4a5-421488cbf74b" authors = ["Stefan Krastanov "] -version = "1.3" +version = "1.3.1" [deps] EndpointRanges = "340492b5-2a47-5f55-813d-aca7ddf97656" diff --git a/src/Quantikz.jl b/src/Quantikz.jl index 4a00bad..1b3f4b5 100644 --- a/src/Quantikz.jl +++ b/src/Quantikz.jl @@ -304,17 +304,22 @@ ClassicalDecision(t::Integer, c::Integer) = ClassicalDecision("\\;\\;", [t], [c] ClassicalDecision(t::ArrayOrRange, c::Integer) = ClassicalDecision("\\;\\;", t, [c]) ClassicalDecision(t::Integer, c::ArrayOrRange) = ClassicalDecision("\\;\\;", [t], c) ClassicalDecision(t::ArrayOrRange, c::ArrayOrRange) = ClassicalDecision("\\;\\;", t, c) +ClassicalDecision(c::ArrayOrRange) = ClassicalDecision("", [], c) affectedqubits(g::ClassicalDecision) = g.targets affectedbits(g::ClassicalDecision) = g.bits function update_table!(qtable,step,g::ClassicalDecision) qvtable = qubitsview(qtable) bvtable = bitsview(qtable) - m, M = explicit_extrema(qvtable, g.targets) - draw_rectangle!(qvtable,step,g.targets,g.str) bits = explicit_targets(bvtable, g.bits) startpoint = minimum(bits) - bvtable[startpoint,step] = "\\cwbend{$(-(qtable.qubits-M)-qtable.ancillaries-startpoint)}" + if !isa(g.targets,AbstractVector) || length(g.targets)>0 + m, M = explicit_extrema(qvtable, g.targets) + draw_rectangle!(qvtable,step,g.targets,g.str) + bvtable[startpoint,step] = "\\cwbend{$(-(qtable.qubits-M)-qtable.ancillaries-startpoint)}" + else + bvtable[startpoint,step] = "\\cwbend{0}" + end for b in sort(bits)[2:end] bvtable[b,step] = "\\cwbend{$(startpoint-b)}" startpoint = b @@ -410,7 +415,11 @@ function circuit2table_compressed(circuit, qubits) for op in circuit qubits = extrema2range(explicit_extrema(qvtable, affectedqubits(op))) if circuitwidthbits(op)!=0 || neededancillaries(op)!=0 - qubits = minimum(qubits):iend + qubits = if length(qubits)==0 + ibegin:iend # TODO this branch is too pessimistic + else + minimum(qubits):iend + end end bits = extrema2range(explicit_extrema(bvtable, affectedbits(op))) ancillaries = neededancillaries(op) diff --git a/test/runtests.jl b/test/runtests.jl index 0a363df..b60fece 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -108,10 +108,19 @@ end @testset "EndpointRanges in ClassicalDecision" begin circuit = [U(5),ClassicalDecision(ibegin:iend,2),ClassicalDecision(1,ibegin:iend)] @test circuit2string(circuit) == circuit2string(circuit,mode=:expanded) == "\\begin{quantikz}[transparent, row sep={0.8cm,between origins}]\n\\qw & \\qw & \\gate[5,disable auto height]{\\;\\;} & \\gate[1]{\\;\\;} & \\qw\\\\\n\\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\\qw & \\qw & \\qw & \\qw & \\qw\\\\\n\\qw & \\gate{\\;\\;} & \\qw & \\qw & \\qw\\\\\n\\cw & \\cw & \\cw & \\cwbend{-5} & \\cw\\\\\n\\cw & \\cw & \\cwbend{-2} & \\cwbend{-1} & \\cw\n\\end{quantikz}" +circuit2string(circuit,mode=:compressed) circuit = [ClassicalDecision(ibegin:iend,ibegin:iend)] @test circuit2string(circuit) == circuit2string(circuit,mode=:expanded) == "\\begin{quantikz}[transparent, row sep={0.8cm,between origins}]\n\\qw & \\gate[1]{\\;\\;} & \\qw\\\\\n\\cw & \\cwbend{-1} & \\cw\n\\end{quantikz}" +circuit2string(circuit,mode=:compressed) end +@testset "no quantum component in ClassicalDecision" begin +circuit = [U(5),ClassicalDecision([2]),ClassicalDecision(ibegin:iend)] +@test circuit2string(circuit) == circuit2string(circuit,mode=:expanded) +circuit2string(circuit,mode=:compressed) +end + + @testset "Consecutive gates should not confuse the `deleted` count in `draw_rectangle`" begin circuit = [MultiControlU("XYZ", [1], [2], [3,4,5]), MultiControlU("U_a", [1], [2], [3,5])] @test circuit2string(circuit) == circuit2string(circuit,mode=:expanded) == "\\begin{quantikz}[transparent, row sep={0.8cm,between origins}]\n\\qw & \\ctrl{0} & \\ctrl{0} & \\qw\\\\\n\\qw & \\octrl{-1} & \\octrl{-1} & \\qw\\\\\n\\qw & \\gate[3,disable auto height]{XYZ}\\vqw{-1} & \\gate[3,label style={yshift=0.2cm},disable auto height]{U_a}\\vqw{-1} & \\qw\\\\\n\\qw & \\qw & \\linethrough & \\qw\\\\\n\\qw & \\qw & \\qw & \\qw\n\\end{quantikz}"