-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add symbol labels #17
Comments
Some potential approaches 1) Symbols "know" their labelsIn this approach each symbol has a label associated with it, and has access to that label. So the API could be something like model = Model()
x = model.binary()
x.label = "x1"
for symbol in model.iter_symbols():
print(symbol.label) which would print From an implementation perspective, there are two ways to do this 1a) C++ nodes add generic storageSomething like struct NodeStorage {
virtual ~NodeStorage() = default;
};
struct Node {
// Hold an (uninitialized) storage pointer that can be initialized by Cython
std::unique_ptr<NodeStorage> storage_ptr;
// existing Node implementation here
}; we could then subclass The cost of this approach is one pointer per node, so potentially ~16 MB in the worst case, assuming our current 2,000,000 node number. Not counting whatever is actually stored in it. This also has the disadvantage of not (easily) allowing retrieval by label. Because you'd need to traverse all of the nodes looking for a specific (not necessarily unique) label. 1b) Cython node storageIn this approach, we let Cython store the node data. So something like cdef class Model:
cdef object node_ptr_to_label = dict()
cdef object label_to_node_ptr = dict() where we store a mapping from labels to nodes and vice versa. There is definitely a source-of-truth issue here when/if we add node removal (#41). In the example above, I've also used 2) Pyomo-style labels
In that case, we would simply encourage users to do model = Model()
model.x1 = model.binary() This already works out-of-the box, so the change would be to encourage this behavior. It's definitely very simple and supports arbitrary storage structured (e.g. We could also potentially add some sort of traversal mechanism by traversing the model >>> model = Model()
>>> model.x = model.binary()
>>> model.__dict__
{'x': <dwave.optimization.symbols.BinaryVariable at 0x7f27ea58c6a0>} This also keeps the symbols as Python objects, which gets expensive. |
We need the ability to label symbols and then retrieve them from their labels. Unfortunately for after launch though.
The text was updated successfully, but these errors were encountered: