From 7f3d09dcd9ce9b995f16f258af983df281f3724a Mon Sep 17 00:00:00 2001 From: Sukrit Kalra Date: Wed, 31 Jan 2024 09:28:06 -0800 Subject: [PATCH] More black formatting with new version. --- .../python/stubs/tetrisched_py/__init__.pyi | 19 ++++++++++++++++ .../python/stubs/tetrisched_py/backends.pyi | 22 +++++++++++++++++++ .../python/stubs/tetrisched_py/model.pyi | 21 ++++++++++++++++++ .../python/stubs/tetrisched_py/strl.pyi | 16 ++++++++++++++ simulator.py | 8 ++++--- visualization/component/utils.py | 10 ++++----- 6 files changed, 88 insertions(+), 8 deletions(-) diff --git a/schedulers/tetrisched/python/stubs/tetrisched_py/__init__.pyi b/schedulers/tetrisched/python/stubs/tetrisched_py/__init__.pyi index ff426f5d..144ebedf 100644 --- a/schedulers/tetrisched/python/stubs/tetrisched_py/__init__.pyi +++ b/schedulers/tetrisched/python/stubs/tetrisched_py/__init__.pyi @@ -1,6 +1,7 @@ """ Python API for TetriSched. """ + from __future__ import annotations import typing @@ -22,6 +23,7 @@ class Partition: """ Adds the given quantity to this Partition. """ + @typing.overload def __init__(self, partitionId: int, partitionName: str) -> None: """ @@ -31,6 +33,7 @@ class Partition: partitionId (int): The ID of this Partition. partitionName (str): The name of this Partition. """ + @typing.overload def __init__(self, partitionId: int, partitionName: str, quantity: int) -> None: """ @@ -41,15 +44,18 @@ class Partition: partitionName (str): The name of this Partition. quantity (int): The quantity of this Partition. """ + def __len__(self) -> int: """ Returns the number of Workers in this Partition. """ + @property def id(self) -> int: """ The ID of this Partition. """ + @property def name(self) -> str: """ @@ -61,14 +67,17 @@ class Partitions: """ Returns the Partition with the given ID (if exists). """ + def __init__(self) -> None: """ Initializes an empty Partitions. """ + def __len__(self) -> int: """ Returns the number of Partitions in this Partitions. """ + def addPartition(self, partition: Partition) -> None: """ Adds a Partition to this Partitions. @@ -76,6 +85,7 @@ class Partitions: Args: partition (Partition): The Partition to add to this Partitions. """ + def getPartitions(self) -> list[Partition]: """ Returns the Partitions in this Partitions. @@ -102,6 +112,7 @@ class Scheduler: maxDiscretization (int): The maximum discretization to use for dynamic discretization. maxOccupancyThreshold (float): The maximum occupancy threshold to use for dynamic discretization. """ + def exportLastSolverModel(self, fileName: str) -> None: """ Exports the model from the last invocation of the solver. @@ -109,10 +120,12 @@ class Scheduler: Args: fileName (str): The filename to export the model to. """ + def getLastSolverSolution(self) -> backends.SolverSolution: """ Retrieve the solution from the last invocation of the solver. """ + def registerSTRL( self, expression: strl.Expression, @@ -131,6 +144,7 @@ class Scheduler: schedulerConfig (SchedulerConfig): The configuration for the scheduler. timeRangeToGranularities (list): The time ranges to granularities to use for dynamic discretization. """ + def schedule(self, currentTime: int) -> None: """ Invokes the solver to schedule the registered STRL expression. @@ -144,11 +158,13 @@ class SchedulerConfig: """ Initializes an empty SchedulerConfig. """ + @property def newSolutionTimeMs(self) -> int | None: """ The new solution time to use for the solver. """ + @newSolutionTimeMs.setter def newSolutionTimeMs(self, arg0: int | None) -> None: ... @property @@ -156,6 +172,7 @@ class SchedulerConfig: """ The number of threads to use for the solver. """ + @numThreads.setter def numThreads(self, arg0: int | None) -> None: ... @property @@ -163,6 +180,7 @@ class SchedulerConfig: """ If True, the scheduler will optimize the STRL expression. """ + @optimize.setter def optimize(self, arg0: bool) -> None: ... @property @@ -170,5 +188,6 @@ class SchedulerConfig: """ The total solver time to use for the solver. """ + @totalSolverTimeMs.setter def totalSolverTimeMs(self, arg0: int | None) -> None: ... diff --git a/schedulers/tetrisched/python/stubs/tetrisched_py/backends.pyi b/schedulers/tetrisched/python/stubs/tetrisched_py/backends.pyi index 4ab455b9..7dcad977 100644 --- a/schedulers/tetrisched/python/stubs/tetrisched_py/backends.pyi +++ b/schedulers/tetrisched/python/stubs/tetrisched_py/backends.pyi @@ -1,6 +1,7 @@ """ Solver backends for the TetriSched Python API. """ + from __future__ import annotations import typing @@ -25,10 +26,12 @@ class CPLEXSolver: Args: filename (str): The filename to export the model to. """ + def getModel(self) -> tetrisched_py.model.SolverModel: """ Returns the underlying SolverModel abstraction used by this instance of CPLEXSolver. """ + def solveModel(self) -> SolverSolution: """ Solves the CPLEX model. @@ -36,6 +39,7 @@ class CPLEXSolver: Returns: SolverSolution: The characteristics of the solution. """ + def translateModel(self, solverConfig: SolverConfig) -> None: """ Translates the underlying SolverModel to a CPLEX model instance. @@ -53,10 +57,12 @@ class GurobiSolver: Args: filename (str): The filename to export the model to. """ + def getModel(self) -> tetrisched_py.model.SolverModel: """ Returns the underlying SolverModel abstraction used by this instance of GurobiSolver. """ + def solveModel(self) -> SolverSolution: """ Solves the Gurobi model. @@ -64,6 +70,7 @@ class GurobiSolver: Returns: SolverSolution: The characteristics of the solution. """ + def translateModel(self, solverConfig: SolverConfig) -> None: """ Translates the underlying SolverModel to a Gurobi model instance. @@ -152,11 +159,13 @@ class SolverConfig: """ Initializes an empty SolverConfig. """ + @property def newSolutionTimeMs(self) -> int | None: """ The total time to be spent between finding new incumbent solutions. """ + @newSolutionTimeMs.setter def newSolutionTimeMs(self, arg0: int | None) -> None: ... @property @@ -164,6 +173,7 @@ class SolverConfig: """ The total number of threads to allocate to the Solver. """ + @numThreads.setter def numThreads(self, arg0: int | None) -> None: ... @property @@ -171,6 +181,7 @@ class SolverConfig: """ The total time to be spent on the Solver. """ + @totalSolverTimeMs.setter def totalSolverTimeMs(self, arg0: int | None) -> None: ... @@ -180,56 +191,67 @@ class SolverSolution: """ Check if the solution was valid. """ + @property def numCachedVariables(self) -> int | None: """ The number of variables that were cached before. """ + @property def numConstraints(self) -> int | None: """ The number of constraints in the model. """ + @property def numDeactivatedConstraints(self) -> int | None: """ The number of constraints that were generated but deactivated. """ + @property def numNonZeroCoefficients(self) -> int | None: """ The number of non-zero coefficients in the model. """ + @property def numSolutions(self) -> int | None: """ The number of solutions found by the solver. """ + @property def numUncachedVariables(self) -> int | None: """ The number of variables that were not cached before. """ + @property def numVariables(self) -> int | None: """ The number of variables in the model. """ + @property def objectiveValue(self) -> float | None: """ The objective value of the solution (if available). """ + @property def objectiveValueBound(self) -> float | None: """ The objective value of the bound retrieved from STRL (if available). """ + @property def solutionType(self) -> SolutionType: """ The type of solution returned by the solver. """ + @property def solverTimeMicroseconds(self) -> int: """ diff --git a/schedulers/tetrisched/python/stubs/tetrisched_py/model.pyi b/schedulers/tetrisched/python/stubs/tetrisched_py/model.pyi index bad1ecce..b422aaab 100644 --- a/schedulers/tetrisched/python/stubs/tetrisched_py/model.pyi +++ b/schedulers/tetrisched/python/stubs/tetrisched_py/model.pyi @@ -1,6 +1,7 @@ """ Modelling primitives for the TetriSched Python API. """ + from __future__ import annotations import typing @@ -25,6 +26,7 @@ class Constraint: type (ConstraintType): The type of this Constraint. rhs (int): The RHS of this Constraint. """ + def __len__(self) -> int: ... def __str__(self) -> str: ... @typing.overload @@ -36,6 +38,7 @@ class Constraint: coefficient (int): The coefficient of the new term. variable (Variable): The Variable of the new term. """ + @typing.overload def addTerm(self, constant: float) -> None: """ @@ -44,11 +47,13 @@ class Constraint: Args: constant (int): The constant of the new term. """ + @property def id(self) -> int: """ The ID of this Constraint. """ + @property def name(self) -> str: """ @@ -95,6 +100,7 @@ class ObjectiveFunction: Args: type (ObjectiveType): The type of this ObjectiveFunction. """ + def __len__(self) -> int: ... def __str__(self) -> str: ... @typing.overload @@ -106,6 +112,7 @@ class ObjectiveFunction: coefficient (int): The coefficient of the new term. variable (Variable): The Variable of the new term. """ + @typing.overload def addTerm(self, constant: float) -> None: """ @@ -114,6 +121,7 @@ class ObjectiveFunction: Args: constant (int): The constant of the new term. """ + def toConstraint(self, name: str, type: ConstraintType, rhs: float) -> Constraint: """ Converts this ObjectiveFunction into a Constraint. @@ -123,6 +131,7 @@ class ObjectiveFunction: type (ConstraintType): The type of the Constraint to be returned. rhs (int): The RHS of the Constraint to be returned. """ + @property def value(self) -> float: """ @@ -171,6 +180,7 @@ class SolverModel: Args: constraint (Constraint): The Constraint to add to the model. """ + def addVariable(self, variable: Variable) -> None: """ Adds a new Variable to the model. @@ -178,6 +188,7 @@ class SolverModel: Args: variable (Variable): The Variable to add to the model. """ + def exportModel(self, fileName: str) -> None: """ Exports the model to the given file. @@ -185,6 +196,7 @@ class SolverModel: Args: fileName (str): The name of the file to export the model to. """ + def setObjectiveFunction(self, objective: ObjectiveFunction) -> None: """ Sets the ObjectiveFunction of the model. @@ -192,16 +204,19 @@ class SolverModel: Args: objective (ObjectiveFunction): The ObjectiveFunction to set. """ + @property def num_constraints(self) -> int: """ The number of constraints in the model. """ + @property def num_variables(self) -> int: """ The number of variables in the model. """ + @property def objective_value(self) -> float: """ @@ -218,6 +233,7 @@ class Variable: type (VariableType): The type of this Variable. name (str): The name of this Variable. """ + @typing.overload def __init__(self, type: VariableType, name: str, lowerBound: float) -> None: """ @@ -228,6 +244,7 @@ class Variable: name (str): The name of this Variable. lowerBound (int): The lower bound of this Variable. """ + @typing.overload def __init__( self, type: VariableType, name: str, lowerBound: float, upperBound: float @@ -241,6 +258,7 @@ class Variable: lowerBound (int): The lower bound of this Variable. upperBound (int): The upper bound of this Variable. """ + def __str__(self) -> str: ... def hint(self, value: float) -> None: """ @@ -249,16 +267,19 @@ class Variable: Args: value (int): The value to set for this Variable. """ + @property def id(self) -> int: """ The ID of this Variable. """ + @property def name(self) -> str: """ The name of this Variable. """ + @property def value(self) -> float | None: """ diff --git a/schedulers/tetrisched/python/stubs/tetrisched_py/strl.pyi b/schedulers/tetrisched/python/stubs/tetrisched_py/strl.pyi index 9cd0016e..e056e3e2 100644 --- a/schedulers/tetrisched/python/stubs/tetrisched_py/strl.pyi +++ b/schedulers/tetrisched/python/stubs/tetrisched_py/strl.pyi @@ -1,6 +1,7 @@ """ STRL primitives for the TetriSched Python API. """ + from __future__ import annotations import typing @@ -75,6 +76,7 @@ class ChooseExpression(Expression): priorPlacements (PriorPlacement): The prior placements of the expression in a previous cycle, if available. """ + @typing.overload def __init__( self, @@ -115,6 +117,7 @@ class Expression: Args: child (Expression): The child to add to this Expression. """ + def exportToDot(self, fileName: str, emitChooseExpressions: bool = False) -> None: """ Exports the Expression to a dot file. @@ -124,26 +127,32 @@ class Expression: emitChooseExpressions (bool): If True, ChooseExpressions are included in the dot file. If False, they are not included. """ + def getChildren(self) -> list[Expression]: """ Returns the children of this Expression. """ + def getNumChildren(self) -> int: """ Returns the number of children of this Expression. """ + def getNumParents(self) -> int: """ Returns the number of parents of this Expression. """ + def getSolution(self) -> SolutionResult | None: """ Returns the solution for this Expression. """ + def getType(self) -> ExpressionType: """ Returns the type of this Expression. """ + @property def id(self) -> str: ... @property @@ -314,15 +323,18 @@ class Placement: """ Returns the Partition assignments for this Placement. """ + def isPlaced(self) -> bool: """ Returns true if the Placement was placed, false otherwise. """ + @property def name(self) -> str: """ The name of the Placement. """ + @property def startTime(self) -> int | None: """ @@ -339,6 +351,7 @@ class ScaleExpression(Expression): name (str): The name of the ScaleExpression. scaleFactor (TETRISCHED_ILP_TYPE): The scaling factor of the ScaleExpression. """ + @typing.overload def __init__(self, name: str, scaleFactor: float, disregardUtility: bool) -> None: """ @@ -360,16 +373,19 @@ class SolutionResult: Args: taskName (str): The name of the task to get the Placement for. """ + @property def endTime(self) -> int | None: """ The end time of the expression. """ + @property def startTime(self) -> int | None: """ The start time of the expression. """ + @property def utility(self) -> float | None: """ diff --git a/simulator.py b/simulator.py index 568c7715..c86370fd 100644 --- a/simulator.py +++ b/simulator.py @@ -1551,9 +1551,11 @@ def __handle_update_workload(self, event: Event) -> None: next_update_event = Event( event_type=EventType.UPDATE_WORKLOAD, - time=max_release_time + EventTime(1, EventTime.Unit.US) - if self._workload_update_interval.is_invalid() - else self._simulator_time + self._workload_update_interval, + time=( + max_release_time + EventTime(1, EventTime.Unit.US) + if self._workload_update_interval.is_invalid() + else self._simulator_time + self._workload_update_interval + ), ) self._event_queue.add_event(next_update_event) self._logger.info( diff --git a/visualization/component/utils.py b/visualization/component/utils.py index ce68e5cf..51475df3 100644 --- a/visualization/component/utils.py +++ b/visualization/component/utils.py @@ -172,11 +172,11 @@ def visualize_task_graph(task_graph_id, df_tasks, trace_data): + f"slowest_runtime={row['slowest_execution_time'].item()}", size=25, shape="dot", - color="red" - if row["cancelled"].item() - else "orange" - if row["missed_deadline"].item() - else "green", + color=( + "red" + if row["cancelled"].item() + else "orange" if row["missed_deadline"].item() else "green" + ), ) )