Implement state checkpointing for decision nodes - #587
Conversation
6df7006 to
953304e
Compare
|
|
||
| CollectionCheckpoint_::CollectionCheckpoint_(CollectionStateData_* state_ptr) : | ||
| updates_(), | ||
| drop_(state_ptr->all_updates_.size()), // so we ignore any updates added before we're made |
There was a problem hiding this comment.
What happens if some mutations are made to the node, then you make a checkpoint (causing the drop_ to be set > 0), and then you revert, make more mutations, and commit? Won't this cause some updates to be "dropped" that are actually relevant to the checkpoint?
There was a problem hiding this comment.
Actually, I think I mean "make another checkpoint" as final step in the example rather than commit.
b4679c2 to
214c5e2
Compare
This avoids using GCC11 which had some bugs in their ranges implementation.
86b97e8 to
9cd035b
Compare
f1aa563 to
06b9dc5
Compare
06b9dc5 to
f70699e
Compare
30637e6 to
5fbe15b
Compare
|
|
||
| // Overloads required by the DecisionNode ABC ***************************** | ||
|
|
||
| // DynamicArrayTestingNode does not impement checkpointing |
5fbe15b to
4402568
Compare
| } | ||
| } | ||
|
|
||
| void Graph::propose(State& state) const { |
|
|
||
| set_ptr->assign_from_checkpoint(state, std::move(checkpoint0)); | ||
|
|
||
| // CHECK_THAT(set_ptr->view(state), RangeEquals({0, 1})); |
| } | ||
| } | ||
|
|
||
| // TODO: within one propagation |
There was a problem hiding this comment.
this is done, need to remove this comment
| auto checkpoint = ptr->checkpoint(state); // 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 | ||
|
|
||
| THEN("We can mutate and then assign from that checkpoint") { | ||
| ptr->set_value(state, 0, 1); // 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 |
There was a problem hiding this comment.
// 1, 1, 0, 1, 0, 1, 0, 1, 0, 1since you called set_value()
| ptr->exchange(state, 0, 2); // [-2, -4, -4, -2, 0, 0, 2, 2, 4, 4] | ||
| ptr->set_value(state, 3, 1); // [-2, -4, -4, 1, 0, 0, 2, 2, 4, 4] | ||
|
|
||
| THEN("We can commit, then assign from the checkpoint") { |
There was a problem hiding this comment.
Nit:
THEN("We can propose, then assign from the checkpoint") {I realize propose is propagate and commit. As this is a Nit, I am not going to comment at all duplicate instances.
| AND_WHEN("We create a checkpoint to that state") { | ||
| auto checkpoint = ptr->checkpoint(state); // 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 | ||
|
|
||
| THEN("We can mutate and then assign from that checkpoint") { |
There was a problem hiding this comment.
Nit
THEN("We can mutate, then propose, and then assign from that checkpoint") {| CHECK_THAT(inode_ptr->view(state), RangeEquals({8, 8, 8, 8, 8, 8, -3, 3})); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
A bit of a pain, but I think it might be worth adding a single test for BinaryNode with checkpointing to check that all the correct indices are cached with 1s and 0s (I am referring to the BinaryNode DisjointSparseSet).
THEN("Sum constraint sums, tracked indices, and state are correct") {
CHECK(bnode_ptr->sum_constraints_lhs(state).size() == 1);
CHECK(bnode_ptr->sum_constraints_lhs(state).data()[0].size() == 1);
CHECK_THAT(bnode_ptr->sum_constraints_lhs(state)[0], RangeEquals({3}));
check_indices<true>(state, bnode_ptr, 0, 0, {1, 2, 5}); // <- ***** This check is the important one ******
check_indices<false>(state, bnode_ptr, 0, 0, {0, 3, 4}); // <- ***** And this one ******
CHECK_THAT(bnode_ptr->view(state), RangeEquals(expected_init));
}|
|
||
| class NumberNodeCheckpoint_ : public DiffCheckpoint { | ||
| public: | ||
| using slice_cache_type = std::vector<std::vector<ssize_t>>; |
There was a problem hiding this comment.
Wishing I had used this elsewhere 😂
| assert(size_ >= 0 && static_cast<std::size_t>(size_) == buffer.size()); | ||
| } | ||
|
|
||
| // Commit the changes and clear the diff by returning the diff buffer. |
There was a problem hiding this comment.
Confused where the commit() is and am feeling like I am missing something.
| size_ = buffer.size(); | ||
| } | ||
|
|
||
| // Commit the changes and clear the diff by returning the diff buffer. |
There was a problem hiding this comment.
Same doc string comments as commit_and_detach(). Intentional?
| return static_cast<T*>(prev_ptr_); | ||
| } | ||
|
|
||
| private: // todo: private? |
Closes #510
Closes #552 by replacing it
AI Generation Disclosure
No AI was used to write the code. I intend to use it to review this PR.