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

Single qubit expectation values give incorrect results if state is not normalized #75

Open
aschmitz87 opened this issue Jan 31, 2022 · 0 comments

Comments

@aschmitz87
Copy link

aschmitz87 commented Jan 31, 2022

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":

 BaseType expectation = 1. - 2.*GetProbability(qubit);

This expression assumes the vector is normalized. In particular 1. -> (state norm)^2 for this to be correct in general.

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

1 participant