





import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_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 transformers import MobileNetVaForImageClassification, MobileNetVaModel
      from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import MobileNetVaImageProcessor







class    __snake_case	(							_a      ):





       '''simple docstring'''







       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         __snake_case:						Any			  =						self.config_class(**self.inputs_dict		)
         self.parent.assertTrue(hasattr(_a							,    """tf_padding"""		)		)
         self.parent.assertTrue(hasattr(_a							,    """depth_multiplier"""		)		)







class    __snake_case	:





       '''simple docstring'''







       def __init__(  self			:   Any							,    A			:   List[str]							,    A			:   Optional[Any]=13							,    A			:   Dict=3							,    A			:   str=32							,    A			:   List[Any]=0.25							,    A			:   List[Any]=8							,    A			:   Optional[Any]=True							,    A			:   Optional[int]=1_024							,    A			:   int=32							,    A			:   Optional[Any]="relu6"							,    A			:   Tuple=0.1							,    A			:   Any=0.02							,    A			:   Any=True							,    A			:   Union[str, Any]=True							,    A			:   List[str]=10							,    A			:   Dict=None							,    ):
         __snake_case:						Optional[int]			  =						parent
         __snake_case:						List[str]			  =						batch_size
         __snake_case:						List[Any]			  =						num_channels
         __snake_case:						List[Any]			  =						image_size
         __snake_case:						Dict			  =						depth_multiplier
         __snake_case:						Optional[int]			  =						min_depth
         __snake_case:						str			  =						tf_padding
         __snake_case:						str			  =						int(last_hidden_size * depth_multiplier		)
         __snake_case:						Any			  =						output_stride
         __snake_case:						str			  =						hidden_act
         __snake_case:						Optional[int]			  =						classifier_dropout_prob
         __snake_case:						Any			  =						use_labels
         __snake_case:						Any			  =						is_training
         __snake_case:						str			  =						num_labels
         __snake_case:						Dict			  =						initializer_range
         __snake_case:						Optional[int]			  =						scope




       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         __snake_case:						int			  =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

         __snake_case:						int			  =						None
         __snake_case:						Tuple			  =						None
         if self.use_labels:
           __snake_case:						Any			  =						ids_tensor([self.batch_size]							,    self.num_labels		)
           __snake_case:						Dict			  =						ids_tensor([self.batch_size, self.image_size, self.image_size]							,    self.num_labels		)

         __snake_case:						str			  =						self.get_config()

         return config, pixel_values, labels, pixel_labels




       def 							UpperCAmelCase__			(  self			:   Union[str, Any]		):
         return MobileNetVaConfig(
             num_channels=self.num_channels							,    image_size=self.image_size							,    depth_multiplier=self.depth_multiplier							,    min_depth=self.min_depth							,    tf_padding=self.tf_padding							,    hidden_act=self.hidden_act							,    classifier_dropout_prob=self.classifier_dropout_prob							,    initializer_range=self.initializer_range							,    )




       def 							UpperCAmelCase__			(  self			:   Union[str, Any]							,    A			:   List[str]							,    A			:   Dict							,    A			:   int							,    A			:   Optional[Any]		):
         __snake_case:						Optional[Any]			  =						MobileNetVaModel(config=_a		)
         model.to(_a		)
         model.eval()
         __snake_case:						Union[str, Any]			  =						model(_a		)
         self.parent.assertEqual(
             result.last_hidden_state.shape							,    (
                 self.batch_size,
                 self.last_hidden_size,
                 self.image_size // self.output_stride,
                 self.image_size // self.output_stride,
             )							,    )




       def 							UpperCAmelCase__			(  self			:   str							,    A			:   Optional[Any]							,    A			:   int							,    A			:   str							,    A			:   Optional[int]		):
         __snake_case:						Tuple			  =						self.num_labels
         __snake_case:						str			  =						MobileNetVaForImageClassification(_a		)
         model.to(_a		)
         model.eval()
         __snake_case:						Optional[int]			  =						model(_a							,    labels=_a		)
         self.parent.assertEqual(result.logits.shape							,    (self.batch_size, self.num_labels)		)






       def 							UpperCAmelCase__			(  self			:   List[Any]		):
         __snake_case:						Optional[int]			  =						self.prepare_config_and_inputs()
         __snake_case:						Dict			  =						config_and_inputs
         __snake_case:						Tuple			  =						{"pixel_values": pixel_values}
         return config, inputs_dict







