






'''simple docstring'''







import json
import logging
import os
import sys
from time import time
from unittest.mock import patch

from transformers.testing_utils import TestCasePlus, require_torch_tpu


logging.basicConfig(level=logging.DEBUG)

_A     :      Union[str, Any]   					=logging.getLogger()





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	int:
							lowerCamelCase__ :     Any	  =	{}
							lowerCamelCase__ :     List[Any]	  =	os.path.join(_UpperCamelCase    ,      """all_results.json"""				)
							if os.path.exists(_UpperCamelCase				):
														with open(_UpperCamelCase    ,      """r"""				) as f:
																					lowerCamelCase__ :     Dict	  =	json.load(_UpperCamelCase				)
							else:
														raise ValueError(f'''can\'t find {path}'''				)
							return results


_A     :      List[str]   					=logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)



@require_torch_tpu
class _lowercase     (    SCREAMING_SNAKE_CASE__		):




							def 		lowerCamelCase_    (							self:    Tuple					):
														import xla_spawn

														lowerCamelCase__ :     Any	  =	self.get_auto_remove_tmp_dir()
														lowerCamelCase__ :     List[str]	  =	F'''\n            ./examples/pytorch/text-classification/run_glue.py\n            --num_cores=8\n            ./examples/pytorch/text-classification/run_glue.py\n            --model_name_or_path distilbert-base-uncased\n            --output_dir {tmp_dir}\n            --overwrite_output_dir\n            --train_file ./tests/fixtures/tests_samples/MRPC/train.csv\n            --validation_file ./tests/fixtures/tests_samples/MRPC/dev.csv\n            --do_train\n            --do_eval\n            --debug tpu_metrics_debug\n            --per_device_train_batch_size=2\n            --per_device_eval_batch_size=1\n            --learning_rate=1e-4\n            --max_steps=10\n            --warmup_steps=2\n            --seed=42\n            --max_seq_length=128\n            '''.split()

														with patch.object(a_      ,							"""argv"""      ,							a_					):
																					lowerCamelCase__ :     List[Any]	  =	time()
																					xla_spawn.main()
																					lowerCamelCase__ :     List[Any]	  =	time()

																					lowerCamelCase__ :     Optional[int]	  =	get_results(a_					)
																					self.assertGreaterEqual(result["""eval_accuracy"""]      ,							0.75					)

																					# Assert that the script takes less than 500 seconds to make sure it doesn't hang.
																					self.assertLess(end - start      ,							500					)




							def 		lowerCamelCase_    (							self:    Optional[Any]					):
														import xla_spawn

														lowerCamelCase__ :     Union[str, Any]	  =	"""\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            """.split()
														with patch.object(a_      ,							"""argv"""      ,							a_					):
																					xla_spawn.main()









'''simple docstring'''







from math import asin, atan, cos, radians, sin, sqrt, tan

_A     :      List[str]   					=637_8137.0
_A     :      Dict   					=635_6752.31_4245
_A     :      int   					=6_378_137





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase    ,      UpperCamelCase				)				->	float:
							lowerCamelCase__ :     str	  =	(AXIS_A - AXIS_B) / AXIS_A
							lowerCamelCase__ :     Dict	  =	atan((1 - flattening) * tan(radians(UpperCamelCase				)				)				)
							lowerCamelCase__ :     Dict	  =	atan((1 - flattening) * tan(radians(UpperCamelCase				)				)				)
							lowerCamelCase__ :     Optional[Any]	  =	radians(UpperCamelCase				)
							lowerCamelCase__ :     List[Any]	  =	radians(UpperCamelCase				)
							# Equation
							lowerCamelCase__ :     Tuple	  =	sin((phi_a - phi_a) / 2				)
							lowerCamelCase__ :     List[Any]	  =	sin((lambda_a - lambda_a) / 2				)
							# Square both values
							sin_sq_phi *= sin_sq_phi
							sin_sq_lambda *= sin_sq_lambda
							lowerCamelCase__ :     Tuple	  =	sqrt(sin_sq_phi + (cos(UpperCamelCase				) * cos(UpperCamelCase				) * sin_sq_lambda)				)
							return 2 * RADIUS * asin(UpperCamelCase				)


if __name__ == "__main__":
			import doctest

			doctest.testmod()

