Source code for qiskit_dynamics.perturbation.perturbation_data
# This code is part of Qiskit.## (C) Copyright IBM 2022.## This code is licensed under the Apache License, Version 2.0. You may# obtain a copy of this license in the LICENSE.txt file in the root directory# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.## Any modifications or derivative works of this code must retain this# copyright notice, and modified files need to carry a notice indicating# that they have been altered from the originals.r"""Class for storing results of perturbation theory computations."""fromtypingimportList,Mapping,OptionalfromdataclassesimportdataclassfrommultisetimportMultisetfromqiskitimportQiskitError@dataclassclass_LabeledData:"""Container for arbitrarily "labeled data", i.e. data whose indices are arbitrary python objects. The method ``get_item`` looks up an item according to the label. """data:Mapping[int,any]labels:List[any]metadata:Optional[any]=Nonedefget_item(self,label:any)->any:"""Look up an item in self.data according to the location of label in self.labels."""label=self._preprocess_label(label)iflabelinself.labels:returnself.data[self.labels.index(label)]raiseQiskitError("label is not present in self.labels.")def_preprocess_label(self,label:any)->any:returnlabel
[docs]classPowerSeriesData(_LabeledData):"""Storage container for power series data. Labels are assumed to be ``Multiset`` instances, and data is assumed to be a dense ``ArrayLike``. """def_preprocess_label(self,label:Multiset)->Multiset:"""Cast to a Multiset."""returnMultiset(label)
[docs]classDysonLikeData(_LabeledData):"""Storage container for DysonLike series data. Labels are assumed to be lists of ints, and data is assumed to be a dense ``ArrayLike``. """def_preprocess_label(self,label:list)->list:"""Cast to a list."""returnlist(label)