Skip to main content
IBM Quantum Platform
This page is from the dev version of Qiskit SDK. Go to the stable version.

DataBin

class qiskit.primitives.DataBin(*, shape=(), **data)

GitHub

Bases: ShapedMixin

The main data return from a single pub out of PubResult.

You access the data within this object either by attribute access (data_bin.my_field) or by dict-like string keys (data_bin["my_field"]). This class behaves as a Python immutable mapping, so you can (for example) query the available keys with keys(), and iterate through both keys and values with items().

This class will have different attributes and keys, depending on the primitive used and the pub submitted. These “special” attributes will have names that match the keys. For example, if you submitted a SamplerV2 job, typically the attributes and keys are the names of the ClassicalRegister objects that were in the circuit defining this pub.

All of the attributes and keys have the same shape associated with them, which is the n-dimensional shape of the corresponding pub. The attributes and keys will typically either be BitArray or numpy.ndarray instances, depending on the primitive used and the input pub.

Users do not typically construct this class themselves. Instead, you receive it as the PubResult.data field for a single pub’s result out of a complete execution.

Examples:

import numpy as np
from qiskit.primitives import DataBin, BitArray
 
data = DataBin(
    alpha=BitArray.from_samples(["0010"]),
    beta=np.array([1.2])
)
 
print("alpha data:", data.alpha)
print("beta data:", data.beta)
alpha data: BitArray(<shape=(), num_shots=1, num_bits=2>)
beta data: [1.2]

Parameters

  • data – Name/value data to place in the data bin.
  • shape (ShapeInput) – The leading shape common to all entries in the data bin. This defaults to the trivial leading shape of () that is compatible with all objects.

Raises

  • ValueError – If a name overlaps with a method name on this class.
  • ValueError – If some value is inconsistent with the provided shape.

Attributes

ndim

shape

size


Methods

items

items()

GitHub

Return a view of field names and values

Return type

ItemsView[str, Any]

keys

keys()

GitHub

Return a view of field names.

Return type

KeysView[str]

values

values()

GitHub

Return a view of values.

Return type

ValuesView[Any]

Was this page helpful?
Report a bug, typo, or request content on GitHub.