
'''simple docstring'''


import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_torch_available
from transformers.testing_utils import require_torch, torch_device


if is_torch_available():
					from transformers import PyTorchBenchmark, PyTorchBenchmarkArguments

@require_torch
class 	__lowercase				(  unittest.TestCase    ):

			def        UpperCAmelCase__ (self			,   A      ):
								for model_result in results.values():
													for batch_size, sequence_length in zip(model_result['''bs''']			,   model_result['''ss''']      ):
																		lowerCamelCase_					:      Optional[int]     =		model_result['''result'''][batch_size][sequence_length]
																		self.assertIsNotNone(A      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Any     =		'''sshleifer/tiny-gpt2'''
								lowerCamelCase_					:      Union[str, Any]     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   )
								lowerCamelCase_					:      str     =		PyTorchBenchmark(A      )
								lowerCamelCase_					:      Dict     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      List[Any]     =		'''sgugger/tiny-distilbert-classification'''
								lowerCamelCase_					:      List[Any]     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   only_pretrain_model=A			,   )
								lowerCamelCase_					:      List[str]     =		PyTorchBenchmark(A      )
								lowerCamelCase_					:      Optional[Any]     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      List[str]     =		'''sshleifer/tiny-gpt2'''
								lowerCamelCase_					:      Any     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   torchscript=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   )
								lowerCamelCase_					:      int     =		PyTorchBenchmark(A      )
								lowerCamelCase_					:      Optional[int]     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )

			@unittest.skipIf(torch_device == '''cpu'''			,   '''Cant do half precision'''      )
			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		'''sshleifer/tiny-gpt2'''
								lowerCamelCase_					:      Optional[int]     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   fpaa=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   )
								lowerCamelCase_					:      Optional[int]     =		PyTorchBenchmark(A      )
								lowerCamelCase_					:      Tuple     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[int]     =		'''sshleifer/tiny-gpt2'''
								lowerCamelCase_					:      Optional[int]     =		AutoConfig.from_pretrained(A      )
								# set architectures equal to `None`
								lowerCamelCase_					:      Union[str, Any]     =		None
								lowerCamelCase_					:      Tuple     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   )
								lowerCamelCase_					:      Tuple     =		PyTorchBenchmark(A			,   configs=[config]      )
								lowerCamelCase_					:      Tuple     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Union[str, Any]     =		'''sshleifer/tiny-gpt2'''
								lowerCamelCase_					:      Any     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   )
								lowerCamelCase_					:      Union[str, Any]     =		PyTorchBenchmark(A      )
								lowerCamelCase_					:      Optional[int]     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result      )
								self.check_results_dict_not_empty(results.memory_train_result      )

			@unittest.skipIf(torch_device == '''cpu'''			,   '''Can\'t do half precision'''      )
			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Dict     =		'''sshleifer/tiny-gpt2'''
								lowerCamelCase_					:      Tuple     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   fpaa=A			,   multi_process=A			,   )
								lowerCamelCase_					:      List[str]     =		PyTorchBenchmark(A      )
								lowerCamelCase_					:      Tuple     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result      )
								self.check_results_dict_not_empty(results.memory_train_result      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      List[str]     =		'''sshleifer/tiny-gpt2'''
								lowerCamelCase_					:      Dict     =		AutoConfig.from_pretrained(A      )
								lowerCamelCase_					:      str     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   )
								lowerCamelCase_					:      List[Any]     =		PyTorchBenchmark(A			,   configs=[config]      )
								lowerCamelCase_					:      Dict     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      str     =		'''sshleifer/tinier_bart'''
								lowerCamelCase_					:      List[Any]     =		AutoConfig.from_pretrained(A      )
								lowerCamelCase_					:      List[Any]     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   )
								lowerCamelCase_					:      Optional[Any]     =		PyTorchBenchmark(A			,   configs=[config]      )
								lowerCamelCase_					:      Dict     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Any     =		'''sshleifer/tiny-gpt2'''
								lowerCamelCase_					:      int     =		AutoConfig.from_pretrained(A      )
								lowerCamelCase_					:      Optional[Any]     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   )
								lowerCamelCase_					:      Optional[int]     =		PyTorchBenchmark(A			,   configs=[config]      )
								lowerCamelCase_					:      Tuple     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result      )
								self.check_results_dict_not_empty(results.memory_train_result      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		'''sshleifer/tinier_bart'''
								lowerCamelCase_					:      int     =		AutoConfig.from_pretrained(A      )
								lowerCamelCase_					:      int     =		PyTorchBenchmarkArguments(
								    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   multi_process=A			,   )
								lowerCamelCase_					:      List[Any]     =		PyTorchBenchmark(A			,   configs=[config]      )
								lowerCamelCase_					:      List[str]     =		benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result      )
								self.check_results_dict_not_empty(results.memory_train_result      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      str     =		'''sshleifer/tiny-gpt2'''
								with tempfile.TemporaryDirectory() as tmp_dir:
													lowerCamelCase_					:      List[str]     =		PyTorchBenchmarkArguments(
													    models=[MODEL_ID]			,   training=A			,   inference=A			,   save_to_csv=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   inference_time_csv_file=os.path.join(A			,   '''inf_time.csv'''      )			,   train_memory_csv_file=os.path.join(A			,   '''train_mem.csv'''      )			,   inference_memory_csv_file=os.path.join(A			,   '''inf_mem.csv'''      )			,   train_time_csv_file=os.path.join(A			,   '''train_time.csv'''      )			,   env_info_csv_file=os.path.join(A			,   '''env.csv'''      )			,   multi_process=A			,   )
													lowerCamelCase_					:      Optional[int]     =		PyTorchBenchmark(A      )
													benchmark.run()
													self.assertTrue(Path(os.path.join(A			,   '''inf_time.csv'''      )      ).exists()      )
													self.assertTrue(Path(os.path.join(A			,   '''train_time.csv'''      )      ).exists()      )
													self.assertTrue(Path(os.path.join(A			,   '''inf_mem.csv'''      )      ).exists()      )
													self.assertTrue(Path(os.path.join(A			,   '''train_mem.csv'''      )      ).exists()      )
													self.assertTrue(Path(os.path.join(A			,   '''env.csv'''      )      ).exists()      )






			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      str     =		'''sshleifer/tiny-gpt2'''

								def _check_summary_is_not_empty(A      ):
													self.assertTrue(hasattr(A			,   '''sequential'''      )      )
													self.assertTrue(hasattr(A			,   '''cumulative'''      )      )
													self.assertTrue(hasattr(A			,   '''current'''      )      )
													self.assertTrue(hasattr(A			,   '''total'''      )      )

								with tempfile.TemporaryDirectory() as tmp_dir:
													lowerCamelCase_					:      Any     =		PyTorchBenchmarkArguments(
													    models=[MODEL_ID]			,   training=A			,   inference=A			,   sequence_lengths=[8]			,   batch_sizes=[1]			,   log_filename=os.path.join(A			,   '''log.txt'''      )			,   log_print=A			,   trace_memory_line_by_line=A			,   multi_process=A			,   )
													lowerCamelCase_					:      Optional[int]     =		PyTorchBenchmark(A      )
													lowerCamelCase_					:      str     =		benchmark.run()
													_check_summary_is_not_empty(result.inference_summary      )
													_check_summary_is_not_empty(result.train_summary      )
													self.assertTrue(Path(os.path.join(A			,   '''log.txt'''      )      ).exists()      )




'''simple docstring'''


import qiskit




def lowercase_	(   _lowercase			,       _lowercase				)     ->							qiskit.result.counts.Counts:
					'''simple docstring'''

					lowerCamelCase_					:      Optional[Any]     =		qiskit.Aer.get_backend('''aer_simulator'''				)

					# Create a Quantum Circuit acting on the q register
					lowerCamelCase_					:      Optional[int]     =		qiskit.QuantumCircuit(_lowercase			,       _lowercase				)

					# 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
					lowerCamelCase_					:      Optional[int]     =		qiskit.execute(_lowercase			,       _lowercase			,       shots=1_000				)

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


if __name__ == "__main__":
					__lowercase							:   List[Any]					=     single_qubit_measure(2, 2)
					print(f'Total count for various states are: {counts}')


