
"""simple docstring"""


from typing import List, Optional, Union

import numpy as np

from ....audio_utils import mel_filter_bank, optimal_fft_length, spectrogram, window_function
from ....feature_extraction_sequence_utils import SequenceFeatureExtractor
from ....feature_extraction_utils import BatchFeature
from ....file_utils import PaddingStrategy, TensorType
from ....utils import logging


A_    							=					logging.get_logger(__name__)




class  __lowerCamelCase  ( lowerCAmelCase			):
				a__:      Any          =    ['input_features', 'attention_mask']




				def __init__(				self							,						UpperCAmelCase=80							,						UpperCAmelCase=1_6000							,						UpperCAmelCase=0.0							,						UpperCAmelCase=10							,						UpperCAmelCase=25							,						UpperCAmelCase="hamming_window"							,						UpperCAmelCase=3_2_7_6_8.0							,						UpperCAmelCase=0.9_7							,						UpperCAmelCase=1.0							,						UpperCAmelCase=True							,						UpperCAmelCase=True							,						UpperCAmelCase=False							,						**UpperCAmelCase							,						):
							super().__init__(feature_size=UpperCAmelCase							,						sampling_rate=UpperCAmelCase							,						padding_value=UpperCAmelCase							,						**UpperCAmelCase   )

							lowerCamelCase_					=  feature_size
							lowerCamelCase_					=  sampling_rate
							lowerCamelCase_					=  padding_value
							lowerCamelCase_					=  hop_length
							lowerCamelCase_					=  win_length
							lowerCamelCase_					=  frame_signal_scale
							lowerCamelCase_					=  preemphasis_coeff
							lowerCamelCase_					=  mel_floor
							lowerCamelCase_					=  normalize_means
							lowerCamelCase_					=  normalize_vars
							lowerCamelCase_					=  win_function
							lowerCamelCase_					=  return_attention_mask

							lowerCamelCase_					=  win_length * sampling_rate // 1000
							lowerCamelCase_					=  hop_length * sampling_rate // 1000

							lowerCamelCase_					=  optimal_fft_length(self.sample_size   )
							lowerCamelCase_					=  (self.n_fft // 2) + 1




				def        UpperCAmelCase__						(				self							,						UpperCAmelCase   ):
							if self.win_function == "hamming_window":
										lowerCamelCase_					=  window_function(window_length=self.sample_size							,						name=self.win_function							,						periodic=UpperCAmelCase   )
							else:
										lowerCamelCase_					=  window_function(window_length=self.sample_size							,						name=self.win_function   )

							lowerCamelCase_					=  mel_filter_bank(
							    num_frequency_bins=self.n_freqs							,						num_mel_filters=self.feature_size							,						min_frequency=0.0							,						max_frequency=self.sampling_rate / 2.0							,						sampling_rate=self.sampling_rate							,						)

							lowerCamelCase_					=  spectrogram(
							    one_waveform * self.frame_signal_scale							,						window=UpperCAmelCase							,						frame_length=self.sample_size							,						hop_length=self.sample_stride							,						fft_length=self.n_fft							,						center=UpperCAmelCase							,						preemphasis=self.preemphasis_coeff							,						mel_filters=UpperCAmelCase							,						mel_floor=self.mel_floor							,						log_mel='''log'''							,						)
							return msfc_features.T




				def        UpperCAmelCase__						(				self							,						UpperCAmelCase							,						UpperCAmelCase							,						UpperCAmelCase   ):
							# make sure we normalize float32 arrays
							if self.normalize_means:
										lowerCamelCase_					=  x[:input_length].mean(axis=0   )
										lowerCamelCase_					=  np.subtract(UpperCAmelCase							,						UpperCAmelCase   )
							if self.normalize_vars:
										lowerCamelCase_					=  x[:input_length].std(axis=0   )
										lowerCamelCase_					=  np.divide(UpperCAmelCase							,						UpperCAmelCase   )

							if input_length < x.shape[0]:
										lowerCamelCase_					=  padding_value

							# make sure array is in float32
							lowerCamelCase_					=  x.astype(np.floataa   )

							return x




				def        UpperCAmelCase__						(				self							,						UpperCAmelCase							,						UpperCAmelCase = None   ):
							lowerCamelCase_					=  attention_mask.sum(-1   ) if attention_mask is not None else [x.shape[0] for x in input_features]
							return [self._normalize_one(UpperCAmelCase							,						UpperCAmelCase							,						self.padding_value   ) for x, n in zip(UpperCAmelCase							,						UpperCAmelCase   )]





				def __call__(				self							,						UpperCAmelCase							,						UpperCAmelCase = False							,						UpperCAmelCase = None							,						UpperCAmelCase = False							,						UpperCAmelCase = None							,						UpperCAmelCase = None							,						UpperCAmelCase = None							,						UpperCAmelCase = None							,						**UpperCAmelCase							,						):

							if sampling_rate is not None:
										if sampling_rate != self.sampling_rate:
													raise ValueError(
													    f"The model corresponding to this feature extractor: {self} was trained using a sampling rate of"
													    f" {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled with"
													    f" {self.sampling_rate} and not {sampling_rate}."   )
							else:
										logger.warning(
										    '''It is strongly recommended to pass the ``sampling_rate`` argument to this function. '''
										    '''Failing to do so can result in silent errors that might be hard to debug.'''   )

							lowerCamelCase_					=  isinstance(UpperCAmelCase							,						np.ndarray   ) and len(raw_speech.shape   ) > 1
							if is_batched_numpy and len(raw_speech.shape   ) > 2:
										raise ValueError(f"Only mono-channel audio is supported for input to {self}"   )
							lowerCamelCase_					=  is_batched_numpy or (
							    isinstance(UpperCAmelCase							,						(list, tuple)   ) and (isinstance(raw_speech[0]							,						(np.ndarray, tuple, list)   ))
							)

							if is_batched:
										lowerCamelCase_					=  [np.asarray(UpperCAmelCase							,						dtype=np.floataa   ) for speech in raw_speech]
							elif not is_batched and not isinstance(UpperCAmelCase							,						np.ndarray   ):
										lowerCamelCase_					=  np.asarray(UpperCAmelCase							,						dtype=np.floataa   )
							elif isinstance(UpperCAmelCase							,						np.ndarray   ) and raw_speech.dtype is np.dtype(np.floataa   ):
										lowerCamelCase_					=  raw_speech.astype(np.floataa   )

							# always return batch
							if not is_batched:
										lowerCamelCase_					=  [raw_speech]

							# extract fbank features
							lowerCamelCase_					=  [self._extract_mfsc_features(UpperCAmelCase   ) for one_waveform in raw_speech]

							# convert into correct format for padding
							lowerCamelCase_					=  BatchFeature({'''input_features''': features}   )

							lowerCamelCase_					=  self.pad(
							    UpperCAmelCase							,						padding=UpperCAmelCase							,						max_length=UpperCAmelCase							,						truncation=UpperCAmelCase							,						pad_to_multiple_of=UpperCAmelCase							,						return_attention_mask=UpperCAmelCase							,						**UpperCAmelCase							,						)
							# make sure list is in array format
							lowerCamelCase_					=  padded_inputs.get('''input_features'''   )
							if isinstance(input_features[0]							,						UpperCAmelCase   ):
										lowerCamelCase_					=  [np.asarray(UpperCAmelCase							,						dtype=np.floataa   ) for feature in input_features]

							lowerCamelCase_					=  padded_inputs.get('''attention_mask'''   )
							if attention_mask is not None:
										lowerCamelCase_					=  [np.asarray(UpperCAmelCase							,						dtype=np.intaa   ) for array in attention_mask]

							if self.normalize_means or self.normalize_vars:
										lowerCamelCase_					=  (
										    np.array(UpperCAmelCase							,						dtype=np.intaa   )
										    if self._get_padding_strategies(UpperCAmelCase							,						max_length=UpperCAmelCase   ) is not PaddingStrategy.DO_NOT_PAD
										    and padding
										    else None
										)
										lowerCamelCase_					=  self.normalize(
										    padded_inputs['''input_features''']							,						attention_mask=UpperCAmelCase   )

							if return_tensors is not None:
										lowerCamelCase_					=  padded_inputs.convert_to_tensors(UpperCAmelCase   )

							return padded_inputs





import qiskit


def      UpperCamelCase   (       __lowerCamelCase	:					int							,   __lowerCamelCase	:					int       ):
       snake_case			:  int     							= qiskit.Aer.get_backend("aer_simulator"       )

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

       # 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
       snake_case			:  Dict     							= qiskit.execute(__lowerCamelCase							,   __lowerCamelCase							,   shots=1000       )

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


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





