class_docstr: WorkloadSequencer is the python rewrite of the old golang
  TrialWorkloadSequencer.
  
  Like the go version, it fuses the dual stream of searcher operations +
  descheduling decisions into a single stream of Workload events.
  
  When the sequencer was in the master, the resulting stream of Workloads was
  the basis for all master/harness communications, but now that the sequencer
  lives in the harness, all master/harness communications are over the new
  push APIs.
  
  This Workload stream (and the whole WorkloadSequencer) is only even needed
  for reverse-compatibility with the old TrialControllers that we don't care
  to update (TFKerasTrial and EstimatorTrial).
class_docstr_tok: ["WorkloadSequencer","is","the","python","rewrite","of","the","old","golang","TrialWorkloadSequencer",".","Like","the","go","version",",","it","fuses","the","dual","stream","of","searcher","operations","+","descheduling","decisions","into","a","single","stream","of","Workload","events",".","When","the","sequencer","was","in","the","master",",","the","resulting","stream","of","Workloads","was","the","basis","for","all","master\/harness","communications",",","but","now","that","the","sequencer","lives","in","the","harness",",","all","master\/harness","communications","are","over","the","new","push","APIs",".","This","Workload","stream","(","and","the","whole","WorkloadSequencer",")","is","only","even","needed","for","reverse-compatibility","with","the","old","TrialControllers","that","we","do","n't","care","to","update","(","TFKerasTrial","and","EstimatorTrial",")","."]
code: def as_batches(
      self,
      batches: Optional[int] = None,
      records: Optional[int] = None,
      epochs: Optional[int] = None,
  ) -> int:
      if (
          sum(
              (
                  batches is not None,
                  records is not None,
                  epochs is not None,
              )
          )
          != 1
      ):
          raise ValueError(
              f"invalid length: batches={batches} records={records} epochs={epochs}"
          )
      if batches is not None:
          return batches
      if records is not None:
          check.gt(
              self.global_batch_size,
              0,
              "global_batch_size must be positive",
          )
          return max(records // self.global_batch_size, 1)
      if epochs is not None:
          assert self.records_per_epoch is not None
          check.is_instance(
              self.records_per_epoch, int, "length must be an integer"
          )
          check.gt(
              self.global_batch_size,
              0,
              "global_batch_size must be positive",
          )
          return max(
              (epochs * self.records_per_epoch)
              // self.global_batch_size,
              1,
          )
      # Make mypy happy.
      raise ValueError("invalid length")
  
imports: import logging
  import sys
  from typing import Any, Generator, Optional, Tuple
  import determined
  from determined import core, util, workload
  from determined.common import check
label_desc: Use image node_id 4 for calling the WorkloadSequencer obj's underlying member method code with example usage: obj.as_batches(batches, records, epochs) and returns: batches, max, max