dimod.BinaryQuadraticModel.update¶
-
BinaryQuadraticModel.update(bqm, ignore_info=True)[source]¶ Update one binary quadratic model from another.
Parameters: - bqm (
BinaryQuadraticModel) – The updating binary quadratic model. Any variables in the updating model are added to the updated model. Values of biases and the offset in the updating model are added to the corresponding values in the updated model. - ignore_info (bool, optional, default=True) – If True, info in the given binary quadratic model is ignored, otherwise
BinaryQuadraticModel.infois updated with the given binary quadratic model’s info, potentially overwriting values.
Examples
This example creates two binary quadratic models and updates the first from the second.
>>> import dimod ... >>> linear1 = {1: 1, 2: 2} >>> quadratic1 = {(1, 2): 12} >>> bqm1 = dimod.BinaryQuadraticModel(linear1, quadratic1, 0.5, dimod.SPIN) >>> bqm1.info = {'BQM number 1'} >>> linear2 = {2: 0.25, 3: 0.35} >>> quadratic2 = {(2, 3): 23} >>> bqm2 = dimod.BinaryQuadraticModel(linear2, quadratic2, 0.75, dimod.SPIN) >>> bqm2.info = {'BQM number 2'} >>> bqm1.update(bqm2) >>> bqm1.offset 1.25 >>> 'BQM number 2' in bqm1.info False >>> bqm1.update(bqm2, ignore_info=False) >>> 'BQM number 2' in bqm1.info True >>> bqm1.offset 2.0
- bqm (