dwavesystems / dwavesystems/dimod

fix_variables method for DQM object

Open
#797 5 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
143
Forks
91
Avg merge
1h 24m
Merged PRs (30d)
3

Description

Given a variable, fix the value of the variable to one of its cases and remove the variable.

```
dqm = dimod.DiscreteQuadraticModel()
dqm.add_variable(5, 'a')
dqm.add_variable(5, 'b')
dqm.set_quadratic('a', 'b', {(1, 4): 5})

assert(dqm.get_linear('a', 1) == 0)

dqm.fix_variable('b', 4)

assert(dqm.get_linear('a', 1) == 5)
assert('b' not in dqm.variables)

# also be able to fix a bunch of variables at once

dqm = dimod.DiscreteQuadraticModel()
dqm.add_variable(5, 'a')
dqm.add_variable(5, 'b')
dqm.set_quadratic('a', 'b', {(1, 4): 5})

dqm.fix_variables({'a': 1, 'b': 4})
assert(dqm.num_variables() == 0)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.