



'''simple docstring'''





import ast
import os
import re
import shutil
import tempfile
import unittest
from unittest import mock

import torch

from accelerate.test_utils.examples import compare_against_test
from accelerate.test_utils.testing import TempDirTestCase, require_trackers, run_command, slow
from accelerate.utils import write_basic_config


# DataLoaders built from `test_samples/MRPC` for quick testing
# Should mock `{script_name}.get_dataloaders` via:
# @mock.patch("{script_name}.get_dataloaders", mocked_dataloaders)

_lowerCAmelCase      						=	[
    '''cross_validation.py''',
    '''gradient_accumulation.py''',
    '''local_sgd.py''',
    '''multi_process_metrics.py''',
    '''memory.py''',
    '''automatic_gradient_accumulation.py''',
    '''fsdp_with_peak_mem_tracking.py''',
    '''deepspeed_with_config_support.py''',
    '''megatron_lm_gpt_pretraining.py''',
]






class        lowerCAmelCase_(				unittest.TestCase     ):
  '''simple docstring'''




  def 							UpperCAmelCase_	(    self  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase = None  ,__UpperCAmelCase = None      )    ->		Union[str, Any]:
      lowerCAmelCase__ :  Optional[Any]							      =					None
      lowerCAmelCase__ :  Any							      =					os.path.abspath(os.path.join("""examples"""  ,"""by_feature"""      )      )
      lowerCAmelCase__ :  List[str]							      =					os.path.abspath("""examples"""      )
      for item in os.listdir(__lowerCamelCase      ):
          if item not in EXCLUDE_EXAMPLES:
              lowerCAmelCase__ :  Optional[Any]							      =					os.path.join(__lowerCamelCase  ,__lowerCamelCase      )
              if os.path.isfile(__lowerCamelCase      ) and ".py" in item_path:
                  with self.subTest(
                      tested_script=__lowerCamelCase  ,feature_script=__lowerCamelCase  ,tested_section="""main()""" if parser_only else """training_function()"""  ,):
                      lowerCAmelCase__ :  str							      =					compare_against_test(
                          os.path.join(__lowerCamelCase  ,__lowerCamelCase      )  ,__lowerCamelCase  ,__lowerCamelCase  ,__lowerCamelCase      )
                      lowerCAmelCase__ :  Union[str, Any]							      =					'''\n'''.join(__lowerCamelCase      )
                      if special_strings is not None:
                          for string in special_strings:
                              lowerCAmelCase__ :  int							      =					diff.replace(__lowerCamelCase  ,""""""      )
                      self.assertEqual(__lowerCamelCase  ,""""""      )




  def 							UpperCAmelCase_	(    self      )    ->		Dict:
      self.one_complete_example("""complete_nlp_example.py"""  ,__lowerCamelCase      )
      self.one_complete_example("""complete_nlp_example.py"""  ,__lowerCamelCase      )






  def 							UpperCAmelCase_	(    self      )    ->		Any:
      lowerCAmelCase__ :  List[str]							      =					os.path.abspath(os.path.join("""examples"""  ,"""cv_example.py"""      )      )
      lowerCAmelCase__ :  Any							      =					[
          ''' ''' * 16 + '''{\n\n''',
          ''' ''' * 20 + '''"accuracy": eval_metric["accuracy"],\n\n''',
          ''' ''' * 20 + '''"f1": eval_metric["f1"],\n\n''',
          ''' ''' * 20 + '''"train_loss": total_loss.item() / len(train_dataloader),\n\n''',
          ''' ''' * 20 + '''"epoch": epoch,\n\n''',
          ''' ''' * 16 + '''},\n\n''',
          ''' ''' * 16 + '''step=epoch,\n''',
          ''' ''' * 12,
          ''' ''' * 8 + '''for step, batch in enumerate(active_dataloader):\n''',
      ]
      self.one_complete_example("""complete_cv_example.py"""  ,__lowerCamelCase  ,__lowerCamelCase  ,__lowerCamelCase      )
      self.one_complete_example("""complete_cv_example.py"""  ,__lowerCamelCase  ,__lowerCamelCase  ,__lowerCamelCase      )







