


class 	_a							:

							def __init__(							self:     Optional[Any]   ,						UpperCamelCase_:     int   ,						UpperCamelCase_:     Union[str, Any]=None   ,						UpperCamelCase_:     List[str]=None							)      ->       Optional[int]:





									"""simple docstring"""







									lowercase__						=				data
									lowercase__						=				previous
									lowercase__						=				next_node

							def __str__(							self:     List[str]							)      ->       str:





									"""simple docstring"""







									return f'{self.data}'

							def 				lowerCamelCase_			(							self:     Union[str, Any]							)      ->       int:





									"""simple docstring"""







									return self.data

							def 				lowerCamelCase_			(							self:     List[str]							)      ->       List[Any]:





									"""simple docstring"""







									return self.next


							def 				lowerCamelCase_			(							self:     str							)      ->       List[str]:





									"""simple docstring"""







									return self.previous


class 	_a							:

							def __init__(							self:     Dict   ,						UpperCamelCase_:     str							)      ->       Optional[Any]:





									"""simple docstring"""







									lowercase__						=				head

							def __iter__(							self:     str							)      ->       Optional[int]:





									"""simple docstring"""







									return self


							def 				lowerCamelCase_			(							self:     List[str]							)      ->       Optional[int]:





									"""simple docstring"""







									if not self.current:
											raise StopIteration
									else:
											lowercase__						=				self.current.get_data()
											lowercase__						=				self.current.get_next()
											return value


class 	_a							:

							def __init__(							self:     Union[str, Any]							)      ->       List[str]:





									"""simple docstring"""







									lowercase__						=				None  # First node in list
									lowercase__						=				None  # Last node in list

							def __str__(							self:     Dict							)      ->       int:





									"""simple docstring"""







									lowercase__						=				self.head
									lowercase__						=				[]
									while current is not None:
											nodes.append(current.get_data()							)
											lowercase__						=				current.get_next()
									return " ".join(str(UpperCamelCase_							) for node in nodes							)

							def __contains__(							self:     Union[str, Any]   ,						UpperCamelCase_:     int							)      ->       List[Any]:





									"""simple docstring"""







									lowercase__						=				self.head
									while current:
											if current.get_data() == value:
													return True
											lowercase__						=				current.get_next()
									return False

							def __iter__(							self:     Optional[Any]							)      ->       int:





									"""simple docstring"""







									return LinkedListIterator(self.head							)

							def 				lowerCamelCase_			(							self:     Union[str, Any]							)      ->       Optional[Any]:





									"""simple docstring"""







									if self.head:
											return self.head.get_data()
									return None

							def 				lowerCamelCase_			(							self:     Optional[Any]							)      ->       Tuple:





									"""simple docstring"""







									if self.tail:
											return self.tail.get_data()
									return None

							def 				lowerCamelCase_			(							self:     Tuple   ,						UpperCamelCase_:     Node							)      ->       None:





									"""simple docstring"""







									if self.head is None:
											lowercase__						=				node
											lowercase__						=				node
									else:
											self.insert_before_node(self.head   ,						UpperCamelCase_							)

							def 				lowerCamelCase_			(							self:     Optional[int]   ,						UpperCamelCase_:     Node							)      ->       None:





									"""simple docstring"""







									if self.head is None:
											self.set_head(UpperCamelCase_							)
									else:
											self.insert_after_node(self.tail   ,						UpperCamelCase_							)

							def 				lowerCamelCase_			(							self:     Tuple   ,						UpperCamelCase_:     int							)      ->       None:





									"""simple docstring"""







									lowercase__						=				Node(UpperCamelCase_							)
									if self.head is None:
											self.set_head(UpperCamelCase_							)
									else:
											self.set_tail(UpperCamelCase_							)

							def 				lowerCamelCase_			(							self:     Optional[int]   ,						UpperCamelCase_:     Node   ,						UpperCamelCase_:     Node							)      ->       None:





									"""simple docstring"""







									lowercase__						=				node
									lowercase__						=				node.previous

									if node.get_previous() is None:
											lowercase__						=				node_to_insert
									else:
											lowercase__						=				node_to_insert

									lowercase__						=				node_to_insert

							def 				lowerCamelCase_			(							self:     str   ,						UpperCamelCase_:     Node   ,						UpperCamelCase_:     Node							)      ->       None:





									"""simple docstring"""







									lowercase__						=				node
									lowercase__						=				node.next

									if node.get_next() is None:
											lowercase__						=				node_to_insert
									else:
											lowercase__						=				node_to_insert

									lowercase__						=				node_to_insert

							def 				lowerCamelCase_			(							self:     Union[str, Any]   ,						UpperCamelCase_:     int   ,						UpperCamelCase_:     int							)      ->       None:





									"""simple docstring"""







									lowercase__						=				1
									lowercase__						=				Node(UpperCamelCase_							)
									lowercase__						=				self.head
									while node:
											if current_position == position:
													self.insert_before_node(UpperCamelCase_   ,						UpperCamelCase_							)
													return
											current_position += 1
											lowercase__						=				node.next
									self.insert_after_node(self.tail   ,						UpperCamelCase_							)

							def 				lowerCamelCase_			(							self:     Union[str, Any]   ,						UpperCamelCase_:     int							)      ->       Node:





									"""simple docstring"""







									lowercase__						=				self.head
									while node:
											if node.get_data() == item:
													return node
											lowercase__						=				node.get_next()
									raise Exception('''Node not found'''							)

							def 				lowerCamelCase_			(							self:     Optional[int]   ,						UpperCamelCase_:     str							)      ->       List[str]:





									"""simple docstring"""







									if (node := self.get_node(UpperCamelCase_							)) is not None:
											if node == self.head:
													lowercase__						=				self.head.get_next()

											if node == self.tail:
													lowercase__						=				self.tail.get_previous()

											self.remove_node_pointers(UpperCamelCase_							)

							@staticmethod
							def 				lowerCamelCase_			(							UpperCamelCase_:     Node							)      ->       None:





									"""simple docstring"""







									if node.get_next():
											lowercase__						=				node.previous

									if node.get_previous():
											lowercase__						=				node.next

									lowercase__						=				None
									lowercase__						=				None


							def 				lowerCamelCase_			(							self:     Union[str, Any]							)      ->       Union[str, Any]:





									"""simple docstring"""







									return self.head is None