@require_torch
class    __snake_case	(							_a       ,      _a       ,      unittest.TestCase      ):





       '''simple docstring'''







       lowerCAmelCase__						=					(MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
       lowerCAmelCase__						=					(
           {"""feature-extraction""": MobileNetVaModel, """image-classification""": MobileNetVaForImageClassification}
           if is_torch_available()
           else {}
       )

       lowerCAmelCase__						=					False
       lowerCAmelCase__						=					False
       lowerCAmelCase__						=					False
       lowerCAmelCase__						=					False




       def 							UpperCAmelCase__			(  self			:   List[Any]		):
         __snake_case:						Optional[int]			  =						MobileNetVaModelTester(self		)
         __snake_case:						str			  =						MobileNetVaConfigTester(self							,    config_class=_a							,    has_text_modality=_a		)




       def 							UpperCAmelCase__			(  self			:   Dict		):
         self.config_tester.run_common_tests()




       @unittest.skip(reason="""MobileNetV1 does not use inputs_embeds"""		)
       def 							UpperCAmelCase__			(  self			:   Dict		):
         pass




       @unittest.skip(reason="""MobileNetV1 does not support input and output embeddings"""		)
       def 							UpperCAmelCase__			(  self			:   List[Any]		):
         pass




       @unittest.skip(reason="""MobileNetV1 does not output attentions"""		)
       def 							UpperCAmelCase__			(  self			:   Optional[Any]		):
         pass




       def 							UpperCAmelCase__			(  self			:   List[str]		):
         __snake_case:						Union[str, Any]			  =						self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           __snake_case:						Optional[Any]			  =						model_class(_a		)
           __snake_case:						Tuple			  =						inspect.signature(model.forward		)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           __snake_case:						Any			  =						[*signature.parameters.keys()]

           __snake_case:						str			  =						["pixel_values"]
           self.assertListEqual(arg_names[:1]							,    _a		)




       def 							UpperCAmelCase__			(  self			:   Tuple		):
         __snake_case:						Optional[Any]			  =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_a		)




       def 							UpperCAmelCase__			(  self			:   Optional[Any]		):
         def check_hidden_states_output(A			:   List[str]							,    A			:   Optional[Any]							,    A			:   Any		):
           __snake_case:						List[Any]			  =						model_class(_a		)
           model.to(_a		)
           model.eval()

           with torch.no_grad():
             __snake_case:						str			  =						model(**self._prepare_for_class(_a							,    _a		)		)

           __snake_case:						Dict			  =						outputs.hidden_states

           __snake_case:						List[Any]			  =						26
           self.assertEqual(len(_a		)							,    _a		)

         __snake_case:						Dict			  =						self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           __snake_case:						Optional[Any]			  =						True
           check_hidden_states_output(_a							,    _a							,    _a		)

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           __snake_case:						Optional[Any]			  =						True

           check_hidden_states_output(_a							,    _a							,    _a		)




       def 							UpperCAmelCase__			(  self			:   Any		):
         __snake_case:						int			  =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_image_classification(*_a		)






       @slow
       def 							UpperCAmelCase__			(  self			:   Optional[int]		):
         for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           __snake_case:						Optional[int]			  =						MobileNetVaModel.from_pretrained(_a		)
           self.assertIsNotNone(_a		)







def       A__							(   )       ->   str:
  __snake_case:						Optional[Any]			  =						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""")
  return image







@require_torch
@require_vision
class    __snake_case	(							unittest.TestCase      ):





       '''simple docstring'''







       @cached_property
       def 							UpperCAmelCase__			(  self			:   int		):
         return (
             MobileNetVaImageProcessor.from_pretrained("""google/mobilenet_v1_1.0_224"""		) if is_vision_available() else None
         )






       @slow
       def 							UpperCAmelCase__			(  self			:   int		):
         __snake_case:						Any			  =						MobileNetVaForImageClassification.from_pretrained("""google/mobilenet_v1_1.0_224"""		).to(_a		)

         __snake_case:						Optional[Any]			  =						self.default_image_processor
         __snake_case:						List[str]			  =						prepare_img()
         __snake_case:						Optional[int]			  =						image_processor(images=_a							,    return_tensors="""pt"""		).to(_a		)

         # forward pass
         with torch.no_grad():
           __snake_case:						Optional[int]			  =						model(**_a		)

         # verify the logits
         __snake_case:						Tuple			  =						torch.Size((1, 1_001)		)
         self.assertEqual(outputs.logits.shape							,    _a		)

         __snake_case:						int			  =						torch.tensor([-4.1739, -1.1233, 3.1205]		).to(_a		)

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








import math

import numpy as np
import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute







def       A__							(   SCREAMING_SNAKE_CASE__ = 3)       ->   qiskit.result.counts.Counts:
  if isinstance(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__):
    raise TypeError("""number of qubits must be a integer.""")
  if number_of_qubits <= 0:
    raise ValueError("""number of qubits must be > 0.""")
  if math.floor(SCREAMING_SNAKE_CASE__) != number_of_qubits:
    raise ValueError("""number of qubits must be exact integer.""")
  if number_of_qubits > 10:
    raise ValueError("""number of qubits too large to simulate(>10).""")

  __snake_case:						int			  =						QuantumRegister(SCREAMING_SNAKE_CASE__ , """qr""")
  __snake_case:						List[str]			  =						ClassicalRegister(SCREAMING_SNAKE_CASE__ , """cr""")

  __snake_case:						Optional[Any]			  =						QuantumCircuit(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)

  __snake_case:						Tuple			  =						number_of_qubits

  for i in range(SCREAMING_SNAKE_CASE__):
    quantum_circuit.h(number_of_qubits - i - 1)
    counter -= 1
    for j in range(SCREAMING_SNAKE_CASE__):
      quantum_circuit.cp(np.pi / 2 ** (counter - j) , SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)

  for k in range(number_of_qubits // 2):
    quantum_circuit.swap(SCREAMING_SNAKE_CASE__ , number_of_qubits - k - 1)

  # measure all the qubits
  quantum_circuit.measure(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)
  # simulate with 10000 shots
  __snake_case:						Union[str, Any]			  =						Aer.get_backend("""qasm_simulator""")
  __snake_case:						Optional[Any]			  =						execute(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__ , shots=1_0000)

  return job.result().get_counts(SCREAMING_SNAKE_CASE__)


if __name__ == "__main__":
      print(
          f'Total count for quantum fourier transform state is: \
    {quantum_fourier_transform(3)}'
      )






