



'''simple docstring'''


import contextlib
from multiprocessing import Pool, RLock

from tqdm.auto import tqdm

from ..utils import experimental, logging


lowercase_      :				List[str]   					=    logging.get_logger(__name__)




class      __UpperCamelCase       :
	__A			  =					None







@experimental
def      SCREAMING_SNAKE_CASE				(				lowercase_    :      Union[str, Any] ,  lowercase_    :      str ,  lowercase_    :      Optional[Any] ,  lowercase_    :      Any ,  lowercase_    :      int ,  lowercase_    :      List[str] ,  lowercase_    :      List[Any]						):
						if ParallelBackendConfig.backend_name is None:
												return _map_with_multiprocessing_pool(
												    lowercase_ ,  lowercase_ ,  lowercase_ ,  lowercase_ ,  lowercase_ ,  lowercase_ ,  lowercase_						)

						return _map_with_joblib(lowercase_ ,  lowercase_ ,  lowercase_ ,  lowercase_ ,  lowercase_ ,  lowercase_ ,  lowercase_						)







def      SCREAMING_SNAKE_CASE				(				lowercase_    :      Any ,  lowercase_    :      Dict ,  lowercase_    :      Dict ,  lowercase_    :      Tuple ,  lowercase_    :      int ,  lowercase_    :      int ,  lowercase_    :      Dict						):
						lowercase        =							num_proc if num_proc <= len(lowercase_						) else len(lowercase_						)
						lowercase        =							[]  # We organize the splits ourselve (contiguous splits)
						for index in range(lowercase_						):
												lowercase        =							len(lowercase_						) // num_proc
												lowercase        =							len(lowercase_						) % num_proc
												lowercase        =							div * index + min(lowercase_ ,  lowercase_						)
												lowercase        =							start + div + (1 if index < mod else 0)
												split_kwds.append((function, iterable[start:end], types, index, disable_tqdm, desc)						)

						if len(lowercase_						) != sum(len(i[1]						) for i in split_kwds						):
												raise ValueError(
												    F"""Error dividing inputs iterable among processes. """
												    F"""Total number of objects {len(lowercase_						)}, """
												    F"""length: {sum(len(i[1]						) for i in split_kwds						)}"""						)

						logger.info(
						    F"""Spawning {num_proc} processes for {len(lowercase_						)} objects in slices of {[len(i[1]						) for i in split_kwds]}"""						)
						lowercase     ,   lowercase        =							None, None
						if not disable_tqdm:
												lowercase     ,   lowercase        =							(RLock(),), tqdm.set_lock
						with Pool(lowercase_ ,  initargs=lowercase_ ,  initializer=lowercase_						) as pool:
												lowercase        =							pool.map(lowercase_ ,  lowercase_						)
						logger.info(F"""Finished {num_proc} processes"""						)
						lowercase        =							[obj for proc_res in mapped for obj in proc_res]
						logger.info(F"""Unpacked {len(lowercase_						)} objects"""						)

						return mapped







def      SCREAMING_SNAKE_CASE				(				lowercase_    :      List[str] ,  lowercase_    :      str ,  lowercase_    :      int ,  lowercase_    :      Optional[Any] ,  lowercase_    :      Any ,  lowercase_    :      Dict ,  lowercase_    :      Tuple						):
						# progress bar is not yet supported for _map_with_joblib, because tqdm couldn't accurately be applied to joblib,
						# and it requires monkey-patching joblib internal classes which is subject to change
						import joblib

						with joblib.parallel_backend(ParallelBackendConfig.backend_name ,  n_jobs=lowercase_						):
												return joblib.Parallel()(
												    joblib.delayed(lowercase_						)((function, obj, types, None, True, None)						) for obj in iterable						)







@experimental
@contextlib.contextmanager
def      SCREAMING_SNAKE_CASE				(				lowercase_    :      str						):
						lowercase        =							backend_name

						if backend_name == "spark":
												from joblibspark import register_spark

												register_spark()

												# TODO: call create_cache_and_write_probe if "download" in steps
												# TODO: raise NotImplementedError when Dataset.map etc is called

						try:
												yield
						finally:
												lowercase        =							None







'''simple docstring'''


import os







def      SCREAMING_SNAKE_CASE				(				):
						lowercase        =							os.path.join(os.path.dirname(lowercase_						) ,  """num.txt"""						)
						with open(lowercase_						) as file_hand:
												return str(sum(int(lowercase_						) for line in file_hand						)						)[:10]


if __name__ == "__main__":
						print(solution())


