class_docstr: Allocate the time resources when tuning multiple tasks together.
  This implements two strategies: "round-robin" and "gradient".
  
  Parameters
  ----------
  tasks: List[SearchTask]
      All tasks to tune
  task_weights: Optional[List[float]]
      The weights of tasks.
      If provided, the task scheduler will set the objective function to
      sum(weight[t] * latency[t]), where weight[t] is the weight of a task
      and the lantecy[t] is the lantecy of the task.
      If not provided, the task scheduer will assign equal weights to all
      tasks (i.e., the objective function is sum(latency[t])).
  objective_func: Optional[Callable[List[float] -> float]]
      The objective function to be minimized.
      The objective function accepts the current latencies of all tasks and returns the
      objective.
      If not provided, the objective is the weighted sum of the latencies of all tasks.
  strategy: str = "gradient"
      The scheduling strategy.
      "round-robin": Tune tasks in round robin order.
      "gradient" : Tune tasks with gradient descent.
  load_model_file: Optional[str]
      Load pre-trained model from this file. If this is None, the cost model will
      be trained from scratch.
  load_log_file: Optional[str]
      Load measurement records from this file. If it is not None, the status of the
      task scheduler, search policies and cost models will be restored according to this file.
  verbose: int = 1
      The level of verbosity. 0 means silent.
  alpha: float = 0.2
      The parameter used for 'gradient' strategy
  beta: float = 2
      The parameter used for 'gradient' strategy
  backward_window_size: int = 3
      The parameter used for 'gradient' strategy
  callbacks: Optional[List[TaskSchedulerCallback]]
      The task scheduler callbacks that will be called before and after tuning a task.
      If None, PrintTableInfo and LogEstimatedLatency callback will be used.
class_docstr_tok: ["Allocate","the","time","resources","when","tuning","multiple","tasks","together",".","This","implements","two","strategies",":","``","round-robin","''","and","``","gradient","''",".","Parameters","--","--","--","--","--","tasks",":","List","[","SearchTask","]","All","tasks","to","tune","task_weights",":","Optional","[","List","[","float","]","]","The","weights","of","tasks",".","If","provided",",","the","task","scheduler","will","set","the","objective","function","to","sum","(","weight","[","t","]","*","latency","[","t","]",")",",","where","weight","[","t","]","is","the","weight","of","a","task","and","the","lantecy","[","t","]","is","the","lantecy","of","the","task",".","If","not","provided",",","the","task","scheduer","will","assign","equal","weights","to","all","tasks","(","i.e.",",","the","objective","function","is","sum","(","latency","[","t","]",")",")",".","objective_func",":","Optional","[","Callable","[","List","[","float","]","-",">","float","]","]","The","objective","function","to","be","minimized",".","The","objective","function","accepts","the","current","latencies","of","all","tasks","and","returns","the","objective",".","If","not","provided",",","the","objective","is","the","weighted","sum","of","the","latencies","of","all","tasks",".","strategy",":","str","=","``","gradient","''","The","scheduling","strategy",".","``","round-robin","''",":","Tune","tasks","in","round","robin","order",".","``","gradient","''",":","Tune","tasks","with","gradient","descent",".","load_model_file",":","Optional","[","str","]","Load","pre-trained","model","from","this","file",".","If","this","is","None",",","the","cost","model","will","be","trained","from","scratch",".","load_log_file",":","Optional","[","str","]","Load","measurement","records","from","this","file",".","If","it","is","not","None",",","the","status","of","the","task","scheduler",",","search","policies","and","cost","models","will","be","restored","according","to","this","file",".","verbose",":","int","=","1","The","level","of","verbosity",".","0","means","silent",".","alpha",":","float","=","0.2","The","parameter","used","for","'gradient","'","strategy","beta",":","float","=","2","The","parameter","used","for","'gradient","'","strategy","backward_window_size",":","int","=","3","The","parameter","used","for","'gradient","'","strategy","callbacks",":","Optional","[","List","[","TaskSchedulerCallback","]","]","The","task","scheduler","callbacks","that","will","be","called","before","and","after","tuning","a","task",".","If","None",",","PrintTableInfo","and","LogEstimatedLatency","callback","will","be","used","."]
docstr: restore task_cts and best_costs from a log file
docstr_tok: ["restore","task_cts","and","best_costs","from","a","log","file"]
code: def _restore_status(self, log_file, num_measures_per_round):
      """restore task_cts and best_costs from a log file"""
      str_target = str(self.tasks[0].target)
      workload_key_to_task_id = {
          t.workload_key: i for i, t in enumerate(self.tasks)
      }
      total_ct = -1
  
      for total_ct, (inp, res) in enumerate(RecordReader(log_file)):
          if str(inp.task.target) != str_target:
              continue
          task_idx = workload_key_to_task_id.get(
              inp.task.workload_key, None
          )
          if task_idx is None:
              continue
  
          self.task_cts[task_idx] += 1
  
          if res.error_no == 0:
              cost = array_mean(res.costs)
              if cost < self.best_costs[task_idx]:
                  self.best_costs[task_idx] = cost
                  self.task_best_cts[task_idx] = self.task_cts[task_idx]
  
      for idx in range(len(self.tasks)):
          if (
              self.task_cts[idx] - self.task_best_cts[idx]
              > self.early_stopping_task
          ):
              self.dead_tasks.add(idx)
  
          # The computation of taks_cts is just an estimation.
          # The estimation may not be accurate if the log file is changed externally or
          # `num_measures_per_round` is different from the last tuning.
          self.task_cts[idx] = int(
              self.task_cts[idx] / num_measures_per_round + 0.5
          )
          self.task_best_cts[idx] = int(
              self.task_best_cts[idx] / num_measures_per_round + 0.5
          )
          self.task_costs_history[idx].append(self.best_costs[idx])
  
      self.cur_score = self._compute_score(self.best_costs)
  
      logger.info(
          "TaskScheduler: Loaded %d measurement records from %s",
          total_ct + 1,
          log_file,
      )
  
imports: import os
  import time
  import math
  import logging
  import numpy
  from .search_policy import SearchPolicy, SketchPolicy, PreloadMeasuredStates
  from .cost_model import RandomModel, XGBModel
  from .utils import array_mean
  from .measure import ProgramMeasurer
  from .measure_record import RecordReader
  from .None import _ffi_api
label_desc: Use image node_id 6 for calling the TaskScheduler obj's underlying member method code with example usage: obj._restore_status(log_file, num_measures_per_round) without return types