import re
import time
from typing import Optional

import IPython.display as disp

from ..trainer_callback import TrainerCallback
from ..trainer_utils import IntervalStrategy, has_length


def    a__       (						__UpperCamelCase ):
      SCREAMING_SNAKE_CASE_      =     int(__UpperCamelCase )
      SCREAMING_SNAKE_CASE_   ,       SCREAMING_SNAKE_CASE_   ,       SCREAMING_SNAKE_CASE_      =     t // 3_6_0_0, (t // 6_0) % 6_0, t % 6_0
      return F'''{h}:{m:02d}:{s:02d}''' if h != 0 else F'''{m:02d}:{s:02d}'''


def    a__       (						__UpperCamelCase   ,					__UpperCamelCase   ,					__UpperCamelCase   ,					__UpperCamelCase   ,					__UpperCamelCase=3_0_0 ):
      # docstyle-ignore
      return F'''
    <div>
      {prefix}
      <progress value=\'{value}\' max=\'{total}\' style=\'width:{width}px; height:20px; vertical-align: middle;\'></progress>
      {label}
    </div>
    '''


def    a__       (						__UpperCamelCase ):
      SCREAMING_SNAKE_CASE_      =     "<table border=\"1\" class=\"dataframe\">\n"
      html_code += """  <thead>\n <tr style="text-align: left;">\n"""
      for i in items[0]:
            html_code += F'''      <th>{i}</th>\n'''
      html_code += "    </tr>\n  </thead>\n  <tbody>\n"
      for line in items[1:]:
            html_code += "    <tr>\n"
            for elt in line:
                  SCREAMING_SNAKE_CASE_      =     F'''{elt:.6f}''' if isinstance(__UpperCamelCase   ,					__UpperCamelCase ) else str(__UpperCamelCase )
                  html_code += F'''      <td>{elt}</td>\n'''
            html_code += "    </tr>\n"
      html_code += "  </tbody>\n</table><p>"
      return html_code


class      lowerCamelCase    :
  """simple docstring"""







  lowerCamelCase__   =  5
  lowerCamelCase__   =  0.2







  def __init__(							self       :				Union[str, Any]     ,   __magic_name__       :				int     ,   __magic_name__       :				Optional[str] = None     ,   __magic_name__       :				bool = True     ,   __magic_name__       :				Optional["NotebookTrainingTracker"] = None     ,   __magic_name__       :				int = 300     ,   )     ->		int:
        SCREAMING_SNAKE_CASE_      =     total
        SCREAMING_SNAKE_CASE_      =     "" if prefix is None else prefix
        SCREAMING_SNAKE_CASE_      =     leave
        SCREAMING_SNAKE_CASE_      =     parent
        SCREAMING_SNAKE_CASE_      =     width
        SCREAMING_SNAKE_CASE_      =     None
        SCREAMING_SNAKE_CASE_      =     None
        SCREAMING_SNAKE_CASE_      =     None







  def       __A   (							self       :				List[Any]     ,   __magic_name__       :				int     ,   __magic_name__       :				bool = False     ,   __magic_name__       :				str = None      )     ->		Dict:
        SCREAMING_SNAKE_CASE_      =     value
        if comment is not None:
              SCREAMING_SNAKE_CASE_      =     comment
        if self.last_value is None:
              SCREAMING_SNAKE_CASE_      =     SCREAMING_SNAKE_CASE_      =     time.time()
              SCREAMING_SNAKE_CASE_      =     SCREAMING_SNAKE_CASE_      =     value
              SCREAMING_SNAKE_CASE_      =     SCREAMING_SNAKE_CASE_      =     None
              SCREAMING_SNAKE_CASE_      =     self.warmup
              SCREAMING_SNAKE_CASE_      =     1
              self.update_bar(__magic_name__      )
        elif value <= self.last_value and not force_update:
              return
        elif force_update or self.first_calls > 0 or value >= min(self.last_value + self.wait_for     ,   self.total      ):
              if self.first_calls > 0:
                    self.first_calls -= 1
              SCREAMING_SNAKE_CASE_      =     time.time()
              SCREAMING_SNAKE_CASE_      =     current_time - self.start_time
              # We could have value = self.start_value if the update is called twixe with the same start value.
              if value > self.start_value:
                    SCREAMING_SNAKE_CASE_      =     self.elapsed_time / (value - self.start_value)
              else:
                    SCREAMING_SNAKE_CASE_      =     None
              if value >= self.total:
                    SCREAMING_SNAKE_CASE_      =     self.total
                    SCREAMING_SNAKE_CASE_      =     None
                    if not self.leave:
                          self.close()
              elif self.average_time_per_item is not None:
                    SCREAMING_SNAKE_CASE_      =     self.average_time_per_item * (self.total - value)
              self.update_bar(__magic_name__      )
              SCREAMING_SNAKE_CASE_      =     value
              SCREAMING_SNAKE_CASE_      =     current_time
              if self.average_time_per_item is None:
                    SCREAMING_SNAKE_CASE_      =     1
              else:
                    SCREAMING_SNAKE_CASE_      =     max(int(self.update_every / self.average_time_per_item      )     ,   1      )







  def       __A   (							self       :				str     ,   __magic_name__       :				Optional[Any]     ,   __magic_name__       :				Any=None      )     ->		List[Any]:
        SCREAMING_SNAKE_CASE_      =     " " * (len(str(self.total      )      ) - len(str(__magic_name__      )      )) + str(__magic_name__      )
        if self.elapsed_time is None:
              SCREAMING_SNAKE_CASE_      =     F'''[{spaced_value}/{self.total} : < :'''
        elif self.predicted_remaining is None:
              SCREAMING_SNAKE_CASE_      =     F'''[{spaced_value}/{self.total} {format_time(self.elapsed_time      )}'''
        else:
              SCREAMING_SNAKE_CASE_      =     (
                  F'''[{spaced_value}/{self.total} {format_time(self.elapsed_time      )} <'''
                  F''' {format_time(self.predicted_remaining      )}'''
              )
              self.label += F''', {1/self.average_time_per_item:.2f} it/s'''
        self.label += "]" if self.comment is None or len(self.comment      ) == 0 else F''', {self.comment}]'''
        self.display()







  def       __A   (							self       :				Optional[int]      )     ->		Optional[Any]:
        SCREAMING_SNAKE_CASE_      =     html_progress_bar(self.value     ,   self.total     ,   self.prefix     ,   self.label     ,   self.width      )
        if self.parent is not None:
              # If this is a child bar, the parent will take care of the display.
              self.parent.display()
              return
        if self.output is None:
              SCREAMING_SNAKE_CASE_      =     disp.display(disp.HTML(self.html_code      )     ,   display_id=__magic_name__      )
        else:
              self.output.update(disp.HTML(self.html_code      )      )







  def       __A   (							self       :				int      )     ->		List[Any]:
        if self.parent is None and self.output is not None:
              self.output.update(disp.HTML(""      )      )



