dimod.SampleSet.relabel_variables#

SampleSet.relabel_variables(mapping, inplace=True)[source]#

Relabel the variables of a SampleSet according to the specified mapping.

Parameters:
  • mapping (dict) – Mapping from current variable labels to new, as a dict. If incomplete mapping is specified, unmapped variables keep their current labels.

  • inplace (bool, optional, default=True) – If True, the current SampleSet is updated; otherwise, a new SampleSet is returned.

Returns:

SampleSet with relabeled variables. If inplace is True, returns itself.

Return type:

SampleSet

Notes

This function is non-blocking.

Examples

This example creates a relabeled copy of a SampleSet.

>>> sampleset = dimod.ExactSolver().sample_ising({'a': -0.5, 'b': 1.0}, {('a', 'b'): -1})
>>> new_sampleset = sampleset.relabel_variables({'a': 0, 'b': 1}, inplace=False)
>>> new_sampleset.variables
Variables([0, 1])