dimod icon indicating copy to clipboard operation
dimod copied to clipboard

C++ quadratic model reindexing

Open arcondello opened this issue 4 years ago • 0 comments

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

auto bqm = BinaryQuadraticModel<double>(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(...)

arcondello avatar Jun 29 '21 22:06 arcondello