class      lowerCamelCase    (SCREAMING_SNAKE_CASE__    ):
  """simple docstring"""







  def __init__(							self       :				Optional[int]     ,   __magic_name__       :				List[Any]     ,   __magic_name__       :				Optional[int]=None      )     ->		List[Any]:
        super().__init__(__magic_name__      )
        SCREAMING_SNAKE_CASE_      =     None if column_names is None else [column_names]
        SCREAMING_SNAKE_CASE_      =     None







  def       __A   (							self       :				str      )     ->		Tuple:
        SCREAMING_SNAKE_CASE_      =     html_progress_bar(self.value     ,   self.total     ,   self.prefix     ,   self.label     ,   self.width      )
        if self.inner_table is not None:
              self.html_code += text_to_html_table(self.inner_table      )
        if self.child_bar is not None:
              self.html_code += self.child_bar.html_code
        if self.output is None:
              SCREAMING_SNAKE_CASE_      =     disp.display(disp.HTML(self.html_code      )     ,   display_id=__magic_name__      )
        else:
              self.output.update(disp.HTML(self.html_code      )      )







  def       __A   (							self       :				Dict     ,   __magic_name__       :				Dict      )     ->		List[Any]:
        if self.inner_table is None:
              SCREAMING_SNAKE_CASE_      =     [list(values.keys()      ), list(values.values()      )]
        else:
              SCREAMING_SNAKE_CASE_      =     self.inner_table[0]
              if len(self.inner_table      ) == 1:
                    # We give a chance to update the column names at the first iteration
                    for key in values.keys():
                          if key not in columns:
                                columns.append(__magic_name__      )
                    SCREAMING_SNAKE_CASE_      =     columns
              self.inner_table.append([values[c] for c in columns]      )







  def       __A   (							self       :				Any     ,   __magic_name__       :				List[str]     ,   __magic_name__       :				Dict=None     ,   __magic_name__       :				Optional[int]=300      )     ->		Optional[int]:
        SCREAMING_SNAKE_CASE_      =     NotebookProgressBar(__magic_name__     ,   prefix=__magic_name__     ,   parent=self     ,   width=__magic_name__      )
        return self.child_bar







  def       __A   (							self       :				Optional[int]      )     ->		Optional[Any]:
        SCREAMING_SNAKE_CASE_      =     None
        self.display()



