Skip to content
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 methods to remove unused symbols from a model #161

Merged

Conversation

arcondello
Copy link
Member

Closes #41

@arcondello arcondello added the enhancement New feature or request label Nov 5, 2024
@arcondello arcondello requested a review from wbernoudy November 5, 2024 19:04
@arcondello arcondello marked this pull request as ready for review November 5, 2024 19:04
// This method will reset the topological sort if there is one.
//
// A node is considered unused if all of the following are true:
// * It is not a decision.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently a constraint because of the difficulty of removing some types of decisions, correct?

Copy link
Member Author

@arcondello arcondello Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not actually difficult to implement but there are a few reasons:

  1. I can see how symbols might be accidentally added to the model, but for decisions I think there is a high chance they are there deliberately anyway. I.e. i doubt we'd be removing decisions often.
  2. This way if one was to use this method as part of a presolve step, the serialized states of the model after presolve would still be relevant to the original model.

It's a simple enough thing to add a toggle for at some later date if we really want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I didn't think about the presolve angle.

dwave/optimization/include/dwave-optimization/graph.hpp Outdated Show resolved Hide resolved
// For performance we store a signalling value in the topological_index of the
// nodes. We need to take some care to not override the topological index of
// any decisions.
constexpr ssize_t keep = -2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is set to -2 because -1 already has a meaning of "unsorted", correct? But at this point you've topologically sorted so it should be guaranteed all nodes have an index >= 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. I just need a negative number. I chose -2 because -1 already has meaning as unsorted. Should never matter but 🤷

@wbernoudy
Copy link
Member

What about the case of an unused DisjointListNode (a successor of the DisjointListsNode)? Won't this remove it, and cause issues for DisjointListNode later on?

@arcondello
Copy link
Member Author

Ah! Good catch. Yes. Need to think about how to handle that.

@arcondello
Copy link
Member Author

Ok, added a mechanism for nodes to opt out of removal. Probably good for decisions as well (for safety).

@arcondello arcondello merged commit 7a8c074 into dwavesystems:main Nov 5, 2024
35 checks passed
@arcondello arcondello deleted the feature/redundant-node-removal branch November 5, 2024 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding node removal
2 participants