Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional group theory functions for error correction #351

Merged
merged 87 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
3ec3098
first commit
KDGoodenough Mar 28, 2024
dee1c59
added GT dependecies to project.toml
IsaacP1234 May 18, 2024
a708c00
started GT test file
IsaacP1234 May 20, 2024
8627fee
started groupify tests
IsaacP1234 May 20, 2024
3bf54ae
tests for groupify/generating set, pauli ops don't work
IsaacP1234 May 21, 2024
4f377b7
removing unnecessary dependencies
IsaacP1234 May 23, 2024
929607d
removed print statements
IsaacP1234 May 23, 2024
1161ff2
completed get_gen_set tests
IsaacP1234 May 27, 2024
da32a75
added phase arg to pualigroup and tests for normalize
IsaacP1234 May 28, 2024
09ea8b5
added tests for center, fixed center
IsaacP1234 May 28, 2024
e2af6b7
formatted tests
IsaacP1234 May 28, 2024
c1510a0
added changes to changelog
IsaacP1234 May 28, 2024
f22cf6e
removed SafeTestSets dependency, formatted changelog
IsaacP1234 May 28, 2024
5ded49b
fixed center function and pauligroup phases
IsaacP1234 May 28, 2024
59cf3be
added tests for logical_op_canonicalize
IsaacP1234 Jun 4, 2024
2076a52
updated LOC tests
IsaacP1234 Jun 4, 2024
b7d0eab
updated LOC tests and CHANGELOG
IsaacP1234 Jun 4, 2024
7694800
updated GGS+tests to work with I operators
IsaacP1234 Jun 17, 2024
bd5e63a
added method descriptions
IsaacP1234 Jun 18, 2024
d4265dd
removed print statements + fixed center tests
IsaacP1234 Jun 18, 2024
b9071e1
fixed changelog grammar
IsaacP1234 Jun 18, 2024
43f4736
formatted+commented unfinished functions
IsaacP1234 Jun 18, 2024
afa2d17
fixed changelog
IsaacP1234 Jun 18, 2024
c1282d8
completed changelog
IsaacP1234 Jun 18, 2024
79f8f75
removed unnecessary comments
IsaacP1234 Jun 22, 2024
0fc1725
moved pauli delete to p_o.jl
IsaacP1234 Jun 24, 2024
6029b7f
removed changelog update to prevent merge conflicts
IsaacP1234 Jul 6, 2024
d2bf12a
converted delete to deleteat! and moved to paulioperator.jl
IsaacP1234 Jul 6, 2024
b633615
finished contract, cleaned up code, added documentation
IsaacP1234 Jul 6, 2024
be86915
added tests for contract
IsaacP1234 Jul 6, 2024
61d2b9c
fixed spelling and added CUDA v5 to project.toml
IsaacP1234 Jul 9, 2024
e0ad281
fixed tests
IsaacP1234 Jul 14, 2024
ade696b
finished functions
IsaacP1234 Jul 14, 2024
e9d914f
including new code in tests and package
IsaacP1234 Jul 14, 2024
cb62f53
spell check, JET limit to 33, contractor renamed
IsaacP1234 Jul 15, 2024
ec06fc2
changing JET back to avoid merge conflict
IsaacP1234 Jul 15, 2024
8cc20f8
added see also, fixed doctests+polished documentation
IsaacP1234 Jul 21, 2024
2786c66
bugfixed tests and exporting
IsaacP1234 Jul 21, 2024
14714c2
removed refernce to delete_columns from traceout!
IsaacP1234 Jul 21, 2024
3b23fa9
fixed reference error
IsaacP1234 Jul 27, 2024
eb5dbfe
reset jet to 25
IsaacP1234 Jul 27, 2024
ee3a0fa
added changelog comments
IsaacP1234 Jul 28, 2024
121cd36
removed changelog
IsaacP1234 Jul 28, 2024
a2c8a17
minor doc cleanup
Krastanov Jul 30, 2024
ca05512
removed groupify from contractor and tests
IsaacP1234 Aug 1, 2024
cbd2208
Merge branch 'some_group_functions' of https://github.com/IsaacP1234/…
IsaacP1234 Aug 1, 2024
1697097
Merge branch 'master' into some_group_functions
Krastanov Aug 3, 2024
39af6f0
cleanup and changelog amd version bumb
Krastanov Aug 3, 2024
109104e
added LOC function
IsaacP1234 Aug 3, 2024
f77b7bd
added commutavise and tests
IsaacP1234 Aug 6, 2024
51d5ba6
exported commutavise and embed
IsaacP1234 Aug 13, 2024
0441e25
added testing for embed, improved groupify and normalize
IsaacP1234 Aug 23, 2024
256cfa0
made embed reversible and updated tests
IsaacP1234 Aug 30, 2024
a8a0133
cleaned up comments
IsaacP1234 Aug 30, 2024
c4d3cdc
fixed normalizer and doctests
IsaacP1234 Aug 30, 2024
7d3a7a3
add SSCT datastructure
IsaacP1234 Aug 30, 2024
7440d7d
resolve minor conflicts
IsaacP1234 Aug 30, 2024
3c5f917
merge conflict
IsaacP1234 Aug 30, 2024
8fdd651
fix merge conflicts+SSCT
IsaacP1234 Sep 4, 2024
a1c84b7
fix qc.jl merge conflict
IsaacP1234 Sep 4, 2024
688ca8c
fully implemented SSCT
IsaacP1234 Sep 6, 2024
5cfc2c9
Merge branch 'master' into loc-comm-embed
IsaacP1234 Sep 6, 2024
a4b73d2
spell check
IsaacP1234 Sep 6, 2024
b199101
fixed view functions+allowed identity operators
IsaacP1234 Sep 6, 2024
5b5b45b
fixed doctest
IsaacP1234 Sep 6, 2024
3d2f1d5
Fixing doctests
IsaacP1234 Sep 7, 2024
903d843
remove unnecessary qcdot
IsaacP1234 Sep 9, 2024
50fea07
renamed+changed docs+cleaned up
IsaacP1234 Sep 11, 2024
5500322
fixed doctests+added citations.
IsaacP1234 Sep 12, 2024
04c4c29
Merge branch 'loc-comm-embed' of https://github.com/IsaacP1234/Quantu…
IsaacP1234 Sep 12, 2024
5257f1a
improved docs+added referencese
IsaacP1234 Sep 15, 2024
64e1caa
updated SSCT docs
IsaacP1234 Sep 15, 2024
ee7beb3
fixed citing
IsaacP1234 Sep 16, 2024
c785372
test error fix
IsaacP1234 Sep 16, 2024
023550f
Merge branch 'master' into loc-comm-embed
Krastanov Sep 27, 2024
7f71467
fix whitespace issues (you can configure VScode to fix these automati…
Krastanov Sep 27, 2024
b0bb5e1
ident in bibfile
Krastanov Sep 27, 2024
e50620b
re-enable the tests (why were they disabled?)
Krastanov Sep 27, 2024
bfccfe1
doc and whitespace cleanup
Krastanov Sep 27, 2024
39daadd
do not create a new pauli operator each time a phase is changed
Krastanov Sep 27, 2024
06b9282
added show and fixed copy for SSCT
IsaacP1234 Oct 1, 2024
ea023ca
added mul_left method + fixed del_cols
IsaacP1234 Oct 2, 2024
b29e0f1
changed constructor and updated groupify
IsaacP1234 Oct 2, 2024
dd95172
minor cleanup
Krastanov Oct 25, 2024
c118dba
Merge branch 'master' into loc-comm-embed
Krastanov Oct 25, 2024
3adf539
changelog
Krastanov Oct 25, 2024
8f14bd3
Merge branch 'master' into loc-comm-embed
Krastanov Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export
graphstate, graphstate!, graph_gatesequence, graph_gate,
# Group theory tools
groupify, minimal_generating_set, pauligroup, normalizer, centralizer, contractor, delete_columns,
logical_operator_canonicalize, commutavise, embed, SubsystemCodeTableau,
Copy link
Member

Choose a reason for hiding this comment

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

@KDGoodenough , @IsaacP1234

  • Any preferences between commutavise and commutivise? Is this term used elsewhere by anyone else? Where does the name come frome?
  • Any other suggestions for logical_operator_canonicalize? The name is a bit long and I am not quite sure whether it conveys what is happening well.
  • embed as a name is already used for other purposes so this also would need to be renamed. There is already embed methods which embed a small unitary operator in a larger space by padding it with identities.

Copy link
Member

Choose a reason for hiding this comment

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

let's use the following name for logical_operator_canoninicalize to keep in similar to the other canonicalize methods we have:

canonicalize_noncomm

Copy link
Member

Choose a reason for hiding this comment

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

let's, for now, change commutavise to commutify to keep it in sync with simplify or lambdify or sympify

Copy link
Member

Choose a reason for hiding this comment

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

let's, for now, rename embed to matroid_parent

# Clipped Gauge
canonicalize_clip!, bigram, entanglement_entropy,
# mctrajectories
Expand Down
257 changes: 244 additions & 13 deletions src/grouptableaux.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,92 @@
using Graphs
using LinearAlgebra

"""
A tableau representation of the logical operator canonical form of a set of Paulis.
The index of the first operator that commutes with all others is tracked so that the
stabilizer, destabilizer, logical X, and logical Z aspects of the tableau can be
represented.
Copy link
Member

Choose a reason for hiding this comment

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

I do not think logical operator canonical form is a known thing in the field. Could we document this a bit more, with definitions and explanations for why this is interesting and useful, maybe a few doctest examples?

Check with Kenneth on this, maybe ask him to help with the documentation for it.

"""
mutable struct SubsystemCodeTableau <: AbstractStabilizer
tab::Tableau
Copy link
Member

Choose a reason for hiding this comment

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

Parameterize the tableau type (same as MixedDestabilizer for instance), to ensure type information is not lost here.

index::Int
r::Int
m::Int
k::Int
end
function SubsystemCodeTableau(t::Tableau)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this constructor necessary? It is a pretty expensive one. Should this not be a part of the canonicalize_noncomm function itself.

# identity = zero(PauliOperator, nqubits(t))
# num = 0
# for p in t
# if p == identity num+=1 end
# end
index = 1
for i in range(1, stop=length(t), step=2)
if i + 1 > length(t)
break
end
if comm(t[i], t[i+1]) == 0x01
index = i+2 # index to split loc into non-commuting pairs and commuting operators
end
end
s = Stabilizer(t[index:length(t)])
ind = 1
if length(s)>nqubits(s)#if stabilizer is overdetermined, Destabilizer constructor throws error
m = length(s)
tab = zero(Tableau, length(t)+length(s), nqubits(t))
for i in s
tab[ind] = zero(PauliOperator, nqubits(s))
ind+=1
end
else
d = Destabilizer(s)
m = length(d)
tab = zero(Tableau, length(t)+length(d), nqubits(t))
for p in destabilizerview(d)
tab[ind] = p
ind+=1
end
end
for i in range(1, stop=index-1, step=2)
tab[ind] = t[i]
ind+=1
end
for p in s

tab[ind] = p
ind+=1

end
for i in range(2, stop=index, step=2)
tab[ind] = t[i]
ind+=1
end
return SubsystemCodeTableau(tab, index, length(s), m, (index-1)/2)

end
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return SubsystemCodeTableau(tab, index, length(s), m, (index-1)/2)
end
return SubsystemCodeTableau(tab, index, length(s), m, (index-1)/2)
end


Base.length(t::SubsystemCodeTableau) = length(t.tab)
Copy link
Member

Choose a reason for hiding this comment

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

Is this used somewhere? Given the complicated internal structure, I am reluctant to define a "homogenous" length function as I am not sure what it would mean semantically. If it is not used, let's delete it.


Base.copy(t::SubsystemCodeTableau) = SubsystemCodeTableau(copy(t.tab))
Copy link
Member

Choose a reason for hiding this comment

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

This is a very expensive way to make a copy as you are redoing a ton of computation. It would be better if this just copies over the various indices as well.


"""A view of the subtableau corresponding to the stabilizer. See also [`tab`](@ref), [`destabilizerview`](@ref), [`logicalxview`](@ref), [`logicalzview`](@ref)"""
function stabilizerview(s::SubsystemCodeTableau)
return Stabilizer(@view tab(s)[s.m+s.k+1:s.m+s.k+s.r])
end
"""A view of the subtableau corresponding to the destabilizer. See also [`tab`](@ref), [`stabilizerview`](@ref), [`logicalxview`](@ref), [`logicalzview`](@ref)"""
function destabilizerview(s::SubsystemCodeTableau)
return Stabilizer(@view tab(s)[1:s.m])
end
"""A view of the subtableau corresponding to the logical X operators. See also [`tab`](@ref), [`stabilizerview`](@ref), [`destabilizerview`](@ref), [`logicalzview`](@ref)"""
function logicalxview(s::SubsystemCodeTableau)
return Stabilizer(tab(s)[s.m+1:s.m+s.k])
end
"""A view of the subtableau corresponding to the logical Z operators. See also [`tab`](@ref), [`stabilizerview`](@ref), [`destabilizerview`](@ref), [`logicalzview`](@ref)"""
function logicalzview(s::SubsystemCodeTableau)
return Stabilizer(tab(s)[s.m+1+s.k+s.r:length(s)])
end
Copy link
Member

Choose a reason for hiding this comment

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

No need to repeat the docstrings. Each one of these functions already has a docstring. Here you are defining new methods for these pre-existing functions. If the methods are novel or differing in some way, it makes sense to add new docstrings, bug given that these are just repeats of the already existing docstrings, they are not needed.

The help file will already give you the docstrings defined earlier.

You can just remove all four docstrings here.



"""
Return the full stabilizer group represented by the input generating set (a [`Stabilizer`](@ref)).

Expand All @@ -18,16 +104,17 @@ function groupify(s::Stabilizer)
# Create a `Tableau` of 2ⁿ n-qubit identity Pauli operators(where n is the size of
# `Stabilizer` s), then multiply each one by a different subset of the elements in s to
# create all 2ⁿ unique elements in the group generated by s, then return the `Tableau`.
n = length(s)::Int
group = zero(Tableau, 2^n, nqubits(s))
gen_set = minimal_generating_set(s)
n = length(gen_set)::Int
group = zero(Tableau, 2^n, nqubits(gen_set))
for i in 0:2^n-1
for (digit_order, j) in enumerate(digits(i, base=2, pad=n))
if j == 1
group[i+1] *= s[digit_order]
group[i+1] *= gen_set[digit_order]
Copy link
Member

Choose a reason for hiding this comment

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

mul_left!(group, gen_set, i+1, digit_order) would be drastically faster (it will be in-place, avoiding a lot of allocations).

Copy link
Member

Choose a reason for hiding this comment

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

By the way, does this function work correctly if there are terms with non-trivial phases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there are non-real phases it doesn't work because it uses minimal_generating_set which only accepts real phases. Should I rework it to work with imaginary phases or specify in the docs that it only accepts real phases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Additionally, there doesn't seem to be any method of mul_left! that can multiply a single row of a Tableau or Stabilizer by a Pauli. Just indexing doesn't change the original structure.

Copy link
Member

Choose a reason for hiding this comment

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

just writing down what we discussed in the call: just add a kwargument phases=false, and throw an error if someone tries to run phases=true with some message about it not being implemented

For mul_left! could you please just add a new method for it, basically just making a second more general version of this one in the same file

@inline function mul_left!(s::Tableau, m, i; phases::Val{B}=Val(true)) where B

I think it would be just

@inline function mul_left!(s::Tableau, m, t::Tableau, i; phases::Val{B}=Val(true)) where B
    extra_phase = mul_left!((@view s.xzs[:,m]), (@view t.xzs[:,i]); phases=phases)
    B && (s.phases[m] = (extra_phase+s.phases[m]+s.phases[i])&0x3)
    s
end

and then do tab(stabilizer) wherever you call it

end
end
end
return group
return group
end
Krastanov marked this conversation as resolved.
Show resolved Hide resolved


Expand Down Expand Up @@ -59,9 +146,143 @@ function minimal_generating_set(s::Stabilizer)
end
end

"""
For a not-necessarily commutative set of Paulis, returning a generating set of the form
<A₁, B₁, A₂, B₂, ... Aₖ, Bₖ, Aₖ₊₁, ... Aₘ> where two operators anticommute if and only if they
Copy link
Member

Choose a reason for hiding this comment

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

The order of operators does not seem correct anymore

are of the form Aₖ, Bₖ and commute otherwise.

Returns the generating set as a data structure of type [`SubsystemCodeTableau`](@ref).
Copy link
Member

Choose a reason for hiding this comment

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

Mention the four different view functions that can be used to access this structure


```jldoctest
julia> tab(logical_operator_canonicalize(QuantumClifford.Tableau([P"XX", P"XZ", P"XY"])))
Copy link
Member

Choose a reason for hiding this comment

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

we should just make Tableau and T_str public. The documentation should not refer to code and structures that are not public, so if this is necessary for your example, we should consider exporting the appropriate symbols.

+ Z_
+ XX
-iX_
Copy link
Member

Choose a reason for hiding this comment

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

The presence of an i phase is very suspicious to me. A @KDGoodenough , could you check if this is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is happening because the function multiplies PauliOperators together to reduce anticommutivity. resulting in i phases when Paulis like XXY and XXZ are multiplied together. If desired, I can eliminate these i phases from the final output.

Copy link
Member

Choose a reason for hiding this comment

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

yup, let's just remove the phases

+ XZ
```
"""
function logical_operator_canonicalize(t:: QuantumClifford.Tableau)
loc = zero(QuantumClifford.Tableau, length(t), nqubits(t))
IsaacP1234 marked this conversation as resolved.
Show resolved Hide resolved
index = 1
for i in eachindex(t)
for j in eachindex(t)
if comm(t[i], t[j]) == 0x01
for k in eachindex(t)
if k !=i && k != j
if comm(t[k], t[i]) == 0x01
t[k] = t[j] *t[k]
Copy link
Member

Choose a reason for hiding this comment

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

mul_left!

Copy link
Member

Choose a reason for hiding this comment

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

with phases=false

end
if comm(t[k], t[j]) == 0x01
t[k] = t[i] *t[k]
Copy link
Member

Choose a reason for hiding this comment

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

mul_left!

Copy link
Member

Choose a reason for hiding this comment

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

with phases=false

end
end
end
if !(t[i] in loc || -1 *t[i] in loc || 1im *t[i] in loc || -1im * t[i] in loc)
Copy link
Member

Choose a reason for hiding this comment

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

This will probably be extremely slow (especially the phase modification and check... maybe zero out all the phases at the very start to not worry about this). That way it can be one single check instead of 4.

loc[index]= t[i]
index+=1
end
if !(t[j] in loc || -1 *t[j] in loc || 1im *t[j] in loc || -1im * t[j] in loc)
Copy link
Member

Choose a reason for hiding this comment

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

same comment about cost of check

loc[index]= t[j]
index+=1
end
end
end
end
for i in eachindex(t)
if !(t[i] in loc || -1 *t[i] in loc || 1im *t[i] in loc || -1im * t[i] in loc)
loc[index]= t[i]
index+=1
end
end
while length(loc) > 1 && loc[length(loc)-1] == zero(PauliOperator, nqubits(loc))
loc = loc[1:(length(loc)-1)]
end
return SubsystemCodeTableau(loc)
Copy link
Member

Choose a reason for hiding this comment

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

Can you give the constructor more information so it does not run all that expensive processing and searching?

end

"""
For a not-necessarily commutative set of Paulis, return the logical operator canonical
form of that set, and for each pair Aₖ, Bₖ of anticommutative Paulis, add an X to Aₖ,
a Z to Bₖ, and an I to each other operator, such that the set is now fully commutative
as well as return a list of the indices of the added qubits.
Copy link
Member

Choose a reason for hiding this comment

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

Could you significantly expand this into multiple sentences and definitions? Currently, it is one long sentence and it is pretty difficult to understand.

Could you also add a comment on what this is useful for? Is there a reference for this? Probably check with Kenneth about documenting it a bit more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used in the 'matroid_parent' function. By comment, do you mean as a comment in the code or a line in the documentation?

Copy link
Member

Choose a reason for hiding this comment

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

In the docs. And in terms of use, do mention matroid_parent but more generally mention why one would use it in principle.


Phases are ignored, and returned Stabilizers contain only the + phase

```jldoctest
julia> commutavise(QuantumClifford.Tableau([P"XX", P"XZ", P"XY"]))[1]
+ XXX
+ XZZ
+ X__

julia> commutavise(QuantumClifford.Tableau([P"XX", P"XZ", P"XY"]))[2]
1-element Vector{Any}:
3
```
"""
function commutavise(t)
Copy link
Member

Choose a reason for hiding this comment

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

mentioned elsewhere as well, but let's bikeshed the name a bit. Currently it is not very clear what it means and whether there is a precedent for this name (precedent is not necessary, but it helps)

loc = QuantumClifford.logical_operator_canonicalize(t)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
loc = QuantumClifford.logical_operator_canonicalize(t)
loc = logical_operator_canonicalize(t)

commutative = zero(Stabilizer, 2*loc.k+loc.r, nqubits(loc)+loc.k)
ind = 1
for i in 1:loc.k
dummy = commutative[ind]
for j in eachindex(logicalxview(loc)[i]) dummy[j] = logicalxview(loc)[i][j] end
dummy[nqubits(loc)+i] = (true, false)
commutative[ind] = dummy
ind+=1
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need the dummy? I think the following two are equivalent:

dummy[j] = ...
commutative[ind, j] = ...

More generally though, I have the impression that a lot of this code (at least all of the inner loops) can be replaced with just 4 calls to puttableaux!:

@inline function puttableau!(target::Tableau{V1,M1}, source::Tableau{V2,M2}, row::Int, col::Int; phases::Val{B}=Val(true)) where {B,V1,V2,T<:Unsigned,M1<:AbstractMatrix{T},M2<:AbstractMatrix{T}}

end
for i in 1:loc.k
dummy = commutative[ind]
for j in eachindex(logicalzview(loc)[i]) dummy[j] = logicalzview(loc)[i][j] end
dummy[nqubits(loc)+i] = (false, true)
commutative[ind] = dummy
ind+=1
end
for i in 1:loc.r
dummy = commutative[ind]
for j in eachindex(stabilizerview(loc)[i]) dummy[j] = stabilizerview(loc)[i][j] end
commutative[ind] = dummy
ind+=1
end
to_delete = []
Copy link
Member

Choose a reason for hiding this comment

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

something more like nqubits+1:nqubits+k would be much simpler and faster

for i in 1:loc.k
push!(to_delete, i+nqubits(tab(loc)))
end
return commutative, to_delete
end

"""
For a given set of Paulis that does not necessarily represent a state, return a set of
Paulis that contains the commutativised given set and represents a state, as well as deletions
needed to return to the original set of Paulis.

By deleting the qubits in the first returned array, taking the normalizer, then deleting the qubits in the
second returned array from the normalizer, the original set is produced.
Copy link
Member

Choose a reason for hiding this comment

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

Add references to the related functions which you are talking about (e.g. commutavise).

Copy link
Member

Choose a reason for hiding this comment

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

This is a bit difficult to follow. Could you rewrite it with shorter sentences and fewer pronouns/references ("original set", "returned array", etc are pretty difficult to follow). Maybe introduce names / letters and some definitions.


```jldoctest
julia> embed(QuantumClifford.Tableau([P"XX"]))[1]
Copy link
Member

Choose a reason for hiding this comment

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

making Tableau public (and just using the T macro)

+ X_X
+ ZZZ
+ XX_
+ ___

julia> embed(QuantumClifford.Tableau([P"XX"]))[2]
1-element Vector{Any}:
Copy link
Member

Choose a reason for hiding this comment

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

these should be ranges or vectors of ints, not vectors of any

3

julia> embed(QuantumClifford.Tableau([P"XX"]))[3]
Any[]
Copy link
Member

Choose a reason for hiding this comment

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

these should be ranges or vectors of ints, not vectors of any

```
"""
function embed(t::QuantumClifford.Tableau)
Copy link
Member

Choose a reason for hiding this comment

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

needs a different name, check with Kenneth as well

com, d1= QuantumClifford.commutavise(t)
norm = QuantumClifford.normalizer(com.tab)
state, d2 = QuantumClifford.commutavise(norm)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
com, d1= QuantumClifford.commutavise(t)
norm = QuantumClifford.normalizer(com.tab)
state, d2 = QuantumClifford.commutavise(norm)
com, d1= commutavise(t)
norm = normalizer(com.tab)
state, d2 = commutavise(norm)

return state, d2, d1
end

"""
Return the full Pauli group of a given length. Phases are ignored by default,
but can be included by setting `phases=true`.
but can be included by setting `phases = true`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
but can be included by setting `phases = true`.
but can be included by setting `phases=true`.


```jldoctest
julia> pauligroup(1)
Expand Down Expand Up @@ -130,27 +351,37 @@ julia> normalizer(T"X")
+ X
```
"""
function normalizer(t::Tableau)
function normalizer(t::Tableau; phases=false)
# For each `PauliOperator` p in the with same number of qubits as the `Stabilizer` s, iterate through s and check each
# operator's commutivity with p. If they all commute, add p a vector of `PauliOperators`. Return the vector
# converted to `Tableau`.
n = nqubits(t)
pgroup = pauligroup(n, phases=false)
ptype = typeof(t[1])
normalizer = ptype[]
for p in pgroup
ptype =typeof(P"I")
norm = ptype[]

p = zero(PauliOperator, n)
paulis = ((false, false), (true, false), (false, true), (true, true))
for i in Iterators.product(Iterators.repeated(paulis, n)...)
QuantumClifford.zero!(p)
for (j, k) in enumerate(i)
p[j] = k
end
commutes = true
for q in t
if comm(p, q) == 0x01
commutes = false
end
end
if commutes
push!(normalizer, p)
push!(norm, copy(p))
end
if phases
for phase in [-1, 1im, -1im]
push!(norm, phase *p)
end
end
end

return Tableau(normalizer)
return QuantumClifford.Tableau(norm)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return QuantumClifford.Tableau(norm)
return Tableau(norm)

end

"""
Expand Down
Loading
Loading