hybrid.utils.bqm_reduced_to#
- bqm_reduced_to(bqm, variables, sample, keep_offset=True)[source]#
Reduce a binary quadratic model by fixing values of some variables.
The function is optimized for
len(variables) ~ len(bqm)
, that is, for small numbers of fixed variables.- Parameters:
bqm (
dimod.BinaryQuadraticModel
) – Binary quadratic model (BQM).variables (list/set) – Subset of variables to keep in the reduced BQM.
sample (dict/list) – Mapping of variable labels to values or a list when labels are sequential integers. Must include all variables not specified in variables.
keep_offset (bool, optional, default=True) – If false, set the reduced binary quadratic model’s offset to zero; otherwise, uses the caluclated energy offset.
- Returns:
A reduced BQM.
- Return type:
dimod.BinaryQuadraticModel
Examples
This example reduces a 3-variable BQM to two variables.
>>> import dimod >>> bqm = dimod.BQM({}, {'ab': -1, 'bc': -1, 'ca': -1}, 0, 'BINARY') >>> sample = {'a': 1, 'b': 1, 'c': 0} >>> subbqm = bqm_reduced_to(bqm, ['a', 'b'], sample) >>> len(subbqm) 2