hybrid.utils.select_random_subgraph¶
- select_random_subgraph(bqm, n)[source]¶
Select randomly n variables of the specified binary quadratic model.
- Parameters
bqm (
dimod.BinaryQuadraticModel
) – Binary quadratic model (BQM).n (int) – Number of requested variables. Must be between 0 and len(bqm).
- Returns
n variables selected randomly from the BQM.
- Return type
Examples
This example returns 2 variables of a 4-variable BQM.
>>> import dimod >>> bqm = dimod.BQM({}, {'ab': 0, 'bc': 1, 'cd': 2}, 0, 'BINARY') >>> select_random_subgraph(bqm, 2) ['d', 'b']