Ensures all trials get fair share of time (as defined by time_attr).

        This enables the PBT scheduler to support a greater number of
        concurrent trials than can fit in the cluster at any given time.
332060
def choose_trial_to_run(self, trial_runner):
        

        candidates = []
        for trial in trial_runner.get_trials():
            if trial.status in [Trial.PENDING, Trial.PAUSED] and \
                    trial_runner.has_resources(trial.resources):
                candidates.append(trial)
        candidates.sort(
            key=lambda trial: self._trial_state[trial].last_perturbation_time)
        return candidates[0] if candidates else None
697388
public static void distributeShare(
      double total, final Collection<? extends Schedulable> schedulables,
      ScheduleComparator comparator) {
    switch (comparator) {
    case FIFO:
    case DEADLINE:
      Schedulable.distributeShareSorted(total, schedulables, comparator);
      break;
    case FAIR:
      Schedulable.distributeShareFair(total, schedulables);
      break;
    case PRIORITY:
      Schedulable.distributeSharePriority(total, schedulables);
      break;
    default:
      throw new IllegalArgumentException("Unknown comparator");
    }
  }
28017
def run_tpm(tpm, time_scale):
    
    sbs_tpm = convert.state_by_node2state_by_state(tpm)
    if sparse(tpm):
        tpm = sparse_time(sbs_tpm, time_scale)
    else:
        tpm = dense_time(sbs_tpm, time_scale)
    return convert.state_by_state2state_by_node(tpm)
679672
def _every(times, step_size, index):
        
        current = index * step_size
        step = current // times * times
        reached = current >= step
        overshot = current >= step + step_size
        return current and reached and not overshot
61663
private void scheduleRebalance() {
    if (rebalanceTimer != null) {
      rebalanceTimer.cancel();
    }
    rebalanceTimer = getScheduler().schedule(REBALANCE_DURATION, this::rebalance);
  }
1276131
def advance_cluster_time(self, cluster_time):
        
        if not isinstance(cluster_time, abc.Mapping):
            raise TypeError(
                "cluster_time must be a subclass of collections.Mapping")
        if not isinstance(cluster_time.get("clusterTime"), Timestamp):
            raise ValueError("Invalid cluster_time")
        self._advance_cluster_time(cluster_time)
432236
private static void distributeShareMin(
      Collection<? extends Schedulable> schedulableVector) {
    for (Schedulable schedulable : schedulableVector) {
      schedulable.share += schedulable.getMinimum();
    }
  }
1030504
def future_run_times
      future_run_times = existing_run_times.dup
      last_run_time = future_run_times.last || at - frequency
      last_run_time = last_run_time.in_time_zone(time_zone)

      # Ensure there are at least two future jobs scheduled and that the queue ahead time is filled
      while future_run_times.length < 2 || minutes_queued_ahead(last_run_time) < queue_ahead
        last_run_time = frequency.from_now(last_run_time)
        # The hour may not match because of a shift caused by DST in previous run times,
        # so we need to ensure that the hour matches the specified hour if given.
        last_run_time = last_run_time.change(hour: at.hour, min: at.min) if at.hour?
        future_run_times << last_run_time
      end

      future_run_times
    end
784789
def _makeTimingRelative(absoluteDataList):
    '''
    
    '''

    timingSeq = [row[0] for row in absoluteDataList]
    valueSeq = [list(row[1:]) for row in absoluteDataList]

    relTimingSeq, startTime, endTime = makeSequenceRelative(timingSeq)
    
    relDataList = [tuple([time, ] + row) for time, row
                   in zip(relTimingSeq, valueSeq)]

    return relDataList, startTime, endTime
930857
def time_conflict(self, schedule):
        
        if is_nil(schedule):
            return True
        for timerange in self._excluded_times:
            if timerange.conflicts_with(schedule):
                return False
        return True
947372
private int timeSkewInSeconds(Date clientTime, Date serverTime) {
        ValidationUtils.assertNotNull(clientTime, "clientTime");
        ValidationUtils.assertNotNull(serverTime, "serverTime");

        long value = (clientTime.getTime() - serverTime.getTime()) / 1000;

        if ((int) value != value) {
            throw new IllegalStateException("Time is too skewed to adjust: (clientTime: " + clientTime.getTime() + ", " +
                                            "serverTime: " + serverTime.getTime() + ")");
        }
        return (int) value;
    }
697680
def on_trial_complete(self,
                          trial_id,
                          result=None,
                          error=False,
                          early_terminated=False):
        
        ho_trial = self._get_hyperopt_trial(trial_id)
        if ho_trial is None:
            return
        ho_trial["refresh_time"] = hpo.utils.coarse_utcnow()
        if error:
            ho_trial["state"] = hpo.base.JOB_STATE_ERROR
            ho_trial["misc"]["error"] = (str(TuneError), "Tune Error")
        elif early_terminated:
            ho_trial["state"] = hpo.base.JOB_STATE_ERROR
            ho_trial["misc"]["error"] = (str(TuneError), "Tune Removed")
        else:
            ho_trial["state"] = hpo.base.JOB_STATE_DONE
            hp_result = self._to_hyperopt_result(result)
            ho_trial["result"] = hp_result
        self._hpopt_trials.refresh()
        del self._live_trial_mapping[trial_id]
60129
def next_trials(self):
        
        trials = list(self._trial_generator)
        if self._shuffle:
            random.shuffle(trials)
        self._finished = True
        return trials
425632
private void setItem(int index, Timepoint time) {
        time = roundToValidTime(time, index);
        mCurrentTime = time;
        reselectSelector(time, false, index);
    }
619697
def schedule_saved(sender, instance, **kwargs):
    
    from contentstore.tasks import sync_schedule

    sync_schedule.delay(str(instance.id))
177682
def validate_EQUALTIMESTEPS(value, restriction):
    
    if len(value) == 0:
        return

    if type(value) == pd.DataFrame:
        if str(value.index[0]).startswith('9999'):
            tmp_val = value.to_json().replace('9999', '1900')
            value = pd.read_json(tmp_val)


    #If the timeseries is not datetime-based, check for a consistent timestep
    if type(value.index) == pd.Int64Index:
        timesteps = list(value.index)
        timestep = timesteps[1] - timesteps[0]
        for i, t in enumerate(timesteps[1:]):
            if timesteps[i] - timesteps[i-1] != timestep:
                raise ValidationError("Timesteps not equal: %s"%(list(value.index)))


    if not hasattr(value.index, 'inferred_freq'):
        raise ValidationError("Timesteps not equal: %s"%(list(value.index),))

    if restriction is None:
        if value.index.inferred_freq is None:
            raise ValidationError("Timesteps not equal: %s"%(list(value.index),))
    else:
        if value.index.inferred_freq != restriction:
            raise ValidationError("Timesteps not equal: %s"%(list(value.index),))
324593
async def _fair_recv(self):
        
        with await self._read_lock:
            peer = await self._fair_get_in_peer()
            result = peer.inbox.read_nowait()

        return result