Skip to content

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

Open
@aschmitz87

Description

@aschmitz87

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions