
"""simple docstring"""





import os
import socket
from contextlib import contextmanager

import torch

from ..commands.config.default import write_basic_config  # noqa: F401
from ..state import PartialState
from .dataclasses import DistributedType
from .imports import is_deepspeed_available, is_tpu_available
from .transformer_engine import convert_model
from .versions import is_torch_version


if is_deepspeed_available():
    from deepspeed import DeepSpeedEngine

if is_tpu_available(check_device=False):
    import torch_xla.core.xla_model as xm







def 	__a     (		__lowerCamelCase  ):
   if is_torch_version("<",		"2.0.0"  ) or not hasattr(UpperCAmelCase__,		"_dynamo"  ):
      return False
   return isinstance(UpperCAmelCase__,		torch._dynamo.eval_frame.OptimizedModule  )







def 	__a     (		__lowerCamelCase,		__lowerCamelCase = True  ):
   UpperCAmelCase_					:					Optional[int]			     =    (torch.nn.parallel.DistributedDataParallel, torch.nn.DataParallel)

   UpperCAmelCase_					:					Optional[int]			     =    is_compiled_module(UpperCAmelCase__  )
   if is_compiled:
      UpperCAmelCase_					:					Union[str, Any]			     =    model
      UpperCAmelCase_					:					Dict			     =    model._orig_mod

   if is_deepspeed_available():
      options += (DeepSpeedEngine,)

   while isinstance(UpperCAmelCase__,		UpperCAmelCase__  ):
      UpperCAmelCase_					:					Dict			     =    model.module

   if not keep_fpaa_wrapper:
      UpperCAmelCase_					:					Any			     =    getattr(UpperCAmelCase__,		"forward"  )
      UpperCAmelCase_					:					List[str]			     =    model.__dict__.pop("_original_forward",		UpperCAmelCase__  )
      if original_forward is not None:
         while hasattr(UpperCAmelCase__,		"__wrapped__"  ):
            UpperCAmelCase_					:					Optional[Any]			     =    forward.__wrapped__
            if forward == original_forward:
               break
         UpperCAmelCase_					:					Any			     =    forward
      if getattr(UpperCAmelCase__,		"_converted_to_transformer_engine",		UpperCAmelCase__  ):
         convert_model(UpperCAmelCase__,		to_transformer_engine=UpperCAmelCase__  )

   if is_compiled:
      UpperCAmelCase_					:					List[str]			     =    model
      UpperCAmelCase_					:					Dict			     =    compiled_model

   return model







def 	__a     (		):
   PartialState().wait_for_everyone()







def 	__a     (		__lowerCamelCase,		__lowerCamelCase  ):
   if PartialState().distributed_type == DistributedType.TPU:
      xm.save(UpperCAmelCase__,		UpperCAmelCase__  )
   elif PartialState().local_process_index == 0:
      torch.save(UpperCAmelCase__,		UpperCAmelCase__  )







@contextmanager
def 	__a     (		**__lowerCamelCase  ):
   for key, value in kwargs.items():
      UpperCAmelCase_					:					List[Any]			     =    str(UpperCAmelCase__  )

   yield

   for key in kwargs:
      if key.upper() in os.environ:
         del os.environ[key.upper()]







def 	__a     (		__lowerCamelCase  ):
   if not hasattr(UpperCAmelCase__,		"__qualname__"  ) and not hasattr(UpperCAmelCase__,		"__name__"  ):
      UpperCAmelCase_					:					List[Any]			     =    getattr(UpperCAmelCase__,		"__class__",		UpperCAmelCase__  )
   if hasattr(UpperCAmelCase__,		"__qualname__"  ):
      return obj.__qualname__
   if hasattr(UpperCAmelCase__,		"__name__"  ):
      return obj.__name__
   return str(UpperCAmelCase__  )







def 	__a     (		__lowerCamelCase,		__lowerCamelCase  ):
   for key, value in source.items():
      if isinstance(UpperCAmelCase__,		UpperCAmelCase__  ):
         UpperCAmelCase_					:					str			     =    destination.setdefault(UpperCAmelCase__,		{}  )
         merge_dicts(UpperCAmelCase__,		UpperCAmelCase__  )
      else:
         UpperCAmelCase_					:					Optional[int]			     =    value

   return destination







def 	__a     (		__lowerCamelCase = None  ):
   if port is None:
      UpperCAmelCase_					:					Tuple			     =    2_9500
   with socket.socket(socket.AF_INET,		socket.SOCK_STREAM  ) as s:
      return s.connect_ex(("localhost", port)  ) == 0



'''simple docstring'''




import operator as op




def 							lowerCamelCase	(      UpperCAmelCase__       :					Optional[Any] )			->      int:
							lowercase_					:			Optional[Any]										=       []
							lowercase_					:			str										=       lambda UpperCAmelCase__      ,      UpperCAmelCase__ : int(x / y )  # noqa: E731 integer division operation
							lowercase_					:			Optional[Any]										=       {
							    """^""": op.pow,
							    """*""": op.mul,
							    """/""": div,
							    """+""": op.add,
							    """-""": op.sub,
							}  # operators & their respective operation

							# print table header
							print("""Symbol""".center(8 )      ,      """Action""".center(12 )      ,      """Stack"""      ,      sep=""" | """ )
							print("""-""" * (30 + len(UpperCAmelCase__ )) )

							for x in post_fix:
														if x.isdigit():  # if x in digit
																					stack.append(UpperCAmelCase__ )  # append x to stack
																					# output in tabular format
																					print(x.rjust(8 )      ,      ("""push(""" + x + """)""").ljust(12 )      ,      """,""".join(UpperCAmelCase__ )      ,      sep=""" | """ )
														else:
																					lowercase_					:			str										=       stack.pop()  # pop stack
																					# output in tabular format
																					print("""""".rjust(8 )      ,      ("""pop(""" + b + """)""").ljust(12 )      ,      """,""".join(UpperCAmelCase__ )      ,      sep=""" | """ )

																					lowercase_					:			Optional[int]										=       stack.pop()  # pop stack
																					# output in tabular format
																					print("""""".rjust(8 )      ,      ("""pop(""" + a + """)""").ljust(12 )      ,      """,""".join(UpperCAmelCase__ )      ,      sep=""" | """ )

																					stack.append(
																					    str(opr[x](int(UpperCAmelCase__ )      ,      int(UpperCAmelCase__ ) ) ) )  # evaluate the 2 values popped from stack & push result to stack
																					# output in tabular format
																					print(
																					    x.rjust(8 )      ,      ("""push(""" + a + x + b + """)""").ljust(12 )      ,      """,""".join(UpperCAmelCase__ )      ,      sep=""" | """      ,      )

							return int(stack[0] )


if __name__ == "__main__":
						_lowercase						: Tuple						=						input("\n\nEnter a Postfix Equation (space separated) = ").split(" ")
						print("\n\tResult = ", solve(Postfix))





