

import inspect
import logging
import os
import random
import shutil
import tempfile
import unittest

import pytest
import torch
from torch import nn
from torch.utils.data import DataLoader, TensorDataset

from accelerate import Accelerator
from accelerate.test_utils import execute_subprocess_async, require_cuda
from accelerate.utils import ProjectConfiguration, set_seed


lowerCAmelCase     :   Optional[int]						     =  logging.getLogger(__name__)

def    A_  (							a=2					,   a=3					,   a=1_6					,   a = 1_0					,   a = 2  ):

      """simple docstring"""



      def get_dataset(a  ):
            SCREAMING_SNAKE_CASE_				:  Any           =     torch.randn(batch_size * n_batches					,   1  )
            return TensorDataset(a					,   a * x + b + 0.1 * torch.randn(batch_size * n_batches					,   1  )  )

      SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     get_dataset(a  )
      SCREAMING_SNAKE_CASE_				:  Tuple           =     get_dataset(a  )
      SCREAMING_SNAKE_CASE_				:  Any           =     DataLoader(a					,   shuffle=a					,   batch_size=a					,   num_workers=4  )
      SCREAMING_SNAKE_CASE_				:  Optional[int]           =     DataLoader(a					,   shuffle=a					,   batch_size=a					,   num_workers=4  )
      return (train_dataloader, valid_dataloader)

def    A_  (							a					,   a					,   a					,   a					,   a					,   a=None  ):

      """simple docstring"""



      SCREAMING_SNAKE_CASE_				:  List[str]           =     []
      for epoch in range(a  ):
            # Train quickly
            model.train()
            for batch in dataloader:
                  SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  int           =     batch
                  SCREAMING_SNAKE_CASE_				:  Dict           =     model(a  )
                  SCREAMING_SNAKE_CASE_				:  Tuple           =     torch.nn.functional.mse_loss(a					,   a  )
                  accelerator.backward(a  )
                  optimizer.step()
                  optimizer.zero_grad()
            rands.append(random.random()  )  # Introduce some randomness
            if scheduler is not None:
                  scheduler.step()
      return rands
class  _A		(  nn.Module):

  def __init__(				self					):





        """simple docstring"""







        super().__init__()
        SCREAMING_SNAKE_CASE_				:  str           =     nn.Parameter(torch.randn(1					)					)
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     nn.Parameter(torch.randn(1					)					)



  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        return x * self.a + self.b

