iqm.error_reduction_tools.utils.general_utils.expectation_from_counts

iqm.error_reduction_tools.utils.general_utils.expectation_from_counts#

iqm.error_reduction_tools.utils.general_utils.expectation_from_counts(counts, pauli_string=None)#

Calculate expectation value of a Pauli string from measurement counts.

Parameters:
  • counts (dict[str, int] | dict[str, float]) – Dictionary mapping bitstrings to their counts (int or float after mitigation).

  • pauli_string (str | None) – String of Pauli operators (‘I’ or ‘Z’) for each qubit. If None, defaults to all ‘Z’ operators.

Return type:

float

Note

Bitstrings and Pauli strings both follow the same ordering (typically little-endian). This is consistent with qiskit.result.sampled_expectation_value.

Example

>>> counts = {"01": 10}
>>> pauli_string = "ZI"
>>> expectation_from_counts(counts, pauli_string)
1.0
Returns:

Expectation value.

Parameters:
Return type:

float