def       _a			(				):
		pass






if __name__ == "__main__":
			import doctest

			doctest.testmod()






import json
import logging
import os
import socket

import git
import numpy as np
import torch


logging.basicConfig(
    format='%(asctime)s - %(levelname)s - %(name)s - PID: %(process)d -  %(message)s',
    datefmt='%m/%d/%Y %H:%M:%S',
    level=logging.INFO,
)
lowerCAmelCase	=							logging.getLogger(__name__)
def       _a			(				SCREAMING_SNAKE_CASE					):


		"""simple docstring"""




		lowercase__						=				git.Repo(search_parent_directories=SCREAMING_SNAKE_CASE					)
		lowercase__						=				{
		    '''repo_id''': str(SCREAMING_SNAKE_CASE					),
		    '''repo_sha''': str(repo.head.object.hexsha					),
		    '''repo_branch''': str(repo.active_branch					),
		}

		with open(os.path.join(SCREAMING_SNAKE_CASE						,    '''git_log.json'''					)						,    '''w'''					) as f:
				json.dump(SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE						,    indent=4					)
def       _a			(				SCREAMING_SNAKE_CASE					):


		"""simple docstring"""




		if params.n_gpu <= 0:
				lowercase__						=				0
				lowercase__						=				-1
				lowercase__						=				True
				lowercase__						=				False
				return

		assert torch.cuda.is_available()

		logger.info('''Initializing GPUs'''					)
		if params.n_gpu > 1:
				assert params.local_rank != -1

				lowercase__						=				int(os.environ['''WORLD_SIZE''']					)
				lowercase__						=				int(os.environ['''N_GPU_NODE''']					)
				lowercase__						=				int(os.environ['''RANK''']					)

				# number of nodes / node ID
				lowercase__						=				params.world_size // params.n_gpu_per_node
				lowercase__						=				params.global_rank // params.n_gpu_per_node
				lowercase__						=				True

				assert params.n_nodes == int(os.environ['''N_NODES''']					)
				assert params.node_id == int(os.environ['''NODE_RANK''']					)

		# local job (single GPU)
		else:
				assert params.local_rank == -1

				lowercase__						=				1
				lowercase__						=				0
				lowercase__						=				0
				lowercase__						=				0
				lowercase__						=				1
				lowercase__						=				1
				lowercase__						=				False

		# sanity checks
		assert params.n_nodes >= 1
		assert 0 <= params.node_id < params.n_nodes
		assert 0 <= params.local_rank <= params.global_rank < params.world_size
		assert params.world_size == params.n_nodes * params.n_gpu_per_node

		# define whether this is the master process / if we are in multi-node distributed mode
		lowercase__						=				params.node_id == 0 and params.local_rank == 0
		lowercase__						=				params.n_nodes > 1

		# summary
		lowercase__						=				f'--- Global rank: {params.global_rank} - '
		logger.info(PREFIX + '''Number of nodes: %i''' % params.n_nodes					)
		logger.info(PREFIX + '''Node ID        : %i''' % params.node_id					)
		logger.info(PREFIX + '''Local rank     : %i''' % params.local_rank					)
		logger.info(PREFIX + '''World size     : %i''' % params.world_size					)
		logger.info(PREFIX + '''GPUs per node  : %i''' % params.n_gpu_per_node					)
		logger.info(PREFIX + '''Master         : %s''' % str(params.is_master					)					)
		logger.info(PREFIX + '''Multi-node     : %s''' % str(params.multi_node					)					)
		logger.info(PREFIX + '''Multi-GPU      : %s''' % str(params.multi_gpu					)					)
		logger.info(PREFIX + '''Hostname       : %s''' % socket.gethostname()					)

		# set GPU device
		torch.cuda.set_device(params.local_rank					)

		# initialize multi-GPU
		if params.multi_gpu:
				logger.info('''Initializing PyTorch distributed'''					)
				torch.distributed.init_process_group(
				    init_method='''env://'''						,    backend='''nccl'''						,    )
def       _a			(				SCREAMING_SNAKE_CASE					):


		"""simple docstring"""




		np.random.seed(args.seed					)
		torch.manual_seed(args.seed					)
		if args.n_gpu > 0:
				torch.cuda.manual_seed_all(args.seed					)