@mock.patch.dict(os.environ						, {'''TESTING_MOCKED_DATALOADERS''': '''1'''}     )
class        lowerCAmelCase_(				SCREAMING_SNAKE_CASE__     ):
  '''simple docstring'''




  __lowercase							:      List[Any]				=      False




  @classmethod
  def 							UpperCAmelCase_	(    cls      )    ->		Union[str, Any]:
      super().setUpClass()
      lowerCAmelCase__ :  Dict							      =					tempfile.mkdtemp()
      lowerCAmelCase__ :  Tuple							      =					os.path.join(cls._tmpdir  ,"""default_config.yml"""      )

      write_basic_config(save_location=cls.configPath      )
      lowerCAmelCase__ :  Dict							      =					['''accelerate''', '''launch''', '''--config_file''', cls.configPath]




  @classmethod
  def 							UpperCAmelCase_	(    cls      )    ->		str:
      super().tearDownClass()
      shutil.rmtree(cls._tmpdir      )




  def 							UpperCAmelCase_	(    self      )    ->		Any:
      lowerCAmelCase__ :  List[Any]							      =					F"""
        examples/by_feature/checkpointing.py
        --checkpointing_steps epoch
        --output_dir {self.tmpdir}
        """.split()
      run_command(self._launch_args + testargs      )
      self.assertTrue(os.path.exists(os.path.join(self.tmpdir  ,"""epoch_0"""      )      )      )




  def 							UpperCAmelCase_	(    self      )    ->		Optional[int]:
      lowerCAmelCase__ :  str							      =					F"""
        examples/by_feature/checkpointing.py
        --checkpointing_steps 1
        --output_dir {self.tmpdir}
        """.split()
      lowerCAmelCase__ :  List[str]							      =					run_command(self._launch_args + testargs      )
      self.assertTrue(os.path.exists(os.path.join(self.tmpdir  ,"""step_2"""      )      )      )




  def 							UpperCAmelCase_	(    self      )    ->		Any:
      lowerCAmelCase__ :  List[str]							      =					F"""
        examples/by_feature/checkpointing.py
        --resume_from_checkpoint {os.path.join(self.tmpdir  ,'epoch_0'      )}
        """.split()
      lowerCAmelCase__ :  Tuple							      =					run_command(self._launch_args + testargs  ,return_stdout=__lowerCamelCase      )
      self.assertNotIn("""epoch 0:"""  ,__lowerCamelCase      )
      self.assertIn("""epoch 1:"""  ,__lowerCamelCase      )




  def 							UpperCAmelCase_	(    self      )    ->		Any:
      lowerCAmelCase__ :  Tuple							      =					F"""
        examples/by_feature/checkpointing.py
        --resume_from_checkpoint {os.path.join(self.tmpdir  ,'step_2'      )}
        """.split()
      lowerCAmelCase__ :  Tuple							      =					run_command(self._launch_args + testargs  ,return_stdout=__lowerCamelCase      )
      if torch.cuda.is_available():
          lowerCAmelCase__ :  str							      =					torch.cuda.device_count()
      else:
          lowerCAmelCase__ :  str							      =					1
      if num_processes > 1:
          self.assertNotIn("""epoch 0:"""  ,__lowerCamelCase      )
          self.assertIn("""epoch 1:"""  ,__lowerCamelCase      )
      else:
          self.assertIn("""epoch 0:"""  ,__lowerCamelCase      )
          self.assertIn("""epoch 1:"""  ,__lowerCamelCase      )




  @slow
  def 							UpperCAmelCase_	(    self      )    ->		Optional[int]:
      lowerCAmelCase__ :  List[str]							      =					'''
        examples/by_feature/cross_validation.py
        --num_folds 2
        '''.split()
      with mock.patch.dict(os.environ  ,{"""TESTING_MOCKED_DATALOADERS""": """0"""}      ):
          lowerCAmelCase__ :  Union[str, Any]							      =					run_command(self._launch_args + testargs  ,return_stdout=__lowerCamelCase      )
          lowerCAmelCase__ :  Optional[Any]							      =					re.findall("""({.+})"""  ,__lowerCamelCase      )
          lowerCAmelCase__ :  Tuple							      =					[r for r in results if '''accuracy''' in r][-1]
          lowerCAmelCase__ :  Optional[Any]							      =					ast.literal_eval(__lowerCamelCase      )
          self.assertGreaterEqual(results["""accuracy"""]  ,0.7_5      )




  def 							UpperCAmelCase_	(    self      )    ->		int:
      lowerCAmelCase__ :  str							      =					['''examples/by_feature/multi_process_metrics.py''']
      run_command(self._launch_args + testargs      )




  @require_trackers
  @mock.patch.dict(os.environ  ,{"""WANDB_MODE""": """offline"""}      )
  def 							UpperCAmelCase_	(    self      )    ->		Dict:




      with tempfile.TemporaryDirectory() as tmpdir:
          lowerCAmelCase__ :  str							      =					F"""
            examples/by_feature/tracking.py
            --with_tracking
            --project_dir {tmpdir}
            """.split()
          run_command(self._launch_args + testargs      )
          self.assertTrue(os.path.exists(os.path.join(__lowerCamelCase  ,"""tracking"""      )      )      )




  def 							UpperCAmelCase_	(    self      )    ->		int:
      lowerCAmelCase__ :  Tuple							      =					['''examples/by_feature/gradient_accumulation.py''']
      run_command(self._launch_args + testargs      )






  def 							UpperCAmelCase_	(    self      )    ->		List[str]:
      lowerCAmelCase__ :  Optional[Any]							      =					['''examples/by_feature/local_sgd.py''']
      run_command(self._launch_args + testargs      )









"""simple docstring"""



import requests

a_ =			""""""  # <-- Put your OpenWeatherMap appid here!
a_ =			"""https://api.openweathermap.org/data/2.5/"""







def 		__lowercase     (   snake_case_  :  str = "Chicago"				,snake_case_  :  str = APPID						)   ->dict:



    '''simple docstring'''







    return requests.get(URL_BASE + '''weather'''				,params=locals()						).json()







def 		__lowercase     (   snake_case_  :  str = "Kolkata, India"				,snake_case_  :  str = APPID						)   ->dict:



    '''simple docstring'''







    return requests.get(URL_BASE + '''forecast'''				,params=locals()						).json()







def 		__lowercase     (   snake_case_  :  float = 55.68				,snake_case_  :  float = 12.57				,snake_case_  :  str = APPID						)   ->dict:



    '''simple docstring'''







    return requests.get(URL_BASE + '''onecall'''				,params=locals()						).json()


if __name__ == "__main__":
       from pprint import pprint

       while True:
              a_ =			input("""Enter a location:""").strip()
              if location:
                     pprint(current_weather(location))
              else:
                     break




