'''simple docstring'''





from pathlib import Path

import torch

from ...utils import is_npu_available, is_xpu_available
from .config_args import ClusterConfig, default_json_config_file
from .config_utils import SubcommandHelpFormatter


_lowerCAmelCase	:str						=     """Create a default config file for Accelerate with only a few flags set."""


def      __lowerCAmelCase    (							a_="no"							,   a_ = default_json_config_file							,   a_ = False		)   ->						Tuple:





     '''simple docstring'''





     SCREAMING_SNAKE_CASE       :      Union[str, Any]     						=							Path(__UpperCamelCase		)
     path.parent.mkdir(parents=__UpperCamelCase							,   exist_ok=__UpperCamelCase		)
     if path.exists():
          print(
              f"""Configuration already exists at {save_location}, will not override. Run `accelerate config` manually or pass a different `save_location`."""		)
          return False
     SCREAMING_SNAKE_CASE       :      Union[str, Any]     						=							mixed_precision.lower()
     if mixed_precision not in ["no", "fp16", "bf16", "fp8"]:
          raise ValueError(
              f"""`mixed_precision` should be one of \'no\', \'fp16\', \'bf16\', or \'fp8\'. Received {mixed_precision}"""		)
     SCREAMING_SNAKE_CASE       :      Any     						=							{
         'compute_environment': 'LOCAL_MACHINE',
         'mixed_precision': mixed_precision,
     }
     if torch.cuda.is_available():
          SCREAMING_SNAKE_CASE       :      Any     						=							torch.cuda.device_count()
          SCREAMING_SNAKE_CASE       :      Optional[int]     						=							num_gpus
          SCREAMING_SNAKE_CASE       :      List[str]     						=							False
          if num_gpus > 1:
               SCREAMING_SNAKE_CASE       :      Optional[Any]     						=							'MULTI_GPU'
          else:
               SCREAMING_SNAKE_CASE       :      Any     						=							'NO'
     elif is_xpu_available() and use_xpu:
          SCREAMING_SNAKE_CASE       :      Tuple     						=							torch.xpu.device_count()
          SCREAMING_SNAKE_CASE       :      Union[str, Any]     						=							num_xpus
          SCREAMING_SNAKE_CASE       :      Tuple     						=							False
          if num_xpus > 1:
               SCREAMING_SNAKE_CASE       :      int     						=							'MULTI_XPU'
          else:
               SCREAMING_SNAKE_CASE       :      Union[str, Any]     						=							'NO'
     elif is_npu_available():
          SCREAMING_SNAKE_CASE       :      Any     						=							torch.npu.device_count()
          SCREAMING_SNAKE_CASE       :      Optional[int]     						=							num_npus
          SCREAMING_SNAKE_CASE       :      Any     						=							False
          if num_npus > 1:
               SCREAMING_SNAKE_CASE       :      List[Any]     						=							'MULTI_NPU'
          else:
               SCREAMING_SNAKE_CASE       :      Tuple     						=							'NO'
     else:
          SCREAMING_SNAKE_CASE       :      List[Any]     						=							0
          SCREAMING_SNAKE_CASE       :      Tuple     						=							True
          SCREAMING_SNAKE_CASE       :      Optional[int]     						=							1
          SCREAMING_SNAKE_CASE       :      List[str]     						=							'NO'
     SCREAMING_SNAKE_CASE       :      Dict     						=							ClusterConfig(**__UpperCamelCase		)
     config.to_json_file(__UpperCamelCase		)
     return path


