Skip to content

Commit

Permalink
Format changes to pass builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
sukritkalra committed Feb 21, 2024
1 parent 69ad629 commit 60d955f
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "tetrisched/Partition.hpp"
#include "tetrisched/SolverModel.hpp"
#include "tetrisched/Types.hpp"
// #include "tetrisched/Expression.hpp"

namespace tetrisched {

Expand Down Expand Up @@ -145,7 +144,8 @@ class CapacityConstraintMap {
const Time startTime, const Time duration,
const IndicatorT usageIndicator,
const PartitionUsageT usageVariable,
std::optional<Time> granularity, bool print = false, std::string exprName= "");
std::optional<Time> granularity,
bool print = false, std::string exprName = "");

/// Translate the CapacityConstraintMap by moving its constraints
/// to the given model.
Expand Down
32 changes: 18 additions & 14 deletions schedulers/tetrisched/include/tetrisched/OptimizationPasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ class DiscretizationSelectorOptimizationPass : public OptimizationPass {
public:
/// Instantiate the DiscretizationSelectorOptimizationPass.
DiscretizationSelectorOptimizationPass();
DiscretizationSelectorOptimizationPass(Time minDiscretization = 1,
Time maxDiscretization = 5,
float maxOccupancyThreshold = 0.8, bool finerDiscretizationAtPrevSolution = false, Time finerDiscretizationWindow = 5);
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 @@ -162,18 +164,20 @@ class OptimizationPassRunner {

public:
/// Initialize the OptimizationPassRunner.
OptimizationPassRunner(bool debug = false,
bool enableDynamicDiscretization = false,
Time minDiscretization = 1, Time maxDiscretization = 5,
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,
OptimizationPassRunner(bool debug = false,
bool enableDynamicDiscretization = false,
Time minDiscretization = 1, Time maxDiscretization = 5,
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,
CapacityConstraintMapPtr capacityConstraints);

/// Run the post-translation optimization passes on the given STRL expression.
void runPostTranslationPasses(Time currentTime, ExpressionPtr strlExpression,
CapacityConstraintMapPtr capacityConstraints);

/// Run the post-translation optimization passes on the given STRL expression.
void runPostTranslationPasses(Time currentTime, ExpressionPtr strlExpression,
CapacityConstraintMapPtr capacityConstraints);
};
} // namespace tetrisched
#endif // _TETRISCHED_OPTIMIZATION_PASSES_HPP_
119 changes: 59 additions & 60 deletions schedulers/tetrisched/include/tetrisched/Scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,72 @@
#include "tetrisched/Partition.hpp"
#include "tetrisched/Solver.hpp"

namespace tetrisched
{
namespace tetrisched {

/// The `SchedulerConfig` structure represents the configuration of the
/// scheduler. This config is used to inform the choice of how the scheduler
/// should schedule the STRL expression.
struct SchedulerConfig
{
/// If True, the scheduler will optimize the STRL expression.
bool optimize;
/// The `SchedulerConfig` structure represents the configuration of the
/// scheduler. This config is used to inform the choice of how the scheduler
/// should schedule the STRL expression.
struct SchedulerConfig {
/// If True, the scheduler will optimize the STRL expression.
bool optimize;

/// The configuration for the solver backend.
std::optional<uint64_t> numThreads;
std::optional<Time> totalSolverTimeMs;
std::optional<Time> newSolutionTimeMs;
};
using SchedulerConfig = struct SchedulerConfig;
using SchedulerConfigPtr = std::shared_ptr<SchedulerConfig>;
/// The configuration for the solver backend.
std::optional<uint64_t> numThreads;
std::optional<Time> totalSolverTimeMs;
std::optional<Time> newSolutionTimeMs;
};
using SchedulerConfig = struct SchedulerConfig;
using SchedulerConfigPtr = std::shared_ptr<SchedulerConfig>;

class Scheduler
{
private:
/// The solver instance underlying the Scheduler with the given type.
std::shared_ptr<Solver> solver;
SolverBackendType solverBackend;
/// The solver model to be passed to the expressions during parsing.
SolverModelPtr solverModel;
/// The configuration for the Solver.
SolverConfigPtr solverConfig;
/// The solution to the last solver invocation (if available).
std::optional<SolverSolutionPtr> solverSolution;
/// The time discretization to use for the solver.
Time discretization;
/// The registered STRL expression (if available).
std::optional<ExpressionPtr> expression;
/// The registered OptimizationPasses to run.
OptimizationPassRunner optimizationPasses;
/// The directory where the logs are to be output.
std::string logDir;
class Scheduler {
private:
/// The solver instance underlying the Scheduler with the given type.
std::shared_ptr<Solver> solver;
SolverBackendType solverBackend;
/// The solver model to be passed to the expressions during parsing.
SolverModelPtr solverModel;
/// The configuration for the Solver.
SolverConfigPtr solverConfig;
/// The solution to the last solver invocation (if available).
std::optional<SolverSolutionPtr> solverSolution;
/// The time discretization to use for the solver.
Time discretization;
/// The registered STRL expression (if available).
std::optional<ExpressionPtr> expression;
/// The registered OptimizationPasses to run.
OptimizationPassRunner optimizationPasses;
/// The directory where the logs are to be output.
std::string logDir;

public:
/// 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, bool finerDiscretizationAtPrevSolution = false, Time finerDiscretizationWindow = 5);
public:
/// 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,
bool finerDiscretizationAtPrevSolution = false,
Time finerDiscretizationWindow = 5);

/// Registers the STRL expression for the scheduler to schedule from
/// and parses it to populate the SolverModel.
void registerSTRL(
ExpressionPtr expression, Partitions availablePartitions,
Time currentTime, SchedulerConfigPtr schedulerConfig,
std::vector<std::pair<TimeRange, Time>> timeRangeToGranularities = {});
/// Registers the STRL expression for the scheduler to schedule from
/// and parses it to populate the SolverModel.
void registerSTRL(
ExpressionPtr expression, Partitions availablePartitions,
Time currentTime, SchedulerConfigPtr schedulerConfig,
std::vector<std::pair<TimeRange, Time>> timeRangeToGranularities = {});

/// Invokes the solver to schedule the registered STRL expression
/// on the given partitions at the given time.
/// Use expression->getSolution() to retrieve the solution.
void schedule(Time currentTime);
/// Invokes the solver to schedule the registered STRL expression
/// on the given partitions at the given time.
/// Use expression->getSolution() to retrieve the solution.
void schedule(Time currentTime);

/// Retrieve the solution from the last invocation of the solver.
SolverSolutionPtr getLastSolverSolution() const;
/// Retrieve the solution from the last invocation of the solver.
SolverSolutionPtr getLastSolverSolution() const;

/// Exports the model from the last invocation of the solver.
void exportLastSolverModel(const std::string &fileName) const;
/// Exports the model from the last invocation of the solver.
void exportLastSolverModel(const std::string &fileName) const;

/// Exports the solution from the last invocation of the solver.
void exportLastSolverSolution(const std::string &fileName) const;
};
} // namespace tetrisched
/// Exports the solution from the last invocation of the solver.
void exportLastSolverSolution(const std::string &fileName) const;
};
} // namespace tetrisched

