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

Correct set_index(Stabilizer_Tableau, rows, cols) #287

Closed
Fe-r-oz opened this issue Jun 6, 2024 · 2 comments
Closed

Correct set_index(Stabilizer_Tableau, rows, cols) #287

Fe-r-oz opened this issue Jun 6, 2024 · 2 comments

Comments

@Fe-r-oz
Copy link
Contributor

Fe-r-oz commented Jun 6, 2024

Suppose

julia> H
+ X_X_ZYZY
+ X_YZX_YZ
+ XZ_Y_YXZ

I want to apply Hadamard Rotation operaton to each element in each row, H*X

julia> for rows in 1:3
                 for cols in 1:2^3
                       setindex!(H, rows, cols) = sHadamard(1)*H[[rows], [cols]]                                                                                                
                  end 
          end     

I get wrong output, no change!
julia> H
+ X_X_ZYZY
+ X_YZX_YZ
+ XZ_Y_YXZ

Expected Output

 Z_Z_XYXY
Z_YXZ_YX
ZX_Y_YZX

There seems to be a problem with setindex! Because H operation is applied correctly as shown in the output

julia> for rows in 1:3
              for cols in 1:2^3
                    println(sHadamard(1)*Hⱼ[[rows], [cols]] )                                                                                                                                                                                                                                                        
              end
           end
+ Z
+ _
+ Z
+ _
+ X
- Y
+ X
- Y
+ Z
+ _
- Y
+ X
+ Z
+ _
- Y
+ X
+ Z
+ X
+ _
- Y
+ _
- Y
+ Z
+ X
                           

The problem either lies in the assignment ( setindex!(H, rows, cols)) or in setindex! Please feel free to assign an better name to the issue.

@Fe-r-oz Fe-r-oz changed the title Correct set_index(Stabilizer_Tableau, rows, rols) Correct set_index(Stabilizer_Tableau, rows, cols) Jun 6, 2024
@Krastanov
Copy link
Member

I think there is some conceptual confusion here. A gate is supposed to be applied to the tableau (state) as a whole, not row-by-row. Thus I am not sure what setindex!(H, rows, cols) = sHadamard(1)*H[[rows], [cols]] is supposed to do.

If one wants to apply a gate, they should just do apply!(state, sHadamard(qubit_index)) (which is also non-allocating, unlike this loop).

If the Hadamard needs to be applied to all qubits, it would looks something like:

for q_i in 1:nqubits(state)
    apply!(state, sHadamard(q_i))
end

There is a bit of a misuse of julia syntax here, which is a separate problem. If you want to set an index, you should write:

H[rows, cols] = sHadamard(1)*H[[rows], [cols]]

Instead, you are writing

setindex!(H, rows, cols) = sHadamard(1)*H[[rows], [cols]]                                                                                                

which simply redefines the setindex! function. You are defining new methods, not calling a function with this syntax.

For the moment I will close this issue, but feel free to reopen it if something was unclear.

@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Jun 14, 2024

Thanks a lot!

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

No branches or pull requests

2 participants