-
I noticed that there are differences in the runtime of Maybe this is a feature not a bug, such that the user can decide if the whole state is always considered in calculation; but since the register holds physically the same state and it makes a large difference performance wise, it would be good for the user to get e.g., a warning that not only the specific subspace is used during calculation but the whole initialized Hilbert space. Expected behavior I would expect the below example to either run with the same execution time or trigger a warning in case 1. Minimal Reproducible Example 👇 using QuantumSavory
n = 15
# Case 1: register initialized with X1 product state
reg = Register(n, QuantumOpticsRepr())
initialize!(reg[1:n], reduce(⊗, fill(X1,n)))
timed_compile = @elapsed apply!((reg[1]), H)
timed_compute = @elapsed apply!((reg[1]), H)
@info timed_compile, timed_compute
# Case 2: register initialized with X1 individual states
reg = Register(n, QuantumOpticsRepr())
for i in 1:n initialize!(reg[i], X1) end
timed_compile = @elapsed apply!(reg[1], H)
timed_compute = @elapsed apply!(reg[1], H)
@info timed_compile, timed_compute [ Info: (48.7393675, 46.076166333)
[ Info: (0.072435042, 0.000156375) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
I am converting this to a discussion as it is an interesting question, but it is not a bug, rather an expected behavior. If you initialize To be fair, in your particular case we are not given a state vector, rather we are given a symbolic tensor product. So in principle it is possible to special-case the tensor product. I will look into this... I guess I should not have converted this to a discussion :D But the bigger point is, this type of "detect that a big state is separable" are generally expensive and unreliable and code should be structured to not expect them to exist. |
Beta Was this translation helpful? Give feedback.
-
Here is an attempt to do a special case for tensor products: Here is the result on my computer for your benchmarks:
|
Beta Was this translation helpful? Give feedback.
-
It is now merged. Let me know if you still have this slowdown |
Beta Was this translation helpful? Give feedback.
I am converting this to a discussion as it is an interesting question, but it is not a bug, rather an expected behavior.
If you initialize
n
slots to an entangled multi-qubit state, behind the scenes we need to store2^n
complex numbers. If the state is not entangled but completely separable, it isn*2
complex numbers. But if you are given an arbitrary state vector, it is a very expensive operation to check whether the state is entangled or not, so we can not automatically go to the non-entangled storage format.To be fair, in your particular case we are not given a state vector, rather we are given a symbolic tensor product. So in principle it is possible to special-case the tensor produ…