Closed Fe-r-oz closed 2 weeks ago
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.
Thanks a lot!
Suppose
I want to apply Hadamard Rotation operaton to each element in each row, H*X
Expected Output
There seems to be a problem with
setindex!
Because H operation is applied correctly as shown in the outputThe problem either lies in the assignment
( setindex!(H, rows, cols))
or insetindex!
Please feel free to assign an better name to the issue.