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

Cache And Reuse Solution Values Across Solver Invocations #66

Merged
merged 9 commits into from
Nov 6, 2023

Conversation

ruizehung
Copy link
Contributor

Summary

This PR introduces functionality to retain the solution values of variables from the previous invocation of the solver. These values are stored in a cache that persists between solver runs.

When a new variable is added to the solver model, addition logic now checks whether a solution value for a variable with the same name exists in the cache. If a cached value exists, it sets this value as the initial hint for the variable.

Test Plan

Pass unit test

Output for ./test_tetrisched: https://app.warp.dev/block/j3sg3Urzyn1EIfns9CkQsY

Can run python3 main.py --flagfile=configs/new_av_workload.conf with debug enabled

There are too many debug statements being printed and it's hard to capture ones that are relevant to this PR. So I just record a short video instead : )

Screen.Recording.2023-11-05.at.6.15.34.PM.mov

@@ -162,6 +162,11 @@ void GurobiSolver::translateModel() {
TETRISCHED_DEBUG("Adding variable " << variable->getName() << "("
<< variableId << ") to Gurobi Model.");
gurobiVariables[variableId] = translateVariable(*gurobiModel, variable);
// Give the Gurobi variable an initial solution value if it is available.
if (variable->getInitialValue().has_value()) {
gurobiVariables[variableId].set(GRB_DoubleAttr_Start, variable->getInitialValue().value());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like it would be better if I set start attribute for gurobi variables inside translateVariable? Let me know if you think so and I can change it

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that would be ideal!

Copy link
Contributor

@sukritkalra sukritkalra left a comment

Choose a reason for hiding this comment

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

LGTM. Minor changes, let me know if you want me to take them on!

For the logging issue, just set TETRISCHED_DEBUG_ENABLED to false in Types.hpp. :)

@@ -162,6 +162,11 @@ void GurobiSolver::translateModel() {
TETRISCHED_DEBUG("Adding variable " << variable->getName() << "("
<< variableId << ") to Gurobi Model.");
gurobiVariables[variableId] = translateVariable(*gurobiModel, variable);
// Give the Gurobi variable an initial solution value if it is available.
if (variable->getInitialValue().has_value()) {
gurobiVariables[variableId].set(GRB_DoubleAttr_Start, variable->getInitialValue().value());
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that would be ideal!

schedulers/tetrisched/include/tetrisched/SolverModel.hpp Outdated Show resolved Hide resolved
@ruizehung ruizehung requested a review from sukritkalra November 6, 2023 01:49
Copy link
Contributor

@sukritkalra sukritkalra left a comment

Choose a reason for hiding this comment

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

LGTM

@sukritkalra sukritkalra merged commit 9f90383 into main Nov 6, 2023
1 check passed
@sukritkalra sukritkalra deleted the solver-model-variable-caching branch November 6, 2023 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants