Skip to content

Sample

A sample object is an assignment of an actual value to each of the models' variables.

The Sample class is readonly as it's merely a helper class for looking into a single sample of a solution.

Note: a Sample can be converted to list[int | float] simply by calling list(sample).

Examples:

>>> from luna_quantum import Model, Sample, Solution
>>> model: Model = ...
>>> solution: Solution = ...
>>> sample: Sample = solution.samples[0]
>>> sample
[0, -5, 0.28]

__getitem__ method descriptor

__getitem__(key) -> int | float

Return self[key].

__iter__ method descriptor

__iter__() -> SampleIterator

Implement iter(self).

__len__ method descriptor

__len__() -> int

Return len(self).

__str__ method descriptor

__str__() -> str

Return str(self).

to_dict method descriptor

to_dict() -> dict[str, int | float]

Convert the sample to a dictionary.

Returns:

Type Description
dict

A dictionary representation of the sample, where the keys are the variable names and the values are the variables' assignments.