classmethod SampleSet.from_samples_cqm(samples_like, cqm, rtol=1e-06, atol=1e-08, **kwargs)[source]#

Build a sample set from raw samples and a constrained quadratic model.

The constrained quadratic model is used to calculate energies and feasibility.

  • samples_like – A collection of raw samples. ‘samples_like’ is an extension of NumPy’s array_like. See as_samples().

  • cqm (ConstrainedQuadraticModel) – A constrained quadratic model.

  • rtol (float, optional, default=1e-6) – Relative tolerance for constraint violation. See ConstrainedQuadraticModel.check_feasible() for more information.

  • atol (float, optional, default=1e-8) – Absolute tolerance for constraint violations. See ConstrainedQuadraticModel.check_feasible() for more information.

  • info (dict, optional) – Information about the SampleSet as a whole formatted as a dict.

  • num_occurrences (array_like, optional) – Number of occurrences for each sample. If not provided, defaults to a vector of 1s.

  • aggregate_samples (bool, optional, default=False) – If True, all samples in returned SampleSet are unique, with num_occurrences accounting for any duplicate samples in samples_like.

  • sort_labels (bool, optional, default=True) – Return SampleSet.variables in sorted order. For mixed (unsortable) types, the given order is maintained.

  • **vectors (array_like) – Other per-sample data.




>>> cqm = dimod.ConstrainedQuadraticModel()
>>> x, y, z = dimod.Binaries(['x', 'y', 'z'])
>>> cqm.set_objective(x*y + 2*y*z)
>>> label = cqm.add_constraint(x*y == 1, label='constraint_1')
>>> sampleset = dimod.SampleSet.from_samples_cqm({'x': 0, 'y': 1, 'z': 1}, cqm)