dwavesystems / dwavesystems/dimod
C++ quadratic model reindexing
- Dominant language
- Python
- Stars
- 143
- Forks
- 91
- Avg merge
- 1h 24m
- Merged PRs (30d)
- 3
Description
Currently the C++ quadratic models are all indexed `[0, num_variables)` always. That makes working with multiple QMs tricky. For instance, say that you had two bqms, `x0 + x1` and `x1 + x2`, that you want to add together. You need to somehow signal to the C++ code that some variables overlap and some do not. We handle this currently in one place https://github.com/dwavesystems/dimod/blob/9b9bbe30b8f448dde87e09e73c9f3c5c8739c442/dimod/include/dimod/quadratic_model.h#L827 by allowing the user to provide a remapping. However, it would be nice to have a more general interface. Something like
```c++
auto bqm = BinaryQuadraticModel(2, Vartype::SPIN);
bqm.linear(0) = 1;
bqm.linear(1) = 2;
auto view = bqm.reindex({1, 2})
assert(view.linear(1) == 1);
assert(view.linear(2) == 2);
```
this would open up nice syntax like
```
bqm1 += bqm2.reindex(...)
```
Contributor guide
Assessment
This issue has not been assessed yet.