
'''simple docstring'''





from __future__ import annotations

import inspect
import unittest

import numpy as np

from transformers import ResNetConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
      import tensorflow as tf

      from transformers import TFResNetForImageClassification, TFResNetModel
      from transformers.models.resnet.modeling_tf_resnet import TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor






class 							UpperCAmelCase_							:

 '''simple docstring'''







 def __init__(					self		:  Optional[int]			,				snake_case__		:  Optional[int]			,				snake_case__		:  Union[str, Any]=3			,				snake_case__		:  Optional[int]=32			,				snake_case__		:  Union[str, Any]=3			,				snake_case__		:  Any=10			,				snake_case__		:  str=[10, 20, 30, 40]			,				snake_case__		:  Optional[int]=[1, 1, 2, 1]			,				snake_case__		:  Union[str, Any]=True			,				snake_case__		:  Dict=True			,				snake_case__		:  str="relu"			,				snake_case__		:  Optional[Any]=3			,				snake_case__		:  Optional[int]=None			,				):



   '''simple docstring'''




   UpperCAmelCase__      :					Optional[int]				       =							parent
   UpperCAmelCase__      :					Union[str, Any]				       =							batch_size
   UpperCAmelCase__      :					Optional[int]				       =							image_size
   UpperCAmelCase__      :					Tuple				       =							num_channels
   UpperCAmelCase__      :					Optional[int]				       =							embeddings_size
   UpperCAmelCase__      :					Any				       =							hidden_sizes
   UpperCAmelCase__      :					Any				       =							depths
   UpperCAmelCase__      :					List[Any]				       =							is_training
   UpperCAmelCase__      :					List[str]				       =							use_labels
   UpperCAmelCase__      :					Optional[int]				       =							hidden_act
   UpperCAmelCase__      :					Dict				       =							num_labels
   UpperCAmelCase__      :					Any				       =							scope
   UpperCAmelCase__      :					Union[str, Any]				       =							len(snake_case__ )







 def 							UpperCamelCase  (					self		:  List[str] ):



   '''simple docstring'''




   UpperCAmelCase__      :					Union[str, Any]				       =							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

   UpperCAmelCase__      :					List[Any]				       =							None
   if self.use_labels:
     UpperCAmelCase__      :					Tuple				       =							ids_tensor([self.batch_size]			,				self.num_labels )

   UpperCAmelCase__      :					Optional[Any]				       =							self.get_config()

   return config, pixel_values, labels







 def 							UpperCamelCase  (					self		:  str ):



   '''simple docstring'''




   return ResNetConfig(
       num_channels=self.num_channels			,				embeddings_size=self.embeddings_size			,				hidden_sizes=self.hidden_sizes			,				depths=self.depths			,				hidden_act=self.hidden_act			,				num_labels=self.num_labels			,				image_size=self.image_size			,				)







 def 							UpperCamelCase  (					self		:  int			,				snake_case__		:  Tuple			,				snake_case__		:  Tuple			,				snake_case__		:  Optional[Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					List[str]				       =							TFResNetModel(config=snake_case__ )
   UpperCAmelCase__      :					Tuple				       =							model(snake_case__ )
   # expected last hidden states: B, C, H // 32, W // 32
   self.parent.assertEqual(
       result.last_hidden_state.shape			,				(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)			,				)







 def 							UpperCamelCase  (					self		:  Optional[Any]			,				snake_case__		:  str			,				snake_case__		:  Tuple			,				snake_case__		:  int ):



   '''simple docstring'''




   UpperCAmelCase__      :					int				       =							self.num_labels
   UpperCAmelCase__      :					Optional[int]				       =							TFResNetForImageClassification(snake_case__ )
   UpperCAmelCase__      :					Any				       =							model(snake_case__			,				labels=snake_case__ )
   self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.num_labels) )







 def 							UpperCamelCase  (					self		:  List[Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					List[Any]				       =							self.prepare_config_and_inputs()
   UpperCAmelCase__       ,			UpperCAmelCase__       ,			UpperCAmelCase__      :					str				       =							config_and_inputs
   UpperCAmelCase__      :					List[str]				       =							{"pixel_values": pixel_values}
   return config, inputs_dict






@require_tf
class 							UpperCAmelCase_							(    A					,				A					,				unittest.TestCase				):

 '''simple docstring'''
 lowercase_					:    Tuple				=							(TFResNetModel, TFResNetForImageClassification) if is_tf_available() else ()
 lowercase_					:    List[Any]				=							(
     {"feature-extraction": TFResNetModel, "image-classification": TFResNetForImageClassification}
     if is_tf_available()
     else {}
 )

 lowercase_					:    int				=							False
 lowercase_					:    List[str]				=							False
 lowercase_					:    Tuple				=							False
 lowercase_					:    str				=							False
 lowercase_					:    List[str]				=							False







 def 							UpperCamelCase  (					self		:  Optional[int] ):



   '''simple docstring'''




   UpperCAmelCase__      :					int				       =							TFResNetModelTester(self )
   UpperCAmelCase__      :					Union[str, Any]				       =							ConfigTester(self			,				config_class=snake_case__			,				has_text_modality=snake_case__ )







 def 							UpperCamelCase  (					self		:  Optional[int] ):



   '''simple docstring'''




   self.create_and_test_config_common_properties()
   self.config_tester.create_and_test_config_to_json_string()
   self.config_tester.create_and_test_config_to_json_file()
   self.config_tester.create_and_test_config_from_and_save_pretrained()
   self.config_tester.create_and_test_config_with_num_labels()
   self.config_tester.check_config_can_be_init_without_params()
   self.config_tester.check_config_arguments_init()







 def 							UpperCamelCase  (					self		:  Tuple ):



   '''simple docstring'''




   return







 @unittest.skip(reason="ResNet does not use inputs_embeds" )
 def 							UpperCamelCase  (					self		:  str ):



   '''simple docstring'''




   pass







 @unittest.skip(reason="ResNet does not support input and output embeddings" )
 def 							UpperCamelCase  (					self		:  Dict ):



   '''simple docstring'''




   pass







 def 							UpperCamelCase  (					self		:  Any ):



   '''simple docstring'''




   UpperCAmelCase__       ,			UpperCAmelCase__      :					int				       =							self.model_tester.prepare_config_and_inputs_for_common()

   for model_class in self.all_model_classes:
     UpperCAmelCase__      :					Optional[int]				       =							model_class(snake_case__ )
     UpperCAmelCase__      :					Optional[Any]				       =							inspect.signature(model.call )
     # signature.parameters is an OrderedDict => so arg_names order is deterministic
     UpperCAmelCase__      :					Optional[int]				       =							[*signature.parameters.keys()]

     UpperCAmelCase__      :					str				       =							["pixel_values"]
     self.assertListEqual(arg_names[:1]			,				snake_case__ )







 def 							UpperCamelCase  (					self		:  Union[str, Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					Optional[Any]				       =							self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*snake_case__ )







 def 							UpperCamelCase  (					self		:  List[Any] ):



   '''simple docstring'''




   def check_hidden_states_output(snake_case__		:  Union[str, Any]			,				snake_case__		:  Dict			,				snake_case__		:  List[str] ):
     UpperCAmelCase__      :					int				       =							model_class(snake_case__ )
     UpperCAmelCase__      :					Any				       =							model(**self._prepare_for_class(snake_case__			,				snake_case__ ) )

     UpperCAmelCase__      :					Any				       =							outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

     UpperCAmelCase__      :					Any				       =							self.model_tester.num_stages
     self.assertEqual(len(snake_case__ )			,				expected_num_stages + 1 )

     # ResNet's feature maps are of shape (batch_size, num_channels, height, width)
     self.assertListEqual(
         list(hidden_states[0].shape[-2:] )			,				[self.model_tester.image_size // 4, self.model_tester.image_size // 4]			,				)

   UpperCAmelCase__       ,			UpperCAmelCase__      :					List[Any]				       =							self.model_tester.prepare_config_and_inputs_for_common()
   UpperCAmelCase__      :					Optional[Any]				       =							["basic", "bottleneck"]
   for model_class in self.all_model_classes:
     for layer_type in layers_type:
       UpperCAmelCase__      :					Optional[int]				       =							layer_type
       UpperCAmelCase__      :					List[str]				       =							True
       check_hidden_states_output(snake_case__			,				snake_case__			,				snake_case__ )

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

       check_hidden_states_output(snake_case__			,				snake_case__			,				snake_case__ )







 def 							UpperCamelCase  (					self		:  List[Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					Optional[Any]				       =							self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_image_classification(*snake_case__ )







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



   '''simple docstring'''




   for model_name in TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     UpperCAmelCase__      :					Union[str, Any]				       =							TFResNetModel.from_pretrained(snake_case__ )
     self.assertIsNotNone(snake_case__ )







def snake_case_     (					):
  UpperCAmelCase__      :					List[Any]				       =							Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
  return image






@require_tf
@require_vision
class 							UpperCAmelCase_							(    unittest.TestCase				):

 '''simple docstring'''







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



   '''simple docstring'''




   return (
       AutoImageProcessor.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0] )
       if is_vision_available()
       else None
   )







 @slow
 def 							UpperCamelCase  (					self		:  List[Any] ):



   '''simple docstring'''




   UpperCAmelCase__      :					List[Any]				       =							TFResNetForImageClassification.from_pretrained(TF_RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0] )

   UpperCAmelCase__      :					str				       =							self.default_image_processor
   UpperCAmelCase__      :					List[str]				       =							prepare_img()
   UpperCAmelCase__      :					Any				       =							image_processor(images=snake_case__			,				return_tensors="tf" )

   # forward pass
   UpperCAmelCase__      :					List[str]				       =							model(**snake_case__ )

   # verify the logits
   UpperCAmelCase__      :					Dict				       =							tf.TensorShape((1, 10_00) )
   self.assertEqual(outputs.logits.shape			,				snake_case__ )

   UpperCAmelCase__      :					str				       =							tf.constant([-11.1069, -9.7877, -8.3777] )

   self.assertTrue(np.allclose(outputs.logits[0, :3].numpy()			,				snake_case__			,				atol=1e-4 ) )





'''simple docstring'''





import math

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







def snake_case_     (					lowercase__ = 3		):
  if isinstance(lowercase__   ,       lowercase__		):
    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(lowercase__		) != number_of_qubits:
    raise ValueError("number of qubits must be exact integer."		)
  if number_of_qubits > 1_0:
    raise ValueError("number of qubits too large to simulate(>10)."		)

  UpperCAmelCase__      :					Optional[int]				       =							QuantumRegister(lowercase__   ,       "qr"		)
  UpperCAmelCase__      :					List[Any]				       =							ClassicalRegister(lowercase__   ,       "cr"		)

  UpperCAmelCase__      :					List[str]				       =							QuantumCircuit(lowercase__   ,       lowercase__		)

  UpperCAmelCase__      :					Union[str, Any]				       =							number_of_qubits

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

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

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

  return job.result().get_counts(lowercase__		)


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



