iqm.error_reduction_tools.utils.general_utils.marginalize_counts

iqm.error_reduction_tools.utils.general_utils.marginalize_counts#

iqm.error_reduction_tools.utils.general_utils.marginalize_counts(counts, qubit_indices)#

Marginalize counts with respect to a subset of qubits.

Parameters:
  • counts (dict[str, int]) – A dictionary of counts with bitstrings as keys.

  • qubit_indices (list[int]) – A list of qubit indices to keep.

Return type:

dict[str, int]

Note

The qubit indexes relates to the bitstring in little-endian format (consistent with qiskit.result.marginal_counts).

Example

>>> counts = {"000": 10, "100": 20, "110": 10}
>>> qubit_indices = [2]
>>> marginalize_counts(counts, qubit_indices)
{'0': 10, '1': 30}
Returns:

A dictionary of marginalized counts.

Raises:

ValueError – If qubit indices are outside of valid range.

Parameters:
Return type:

dict[str, int]