dimod.ConstrainedQuadraticModel.relabel_constraints#

ConstrainedQuadraticModel.relabel_constraints(mapping: Mapping[Hashable, Hashable])[source]#

Relabel the constraints.

Note that this method does not maintain the constraint order.

Parameters:

mapping – Mapping from the old constraint labels to the new.

Examples

>>> x, y, z = dimod.Binaries(['x', 'y', 'z'])
>>> cqm = dimod.ConstrainedQuadraticModel()
>>> cqm.add_constraint(x + y == 1, label='c0')
'c0'
>>> cqm.add_constraint(y*z == 0, label='c1')
'c1'
>>> cqm.relabel_constraints({'c1': 'c2'})
>>> list(cqm.constraints)
['c0', 'c2']