Skip to content

Commit

Permalink
Update Dynamic Discretization to enable Warm Starts (#87)
Browse files Browse the repository at this point in the history
* Fixed Capacity Constraint Map for dynamic Discretization

* Implemented STRL choose exprs reuse from prev sovler invocation in dynamic discretization

* Added finer Grained discretization around prev solutions

* Added input of lower discretization around prev sol

* Rectified Bug

* Added limitation of total solver time to 1 min

* changed time and added more info in errors

* Rectified Dynamic Discretization Bugs

* Implemented getResourceQuantity() for allocation exprs

* Added conf file for dynamic discretization

* Format changes to pass builds.

* Format changes to main to fix builds.

* Changes to pass flake8 compatibility.

---------

Co-authored-by: Sukrit Kalra <[email protected]>
  • Loading branch information
alindkhare and sukritkalra authored Feb 21, 2024
1 parent 79d6259 commit 4c744e7
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 74 deletions.
45 changes: 45 additions & 0 deletions configs/new_motiv_new_conf_sukrit_runs_strl_1_8.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Output configs.
--log_dir=experiments/new_exps_new_conf/strl_1_8
--log_file_name=alibaba_trace_replay_tetrisched.log
--csv_file_name=alibaba_trace_replay_tetrisched.csv
--log_level=debug

# Workload configs.
--execution_mode=replay
--replay_trace=alibaba
--workload_profile_paths=traces/alibaba-cluster-trace-v2018/easy_dag_sukrit_10k.pkl,traces/alibaba-cluster-trace-v2018/medium_dag_sukrit_10k.pkl,traces/alibaba-cluster-trace-v2018/hard_dag_sukrit_10k.pkl
--workload_profile_path_labels=easy,medium,hard
--override_release_policies=poisson,poisson,poisson
--override_num_invocations=0,300,150
--override_poisson_arrival_rates=0.005,0.0125,0.0125
--randomize_start_time_max=50
--min_deadline=5
--max_deadline=500
--min_deadline_variances=25,50,10
--max_deadline_variances=50,100,25

# Worker configs.
--worker_profile_path=./profiles/workers/alibaba_cluster.yaml

# Loader configs.
--alibaba_loader_task_cpu_divisor=10
--alibaba_loader_min_critical_path_runtimes=200,500,600
--alibaba_loader_max_critical_path_runtimes=500,1000,1000

# Scheduler configs.
#--scheduler=EDF
--scheduler=TetriSched
#--drop_skipped_tasks
--release_taskgraphs
--scheduler_runtime=0
--enforce_deadlines
--scheduler_time_discretization=1
--scheduler_enable_optimization_pass
--random_seed=420665456
--retract_schedules
#--scheduler_log_to_file
--scheduler_dynamic_discretization
--scheduler_max_time_discretization=8
--scheduler_max_occupancy_threshold=0.999
--finer_discretization_at_prev_solution
--finer_discretization_window=4
47 changes: 47 additions & 0 deletions configs/new_motiv_new_conf_sukrit_runs_strl_1_8_selective.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Output configs.
--log_dir=experiments/new_exps_new_conf/strl_1_8_selective_new
--log_file_name=alibaba_trace_replay_tetrisched.log
--csv_file_name=alibaba_trace_replay_tetrisched.csv
--log_level=debug

# Workload configs.
--execution_mode=replay
--replay_trace=alibaba
--workload_profile_paths=traces/alibaba-cluster-trace-v2018/easy_dag_sukrit_10k.pkl,traces/alibaba-cluster-trace-v2018/medium_dag_sukrit_10k.pkl,traces/alibaba-cluster-trace-v2018/hard_dag_sukrit_10k.pkl
--workload_profile_path_labels=easy,medium,hard
--override_release_policies=poisson,poisson,poisson
--override_num_invocations=0,300,150
--override_poisson_arrival_rates=0.005,0.0125,0.0125
--randomize_start_time_max=50
--min_deadline=5
--max_deadline=500
--min_deadline_variances=25,50,10
--max_deadline_variances=50,100,25

# Worker configs.
--worker_profile_path=./profiles/workers/alibaba_cluster.yaml

# Loader configs.
--alibaba_loader_task_cpu_divisor=10
--alibaba_loader_min_critical_path_runtimes=200,500,600
--alibaba_loader_max_critical_path_runtimes=500,1000,1000

# Scheduler configs.
#--scheduler=EDF
--scheduler=TetriSched
#--drop_skipped_tasks
--release_taskgraphs
--scheduler_runtime=0
--enforce_deadlines
--scheduler_time_discretization=1
--scheduler_enable_optimization_pass
--random_seed=420665456
--retract_schedules
#--scheduler_log_to_file
--scheduler_dynamic_discretization
--scheduler_max_time_discretization=8
--scheduler_max_occupancy_threshold=0.999
--finer_discretization_at_prev_solution
--finer_discretization_window=4
--scheduler_selective_rescheduling
--scheduler_log_to_file
17 changes: 17 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@
"The discretization is dynamically decided based on the occupancy request for "
"each time slice. (default: False)",
)
flags.DEFINE_bool(
"finer_discretization_at_prev_solution",
False,
"If `True`, the scheduler keeps discretization of 1 around previous solution. "
"The discretization is dynamically decided based on the occupancy request for "
"each time slice. (default: False)",
)
flags.DEFINE_integer(
"finer_discretization_window",
5,
"The window around previous solution that keeps discretization of 1.",
)
flags.DEFINE_integer(
"scheduler_max_time_discretization",
5,
Expand Down Expand Up @@ -782,6 +794,7 @@ def main(args):
_flags=FLAGS,
)
elif FLAGS.scheduler == "TetriSched":
finer_discretization = FLAGS.finer_discretization_at_prev_solution
scheduler = TetriSchedScheduler(
preemptive=FLAGS.preemption,
runtime=EventTime(FLAGS.scheduler_runtime, EventTime.Unit.US),
Expand All @@ -802,6 +815,10 @@ def main(args):
),
dynamic_discretization=FLAGS.scheduler_dynamic_discretization,
max_occupancy_threshold=FLAGS.scheduler_max_occupancy_threshold,
finer_discretization_at_prev_solution=finer_discretization,
finer_discretization_window=EventTime(
FLAGS.finer_discretization_window, EventTime.Unit.US
),
)
elif FLAGS.scheduler == "GraphenePrime":
scheduler = TetriSchedScheduler(
Expand Down
2 changes: 1 addition & 1 deletion profiles/workers/alibaba_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
- name: Worker_1_1
resources:
- name: Slot_1
quantity: 60
quantity: 70
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ class CapacityConstraintMap {
const Time startTime, const Time duration,
const IndicatorT usageIndicator,
const PartitionUsageT usageVariable,
std::optional<Time> granularity);
std::optional<Time> granularity,
bool print = false, std::string exprName = "");

