code: 
  
  
  import random
  from typing import List, Optional, Union
  
  import numpy as np
  import torch
  
  from ..state import AcceleratorState
  from .constants import CUDA_DISTRIBUTED_TYPES
  from .dataclasses import DistributedType, RNGType
  from .imports import is_npu_available, is_tpu_available, is_xpu_available
  
  
  if is_tpu_available(check_device=False):
  						import torch_xla.core.xla_model as xm
  
  
  
  def   SCREAMING_SNAKE_CASE__						(							snake_case_,	snake_case_ = False	)			->							List[str]:
  				if device_specific:
  								seed += AcceleratorState().process_index
  				random.seed(snake_case_	)
  				np.random.seed(snake_case_	)
  				torch.manual_seed(snake_case_	)
  				if is_xpu_available():
  								torch.xpu.manual_seed_all(snake_case_	)
  				elif is_npu_available():
  								torch.npu.manual_seed_all(snake_case_	)
  				else:
  								torch.cuda.manual_seed_all(snake_case_	)
  				# ^^ safe to call this function even if cuda is not available
  				if is_tpu_available():
  								xm.set_rng_state(snake_case_	)
  
  
  
  def   SCREAMING_SNAKE_CASE__						(							snake_case_ = None,	snake_case_ = None	)			->							Dict:
  				# Get the proper rng state
  				if rng_type == RNGType.TORCH:
  								A__     :							int   				=torch.get_rng_state()
  				elif rng_type == RNGType.CUDA:
  								A__     :							Optional[Any]   				=torch.cuda.get_rng_state()
  				elif rng_type == RNGType.XLA:
  								assert is_tpu_available(), "Can't synchronize XLA seeds on an environment without TPUs."
  								A__     :							Dict   				=torch.tensor(xm.get_rng_state()	)
  				elif rng_type == RNGType.NPU:
  								assert is_npu_available(), "Can't synchronize NPU seeds on an environment without NPUs."
  								A__     :							str   				=torch.npu.get_rng_state()
  				elif rng_type == RNGType.XPU:
  								assert is_xpu_available(), "Can't synchronize XPU seeds on an environment without XPUs."
  								A__     :							Any   				=torch.xpu.get_rng_state()
  				elif rng_type == RNGType.GENERATOR:
  								assert generator is not None, "Need a generator to synchronize its seed."
  								A__     :							Tuple   				=generator.get_state()
  
  				# Broadcast the rng state from device 0 to other devices
  				A__     :							int   				=AcceleratorState()
  				if state.distributed_type == DistributedType.TPU:
  								A__     :							Optional[int]   				=rng_state.to(xm.xla_device()	)
  								xm.collective_broadcast([rng_state]	)
  								xm.mark_step()
  								A__     :							int   				=rng_state.cpu()
  				elif (
  				    state.distributed_type in CUDA_DISTRIBUTED_TYPES
  				    or state.distributed_type == DistributedType.MULTI_NPU
  				    or state.distributed_type == DistributedType.MULTI_XPU
  				):
  								A__     :							List[str]   				=rng_state.to(state.device	)
  								torch.distributed.broadcast(snake_case_,	0	)
  								A__     :							Dict   				=rng_state.cpu()
  				elif state.distributed_type == DistributedType.MULTI_CPU:
  								torch.distributed.broadcast(snake_case_,	0	)
  
  				# Set the broadcast rng state
  				if rng_type == RNGType.TORCH:
  								torch.set_rng_state(snake_case_	)
  				elif rng_type == RNGType.CUDA:
  								torch.cuda.set_rng_state(snake_case_	)
  				elif rng_type == RNGType.NPU:
  								torch.npu.set_rng_state(snake_case_	)
  				elif rng_type == RNGType.XPU:
  								torch.xpu.set_rng_state(snake_case_	)
  				elif rng_type == RNGType.XLA:
  								xm.set_rng_state(rng_state.item()	)
  				elif rng_type == RNGType.GENERATOR:
  								generator.set_state(snake_case_	)
  
  
  
  
  def   SCREAMING_SNAKE_CASE__						(							snake_case_,	snake_case_ = None	)			->							Tuple:
  				for rng_type in rng_types:
  								synchronize_rng_state(RNGType(snake_case_	),	generator=snake_case_	)
  
  
  
  
style_context: 
  
  
  def   SCREAMING_SNAKE_CASE__						(							snake_case_	)			->							int:
  				barcode //= 1_0  # exclude the last digit
  				A__     :							List[str]   				=False
  				A__     :							Dict   				=0
  
  				# extract and check each digit
  				while barcode != 0:
  								A__     :							Union[str, Any]   				=1 if checker else 3
  								s += mult * (barcode % 1_0)
  								barcode //= 1_0
  								A__     :							Union[str, Any]   				=not checker
  
  				return (1_0 - (s % 1_0)) % 1_0
  
  
  
  def   SCREAMING_SNAKE_CASE__						(							snake_case_	)			->							bool:
  				return len(str(snake_case_	)	) == 1_3 and get_check_digit(snake_case_	) == barcode % 1_0
  
  
  
  def   SCREAMING_SNAKE_CASE__						(							snake_case_	)			->							int:
  				if str(snake_case_	).isalpha():
  								A__     :							Tuple   				=f'Barcode \'{barcode}\' has alphabetic characters.'
  								raise ValueError(snake_case_	)
  				elif int(snake_case_	) < 0:
  								raise ValueError('''The entered barcode has a negative value. Try again.'''	)
  				else:
  								return int(snake_case_	)
  
  
  if __name__ == "__main__":
  						import doctest
  
  						doctest.testmod()
  						__lowerCamelCase       :       List[Any]				   =			get_barcode(input("Barcode: ").strip())
  
  						if is_valid(barcode):
  												print(F"'{barcode}' is a valid barcode.")
  						else:
  												print(F"'{barcode}' is NOT a valid barcode.")
  
  
  
  