mthree.utils.marginal_distribution

marginal_distribution(dist, indices, mapping=None)[source]

Grab the marginal counts from a given distribution.

If an operator is passed for the indices then the position of the non-identity elements in the string will be used to set the indices to marginalize over.

The mapping passed will be marginalized so that it can be directly used in applying the correction. The type of mapping at output is the same as that input.

Parameters:
  • dist (dict) – Input distribution

  • indices (array_like or str) – Indices (qubits) to keep or operator string

  • mapping (dict or array_like) – Optional, final measurement mapping.

Returns:

Marginal distribution list or dict: The reduced mapping if an optional mapping (list or dict) is given

Return type:

dict

Raises:
  • M3Error – Operator length does not equal bit-string length

  • M3Error – One or more indices is out of bounds