Skip to content

Implement state checkpointing for decision nodes - #587

Open
arcondello wants to merge 12 commits into
dwavesystems:mainfrom
arcondello:feature/decision-checkpoints
Open

Implement state checkpointing for decision nodes#587
arcondello wants to merge 12 commits into
dwavesystems:mainfrom
arcondello:feature/decision-checkpoints

Conversation

@arcondello

@arcondello arcondello commented Jul 17, 2026

Copy link
Copy Markdown
Member

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.

@arcondello arcondello added the enhancement New feature or request label Jul 17, 2026
@arcondello
arcondello force-pushed the feature/decision-checkpoints branch from 6df7006 to 953304e Compare July 17, 2026 23:25

CollectionCheckpoint_::CollectionCheckpoint_(CollectionStateData_* state_ptr) :
updates_(),
drop_(state_ptr->all_updates_.size()), // so we ignore any updates added before we're made

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually, I think I mean "make another checkpoint" as final step in the example rather than commit.

@arcondello arcondello Jul 20, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yup! Good catch. Fixed in 214c5e2

@arcondello
arcondello force-pushed the feature/decision-checkpoints branch 2 times, most recently from b4679c2 to 214c5e2 Compare July 20, 2026 18:59
This avoids using GCC11 which had some bugs in their ranges
implementation.
@arcondello
arcondello force-pushed the feature/decision-checkpoints branch from 86b97e8 to 9cd035b Compare July 20, 2026 19:18
Comment thread dwave/optimization/include/dwave-optimization/state.hpp Outdated
@arcondello
arcondello force-pushed the feature/decision-checkpoints branch 2 times, most recently from f1aa563 to 06b9dc5 Compare July 21, 2026 21:20
@arcondello
arcondello force-pushed the feature/decision-checkpoints branch from 06b9dc5 to f70699e Compare July 21, 2026 21:21
@arcondello
arcondello force-pushed the feature/decision-checkpoints branch from 30637e6 to 5fbe15b Compare July 27, 2026 18:46
@arcondello arcondello changed the title Implement state checkpointing for CollectionNode Implement state checkpointing for decision nodes Jul 27, 2026

// Overloads required by the DecisionNode ABC *****************************

// DynamicArrayTestingNode does not impement checkpointing

@arcondello arcondello Jul 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See #593

Also I see the typo here.

@arcondello
arcondello force-pushed the feature/decision-checkpoints branch from 5fbe15b to 4402568 Compare July 27, 2026 18:51
@arcondello
arcondello marked this pull request as ready for review July 27, 2026 18:51
@arcondello
arcondello requested a review from fastbodin July 27, 2026 18:52
}
}

void Graph::propose(State& state) const {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Could be smarter with #589 or #592, but that's for another PR.


set_ptr->assign_from_checkpoint(state, std::move(checkpoint0));

// CHECK_THAT(set_ptr->view(state), RangeEquals({0, 1}));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oops, will restore

}
}

// TODO: within one propagation

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

// 1, 1, 0, 1, 0, 1, 0, 1, 0, 1

since 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") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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}));
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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>>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same doc string comments as commit_and_detach(). Intentional?

return static_cast<T*>(prev_ptr_);
}

private: // todo: private?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hanging comment?

Comment thread dwave/optimization/src/nodes/_checkpoints.cpp
Comment thread dwave/optimization/src/nodes/_checkpoints.cpp
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.

Add checkpointing method(s) for decision array nodes

3 participants