You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The results of the "QubitRegister::ExpectationValueX", "...Y" and "...Z" are incorrect if the state is not normalized.
To Reproduce
The error can be seen from the following code snippet:
QubitRegister<ComplexDP> test(1, "base", 0);
iqs::TinyMatrix<ComplexDP, 2, 2, 32> IDby2;
IDby2(0,1) = IDby2(1,0) = ComplexDP(0., 0.);
IDby2(0,0) = IDby2(1,1)= ComplexDP(std::sqrt(0.5), 0.);
test. Apply1QubitGate(0, IDby2); // state now has a square norm of 1/2.
test.ApplyPauliX(0); //state is |\psi> = 1/sqrt(2) |1>
assert(test.ExpectationValueZ(0) == -0.5); //value should be -1/2 due to un-normalized state
//actual value: test.ExpectationValueZ(0) == 0.
Additional context
I was able to track down the problem. In the expectation value functions, a gate is applied to change the basis to the appropriate Pauli operator, and then the value is calculated via the lines 24, 50 and 72 of "src/qureg_expectval.cpp":
Describe the bug
The results of the "QubitRegister::ExpectationValueX", "...Y" and "...Z" are incorrect if the state is not normalized.
To Reproduce
The error can be seen from the following code snippet:
Additional context
I was able to track down the problem. In the expectation value functions, a gate is applied to change the basis to the appropriate Pauli operator, and then the value is calculated via the lines 24, 50 and 72 of "src/qureg_expectval.cpp":
This expression assumes the vector is normalized. In particular 1. -> (state norm)^2 for this to be correct in general.
The text was updated successfully, but these errors were encountered: