Skip to main contentIBM Quantum Documentation

Experiment Results

qiskit.result

Result(backend_name, backend_version, ...[, ...])Model for Results.
ResultError(error)Exceptions raised due to errors in result output.
Counts(data[, time_taken, creg_sizes, ...])A class to store a counts result from a circuit execution.

marginal_counts

qiskit.result.marginal_counts(result, indices=None, inplace=False, format_marginal=False, marginalize_memory=True) GitHub(opens in a new tab)

Marginalize counts from an experiment over some indices of interest.

Parameters

  • result (dict(opens in a new tab) |Result) – result to be marginalized (a Result object or a dict(str, int) of counts).
  • indices (List(opens in a new tab)[int(opens in a new tab)] | None) – The bit positions of interest to marginalize over. If None (default), do not marginalize at all.
  • inplace (bool(opens in a new tab)) – Default: False. Operates on the original Result argument if True, leading to loss of original Job Result. It has no effect if result is a dict.
  • format_marginal (bool(opens in a new tab)) – Default: False. If True, takes the output of marginalize and formats it with placeholders between cregs and for non-indices.
  • marginalize_memory (bool(opens in a new tab) | None) – If True, then also marginalize the memory field (if present). If False, remove the memory field from the result. If None, leave the memory field as is.

Returns

A Result object or a dictionary with

the observed counts, marginalized to only account for frequency of observations of bits of interest.

Return type

Result or dict(opens in a new tab)(str(opens in a new tab), int(opens in a new tab))

Raises

QiskitError – in case of invalid indices to marginalize over.

marginal_distribution

qiskit.result.marginal_distribution(counts, indices=None, format_marginal=False) GitHub(opens in a new tab)

Marginalize counts from an experiment over some indices of interest.

Unlike marginal_counts() this function respects the order of the input indices. If the input indices list is specified then the order the bit indices are specified will be the output order of the bitstrings in the marginalized output.

Parameters

Returns

A marginalized dictionary

Return type

dict(opens in a new tab)(str(opens in a new tab), int(opens in a new tab))

Raises

  • QiskitError – If any value in indices is invalid or the counts dict
  • is invalid.

marginal_memory

qiskit.result.marginal_memory(memory, indices=None, int_return=False, hex_return=False, avg_data=False, parallel_threshold=1000) GitHub(opens in a new tab)

Marginalize shot memory

This function is multithreaded and will launch a thread pool with threads equal to the number of CPUs by default. You can tune the number of threads with the RAYON_NUM_THREADS environment variable. For example, setting RAYON_NUM_THREADS=4 would limit the thread pool to 4 threads.

Parameters

  • memory (List(opens in a new tab)[str(opens in a new tab)] | ndarray(opens in a new tab)) – The input memory list, this is either a list of hexadecimal strings to be marginalized representing measure level 2 memory or a numpy array representing level 0 measurement memory (single or avg) or level 1 measurement memory (single or avg).
  • indices (List(opens in a new tab)[int(opens in a new tab)] | None) – The bit positions of interest to marginalize over. If None (default), do not marginalize at all.
  • int_return (bool(opens in a new tab)) – If set to True the output will be a list of integers. By default the return type is a bit string. This and hex_return are mutually exclusive and can not be specified at the same time. This option only has an effect with memory level 2.
  • hex_return (bool(opens in a new tab)) – If set to True the output will be a list of hexadecimal strings. By default the return type is a bit string. This and int_return are mutually exclusive and can not be specified at the same time. This option only has an effect with memory level 2.
  • avg_data (bool(opens in a new tab)) – If a 2 dimensional numpy array is passed in for memory this can be set to True to indicate it’s a avg level 0 data instead of level 1 single data.
  • parallel_threshold (int(opens in a new tab)) – The number of elements in memory to start running in multiple threads. If len(memory) is >= this value, the function will run in multiple threads. By default this is set to 1000.

Returns

The list of marginalized memory

Return type

marginal_memory

Raises

ValueError(opens in a new tab) – if both int_return and hex_return are set to True


Distributions

ProbDistribution(data[, shots])A generic dict-like class for probability distributions.
QuasiDistribution(data[, shots, ...])A dict-like class for representing quasi-probabilities.

Expectation values

sampled_expectation_value

qiskit.result.sampled_expectation_value(dist, oper) GitHub(opens in a new tab)

Computes expectation value from a sampled distribution

Note that passing a raw dict requires bit-string keys.

Parameters

Returns

The expectation value

Return type

float(opens in a new tab)

Raises

QiskitError – if the input distribution or operator is an invalid type


Mitigation

BaseReadoutMitigator()Base readout error mitigator class.
CorrelatedReadoutMitigator(assignment_matrix)N-qubit readout error mitigator.
LocalReadoutMitigator([assignment_matrices, ...])1-qubit tensor product readout error mitigator.
Was this page helpful?