class  _A		(  unittest.TestCase):

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        with tempfile.TemporaryDirectory() as tmpdir:
              set_seed(42					)
              SCREAMING_SNAKE_CASE_				:  int           =     DummyModel()
              SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     torch.optim.Adam(params=model.parameters() ,					lr=1e-3					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  List[Any]           =     dummy_dataloaders()
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     ProjectConfiguration(total_limit=1 ,					project_dir=_SCREAMING_SNAKE_CASE ,					automatic_checkpoint_naming=_SCREAMING_SNAKE_CASE					)
              # Train baseline
              SCREAMING_SNAKE_CASE_				:  str           =     Accelerator(project_config=_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  int           =     accelerator.prepare(
                  _SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              # Save initial
              accelerator.save_state()

              # Save second state
              accelerator.save_state()
              self.assertEqual(len(os.listdir(accelerator.project_dir					)					) ,					1					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        with tempfile.TemporaryDirectory() as tmpdir:
              set_seed(42					)
              SCREAMING_SNAKE_CASE_				:  Tuple           =     DummyModel()
              SCREAMING_SNAKE_CASE_				:  int           =     torch.optim.Adam(params=model.parameters() ,					lr=1e-3					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  List[Any]           =     dummy_dataloaders()
              # Train baseline
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     Accelerator()
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     accelerator.prepare(
                  _SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              # Save initial
              SCREAMING_SNAKE_CASE_				:  Any           =     os.path.join(_SCREAMING_SNAKE_CASE ,					'initial'					)
              accelerator.save_state(_SCREAMING_SNAKE_CASE					)
              ((SCREAMING_SNAKE_CASE_)       ,						(SCREAMING_SNAKE_CASE_))				:  Tuple           =     model.a.item(), model.b.item()
              SCREAMING_SNAKE_CASE_				:  Tuple           =     optimizer.state_dict()
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     train(3 ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              ((SCREAMING_SNAKE_CASE_)       ,						(SCREAMING_SNAKE_CASE_))				:  str           =     model.a.item(), model.b.item()
              SCREAMING_SNAKE_CASE_				:  Tuple           =     optimizer.state_dict()

              # Train partially
              set_seed(42					)
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     DummyModel()
              SCREAMING_SNAKE_CASE_				:  str           =     torch.optim.Adam(params=model.parameters() ,					lr=1e-3					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Any           =     dummy_dataloaders()
              SCREAMING_SNAKE_CASE_				:  List[str]           =     Accelerator()
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  str           =     accelerator.prepare(
                  _SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              accelerator.load_state(_SCREAMING_SNAKE_CASE					)
              ((SCREAMING_SNAKE_CASE_)       ,						(SCREAMING_SNAKE_CASE_))				:  Optional[int]           =     model.a.item(), model.b.item()
              SCREAMING_SNAKE_CASE_				:  List[str]           =     optimizer.state_dict()
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)

              SCREAMING_SNAKE_CASE_				:  List[str]           =     train(2 ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              # Save everything
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     os.path.join(_SCREAMING_SNAKE_CASE ,					'checkpoint'					)
              accelerator.save_state(_SCREAMING_SNAKE_CASE					)

              # Load everything back in and make sure all states work
              accelerator.load_state(_SCREAMING_SNAKE_CASE					)
              test_rands += train(1 ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              ((SCREAMING_SNAKE_CASE_)       ,						(SCREAMING_SNAKE_CASE_))				:  List[str]           =     model.a.item(), model.b.item()
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     optimizer.state_dict()
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        with tempfile.TemporaryDirectory() as tmpdir:
              set_seed(42					)
              SCREAMING_SNAKE_CASE_				:  Dict           =     DummyModel()
              SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     torch.optim.Adam(params=model.parameters() ,					lr=1e-3					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Tuple           =     dummy_dataloaders()
              SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     ProjectConfiguration(automatic_checkpoint_naming=_SCREAMING_SNAKE_CASE					)

              # Train baseline
              SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     Accelerator(project_dir=_SCREAMING_SNAKE_CASE ,					project_config=_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     accelerator.prepare(
                  _SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              # Save initial
              accelerator.save_state()
              ((SCREAMING_SNAKE_CASE_)       ,						(SCREAMING_SNAKE_CASE_))				:  Any           =     model.a.item(), model.b.item()
              SCREAMING_SNAKE_CASE_				:  str           =     optimizer.state_dict()
              SCREAMING_SNAKE_CASE_				:  Any           =     train(3 ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              ((SCREAMING_SNAKE_CASE_)       ,						(SCREAMING_SNAKE_CASE_))				:  Dict           =     model.a.item(), model.b.item()
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     optimizer.state_dict()

              # Train partially
              set_seed(42					)
              SCREAMING_SNAKE_CASE_				:  Tuple           =     DummyModel()
              SCREAMING_SNAKE_CASE_				:  str           =     torch.optim.Adam(params=model.parameters() ,					lr=1e-3					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Tuple           =     dummy_dataloaders()
              SCREAMING_SNAKE_CASE_				:  int           =     ProjectConfiguration(iteration=1 ,					automatic_checkpoint_naming=_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_				:  Any           =     Accelerator(project_dir=_SCREAMING_SNAKE_CASE ,					project_config=_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  str           =     accelerator.prepare(
                  _SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              accelerator.load_state(os.path.join(_SCREAMING_SNAKE_CASE ,					'checkpoints' ,					'checkpoint_0'					)					)
              ((SCREAMING_SNAKE_CASE_)       ,						(SCREAMING_SNAKE_CASE_))				:  Any           =     model.a.item(), model.b.item()
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     optimizer.state_dict()
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)

              SCREAMING_SNAKE_CASE_				:  Optional[int]           =     train(2 ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              # Save everything
              accelerator.save_state()

              # Load everything back in and make sure all states work
              accelerator.load_state(os.path.join(_SCREAMING_SNAKE_CASE ,					'checkpoints' ,					'checkpoint_1'					)					)
              test_rands += train(1 ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              ((SCREAMING_SNAKE_CASE_)       ,						(SCREAMING_SNAKE_CASE_))				:  str           =     model.a.item(), model.b.item()
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     optimizer.state_dict()
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  int           =     torch.tensor([1, 2, 3]					)
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     torch.tensor([2, 3, 4]					)
        SCREAMING_SNAKE_CASE_				:  Any           =     DummyModel()
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     torch.optim.Adam(net.parameters()					)
        SCREAMING_SNAKE_CASE_				:  int           =     Accelerator()
        with self.assertRaises(_SCREAMING_SNAKE_CASE					) as ve:
              accelerator.register_for_checkpointing(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     str(ve.exception					)
        self.assertTrue('Item at index 0' in message					)
        self.assertTrue('Item at index 1' in message					)
        self.assertFalse('Item at index 2' in message					)
        self.assertFalse('Item at index 3' in message					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        with tempfile.TemporaryDirectory() as tmpdir:
              set_seed(42					)
              SCREAMING_SNAKE_CASE_				:  Dict           =     DummyModel()
              SCREAMING_SNAKE_CASE_				:  int           =     torch.optim.Adam(params=model.parameters() ,					lr=1e-3					)
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     torch.optim.lr_scheduler.StepLR(_SCREAMING_SNAKE_CASE ,					step_size=1 ,					gamma=0.99					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  List[str]           =     dummy_dataloaders()
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     ProjectConfiguration(automatic_checkpoint_naming=_SCREAMING_SNAKE_CASE					)
              # Train baseline
              SCREAMING_SNAKE_CASE_				:  Dict           =     Accelerator(project_dir=_SCREAMING_SNAKE_CASE ,					project_config=_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  List[str]           =     accelerator.prepare(
                  _SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              # Save initial
              accelerator.save_state()
              SCREAMING_SNAKE_CASE_				:  Any           =     scheduler.state_dict()
              train(3 ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)
              self.assertNotEqual(_SCREAMING_SNAKE_CASE ,					scheduler.state_dict()					)

              # Load everything back in and make sure all states work
              accelerator.load_state(os.path.join(_SCREAMING_SNAKE_CASE ,					'checkpoints' ,					'checkpoint_0'					)					)
              self.assertEqual(_SCREAMING_SNAKE_CASE ,					scheduler.state_dict()					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        with tempfile.TemporaryDirectory() as tmpdir:
              set_seed(42					)
              SCREAMING_SNAKE_CASE_				:  Optional[int]           =     DummyModel()
              SCREAMING_SNAKE_CASE_				:  List[str]           =     ProjectConfiguration(automatic_checkpoint_naming=_SCREAMING_SNAKE_CASE ,					total_limit=2					)
              # Train baseline
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     Accelerator(project_dir=_SCREAMING_SNAKE_CASE ,					project_config=_SCREAMING_SNAKE_CASE					)
              SCREAMING_SNAKE_CASE_				:  Tuple           =     accelerator.prepare(_SCREAMING_SNAKE_CASE					)
              # Save 3 states:
              for _ in range(11					):
                    accelerator.save_state()
              self.assertTrue(not os.path.exists(os.path.join(_SCREAMING_SNAKE_CASE ,					'checkpoints' ,					'checkpoint_0'					)					)					)
              self.assertTrue(os.path.exists(os.path.join(_SCREAMING_SNAKE_CASE ,					'checkpoints' ,					'checkpoint_9'					)					)					)
              self.assertTrue(os.path.exists(os.path.join(_SCREAMING_SNAKE_CASE ,					'checkpoints' ,					'checkpoint_10'					)					)					)



  @require_cuda
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     ['torchrun', f"--nproc_per_node={torch.cuda.device_count()}", inspect.getfile(self.__class__					)]
        execute_subprocess_async(_SCREAMING_SNAKE_CASE ,					env=os.environ.copy()					)


if __name__ == "__main__":
    lowerCAmelCase     :   int						     =  '/tmp/accelerate/state_checkpointing'
    lowerCAmelCase     :   Any						     =  DummyModel()
    lowerCAmelCase     :   Tuple						     =  torch.optim.Adam(params=model.parameters(), lr=1e-3)
    lowerCAmelCase     :   Optional[Any]						     =  torch.optim.lr_scheduler.StepLR(optimizer, step_size=1, gamma=0.99)
    lowerCAmelCase     ,       lowerCAmelCase     :   List[Any]						     =  dummy_dataloaders()
    lowerCAmelCase     :   Dict						     =  ProjectConfiguration(automatic_checkpoint_naming=True)
    # Train baseline
    lowerCAmelCase     :   List[Any]						     =  Accelerator(project_dir=savedir, project_config=project_config, mixed_precision='no')
    if accelerator.process_index == 0:
        if os.path.exists(savedir):
            shutil.rmtree(savedir)
        os.makedirs(savedir)
    lowerCAmelCase     ,       lowerCAmelCase     ,       lowerCAmelCase     ,       lowerCAmelCase     ,       lowerCAmelCase     :   List[Any]						     =  accelerator.prepare(
        model, optimizer, train_dataloader, valid_dataloader, scheduler
    )
    lowerCAmelCase     ,       lowerCAmelCase     :   Any						     =  accelerator.prepare(model, optimizer)
    train(3, model, train_dataloader, optimizer, accelerator, scheduler)
    # Check that the intial optimizer is loaded on the GPU
    for group in optimizer.param_groups:
        lowerCAmelCase     :   List[str]						     =  group['params'][0].device
        break
    assert param_device.type == accelerator.device.type
    lowerCAmelCase     :   List[Any]						     =  model.cpu()
    accelerator.wait_for_everyone()
    accelerator.save_state()
    accelerator.wait_for_everyone()

    # Check CPU state
    accelerator.load_state(os.path.join(savedir, 'checkpoints', 'checkpoint_0'), map_location='cpu')
    for group in optimizer.param_groups:
        lowerCAmelCase     :   Any						     =  group['params'][0].device
        break
    assert (
        param_device.type == torch.device('cpu').type
    ), F"Loaded optimizer states did not match, expected to be loaded on the CPU but got {param_device}"

    # Check device state
    model.to(accelerator.device)
    accelerator.load_state(os.path.join(savedir, 'checkpoints', 'checkpoint_0'), map_location='on_device')
    for group in optimizer.param_groups:
        lowerCAmelCase     :   Optional[Any]						     =  group['params'][0].device
        break
    assert (
        param_device.type == accelerator.device.type
    ), F"Loaded optimizer states did not match, expected to be loaded on {accelerator.device} but got {param_device}"

    # Check error
    with pytest.raises(TypeError, match='Unsupported optimizer map location passed'):
        accelerator.load_state(os.path.join(savedir, 'checkpoints', 'checkpoint_0'), map_location='invalid')
    accelerator.wait_for_everyone()
    if accelerator.process_index == 0:
        shutil.rmtree(savedir)
    accelerator.wait_for_everyone()









lowerCAmelCase     :   Tuple						     =  {
    'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.',
    'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.',
    'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', 'U': '..-',
    'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--', 'Z': '--..', '1': '.----',
    '2': '..---', '3': '...--', '4': '....-', '5': '.....', '6': '-....', '7': '--...',
    '8': '---..', '9': '----.', '0': '-----', '&': '.-...', '@': '.--.-.',
    ':': '---...', ',': '--..--', '.': '.-.-.-', '\'': '.----.', '"': '.-..-.',
    '?': '..--..', '/': '-..-.', '=': '-...-', '+': '.-.-.', '-': '-....-',
    '(': '-.--.', ')': '-.--.-', '!': '-.-.--', ' ': '/'
}  # Exclamation mark is not in ITU-R recommendation
# fmt: on
lowerCAmelCase     :   Optional[int]						     =  {value: key for key, value in MORSE_CODE_DICT.items()}

def    A_  (							a  ):

      """simple docstring"""



      return " ".join(MORSE_CODE_DICT[char] for char in message.upper()  )

def    A_  (							a  ):

      """simple docstring"""



      return "".join(REVERSE_DICT[char] for char in message.split()  )

def    A_  (							):

      """simple docstring"""



      SCREAMING_SNAKE_CASE_				:  Tuple           =     'Morse code here!'
      print(a  )
      SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     encrypt(a  )
      print(a  )
      SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     decrypt(a  )
      print(a  )


if __name__ == "__main__":
    main()






