dimod.BinaryQuadraticModel.relabel_variables¶
-
BinaryQuadraticModel.relabel_variables(mapping, inplace=True)[source]¶ Relabel variables of a binary quadratic model 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 quadratic model is updated in-place; otherwise, a new binary quadratic model is returned.
Returns: A binary quadratic model with the variables relabeled. If inplace is set to True, returns itself.
Return type: Examples
This example creates a binary quadratic model with two variables and relables one.
>>> import dimod ... >>> model = dimod.BinaryQuadraticModel({0: 0., 1: 1.}, {(0, 1): -1}, 0.0, vartype=dimod.SPIN) >>> model.relabel_variables({0: 'a'}) # doctest: +SKIP BinaryQuadraticModel({1: 1.0, 'a': 0.0}, {('a', 1): -1}, 0.0, Vartype.SPIN)
This example creates a binary quadratic model with two variables and returns a new model with relabled variables.
>>> import dimod ... >>> model = dimod.BinaryQuadraticModel({0: 0., 1: 1.}, {(0, 1): -1}, 0.0, vartype=dimod.SPIN) >>> new_model = model.relabel_variables({0: 'a', 1: 'b'}, inplace=False) # doctest: +SKIP >>> new_model.quadratic # doctest: +SKIP {('a', 'b'): -1}