-
Notifications
You must be signed in to change notification settings - Fork 35
Add method for removing redundant nodes #571
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
Open
arcondello
wants to merge
27
commits into
dwavesystems:main
Choose a base branch
from
arcondello:feature/node-equality-and-successor-transfer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,586
−118
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
82cc356
Add methods to remove redundant nodes
arcondello 57638a8
Add BinaryOpNode equality and predecessor replacement
arcondello 16a2938
Switch from Node::operator== to Node::equal_to
arcondello c0e52bc
Add ARangeNode equality and predecessor replacement
arcondello 948c199
Add flow nodes equality and predecessor replacement
arcondello 0443585
Add indexing nodes equality and predecessor replacement
arcondello 2985dcf
Add InputNode equality and predecessor replacement
arcondello 1cece38
Add interpolation node equality and predecessor replacement
arcondello 055fe62
Add lambda node equality and predecessor replacement
arcondello 770a9cb
Add EqualityMixin to reduce code duplication
arcondello 5b213bc
Use EqualityMixin with BinaryOpNode
arcondello 47e1be7
Add node equality and predecessor replacement to MatrixMultiplyNode
arcondello cd107a0
Add node equality and predecessor replacement for LP nodes
arcondello 6915ba4
Add equality and predecessor replacement for manipulation nodes
arcondello edf9a68
Add equality and predecessor replacement for nary op nodes
arcondello f7a75d1
Add equality for QuadraticModelNode
arcondello cf7f812
Add equality and predecessor replacement for ReduceNode
arcondello b1df040
Add equality and predecessor replacement for IsInNode
arcondello f643bca
Add equality and predecessor replacement to SoftMaxNode
arcondello 08728d9
Add equality and predecessor replacement to ArgSortNode
arcondello 7e3ccae
Add equality and predecessor replacement to MeanNode
arcondello 918d197
Add equality and predecessor replacement to unary op nodes
arcondello b43d9d3
Make Node::equal_to() and abstract method
arcondello c60bcb7
Fix misc issues with redundant_node PR
arcondello d0dd3d3
Fix objective handling in Graph::remove_redundant_nodes()
arcondello a7912dd
Add a test for removing redundant constants
arcondello 3583a42
Add a smoke test for Model.remove_redundant_symbols()
arcondello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,14 +29,19 @@ | |
| namespace dwave::optimization { | ||
|
|
||
| template <class BinaryOp> | ||
| class BinaryOpNode : public ArrayOutputMixin<ArrayNode> { | ||
| class BinaryOpNode : public ArrayOutputMixin<EqualityMixin<ArrayNode, BinaryOpNode<BinaryOp>>> { | ||
| public: | ||
| // We need at least two nodes, and they must be the same shape | ||
| BinaryOpNode(ArrayNode* a_ptr, ArrayNode* b_ptr); | ||
|
|
||
| double const* buff(const State& state) const override; | ||
| std::span<const Update> diff(const State& state) const override; | ||
|
|
||
| /// Two BinaryOpNodes are equal if they have the same operation and the | ||
| /// same predecessors. If the BinaryOp is commutative, then permutations | ||
| /// of predecessors are allowed. | ||
| bool equal_to(const BinaryOpNode& rhs) const override; | ||
|
|
||
| /// @copydoc Array::integral() | ||
| bool integral() const override; | ||
|
|
||
|
|
@@ -46,10 +51,10 @@ class BinaryOpNode : public ArrayOutputMixin<ArrayNode> { | |
| /// @copydoc Array::max() | ||
| double max() const override; | ||
|
|
||
| using ArrayOutputMixin::shape; | ||
| using ArrayOutputMixin<EqualityMixin<ArrayNode, BinaryOpNode<BinaryOp>>>::shape; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the commit message for 5b213bc
|
||
| std::span<const ssize_t> shape(const State& state) const override; | ||
|
|
||
| using ArrayOutputMixin::size; | ||
| using ArrayOutputMixin<EqualityMixin<ArrayNode, BinaryOpNode<BinaryOp>>>::size; | ||
| ssize_t size(const State& state) const override; | ||
|
|
||
| ssize_t size_diff(const State& state) const override; | ||
|
|
@@ -63,20 +68,22 @@ class BinaryOpNode : public ArrayOutputMixin<ArrayNode> { | |
|
|
||
| // The predecessors of the operation, as Array*. | ||
| std::span<Array* const> operands() { | ||
| assert(predecessors().size() == operands_.size()); | ||
| assert(this->predecessors().size() == operands_.size()); | ||
| return operands_; | ||
| } | ||
| std::span<const Array* const> operands() const { | ||
| assert(predecessors().size() == operands_.size()); | ||
| assert(this->predecessors().size() == operands_.size()); | ||
| return operands_; | ||
| } | ||
|
|
||
| private: | ||
| void replace_predecessor_(ssize_t previous_index, Node* node_ptr) override; | ||
|
|
||
| BinaryOp op; | ||
|
|
||
| // There are redundant, because we could dynamic_cast each time from | ||
| // predecessors(), but this is more performant | ||
| std::array<Array* const, 2> operands_; | ||
| std::array<Array*, 2> operands_; | ||
|
|
||
| const ValuesInfo values_info_; | ||
| const SizeInfo sizeinfo_; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A doubt I have is whether these two overloads are different enough that they should actually be given different names 🤔