Skip to content

Commit

Permalink
a dirty workaround for compactifying ClassicalXOR
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Jan 19, 2024
1 parent cef8376 commit efa6069
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion ext/QuantumCliffordQuantikzExt/QuantumCliffordQuantikzExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Quantikz
using QuantumClifford
using QuantumClifford.Experimental.NoisyCircuits
using QuantumClifford: AbstractOperation
using QuantumClifford: ClassicalXORConcreteWorkaround

function Quantikz.QuantikzOp(op::SparseGate)
g = op.cliff
Expand Down Expand Up @@ -72,7 +73,7 @@ function Quantikz.QuantikzOp(op::Reset) # TODO This is complicated because quant
end
Quantikz.QuantikzOp(op::NoiseOp) = Quantikz.Noise(op.indices)
Quantikz.QuantikzOp(op::NoiseOpAll) = Quantikz.NoiseAll()
Quantikz.QuantikzOp(op::ClassicalXOR) = Quantikz.ClassicalDecision(sort([op.store, op.bits...]))
Quantikz.QuantikzOp(op::ClassicalXORConcreteWorkaround) = Quantikz.ClassicalDecision(sort([op.store, op.bits...]))

function lstring(pauli::PauliOperator)
v = join(("\\mathtt{$(o)}" for o in replace(string(pauli)[3:end],"_"=>"I")),"\\\\")
Expand Down
4 changes: 2 additions & 2 deletions src/affectedqubits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ affectedqubits(p::PauliOperator) = 1:length(p)
affectedqubits(m::Union{AbstractMeasurement,sMRX,sMRY,sMRZ}) = (m.qubit,)
affectedqubits(v::VerifyOp) = v.indices
affectedqubits(c::CliffordOperator) = 1:nqubits(c)
affectedqubits(c::ClassicalXOR) = ()
affectedqubits(c::ClassicalXORConcreteWorkaround) = ()

affectedbits(o) = ()
affectedbits(m::sMRZ) = (m.bit,)
affectedbits(m::sMZ) = (m.bit,)
affectedbits(c::ClassicalXOR) = (c.bits..., c.store)
affectedbits(c::ClassicalXORConcreteWorkaround) = (c.bits..., c.store)
27 changes: 25 additions & 2 deletions src/misc_ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,34 @@ end

operatordeterminism(::Type{VerifyOp}) = DeterministicOperatorTrait()

abstract type ClassicalXORConcreteWorkaround <: AbstractOperation end # See below for more of this abomination - replace everywhere by ClassicalXOR when compactification is fixed
"""Applies an XOR gate to classical bits. Currently only implemented for funcitonality with pauli frames."""
struct ClassicalXOR{N} <: AbstractOperation
struct ClassicalXOR{N} <: ClassicalXORConcreteWorkaround
"The indices of the classical bits to be xor-ed"
bits::NTuple{N,Int}
"The index of the classical bit that will store the results"
store::Int
function ClassicalXOR(bits, store) # See below for more of this abomination
tbits = tuple(bits...)
n = length(bits)
if n <= 15
return eval(Symbol("ClassicalXOR",string(n)))(tbits, store)
else
return new{n}(tbits, store)
end
end
end
#ClassicalXOR(bits::Vector, store::Int) = ClassicalXOR(tuple(bits...),store)
# XXX TODO remove this abomination
# Workaround for not being able to compactify non-concrete types
for n in 2:15
name = Symbol("ClassicalXOR",string(n))
eval(
quote
struct $name <: ClassicalXORConcreteWorkaround
bits::NTuple{$n,Int}
store::Int
end
end
)
end
ClassicalXOR(bits::Vector, store::Int) = ClassicalXOR(tuple(bits...),store)
2 changes: 1 addition & 1 deletion src/pauli_frames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function apply!(f::PauliFrame, op::AbstractCliffordOperator)
return f
end

function apply!(frame::PauliFrame, xor::ClassicalXOR)
function apply!(frame::PauliFrame, xor::ClassicalXORConcreteWorkaround)
for f in eachindex(frame)
value = frame.measurements[f,xor.bits[1]]
for i in xor.bits[2:end]
Expand Down

0 comments on commit efa6069

Please sign in to comment.