class      lowerCamelCase    (SCREAMING_SNAKE_CASE__    ):
  """simple docstring"""







  def __init__(							self       :				List[Any]      )     ->		Union[str, Any]:
        SCREAMING_SNAKE_CASE_      =     None
        SCREAMING_SNAKE_CASE_      =     None
        SCREAMING_SNAKE_CASE_      =     False







  def       __A   (							self       :				Optional[int]     ,   __magic_name__       :				int     ,   __magic_name__       :				str     ,   __magic_name__       :				Tuple     ,   **__magic_name__       :				Tuple      )     ->		str:
        SCREAMING_SNAKE_CASE_      =     "Epoch" if args.evaluation_strategy == IntervalStrategy.EPOCH else "Step"
        SCREAMING_SNAKE_CASE_      =     0
        SCREAMING_SNAKE_CASE_      =     0
        SCREAMING_SNAKE_CASE_      =     [self.first_column] + ["Training Loss"]
        if args.evaluation_strategy != IntervalStrategy.NO:
              column_names.append("Validation Loss"      )
        SCREAMING_SNAKE_CASE_      =     NotebookTrainingTracker(state.max_steps     ,   __magic_name__      )







  def       __A   (							self       :				Optional[int]     ,   __magic_name__       :				str     ,   __magic_name__       :				Any     ,   __magic_name__       :				Any     ,   **__magic_name__       :				Dict      )     ->		List[str]:
        SCREAMING_SNAKE_CASE_      =     int(state.epoch      ) if int(state.epoch      ) == state.epoch else F'''{state.epoch:.2f}'''
        self.training_tracker.update(
            state.global_step + 1     ,   comment=F'''Epoch {epoch}/{state.num_train_epochs}'''     ,   force_update=self._force_next_update     ,   )
        SCREAMING_SNAKE_CASE_      =     False







  def       __A   (							self       :				List[str]     ,   __magic_name__       :				Any     ,   __magic_name__       :				List[Any]     ,   __magic_name__       :				str     ,   __magic_name__       :				Union[str, Any]=None     ,   **__magic_name__       :				Any      )     ->		Union[str, Any]:
        if not has_length(__magic_name__      ):
              return
        if self.prediction_bar is None:
              if self.training_tracker is not None:
                    SCREAMING_SNAKE_CASE_      =     self.training_tracker.add_child(len(__magic_name__      )      )
              else:
                    SCREAMING_SNAKE_CASE_      =     NotebookProgressBar(len(__magic_name__      )      )
              self.prediction_bar.update(1      )
        else:
              self.prediction_bar.update(self.prediction_bar.value + 1      )







  def       __A   (							self       :				str     ,   __magic_name__       :				List[Any]     ,   __magic_name__       :				List[str]     ,   __magic_name__       :				Union[str, Any]     ,   **__magic_name__       :				Any      )     ->		Optional[Any]:
        if self.prediction_bar is not None:
              self.prediction_bar.close()
        SCREAMING_SNAKE_CASE_      =     None







  def       __A   (							self       :				Dict     ,   __magic_name__       :				Optional[Any]     ,   __magic_name__       :				Tuple     ,   __magic_name__       :				List[Any]     ,   __magic_name__       :				Optional[int]=None     ,   **__magic_name__       :				Optional[int]      )     ->		Tuple:
        # Only for when there is no evaluation
        if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
              SCREAMING_SNAKE_CASE_      =     {"Training Loss": logs["loss"]}
              # First column is necessarily Step sine we're not in epoch eval strategy
              SCREAMING_SNAKE_CASE_      =     state.global_step
              self.training_tracker.write_line(__magic_name__      )







  def       __A   (							self       :				Dict     ,   __magic_name__       :				List[str]     ,   __magic_name__       :				str     ,   __magic_name__       :				Tuple     ,   __magic_name__       :				Optional[Any]=None     ,   **__magic_name__       :				Dict      )     ->		List[str]:
        if self.training_tracker is not None:
              SCREAMING_SNAKE_CASE_      =     {"Training Loss": "No log", "Validation Loss": "No log"}
              for log in reversed(state.log_history      ):
                    if "loss" in log:
                          SCREAMING_SNAKE_CASE_      =     log["loss"]
                          break

              if self.first_column == "Epoch":
                    SCREAMING_SNAKE_CASE_      =     int(state.epoch      )
              else:
                    SCREAMING_SNAKE_CASE_      =     state.global_step
              SCREAMING_SNAKE_CASE_      =     "eval"
              for k in metrics:
                    if k.endswith("_loss"      ):
                          SCREAMING_SNAKE_CASE_      =     re.sub(r"\_loss$"     ,   ""     ,   __magic_name__      )
              SCREAMING_SNAKE_CASE_      =     metrics.pop("total_flos"     ,   __magic_name__      )
              SCREAMING_SNAKE_CASE_      =     metrics.pop("epoch"     ,   __magic_name__      )
              SCREAMING_SNAKE_CASE_      =     metrics.pop(F'''{metric_key_prefix}_runtime'''     ,   __magic_name__      )
              SCREAMING_SNAKE_CASE_      =     metrics.pop(F'''{metric_key_prefix}_samples_per_second'''     ,   __magic_name__      )
              SCREAMING_SNAKE_CASE_      =     metrics.pop(F'''{metric_key_prefix}_steps_per_second'''     ,   __magic_name__      )
              SCREAMING_SNAKE_CASE_      =     metrics.pop(F'''{metric_key_prefix}_jit_compilation_time'''     ,   __magic_name__      )
              for k, v in metrics.items():
                    if k == F'''{metric_key_prefix}_loss''':
                          SCREAMING_SNAKE_CASE_      =     v
                    else:
                          SCREAMING_SNAKE_CASE_      =     k.split("_"      )
                          SCREAMING_SNAKE_CASE_      =     " ".join([part.capitalize() for part in splits[1:]]      )
                          SCREAMING_SNAKE_CASE_      =     v
              self.training_tracker.write_line(__magic_name__      )
              self.training_tracker.remove_child()
              SCREAMING_SNAKE_CASE_      =     None
              # Evaluation takes a long time so we should force the next update.
              SCREAMING_SNAKE_CASE_      =     True







  def       __A   (							self       :				Any     ,   __magic_name__       :				Optional[Any]     ,   __magic_name__       :				Optional[int]     ,   __magic_name__       :				List[Any]     ,   **__magic_name__       :				List[Any]      )     ->		Dict:
        self.training_tracker.update(
            state.global_step     ,   comment=F'''Epoch {int(state.epoch      )}/{state.num_train_epochs}'''     ,   force_update=__magic_name__      )
        SCREAMING_SNAKE_CASE_      =     None



