




import functools
import gc
import inspect

import torch

from .imports import is_npu_available, is_xpu_available




def 		lowerCAmelCase_ (						*lowerCamelCase ):
				if not isinstance(lowerCamelCase						,  lowerCamelCase ):
								__magic_name__						:						Union[str, Any]										=list(lowerCamelCase )
				for i in range(len(lowerCamelCase ) ):
								__magic_name__						:						Dict										=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_ (						lowerCamelCase ):
				__magic_name__						:						List[str]										=[
				    """CUDA out of memory.""",  # CUDA OOM
				    """cuDNN error: CUDNN_STATUS_NOT_SUPPORTED.""",  # CUDNN SNAFU
				    """DefaultCPUAllocator: can't allocate memory""",  # CPU OOM
				]
				if isinstance(lowerCamelCase						,  lowerCamelCase ) and len(exception.args ) == 1:
								return any(err in exception.args[0] for err in _statements )
				return False




def 		lowerCAmelCase_ (						lowerCamelCase = None						,  lowerCamelCase = 128 ):
				if function is None:
								return functools.partial(lowerCamelCase						,  starting_batch_size=lowerCamelCase )

				__magic_name__						:						List[Any]										=starting_batch_size

				def decorator(*lowerCamelCase						,  **lowerCamelCase ):
								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()
								__magic_name__						:						Optional[Any]										=list(inspect.signature(lowerCamelCase ).parameters.keys() )
								# Guard against user error
								if len(lowerCamelCase ) < (len(lowerCamelCase ) + 1):
												__magic_name__						:						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(lowerCamelCase						,  *lowerCamelCase						,  **lowerCamelCase )
												except Exception as e:
																if should_reduce_batch_size(lowerCamelCase ):
																				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 a_     (    __UpperCAmelCase				,							__UpperCAmelCase					)				->					qiskit.result.counts.Counts:





			"""simple docstring"""







			snake_case:    Union[str, Any]      							=qiskit.Aer.get_backend('aer_simulator'					)

			# Create a Quantum Circuit acting on the q register
			snake_case:    Dict      							=qiskit.QuantumCircuit(__UpperCAmelCase				,							__UpperCAmelCase					)

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

			# Execute the circuit on the simulator
			snake_case:    Dict      							=qiskit.execute(__UpperCAmelCase				,							__UpperCAmelCase				,							shots=10_00					)

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


if __name__ == "__main__":
	print(F"""Total count for various states are: {single_qubit_measure(1, 1)}""")




