





"""simple docstring"""
import functools
import gc
import inspect

import torch

from .imports import is_npu_available, is_xpu_available



def      __lowerCamelCase   (							*a_     :		Optional[Any]							)			->      Dict:
      if not isinstance(a_ ,   a_							):
            __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  list(a_							)
      for i in range(len(a_							)							):
            __SCREAMING_SNAKE_CASE   :List[Any]						=  None
      gc.collect()
      if is_xpu_available():
            torch.xpu.empty_cache()
      elif is_npu_available():
            torch.npu.empty_cache()
      else:
            torch.cuda.empty_cache()
      return objects



def      __lowerCamelCase   (							a_     :		Exception							)			->      bool:
      __SCREAMING_SNAKE_CASE   :Optional[int]						=  [
          '''CUDA out of memory.''',  # CUDA OOM
          '''cuDNN error: CUDNN_STATUS_NOT_SUPPORTED.''',  # CUDNN SNAFU
          '''DefaultCPUAllocator: can\'t allocate memory''',  # CPU OOM
      ]
      if isinstance(a_ ,   a_							) and len(exception.args							) == 1:
            return any(err in exception.args[0] for err in _statements							)
      return False







def      __lowerCamelCase   (							a_     :		callable = None ,   a_     :		int = 1_28							)			->      Union[str, Any]:
      if function is None:
            return functools.partial(a_ ,   starting_batch_size=a_							)

      __SCREAMING_SNAKE_CASE   :Optional[Any]						=  starting_batch_size

      def decorator(*a_     :		Tuple ,   **a_     :		Optional[Any]							):
            nonlocal batch_size
            gc.collect()
            if is_xpu_available():
                  torch.xpu.empty_cache()
            elif is_npu_available():
                  torch.npu.empty_cache()
            else:
                  torch.cuda.empty_cache()
            __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  list(inspect.signature(a_							).parameters.keys()							)
            # Guard against user error
            if len(a_							) < (len(a_							) + 1):
                  __SCREAMING_SNAKE_CASE   :Optional[int]						=  ''', '''.join([f'''{arg}={value}''' for arg, value in zip(params[1:] ,   args[1:]							)]							)
                  raise TypeError(
                      f'''Batch size was passed into `{function.__name__}` as the first argument when called.'''
                      f'''Remove this as the decorator already does so: `{function.__name__}({arg_str})`'''							)
            while True:
                  if batch_size == 0:
                        raise RuntimeError('''No executable batch size found, reached zero.'''							)
                  try:
                        return function(a_ ,   *a_ ,   **a_							)
                  except Exception as e:
                        if should_reduce_batch_size(a_							):
                              gc.collect()
                              if is_xpu_available():
                                    torch.xpu.empty_cache()
                              elif is_npu_available():
                                    torch.npu.empty_cache()
                              else:
                                    torch.cuda.empty_cache()
                              batch_size //= 2
                        else:
                              raise

      return decorator






"""simple docstring"""
import qiskit



def      __lowerCamelCase   (							a_     :		int ,   a_     :		int							)			->      qiskit.result.counts.Counts:
      __SCREAMING_SNAKE_CASE   :Tuple						=  qiskit.Aer.get_backend('''aer_simulator'''							)

      # Create a Quantum Circuit acting on the q register
      __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  qiskit.QuantumCircuit(a_ ,   a_							)

      # Apply X (NOT) Gate to Qubits 0 & 1
      circuit.x(0							)
      circuit.x(1							)

      # Map the quantum measurement to the classical bits
      circuit.measure([0, 1] ,   [0, 1]							)

      # Execute the circuit on the qasm simulator
      __SCREAMING_SNAKE_CASE   :Tuple						=  qiskit.execute(a_ ,   a_ ,   shots=10_00							)

      # Return the histogram data of the results of the experiment.
      return job.result().get_counts(a_							)


if __name__ == "__main__":
  lowerCamelCase_								=		single_qubit_measure(2, 2)
  print(f'Total count for various states are: {counts}')