import math
from datetime import datetime, timedelta


def    a__       (						__UpperCamelCase ):
      SCREAMING_SNAKE_CASE_      =     year % 1_9
      SCREAMING_SNAKE_CASE_      =     year % 4
      SCREAMING_SNAKE_CASE_      =     year % 7
      SCREAMING_SNAKE_CASE_      =     math.floor(year / 1_0_0 )
      SCREAMING_SNAKE_CASE_      =     math.floor((1_3 + 8 * leap_day_inhibits) / 2_5 )
      SCREAMING_SNAKE_CASE_      =     leap_day_inhibits / 4
      SCREAMING_SNAKE_CASE_      =     (
          1_5 - lunar_orbit_correction + leap_day_inhibits - leap_day_reinstall_number
      ) % 3_0
      SCREAMING_SNAKE_CASE_      =     (4 + leap_day_inhibits - leap_day_reinstall_number) % 7

      # days to be added to March 21
      SCREAMING_SNAKE_CASE_      =     (1_9 * metonic_cycle + secular_moon_shift) % 3_0

      # PHM -> Paschal Full Moon
      SCREAMING_SNAKE_CASE_      =     (
          2 * julian_leap_year
          + 4 * non_leap_year
          + 6 * days_to_add
          + century_starting_point
      ) % 7

      if days_to_add == 2_9 and days_from_phm_to_sunday == 6:
            return datetime(__UpperCamelCase   ,					4   ,					1_9 )
      elif days_to_add == 2_8 and days_from_phm_to_sunday == 6:
            return datetime(__UpperCamelCase   ,					4   ,					1_8 )
      else:
            return datetime(__UpperCamelCase   ,					3   ,					2_2 ) + timedelta(
                days=int(days_to_add + days_from_phm_to_sunday ) )


if __name__ == "__main__":
      for year in (19_94, 20_00, 20_10, 20_21, 20_23):
            A   :     Dict       =				"will be" if year > datetime.now().year else "was"
            print(f"Easter in {year} {tense} {gauss_easter(year)}")


