'''simple docstring'''

import math
import time

from transformers import Trainer, is_torch_tpu_available
from transformers.trainer_utils import PredictionOutput, speed_metrics


if is_torch_tpu_available(check_device=False):
  import torch_xla.core.xla_model as xm
  import torch_xla.debug.metrics as met


class 				_lowercase	(      lowerCAmelCase   ):
      '''simple docstring'''


      def __init__(				self					,*lowerCamelCase_					,lowerCamelCase_=None					,lowerCamelCase_=None					,**lowerCamelCase_							)			->			Any:



         '''simple docstring'''



         super().__init__(*lowerCamelCase_					,**lowerCamelCase_							)
         UpperCAmelCase__							:				int   				=  eval_examples
         UpperCAmelCase__							:				List[Any]   				=  post_process_function




      def 		lowerCAmelCase__					(				self					,lowerCamelCase_=None					,lowerCamelCase_=None					,lowerCamelCase_=None					,lowerCamelCase_ = "eval"							)			->			Tuple:



         '''simple docstring'''



         UpperCAmelCase__							:				List[Any]   				=  self.eval_dataset if eval_dataset is None else eval_dataset
         UpperCAmelCase__							:				List[str]   				=  self.get_eval_dataloader(lowerCamelCase_							)
         UpperCAmelCase__							:				Optional[int]   				=  self.eval_examples if eval_examples is None else eval_examples

         # Temporarily disable metric computation, we will do it in the loop here.
         UpperCAmelCase__							:				Union[str, Any]   				=  self.compute_metrics
         UpperCAmelCase__							:				Tuple   				=  None
         UpperCAmelCase__							:				Optional[Any]   				=  self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
         UpperCAmelCase__							:				Optional[Any]   				=  time.time()
         try:
            UpperCAmelCase__							:				Dict   				=  eval_loop(
                lowerCamelCase_					,description='''Evaluation'''					,prediction_loss_only=True if compute_metrics is None else None					,ignore_keys=lowerCamelCase_					,metric_key_prefix=lowerCamelCase_					,)
         finally:
            UpperCAmelCase__							:				Tuple   				=  compute_metrics
         UpperCAmelCase__							:				str   				=  self.args.eval_batch_size * self.args.world_size
         if f'''{metric_key_prefix}_jit_compilation_time''' in output.metrics:
            start_time += output.metrics[f'''{metric_key_prefix}_jit_compilation_time''']
         output.metrics.update(
             speed_metrics(
                 lowerCamelCase_					,lowerCamelCase_					,num_samples=output.num_samples					,num_steps=math.ceil(output.num_samples / total_batch_size							)					,)							)
         if self.post_process_function is not None and self.compute_metrics is not None and self.args.should_save:
            # Only the main node write the results by default
            UpperCAmelCase__							:				str   				=  self.post_process_function(lowerCamelCase_					,lowerCamelCase_					,output.predictions							)
            UpperCAmelCase__							:				Any   				=  self.compute_metrics(lowerCamelCase_							)

            # Prefix all keys with metric_key_prefix + '_'
            for key in list(metrics.keys()							):
               if not key.startswith(f'''{metric_key_prefix}_'''							):
                  UpperCAmelCase__							:				int   				=  metrics.pop(lowerCamelCase_							)
            metrics.update(output.metrics							)
         else:
            UpperCAmelCase__							:				Tuple   				=  output.metrics

         if self.args.should_log:
            # Only the main node log the results by default
            self.log(lowerCamelCase_							)

         if self.args.tpu_metrics_debug or self.args.debug:
            # tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)
            xm.master_print(met.metrics_report()							)

         UpperCAmelCase__							:				Optional[Any]   				=  self.callback_handler.on_evaluate(self.args					,self.state					,self.control					,lowerCamelCase_							)
         return metrics




      def 		lowerCAmelCase__					(				self					,lowerCamelCase_					,lowerCamelCase_					,lowerCamelCase_=None					,lowerCamelCase_ = "test"							)			->			List[str]:



         '''simple docstring'''



         UpperCAmelCase__							:				int   				=  self.get_test_dataloader(lowerCamelCase_							)

         # Temporarily disable metric computation, we will do it in the loop here.
         UpperCAmelCase__							:				int   				=  self.compute_metrics
         UpperCAmelCase__							:				str   				=  None
         UpperCAmelCase__							:				Any   				=  self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
         UpperCAmelCase__							:				List[str]   				=  time.time()
         try:
            UpperCAmelCase__							:				Optional[Any]   				=  eval_loop(
                lowerCamelCase_					,description='''Prediction'''					,prediction_loss_only=True if compute_metrics is None else None					,ignore_keys=lowerCamelCase_					,metric_key_prefix=lowerCamelCase_					,)
         finally:
            UpperCAmelCase__							:				Tuple   				=  compute_metrics
         UpperCAmelCase__							:				Optional[int]   				=  self.args.eval_batch_size * self.args.world_size
         if f'''{metric_key_prefix}_jit_compilation_time''' in output.metrics:
            start_time += output.metrics[f'''{metric_key_prefix}_jit_compilation_time''']
         output.metrics.update(
             speed_metrics(
                 lowerCamelCase_					,lowerCamelCase_					,num_samples=output.num_samples					,num_steps=math.ceil(output.num_samples / total_batch_size							)					,)							)

         if self.post_process_function is None or self.compute_metrics is None:
            return output

         UpperCAmelCase__							:				Tuple   				=  self.post_process_function(lowerCamelCase_					,lowerCamelCase_					,output.predictions					,'''predict'''							)
         UpperCAmelCase__							:				Optional[int]   				=  self.compute_metrics(lowerCamelCase_							)

         # Prefix all keys with metric_key_prefix + '_'
         for key in list(metrics.keys()							):
            if not key.startswith(f'''{metric_key_prefix}_'''							):
               UpperCAmelCase__							:				Tuple   				=  metrics.pop(lowerCamelCase_							)
         metrics.update(output.metrics							)
         return PredictionOutput(predictions=predictions.predictions					,label_ids=predictions.label_ids					,metrics=lowerCamelCase_							)




'''simple docstring'''

import re







def __UpperCamelCase(   _A					:				str    ):
   '''simple docstring'''

   if len(re.findall('''[ATCG]'''  ,			_A    )    ) != len(_A    ):
      raise ValueError('''Invalid Strand'''    )

   return dna.translate(dna.maketrans('''ATCG'''  ,			'''TAGC'''    )    )


if __name__ == "__main__":
  import doctest

  doctest.testmod()




