dwavesystems / dwavesystems/dimod
Initializing BinaryQuadraticModel using keyword arguments gives empty model
- Dominant language
- Python
- Stars
- 143
- Forks
- 91
- Avg merge
- 1h 24m
- Merged PRs (30d)
- 3
Description
**Description**
When we have tried initializing `BinaryQuadraticModel` using all the keyword arguments, we got an empty model. However, if we use `linear`, `quadratic` and `offset` as positional arguments, it works properly.
We understand that they might be purely positional, but the initializer should at least raise an exception when unrecognized arguments are passed.
**Steps To Reproduce**
This gives expected behaviour:
```
$ dimod.BinaryQuadraticModel({1:0.5, 2:0.5 }, {(1,2): 0.5}, 2, vartype="SPIN")
BinaryQuadraticModel({1: 0.5, 2: 0.5}, {(1, 2): 0.5}, 2.0, 'SPIN')
```
This is unexpected behaviour:
```
$ dimod.BinaryQuadraticModel(linear={1:0.5, 2:0.5 }, quadratic={(1,2): 0.5}, offset=2, vartype="SPIN")
dimod.BinaryQuadraticModel({1:0.5, 2:0.5 }, {(1,2): 0.5}, offset=2, vartype="SPIN")
```
This is also unexpected behaviour:
```
$ dimod.BinaryQuadraticModel(linear={1:0.5, 2:0.5 }, quadratic={(1,2): 0.5}, offset=2, vartype="SPIN")
BinaryQuadraticModel({}, {}, 0.0, 'SPIN')
```
Specifying `linear` twice, once as positional and once as keyword argument is also confusing:
```
$ dimod.BinaryQuadraticModel({1:0.5, 2:0.5 }, {(1,2): 0.5}, 2.0, linear={1:0.7, 2:0.2}, vartype="SPIN")
BinaryQuadraticModel({1: 0.5, 2: 0.5}, {(1, 2): 0.5}, 2.0, 'SPIN')
```
Also, all the other keyword arguments are ignored without throwing a warning or exception.
**Expected Behavior**
Passing `linear`, `quadratic` and `offset` as keyword arguments should work or raise an exception.
**Environment**
- OS: MacOS 10.15.6
- Python version: `Python 3.7.9`
- dimod version: `dimod==0.9.11`
**Additional Context**
CC: @dexter2206
Contributor guide
Assessment
This issue has not been assessed yet.