qml.data.attribute

attribute(val, doc=None, **kwargs)[source]

Creates a dataset attribute that contains both a value and associated metadata.

Parameters
  • val (any) – the dataset attribute value

  • doc (str) – the docstring that describes the attribute

  • **kwargs – Additional keyword arguments may be passed, which represents metadata which describes the attribute.

Returns

an attribute object

Return type

DatasetAttribute

See also

Dataset

Example

>>> hamiltonian = qml.Hamiltonian([1., 1.], [qml.Z(0), qml.Z(1)])
>>> eigvals, eigvecs = np.linalg.eigh(qml.matrix(hamiltonian))
>>> dataset = qml.data.Dataset(hamiltonian = qml.data.attribute(
...     hamiltonian,
...     doc="The hamiltonian of the system"))
>>> dataset.eigen = qml.data.attribute(
...     {"eigvals": eigvals, "eigvecs": eigvecs},
...     doc="Eigenvalues and eigenvectors of the hamiltonain")

This metadata can then be accessed using the attr_info() mapping:

>>> dataset.attr_info["eigen"]["doc"]
'Eigenvalues and eigenvectors of the hamiltonain'