QuEraComputing / Bloqade.jl

Package for the quantum computation and quantum simulation based on the neutral-atom architecture.
https://queracomputing.github.io/Bloqade.jl/dev/
Other
181 stars 35 forks source link

Referencing uninitialized data #464

Open dojt opened 1 year ago

dojt commented 1 year ago

Hey guys,

Is it possible that vm[m+1] may be read out without having been initialized in the following line?

https://github.com/QuEraComputing/Bloqade.jl/blob/4c3b0be48a9840e6f5dd2abd307e44bc2c964717/lib/BloqadeKrylov/src/expmv.jl#L129

It seems to me that it could happen if the "happy breakdown" occurs for j==m in the 1st iteration of the while loop, no?

Roger-luo commented 1 year ago

Good catch... but I'd say this is quite an edge case for evaluation of boxed array, could you elaborate on why this needs to be a Real?

I think a simple fix could be to initialize them to zero since the actual value will be assigned later or not used anyways.

Roger-luo commented 1 year ago

Right, I think using uninitialized memory here is fine, as the Vector{Float64}(undef, n) is usually small (tho not guaranteed), and thus err1 >> err2 is always true. So we could change the initialization from similar to zero which will be a bit costly, but probably not a big deal at all.

This is why I ask what would be the use case for Real or the above case since I think this is really an edge case, it'd be nice to make a decision if there is an actual use case effected by this.