Closed kuehnste closed 4 years ago
The measurement is an evaluation of the operator against the state as prepared by the circuit. To have the eigenvalue as you expect that state supplied by the circuit needs to be the corresponding eigenstate.
Try running VQE on H2 which uses the variational principle to find the minimum eigenvalue. The circuit as described by the variational form (ansatz) at that point will describe eigenstate. For instance the following added to the end of your file correctly evaluates to -3.0 . If you get the parameters for RY at that point you can get the circuit corresponding to that and use it in your code to see that with the right state you will get -3.0
# Get min eigval using VQE
from qiskit.aqua.algorithms import VQE
from qiskit.aqua.components.variational_forms import RY
from qiskit.aqua.components.optimizers import SLSQP
result = VQE(H2, RY(H2.num_qubits), SLSQP()).run(quantum_instance=BasicAer.get_backend('statevector_simulator'))
print('VQE result: {}'.format(result['energy']))
The circuit given in my example prepares the ground state of the Hamiltonian, which is also unique as the exact diagonalization results show. My point is not that I want to get the ground state, but rather that H and H2 are the same operator, the only difference is that H2 is constructed as H2 = 0.5 XX - 0.5 YY - 0.5 ZZ + 0.5 XX - 0.5 YY -0.5 ZZ, whereas H is constructed as H = XX - YY - ZZ. Hence, up to statistical fluctuations due to a finite number of shots, the qasm simulator should yield identical results in both cases if I evaluate it with the same circuit. In fact <psi|H|psi> / <psi|psi> cannot be lower than the ground state energy of the system (up to accumulating errors from measuring the Hamiltonian terms individually with a finite number of shots). So how can measuring H2 yield -6.0?
Thanks it turned out to be a bug in the processing/simplification of the pauli list that is passed.
Informations
What is the current behavior?
Using the output of the function construct_evaluation_circuit of the class WeightedPauliOperator to measure an operator yields an incorrect result in a certain case. The value obtained is twice the correct one.
Steps to reproduce the problem
What is the expected behavior?
Since it is the same Hamiltonian and also the function print_details() shows that it is the same WeightedPauliOperator, the measurement should yield a value of -3 in both cases.
Suggested solutions
Measurement should yield consistent results.