#endif //_TETRISCHED_SCHEDULER_HPP_
#endif //_TETRISCHED_SCHEDULER_HPP_
76 changes: 36 additions & 40 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,61 +46,56 @@ void defineSTRLExpressions(py::module_& tetrisched_m) {
tetrisched_m, "SolutionResult")
.def_property_readonly(
"startTime",
[](const tetrisched::SolutionResult &result)
{
return result.startTime;
[](const tetrisched::SolutionResult &result) {
return result.startTime;
},
"The start time of the expression.")
.def_property_readonly(
"endTime",
[](const tetrisched::SolutionResult &result)
{
return result.endTime;
[](const tetrisched::SolutionResult &result) {
return result.endTime;
},
"The end time of the expression.")
.def_property_readonly(
"utility",
[](const tetrisched::SolutionResult &result)
{
return result.utility;
[](const tetrisched::SolutionResult &result) {
return result.utility;
},
"The utility of the expression.")
.def_property_readonly(
"satsifiedExpressionNames",
[](const tetrisched::SolutionResult &result)
{
return result.satsifiedExpressionNames;
[](const tetrisched::SolutionResult &result) {
return result.satsifiedExpressionNames;
},
"The choose expressions that were satisfied.")
.def(
"getPlacement",
[](const tetrisched::SolutionResult &result,
std::string taskName) -> std::optional<tetrisched::PlacementPtr>
{
if (result.placements.find(taskName) == result.placements.end())
{
return std::nullopt;
}
return result.placements.at(taskName);
std::string taskName) -> std::optional<tetrisched::PlacementPtr> {
if (result.placements.find(taskName) == result.placements.end()) {
return std::nullopt;
}
return result.placements.at(taskName);
},
"Returns the Placement for the given task.\n"
"\nArgs:\n"
" taskName (str): The name of the task to get the Placement for.",
py::arg("taskName"))
.def("__str__", [](const tetrisched::SolutionResult &result)
{ return "Placement<start=" +
(result.startTime.has_value()
? std::to_string(result.startTime.value())
: "None") +
", end=" +
(result.endTime.has_value()
? std::to_string(result.endTime.value())
: "None") +
", utility=" +
(result.utility.has_value()
? std::to_string(result.utility.value())
: "None") +
">"; });
.def("__str__", [](const tetrisched::SolutionResult &result) {
return "Placement<start=" +
(result.startTime.has_value()
? std::to_string(result.startTime.value())
: "None") +
", end=" +
(result.endTime.has_value()
? std::to_string(result.endTime.value())
: "None") +
", utility=" +
(result.utility.has_value()
? std::to_string(result.utility.value())
: "None") +
">";
});

// Define the base Expression.
py::class_<tetrisched::Expression, tetrisched::ExpressionPtr>(tetrisched_m,
Expand All @@ -120,7 +115,8 @@ 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,
.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"
Expand All @@ -130,13 +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)
{
return "Expression<name=" + expr.getName() +
", type=" + expr.getTypeString() + ">";
[](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("discriptiveName",
&tetrisched::Expression::getDescriptiveName)
.def_property_readonly("id", &tetrisched::Expression::getId);

// Define the ChooseExpression.
Expand Down
53 changes: 28 additions & 25 deletions schedulers/tetrisched/python/TetrischedPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +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, 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(
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 60d955f

Please sign in to comment.