

"""simple docstring"""






import math

import qiskit



def   lowercase_	(    _lowercase       :		int = 1							,      _lowercase       :		int = 1							,      _lowercase       :		int = 1	):




					'''simple docstring'''






					if (
					    isinstance(_lowercase							,      _lowercase	)
					    or isinstance(_lowercase							,      _lowercase	)
					    or isinstance(_lowercase							,      _lowercase	)
					):
										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(_lowercase	) != input_a)
					    or (math.floor(_lowercase	) != input_a)
					    or (math.floor(_lowercase	) != 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
					UpperCAmelCase			:   List[Any]      =				qiskit.QuantumRegister(4							,      "qr"	)
					UpperCAmelCase			:   Dict      =				qiskit.ClassicalRegister(2							,      "cr"	)
					# list the entries
					UpperCAmelCase			:   int      =				[input_a, input_a, carry_in]

					UpperCAmelCase			:   Optional[int]      =				qiskit.QuantumCircuit(_lowercase							,      _lowercase	)

					for i in range(0							,      3	):
										if entry[i] == 2:
															quantum_circuit.h(_lowercase	)  # for hadamard entries
										elif entry[i] == 1:
															quantum_circuit.x(_lowercase	)  # for 1 entries
										elif entry[i] == 0:
															quantum_circuit.i(_lowercase	)  # 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]							,      _lowercase	)  # measure the last two qbits

					UpperCAmelCase			:   Dict      =				qiskit.Aer.get_backend("aer_simulator"	)
					UpperCAmelCase			:   List[Any]      =				qiskit.execute(_lowercase							,      _lowercase							,      shots=10_00	)

					return job.result().get_counts(_lowercase	)


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


"""simple docstring"""






import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ASTConfig
from transformers.testing_utils import require_torch, require_torchaudio, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_torchaudio_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch
	from torch import nn

	from transformers import ASTForAudioClassification, ASTModel
	from transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer import (
	    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
	)


if is_torchaudio_available():
	import torchaudio

	from transformers import ASTFeatureExtractor







class       snake_case__  :







			def __init__(			self			: Optional[Any]			,  lowercase			: int			,  lowercase			: List[Any]=13			,  lowercase			: List[str]=2			,  lowercase			: Tuple=24			,  lowercase			: Dict=16			,  lowercase			: Optional[int]=True			,  lowercase			: Any=True			,  lowercase			: Dict=32			,  lowercase			: List[str]=5			,  lowercase			: Union[str, Any]=4			,  lowercase			: Tuple=37			,  lowercase			: Tuple="gelu"			,  lowercase			: Dict=0.1			,  lowercase			: Any=0.1			,  lowercase			: Any=10			,  lowercase			: List[str]=0.0_2			,  lowercase			: int=None			,  lowercase			: Optional[Any]=2			,  lowercase			: str=2			,  ):





								'''simple docstring'''



								UpperCAmelCase			:   int      =				parent
								UpperCAmelCase			:   Optional[int]      =				batch_size
								UpperCAmelCase			:   str      =				patch_size
								UpperCAmelCase			:   Dict      =				max_length
								UpperCAmelCase			:   Dict      =				num_mel_bins
								UpperCAmelCase			:   Optional[Any]      =				is_training
								UpperCAmelCase			:   str      =				use_labels
								UpperCAmelCase			:   Dict      =				hidden_size
								UpperCAmelCase			:   Tuple      =				num_hidden_layers
								UpperCAmelCase			:   Tuple      =				num_attention_heads
								UpperCAmelCase			:   Optional[Any]      =				intermediate_size
								UpperCAmelCase			:   Tuple      =				hidden_act
								UpperCAmelCase			:   Optional[int]      =				hidden_dropout_prob
								UpperCAmelCase			:   Optional[Any]      =				attention_probs_dropout_prob
								UpperCAmelCase			:   Any      =				type_sequence_label_size
								UpperCAmelCase			:   Dict      =				initializer_range
								UpperCAmelCase			:   Optional[int]      =				scope
								UpperCAmelCase			:   List[Any]      =				frequency_stride
								UpperCAmelCase			:   Tuple      =				time_stride

								# in AST, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
								UpperCAmelCase			:   List[str]      =				(self.num_mel_bins - self.patch_size) // self.frequency_stride + 1
								UpperCAmelCase			:   List[str]      =				(self.max_length - self.patch_size) // self.time_stride + 1
								UpperCAmelCase			:   Dict      =				frequency_out_dimension * time_out_dimension
								UpperCAmelCase			:   int      =				num_patches + 2







			def 			__lowerCAmelCase				(			self			: Optional[Any]  ):





								'''simple docstring'''



								UpperCAmelCase			:   List[str]      =				floats_tensor([self.batch_size, self.max_length, self.num_mel_bins]  )

								UpperCAmelCase			:   Optional[Any]      =				None
								if self.use_labels:
													UpperCAmelCase			:   List[str]      =				ids_tensor([self.batch_size]			,  self.type_sequence_label_size  )

								UpperCAmelCase			:   List[str]      =				self.get_config()

								return config, input_values, labels







			def 			__lowerCAmelCase				(			self			: str  ):





								'''simple docstring'''



								return ASTConfig(
								    patch_size=self.patch_size			,  max_length=self.max_length			,  num_mel_bins=self.num_mel_bins			,  hidden_size=self.hidden_size			,  num_hidden_layers=self.num_hidden_layers			,  num_attention_heads=self.num_attention_heads			,  intermediate_size=self.intermediate_size			,  hidden_act=self.hidden_act			,  hidden_dropout_prob=self.hidden_dropout_prob			,  attention_probs_dropout_prob=self.attention_probs_dropout_prob			,  is_decoder=lowercase			,  initializer_range=self.initializer_range			,  frequency_stride=self.frequency_stride			,  time_stride=self.time_stride			,  )







			def 			__lowerCAmelCase				(			self			: List[Any]			,  lowercase			: Optional[int]			,  lowercase			: Any			,  lowercase			: List[str]  ):





								'''simple docstring'''



								UpperCAmelCase			:   Tuple      =				ASTModel(config=lowercase  )
								model.to(lowercase  )
								model.eval()
								UpperCAmelCase			:   Optional[int]      =				model(lowercase  )
								self.parent.assertEqual(result.last_hidden_state.shape			,  (self.batch_size, self.seq_length, self.hidden_size)  )







			def 			__lowerCAmelCase				(			self			: Dict  ):





								'''simple docstring'''



								UpperCAmelCase			:   Union[str, Any]      =				self.prepare_config_and_inputs()
								(
								    (
								    UpperCAmelCase
								)      ,							(
								    UpperCAmelCase
								)      ,							(
								    UpperCAmelCase
								)      ,							
								)			:   Tuple      =				config_and_inputs
								UpperCAmelCase			:   int      =				{"input_values": input_values}
								return config, inputs_dict







@require_torch
class       snake_case__  ( lowerCAmelCase_					,  lowerCAmelCase_					,  unittest.TestCase     ):
			SCREAMING_SNAKE_CASE__     				=						(
			    (
			        ASTModel,
			        ASTForAudioClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			SCREAMING_SNAKE_CASE__     				=						(
			    {'''audio-classification''': ASTForAudioClassification, '''feature-extraction''': ASTModel}
			    if is_torch_available()
			    else {}
			)
			SCREAMING_SNAKE_CASE__     				=						False
			SCREAMING_SNAKE_CASE__     				=						False
			SCREAMING_SNAKE_CASE__     				=						False
			SCREAMING_SNAKE_CASE__     				=						False







			def 			__lowerCAmelCase				(			self			: Optional[Any]			,  lowercase			: Optional[Any]			,  lowercase			: Union[str, Any]			,  lowercase			: List[str]			,  lowercase			: Any			,  lowercase			: str  ):





								'''simple docstring'''



								if pipeline_test_casse_name == "AudioClassificationPipelineTests":
													return True

								return False







			def 			__lowerCAmelCase				(			self			: str  ):





								'''simple docstring'''



								UpperCAmelCase			:   int      =				ASTModelTester(self  )
								UpperCAmelCase			:   Union[str, Any]      =				ConfigTester(self			,  config_class=lowercase			,  has_text_modality=lowercase			,  hidden_size=37  )







			def 			__lowerCAmelCase				(			self			: str  ):





								'''simple docstring'''



								self.config_tester.run_common_tests()







			@unittest.skip(reason="AST does not use inputs_embeds"  )
			def 			__lowerCAmelCase				(			self			: List[str]  ):





								'''simple docstring'''



								pass







			def 			__lowerCAmelCase				(			self			: Dict  ):





								'''simple docstring'''



								UpperCAmelCase      ,							UpperCAmelCase			:   str      =				self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
													UpperCAmelCase			:   Dict      =				model_class(lowercase  )
													self.assertIsInstance(model.get_input_embeddings()			,  (nn.Module)  )
													UpperCAmelCase			:   List[Any]      =				model.get_output_embeddings()
													self.assertTrue(x is None or isinstance(lowercase			,  nn.Linear  )  )







			def 			__lowerCAmelCase				(			self			: List[Any]  ):





								'''simple docstring'''



								UpperCAmelCase      ,							UpperCAmelCase			:   List[str]      =				self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
													UpperCAmelCase			:   Dict      =				model_class(lowercase  )
													UpperCAmelCase			:   Any      =				inspect.signature(model.forward  )
													# signature.parameters is an OrderedDict => so arg_names order is deterministic
													UpperCAmelCase			:   List[str]      =				[*signature.parameters.keys()]

													UpperCAmelCase			:   List[str]      =				["input_values"]
													self.assertListEqual(arg_names[:1]			,  lowercase  )







			def 			__lowerCAmelCase				(			self			: Optional[int]  ):





								'''simple docstring'''



								UpperCAmelCase			:   List[str]      =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*lowercase  )







			@slow
			def 			__lowerCAmelCase				(			self			: str  ):





								'''simple docstring'''



								for model_name in AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													UpperCAmelCase			:   Dict      =				ASTModel.from_pretrained(lowercase  )
													self.assertIsNotNone(lowercase  )



def   lowercase_	(    ):




					'''simple docstring'''






					UpperCAmelCase			:   List[str]      =				hf_hub_download(
					    repo_id="nielsr/audio-spectogram-transformer-checkpoint"							,      filename="sample_audio.flac"							,      repo_type="dataset"	)

					UpperCAmelCase      ,							UpperCAmelCase			:   str      =				torchaudio.load(_lowercase	)

					return audio, sampling_rate







@require_torch
@require_torchaudio
class       snake_case__  ( unittest.TestCase     ):







			@cached_property
			def 			__lowerCAmelCase				(			self			: List[Any]  ):





								'''simple docstring'''



								return (
								    ASTFeatureExtractor.from_pretrained("MIT/ast-finetuned-audioset-10-10-0.4593"  )
								    if is_torchaudio_available()
								    else None
								)







			@slow
			def 			__lowerCAmelCase				(			self			: Union[str, Any]  ):





								'''simple docstring'''



								UpperCAmelCase			:   Union[str, Any]      =				self.default_feature_extractor
								UpperCAmelCase			:   Union[str, Any]      =				ASTForAudioClassification.from_pretrained("MIT/ast-finetuned-audioset-10-10-0.4593"  ).to(lowercase  )

								UpperCAmelCase			:   Any      =				self.default_feature_extractor
								UpperCAmelCase      ,							UpperCAmelCase			:   Optional[int]      =				prepare_audio()
								UpperCAmelCase			:   str      =				audio.squeeze().numpy()
								UpperCAmelCase			:   List[Any]      =				feature_extractor(lowercase			,  sampling_rate=lowercase			,  return_tensors="pt"  ).to(lowercase  )

								# forward pass
								with torch.no_grad():
													UpperCAmelCase			:   Dict      =				model(**lowercase  )

								# verify the logits
								UpperCAmelCase			:   Dict      =				torch.Size((1, 5_27)  )
								self.assertEqual(outputs.logits.shape			,  lowercase  )

								UpperCAmelCase			:   Optional[Any]      =				torch.tensor([-0.8_7_6_0, -7.0_0_4_2, -8.6_6_0_2]  ).to(lowercase  )

								self.assertTrue(torch.allclose(outputs.logits[0, :3]			,  lowercase			,  atol=1E-4  )  )