def      __lowerCAmelCase    (							a_							,   a_		)   ->						Any:





     '''simple docstring'''





     SCREAMING_SNAKE_CASE       :      Union[str, Any]     						=							parser.add_parser('default'							,   parents=__UpperCamelCase							,   help=__UpperCamelCase							,   formatter_class=__UpperCamelCase		)
     parser.add_argument(
         '--config_file'							,   default=__UpperCamelCase							,   help=(
             'The path to use to store the config file. Will default to a file named default_config.yaml in the cache '
             'location, which is the content of the environment `HF_HOME` suffixed with \'accelerate\', or if you don\'t have '
             'such an environment variable, your cache directory (\'~/.cache\' or the content of `XDG_CACHE_HOME`) suffixed '
             'with \'huggingface\'.'
         )							,   dest='save_location'							,   )

     parser.add_argument(
         '--mixed_precision'							,   choices=['no', 'fp16', 'bf16']							,   type=__UpperCamelCase							,   help='Whether or not to use mixed precision training. '
         'Choose between FP16 and BF16 (bfloat16) training. '
         'BF16 training is only supported on Nvidia Ampere GPUs and PyTorch 1.10 or later.'							,   default='no'							,   )
     parser.set_defaults(func=__UpperCamelCase		)
     return parser


def      __lowerCAmelCase    (							a_		)   ->						Union[str, Any]:





     '''simple docstring'''





     SCREAMING_SNAKE_CASE       :      int     						=							write_basic_config(args.mixed_precision							,   args.save_location		)
     if config_file:
          print(f"""accelerate configuration saved at {config_file}"""		)







'''simple docstring'''
import math

import qiskit

def 					lowerCamelCase_ ( __UpperCamelCase					:       int = 1							,    __UpperCamelCase					:       int = 1							,    __UpperCamelCase					:       int = 1		)					->	qiskit.result.counts.Counts:







     """simple docstring"""
     if (
         isinstance(__UpperCamelCase							,    __UpperCamelCase		)
         or isinstance(__UpperCamelCase							,    __UpperCamelCase		)
         or isinstance(__UpperCamelCase							,    __UpperCamelCase		)
     ):
          raise TypeError('inputs must be integers.'		)

     if (input_a < 0) or (input_a < 0) or (carry_in < 0):
          raise ValueError('inputs must be positive.'		)

     if (
         (math.floor(__UpperCamelCase		) != input_a)
         or (math.floor(__UpperCamelCase		) != input_a)
         or (math.floor(__UpperCamelCase		) != carry_in)
     ):
          raise ValueError('inputs must be exact integers.'		)

     if (input_a > 2) or (input_a > 2) or (carry_in > 2):
          raise ValueError('inputs must be less or equal to 2.'		)

     # build registers
     _A				=							qiskit.QuantumRegister(4							,    'qr'		)
     _A				=							qiskit.ClassicalRegister(2							,    'cr'		)
     # list the entries
     _A				=							[input_a, input_a, carry_in]

     _A				=							qiskit.QuantumCircuit(__UpperCamelCase							,    __UpperCamelCase		)

     for i in range(0							,    3		):
          if entry[i] == 2:
               quantum_circuit.h(__UpperCamelCase		)  # for hadamard entries
          elif entry[i] == 1:
               quantum_circuit.x(__UpperCamelCase		)  # for 1 entries
          elif entry[i] == 0:
               quantum_circuit.i(__UpperCamelCase		)  # for 0 entries

    # build the circuit
     quantum_circuit.ccx(0							,    1							,    3		)  # ccx = toffoli gate
     quantum_circuit.cx(0							,    1		)
     quantum_circuit.ccx(1							,    2							,    3		)
     quantum_circuit.cx(1							,    2		)
     quantum_circuit.cx(0							,    1		)

     quantum_circuit.measure([2, 3]							,    __UpperCamelCase		)  # measure the last two qbits

     _A				=							qiskit.Aer.get_backend('aer_simulator'		)
     _A				=							qiskit.execute(__UpperCamelCase							,    __UpperCamelCase							,    shots=1_0_0_0		)

     return job.result().get_counts(__UpperCamelCase		)


if __name__ == "__main__":
    print(F'Total sum count for state is: {quantum_full_adder(1, 1, 1)}')





