dimod.higherorder.polynomial.BinaryPolynomial.relabel_variables#

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

Relabel variables of a binary polynomial as specified by mapping.

Parameters:
  • mapping (dict) – Dict mapping current variable labels to new ones. If an incomplete mapping is provided, unmapped variables retain their current labels.

  • inplace (bool, optional, default=True) – If True, the binary polynomial is updated in-place; otherwise, a new binary polynomial is returned.

Returns:

A binary polynomial with the variables relabeled. If inplace is set to True, returns itself.

Return type:

BinaryPolynomial

Examples

>>> poly = dimod.BinaryPolynomial({('x', 'y'): -1, ('x', 'y', 'z'): 0.5},
...                               'BINARY')
>>> poly2 = poly.relabel_variables({'x': 'k', 'y': 'l'}, inplace=False)
>>> 'k' in poly2.variables and 'z' in poly2.variables
True