-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Closed
Copy link
Description
The calculation for the expectation value of the identity operator seems incorrect when the statevector is not normalized to 1.
I think the reason is that one should use the norm squared rather than the norm in the following lines.
qiskit/qiskit/quantum_info/states/statevector.py
Lines 478 to 479 in 1be2c5a
if x_mask + z_mask == 0: | |
return pauli_phase * np.linalg.norm(self.data) |
The whole function is attached below to provide context.
qiskit/qiskit/quantum_info/states/statevector.py
Lines 458 to 491 in 1be2c5a
def _expectation_value_pauli(self, pauli, qargs=None): | |
"""Compute the expectation value of a Pauli. | |
Args: | |
pauli (Pauli): a Pauli operator to evaluate expval of. | |
qargs (None or list): subsystems to apply operator on. | |
Returns: | |
complex: the expectation value. | |
""" | |
n_pauli = len(pauli) | |
if qargs is None: | |
qubits = np.arange(n_pauli) | |
else: | |
qubits = np.array(qargs) | |
x_mask = np.dot(1 << qubits, pauli.x) | |
z_mask = np.dot(1 << qubits, pauli.z) | |
pauli_phase = (-1j) ** pauli.phase if pauli.phase else 1 | |
if x_mask + z_mask == 0: | |
return pauli_phase * np.linalg.norm(self.data) | |
if x_mask == 0: | |
return pauli_phase * expval_pauli_no_x(self.data, self.num_qubits, z_mask) | |
x_max = qubits[pauli.x][-1] | |
y_phase = (-1j) ** pauli._count_y() | |
y_phase = y_phase[0] | |
return pauli_phase * expval_pauli_with_x( | |
self.data, self.num_qubits, z_mask, x_mask, y_phase, x_max | |
) | |
Metadata
Metadata
Assignees
Labels
No labels