/// Translate the CapacityConstraintMap by moving its constraints
/// to the given model.
Expand Down
11 changes: 11 additions & 0 deletions schedulers/tetrisched/include/tetrisched/Expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ struct SolutionResult {
std::optional<TETRISCHED_ILP_TYPE> utility;
/// The placement objects being bubbled up in the solution.
std::unordered_map<std::string, PlacementPtr> placements;
/// list of satisfied leaf expressions
std::set<std::string> satsifiedExpressionNames;
};
using SolutionResultPtr = std::shared_ptr<SolutionResult>;

Expand Down Expand Up @@ -224,6 +226,8 @@ class Expression : public std::enable_shared_from_this<Expression> {
/// A mutex representing a lock on the parsing and population of results
/// from this Expression.
std::mutex expressionMutex;
/// if this choose expression was previously satisfied
bool previouslySatisfied;

/// Adds a parent to this expression.
void addParent(const Expression* parent);
Expand Down Expand Up @@ -254,6 +258,12 @@ class Expression : public std::enable_shared_from_this<Expression> {
/// Removes a child from this Expression.
void removeChild(ExpressionPtr child);

/// sets that the expression was previously satisfied
void setPreviouslySatisfied(bool satisfied);

/// check of the expression was previously satisfied
bool isPreviouslySatisfied();

/// Replaces the children of this node with the given children.
void replaceChildren(std::vector<ExpressionPtr> children);

Expand Down Expand Up @@ -480,6 +490,7 @@ class AllocationExpression : public Expression {
Time currentTime) override;
SolutionResultPtr populateResults(SolverModelPtr solverModel) override;
std::string getDescriptiveName() const override;
uint32_t getResourceQuantity() const override;
};

/// An `ObjectiveExpression` collates the objectives from its children and
Expand Down
14 changes: 10 additions & 4 deletions schedulers/tetrisched/include/tetrisched/OptimizationPasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ class DiscretizationSelectorOptimizationPass : public OptimizationPass {
Time minDiscretization;
Time maxDiscretization;
float maxOccupancyThreshold;
bool finerDiscretizationAtPrevSolution;
Time finerDiscretizationWindow;

public:
/// Instantiate the DiscretizationSelectorOptimizationPass.
DiscretizationSelectorOptimizationPass();
DiscretizationSelectorOptimizationPass(Time minDiscretization = 1,
Time maxDiscretization = 5,
float maxOccupancyThreshold = 0.8);
DiscretizationSelectorOptimizationPass(
Time minDiscretization = 1, Time maxDiscretization = 5,
float maxOccupancyThreshold = 0.8,
bool finerDiscretizationAtPrevSolution = false,
Time finerDiscretizationWindow = 5);

/// Run the DiscretizationSelectorOptimizationPass on the given STRL
/// expression.
Expand Down Expand Up @@ -163,7 +167,9 @@ class OptimizationPassRunner {
OptimizationPassRunner(bool debug = false,
bool enableDynamicDiscretization = false,
Time minDiscretization = 1, Time maxDiscretization = 5,
float maxOccupancyThreshold = 0.8);
float maxOccupancyThreshold = 0.8,
bool finerDiscretizationAtPrevSolution = false,
Time finerDiscretizationWindow = 5);

/// Run the pre-translation optimization passes on the given STRL expression.
void runPreTranslationPasses(Time currentTime, ExpressionPtr strlExpression,
Expand Down
4 changes: 3 additions & 1 deletion schedulers/tetrisched/include/tetrisched/Scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class Scheduler {
/// Initialize the scheduler with a solver backend.
Scheduler(Time discretization, SolverBackendType solverBackend,
std::string logDir = "./", bool enableDynamicDiscretization = false,
Time maxDiscretization = 5, float maxOccupancyThreshold = 0.8);
Time maxDiscretization = 5, float maxOccupancyThreshold = 0.8,
bool finerDiscretizationAtPrevSolution = false,
Time finerDiscretizationWindow = 5);

/// Registers the STRL expression for the scheduler to schedule from
/// and parses it to populate the SolverModel.
Expand Down
25 changes: 18 additions & 7 deletions schedulers/tetrisched/python/Expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace py = pybind11;

void defineSTRLExpressions(py::module_& tetrisched_m) {
void defineSTRLExpressions(py::module_ &tetrisched_m) {
// Define the ExpressionType enum.
py::enum_<tetrisched::ExpressionType>(tetrisched_m, "ExpressionType")
.value("EXPR_CHOOSE", tetrisched::ExpressionType::EXPR_CHOOSE)
Expand Down Expand Up @@ -46,25 +46,31 @@ void defineSTRLExpressions(py::module_& tetrisched_m) {
tetrisched_m, "SolutionResult")
.def_property_readonly(
"startTime",
[](const tetrisched::SolutionResult& result) {
[](const tetrisched::SolutionResult &result) {
return result.startTime;
},
"The start time of the expression.")
.def_property_readonly(
"endTime",
[](const tetrisched::SolutionResult& result) {
[](const tetrisched::SolutionResult &result) {
return result.endTime;
},
"The end time of the expression.")
.def_property_readonly(
"utility",
[](const tetrisched::SolutionResult& result) {
[](const tetrisched::SolutionResult &result) {
return result.utility;
},
"The utility of the expression.")
.def_property_readonly(
"satsifiedExpressionNames",
[](const tetrisched::SolutionResult &result) {
return result.satsifiedExpressionNames;
},
"The choose expressions that were satisfied.")
.def(
"getPlacement",
[](const tetrisched::SolutionResult& result,
[](const tetrisched::SolutionResult &result,
std::string taskName) -> std::optional<tetrisched::PlacementPtr> {
if (result.placements.find(taskName) == result.placements.end()) {
return std::nullopt;
Expand All @@ -75,7 +81,7 @@ void defineSTRLExpressions(py::module_& tetrisched_m) {
"\nArgs:\n"
" taskName (str): The name of the task to get the Placement for.",
py::arg("taskName"))
.def("__str__", [](const tetrisched::SolutionResult& result) {
.def("__str__", [](const tetrisched::SolutionResult &result) {
return "Placement<start=" +
(result.startTime.has_value()
? std::to_string(result.startTime.value())
Expand Down Expand Up @@ -109,6 +115,9 @@ void defineSTRLExpressions(py::module_& tetrisched_m) {
py::arg("child"))
.def("getSolution", &tetrisched::Expression::getSolution,
"Returns the solution for this Expression.")
.def("setPreviouslySatisfied",
&tetrisched::Expression::setPreviouslySatisfied,
"Sets the flag that this expression was previously satisfied.")
.def("exportToDot", &tetrisched::Expression::exportToDot,
"Exports the Expression to a dot file.\n"
"\nArgs:\n"
Expand All @@ -117,11 +126,13 @@ void defineSTRLExpressions(py::module_& tetrisched_m) {
" included in the dot file. If False, they are not included.",
py::arg("fileName"), py::arg("emitChooseExpressions") = false)
.def("__str__",
[](const tetrisched::Expression& expr) {
[](const tetrisched::Expression &expr) {
return "Expression<name=" + expr.getName() +
", type=" + expr.getTypeString() + ">";
})
.def_property_readonly("name", &tetrisched::Expression::getName)
.def_property_readonly("discriptiveName",
&tetrisched::Expression::getDescriptiveName)
.def_property_readonly("id", &tetrisched::Expression::getId);

// Define the ChooseExpression.
Expand Down
48 changes: 28 additions & 20 deletions schedulers/tetrisched/python/TetrischedPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,34 @@ void defineScheduler(py::module_& tetrisched_m) {

// Define the interface to the Scheduler.
py::class_<tetrisched::Scheduler>(tetrisched_m, "Scheduler")
.def(py::init<tetrisched::Time, tetrisched::SolverBackendType,
std::string, bool, tetrisched::Time, float>(),
"Initializes the Scheduler with the given backend.\n"
"\nArgs:\n"
" discretization (int): The time discretization to use for the "
"scheduler.\n"
" solverBackend (SolverBackendType): The solver backend to use for "
"the scheduler.\n"
" logDir (str): The directory where the logs are to be output.\n"
" enableDynamicDiscretization (bool): Whether to enable dynamic "
"discretization.\n"
" maxDiscretization (int): The maximum discretization to use for "
"dynamic discretization.\n"
" maxOccupancyThreshold (float): The maximum occupancy threshold "
"to use for dynamic discretization.",
py::arg("discretization"), py::arg("solverBackend"),
py::arg("logDir") = "./",
py::arg("enableDynamicDiscretization") = false,
py::arg("maxDiscretization") = 5,
py::arg("maxOccupancyThreshold") = 0.8)
.def(
py::init<tetrisched::Time, tetrisched::SolverBackendType, std::string,
bool, tetrisched::Time, float, bool, tetrisched::Time>(),
"Initializes the Scheduler with the given backend.\n"
"\nArgs:\n"
" discretization (int): The time discretization to use for the "
"scheduler.\n"
" solverBackend (SolverBackendType): The solver backend to use for "
"the scheduler.\n"
" logDir (str): The directory where the logs are to be output.\n"
" enableDynamicDiscretization (bool): Whether to enable dynamic "
"discretization.\n"
" maxDiscretization (int): The maximum discretization to use for "
"dynamic discretization.\n"
" maxOccupancyThreshold (float): The maximum occupancy threshold "
"to use for dynamic discretization.\n",
" finerDiscretizationAtPrevSolution (bool): Enables finer "
"discretization "
"At previous solution.\n",
" finerDiscretizationWindow (int): The discretization around prev "
"solution until which the discretization would be 1 ",
py::arg("discretization"), py::arg("solverBackend"),
py::arg("logDir") = "./",
py::arg("enableDynamicDiscretization") = false,
py::arg("maxDiscretization") = 5,
py::arg("maxOccupancyThreshold") = 0.8,
py::arg("finerDiscretizationAtPrevSolution") = false,
py::arg("finerDiscretizationWindow") = 5)
.def(
"registerSTRL", &tetrisched::Scheduler::registerSTRL,
"Registers the STRL expression for the scheduler to schedule from.\n"
Expand Down
Loading

0 comments on commit 4c744e7

Please sign in to comment.