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

Horizontal concatenation for Tableaux #304

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Fe-r-oz
Copy link
Contributor

@Fe-r-oz Fe-r-oz commented Jul 1, 2024

For hcat, it seems we would need a something like this if we suppose that we have a s1 as 4x4 and s2 as 4x4 stabilizers

julia> hcat(s1, s2),
1-element Vector{Stabilizer{QuantumClifford.Tableau{Vector{UInt8}, Matrix{UInt64}}}}:
 Stabilizer 4×8

julia> vcat(s1, s2)
2-element Vector{Stabilizer{QuantumClifford.Tableau{Vector{UInt8}, Matrix{UInt64}}}}:
 Stabilizer 4×4
 Stabilizer 4×4

This will give method error was we are dealing with AbstractVectors

julia> hcat(s1, s2)
1×2 Matrix{Stabilizer{QuantumClifford.Tableau{Vector{UInt8}, Matrix{UInt64}}}}:
 Stabilizer 4×4  Stabilizer 4×4

I have added the if check that Tableus rows must be the same for horizontal concatenation.

julia> using QuantumClifford.ECC
julia> s1 = random_stabilizer(4)
+ X_XZ
+ X_ZX
- ZX_Y
+ _YXZ

julia> s2 = random_stabilizer(4)
+ _XYY
+ ZYXY
+ _YYX
- ZXYY

julia> vcat(s1,s2)
+ X_XZ
+ X_ZX
- ZX_Y
+ _YXZ
+ _XYY
+ ZYXY
+ _YYX
- ZXYY

I am trying to figure out what happends to the phase vector, In the vcat it is concatenated vertically which makes sense but in hcat, we don't want. We want the size of phase vector to remain the same but phases modified maybe


julia> hcat(s1,s2)
+ + becomes + ? X_XZ_XYY
+ + becomes + ? X_ZXZYXY
+ - becomes - ? ZX_Y_YYX
- + becomes - ? _YXZZXYY

At the moment, hcat is not performing as expected

julia> using QuantumClifford.ECC
julia> s1 = random_stabilizer(4)
- X_XZ
- _YYX
- Y__X
- ZYXY

julia> s2 = random_stabilizer(4)
+ ZXYZ
- XX_X
- ZYZ_
+ _XXX

julia> s2 = random_stabilizer(2)
+ XX
- YZ

julia> hcat(s1, s2)
ERROR: ArgumentError: All Tableaus must have the same number of qubits for horizontal concatenation.
Stacktrace:
 [1] hcat
   @ ~/GitHub/QuantumClifford/QuantumClifford.jl/src/QuantumClifford.jl:929 [inlined]
 [2] hcat(::Stabilizer{QuantumClifford.Tableau{Vector{UInt8}, Matrix{UInt64}}}, ::Stabilizer{QuantumClifford.Tableau{Vector{UInt8}, Matrix{UInt64}}})
   @ QuantumClifford ~/GitHub/QuantumClifford/QuantumClifford.jl/src/QuantumClifford.jl:937
 [3] top-level scope
   @ REPL[6]:1

julia> s2 = random_stabilizer(4)
+ X_ZY
- XYZ_
- X__Y
+ ZZZX

julia> hcat(s1, s2) gives me the s1
- X_XZ
- _YYX
- Y__X
- ZYXY

I have trouble understanding what's hcat xzs is doing inside the vcat function, If xzs are horizontal arrays then horizontally concatenating them form a matrix which makes sense. Since xzs is an AbstractMatrix and hcating them (not sure whats hcat is doing, maybe we are creating a vector of matrices by hcatting then we can perform vcat by wrapper of stabilizers for vcat?

function Base.vcat(tabs::Tableau...)
    Tableau(
        vcat((s.phases for s in tabs)...),
        tabs[1].nqubits,
        hcat((s.xzs for s in tabs)...)) ❓ 
end

Thanks for your help!

@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Jul 1, 2024

A very minor addition towards right track maybe, We need sum(s.nqubits for s in tabs), previouly I was doing tabs[1].nqubits,

julia> s1 = random_stabilizer(4)
+ XX_X
- ZXZY
+ ZYX_
+ YYZ_

julia> s2 = random_stabilizer(4)
- _XYX
+ ZZZX
+ YYYZ
- YZX_

julia> hcat(s1, s2) # maybe right track
+ XX_X____
- ZXZY____
+ ZYX_____
+ YYZ_____

Copy link

codecov bot commented Jul 1, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 82.77%. Comparing base (dddaedb) to head (f7e0a71).

Files Patch % Lines
src/QuantumClifford.jl 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #304      +/-   ##
==========================================
- Coverage   82.85%   82.77%   -0.08%     
==========================================
  Files          60       60              
  Lines        3971     3977       +6     
==========================================
+ Hits         3290     3292       +2     
- Misses        681      685       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

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

Thanks for starting this draft. I left a few quick comments that hopefully would be of help.

You know, but just a reminder, this also will need to have tests.

@@ -5,6 +5,10 @@

# News

## v0.9.5 - dev

- Addition of a horizontal concatenation for Tableaus -- `hcat`.
Copy link
Member

Choose a reason for hiding this comment

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

It is a French word, so the plural is a bit weird: tableaux, not tableaus.

# Ensure all Tableaus have the same number of rows
nqubits = tabs[1].nqubits
if !all(t -> t.nqubits == nqubits, tabs)
throw(ArgumentError("All Tableaus must have the same number of qubits for horizontal concatenation."))
Copy link
Member

Choose a reason for hiding this comment

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

same spelling issue

Tableau(
tabs[1].phases, #does not make sense, better method needed for phases concatenation
sum(s.nqubits for s in tabs),
hcat((s.xzs for s in tabs)...))
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 this would actually work, as the xzs array is padded with zeros. Probably it would be necessary to first allocate the empty larger tableau and to insert the smaller tableaux at the appropriate indices. I think the setindex functions are already relatively efficient and can be used directly here.

Copy link
Member

Choose a reason for hiding this comment

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

you also see this in the example you have already posted as a comment above

@Fe-r-oz Fe-r-oz changed the title Horizontal concatenation for Tableaus Horizontal concatenation for Tableaux Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants