Skip to content

Commit

Permalink
Implement warm starts using prior placements.
Browse files Browse the repository at this point in the history
  • Loading branch information
sukritkalra committed Jan 19, 2024
1 parent dcaf112 commit 4652833
Show file tree
Hide file tree
Showing 6 changed files with 404 additions and 80 deletions.
5 changes: 4 additions & 1 deletion schedulers/tetrisched/include/tetrisched/SolverModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class VariableT {
/// search.
void hint(T hintValue);

/// Retrieves the hinted value for the variable, if available.
std::optional<T> getHint() const;

/// Retrieve a string representation of this VariableT.
std::string toString() const;

Expand Down Expand Up @@ -404,7 +407,7 @@ class SolverModelT {

public:
/// Add a variable to the model.
void addVariable(std::shared_ptr<VariableT<T>> variable, bool useHint = true);
void addVariable(std::shared_ptr<VariableT<T>> variable);

/// Add a batch of variables to the model.
void addVariables(std::vector<std::shared_ptr<VariableT<T>>>& variables);
Expand Down
9 changes: 9 additions & 0 deletions schedulers/tetrisched/include/tetrisched/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
// values for this macro is supposed to be int32_t or double.
#define TETRISCHED_ILP_TYPE double


// Macro for hinting the variables.
// We have two strategies for hinting the variables.
// 1. We can hint the variables from a solution value cache saved from the previous
// iteration. This is the default behavior.
// 2. We can infer hints from which leaves have been previously satisfied. To turn
// this behavior on, set the following macro to true.
#define TETRISCHED_INFER_HINTS_FROM_LEAVES false

namespace tetrisched {
/// Defines the exceptions that the methods can throw.
namespace exceptions {
Expand Down
117 changes: 73 additions & 44 deletions schedulers/tetrisched/python/Expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ void defineSTRLExpressions(py::module_& tetrisched_m) {
.value("EXPR_WINDOWED_CHOOSE",
tetrisched::ExpressionType::EXPR_WINDOWED_CHOOSE);

// Define the ExpressionStatus enum.
py::enum_<tetrisched::ExpressionStatus>(tetrisched_m, "ExpressionStatus")
.value("EXPR_STATUS_UNKNOWN",
tetrisched::ExpressionStatus::EXPR_STATUS_UNKNOWN)
.value("EXPR_STATUS_SATISFIED",
tetrisched::ExpressionStatus::EXPR_STATUS_SATISFIED)
.value("EXPR_STATUS_UNSATISFIED",
tetrisched::ExpressionStatus::EXPR_STATUS_UNSATISFIED);

// Define the Placement object.
py::class_<tetrisched::Placement, tetrisched::PlacementPtr>(tetrisched_m,
"Placement")
Expand Down Expand Up @@ -119,50 +128,70 @@ void defineSTRLExpressions(py::module_& tetrisched_m) {
py::class_<tetrisched::ChooseExpression, tetrisched::Expression,
std::shared_ptr<tetrisched::ChooseExpression>>(tetrisched_m,
"ChooseExpression")
.def(py::init([](std::string taskName, std::string strategyName,
tetrisched::Partitions partitions,
uint32_t numRequiredMachines, tetrisched::Time startTime,
tetrisched::Time duration, TETRISCHED_ILP_TYPE utility) {
return std::make_shared<tetrisched::ChooseExpression>(
taskName, strategyName, partitions, numRequiredMachines,
startTime, duration, utility);
}),
"Initializes a ChooseExpression for the given task to be placed on "
"`numRequiredMachines` from the given partition at the given "
"startTime, running for the given duration.\n"
"\nArgs:\n"
" taskName (str): The name of the task to be placed.\n"
" strategyName (str): The name of the strategy of the Choose.\n"
" partitions (Partitions): The Partitions to be placed on.\n"
" numRequiredMachines (int): The number of machines required "
"for the task.\n"
" startTime (int): The start time of the task.\n"
" duration (int): The duration of the task.\n"
" utility (TETRISCHED_ILP_TYPE): The utility of the task.",
py::arg("taskName"), py::arg("strategyName"), py::arg("partitions"),
py::arg("numRequiredMachines"), py::arg("startTime"),
py::arg("duration"), py::arg("utility"))
.def(py::init([](std::string taskName, tetrisched::Partitions partitions,
uint32_t numRequiredMachines, tetrisched::Time startTime,
tetrisched::Time duration, TETRISCHED_ILP_TYPE utility) {
return std::make_shared<tetrisched::ChooseExpression>(
taskName, partitions, numRequiredMachines, startTime, duration,
utility);
}),
"Initializes a ChooseExpression for the given task to be placed on "
"`numRequiredMachines` from the given partition at the given "
"startTime, running for the given duration.\n"
"\nArgs:\n"
" taskName (str): The name of the task to be placed.\n"
" partitions (Partitions): The Partitions to be placed on.\n"
" numRequiredMachines (int): The number of machines required "
"for the task.\n"
" startTime (int): The start time of the task.\n"
" duration (int): The duration of the task.\n"
" utility (TETRISCHED_ILP_TYPE): The utility of the task.",
py::arg("taskName"), py::arg("partitions"),
py::arg("numRequiredMachines"), py::arg("startTime"),
py::arg("duration"), py::arg("utility"));
.def(
py::init(
[](std::string taskName, std::string strategyName,
tetrisched::Partitions partitions,
uint32_t numRequiredMachines, tetrisched::Time startTime,
tetrisched::Time duration, TETRISCHED_ILP_TYPE utility,
tetrisched::ExpressionStatus status,
std::optional<tetrisched::PriorPlacement> priorPlacements) {
return std::make_shared<tetrisched::ChooseExpression>(
taskName, strategyName, partitions, numRequiredMachines,
startTime, duration, utility, status, priorPlacements);
}),
"Initializes a ChooseExpression for the given task to be placed on "
"`numRequiredMachines` from the given partition at the given "
"startTime, running for the given duration.\n"
"\nArgs:\n"
" taskName (str): The name of the task to be placed.\n"
" strategyName (str): The name of the strategy of the Choose.\n"
" partitions (Partitions): The Partitions to be placed on.\n"
" numRequiredMachines (int): The number of machines required "
" for the task.\n"
" startTime (int): The start time of the task.\n"
" duration (int): The duration of the task.\n"
" utility (TETRISCHED_ILP_TYPE): The utility of the task.\n "
" status (ExpressionStatus): The status of the expression in a "
" previous cycle, if available.\n",
" priorPlacements (PriorPlacement): The prior placements of the "
" expression in a previous cycle, if available.\n",
py::arg("taskName"), py::arg("strategyName"), py::arg("partitions"),
py::arg("numRequiredMachines"), py::arg("startTime"),
py::arg("duration"), py::arg("utility"),
py::arg("status") = tetrisched::ExpressionStatus::EXPR_STATUS_UNKNOWN,
py::arg("priorPlacements") = std::nullopt)
.def(
py::init(
[](std::string taskName, tetrisched::Partitions partitions,
uint32_t numRequiredMachines, tetrisched::Time startTime,
tetrisched::Time duration, TETRISCHED_ILP_TYPE utility,
tetrisched::ExpressionStatus status,
std::optional<tetrisched::PriorPlacement> priorPlacements) {
return std::make_shared<tetrisched::ChooseExpression>(
taskName, partitions, numRequiredMachines, startTime,
duration, utility, status, priorPlacements);
}),
"Initializes a ChooseExpression for the given task to be placed on "
"`numRequiredMachines` from the given partition at the given "
"startTime, running for the given duration.\n"
"\nArgs:\n"
" taskName (str): The name of the task to be placed.\n"
" partitions (Partitions): The Partitions to be placed on.\n"
" numRequiredMachines (int): The number of machines required "
"for the task.\n"
" startTime (int): The start time of the task.\n"
" duration (int): The duration of the task.\n"
" utility (TETRISCHED_ILP_TYPE): The utility of the task.\n",
" status (ExpressionStatus): The status of the expression in a "
" previous cycle, if available.\n",
" priorPlacements (PriorPlacement): The prior placements of the "
" expression in a previous cycle, if available.\n",
py::arg("taskName"), py::arg("partitions"),
py::arg("numRequiredMachines"), py::arg("startTime"),
py::arg("duration"), py::arg("utility"),
py::arg("status") = tetrisched::ExpressionStatus::EXPR_STATUS_UNKNOWN,
py::arg("priorPlacements") = std::nullopt);

// Define the WindowedChooseExpression.
py::class_<tetrisched::WindowedChooseExpression, tetrisched::Expression,
Expand Down
Loading

0 comments on commit 4652833

Please sign in to comment.