


import json
import os
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from requests.exceptions import HTTPError

from transformers.utils import (
    CONFIG_NAME,
    FLAX_WEIGHTS_NAME,
    TF2_WEIGHTS_NAME,
    TRANSFORMERS_CACHE,
    WEIGHTS_NAME,
    cached_file,
    get_file_from_repo,
    has_file,
)


snake_case							:       Tuple										=	'''hf-internal-testing/tiny-random-bert'''
snake_case							:       List[Any]										=	os.path.join(TRANSFORMERS_CACHE, '''models--hf-internal-testing--tiny-random-bert''')
snake_case							:       Tuple										=	'''9b8c223d42b2188cb49d29af482996f9d0f3e5a6'''







class 						_snake_case    ( unittest.TestCase				):




 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       a		:Optional[int]									=			cached_file(_lowerCamelCase   ,    _lowerCamelCase       )
       # Should have downloaded the file in here
       self.assertTrue(os.path.isdir(_lowerCamelCase       )       )
       # Cache should contain at least those three subfolders:
       for subfolder in ["blobs", "refs", "snapshots"]:
             self.assertTrue(os.path.isdir(os.path.join(_lowerCamelCase   ,    _lowerCamelCase       )       )       )
       with open(os.path.join(_lowerCamelCase   ,    '''refs'''   ,    '''main'''       )       ) as f:
             a		:List[str]									=			f.read()
       self.assertEqual(_lowerCamelCase   ,    os.path.join(_lowerCamelCase   ,    '''snapshots'''   ,    _lowerCamelCase   ,    _lowerCamelCase       )       )
       self.assertTrue(os.path.isfile(_lowerCamelCase       )       )

       # File is cached at the same place the second time.
       a		:Union[str, Any]									=			cached_file(_lowerCamelCase   ,    _lowerCamelCase       )
       self.assertEqual(_lowerCamelCase   ,    _lowerCamelCase       )

       # Using a specific revision to test the full commit hash.
       a		:Dict									=			cached_file(_lowerCamelCase   ,    _lowerCamelCase   ,    revision='''9b8c223'''       )
       self.assertEqual(_lowerCamelCase   ,    os.path.join(_lowerCamelCase   ,    '''snapshots'''   ,    _lowerCamelCase   ,    _lowerCamelCase       )       )




 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       with self.assertRaisesRegex(_lowerCamelCase   ,    '''is not a valid model identifier'''       ):
             a		:Tuple									=			cached_file('''tiny-random-bert'''   ,    _lowerCamelCase       )

       with self.assertRaisesRegex(_lowerCamelCase   ,    '''is not a valid git identifier'''       ):
             a		:Dict									=			cached_file(_lowerCamelCase   ,    _lowerCamelCase   ,    revision='''aaaa'''       )

       with self.assertRaisesRegex(_lowerCamelCase   ,    '''does not appear to have a file named'''       ):
             a		:Tuple									=			cached_file(_lowerCamelCase   ,    '''conf'''       )




 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       with self.assertRaisesRegex(_lowerCamelCase   ,    '''does not appear to have a file named'''       ):
             a		:Optional[Any]									=			cached_file(_lowerCamelCase   ,    '''conf'''       )

       with open(os.path.join(_lowerCamelCase   ,    '''refs'''   ,    '''main'''       )       ) as f:
             a		:List[str]									=			f.read()
       self.assertTrue(os.path.isfile(os.path.join(_lowerCamelCase   ,    '''.no_exist'''   ,    _lowerCamelCase   ,    '''conf'''       )       )       )

       a		:Optional[int]									=			cached_file(_lowerCamelCase   ,    '''conf'''   ,    _raise_exceptions_for_missing_entries=_lowerCamelCase       )
       self.assertIsNone(_lowerCamelCase       )

       a		:Tuple									=			cached_file(_lowerCamelCase   ,    '''conf'''   ,    local_files_only=_lowerCamelCase   ,    _raise_exceptions_for_missing_entries=_lowerCamelCase       )
       self.assertIsNone(_lowerCamelCase       )

       a		:Tuple									=			mock.Mock()
       a		:Optional[Any]									=			500
       a		:Any									=			{}
       a		:List[Any]									=			HTTPError
       a		:Optional[Any]									=			{}

       # Under the mock environment we get a 500 error when trying to reach the tokenizer.
       with mock.patch('''requests.Session.request'''   ,    return_value=_lowerCamelCase       ) as mock_head:
             a		:Union[str, Any]									=			cached_file(_lowerCamelCase   ,    '''conf'''   ,    _raise_exceptions_for_connection_errors=_lowerCamelCase       )
             self.assertIsNone(_lowerCamelCase       )
             # This check we did call the fake head request
             mock_head.assert_called()




 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       self.assertTrue(has_file('''hf-internal-testing/tiny-bert-pt-only'''   ,    _lowerCamelCase       )       )
       self.assertFalse(has_file('''hf-internal-testing/tiny-bert-pt-only'''   ,    _lowerCamelCase       )       )
       self.assertFalse(has_file('''hf-internal-testing/tiny-bert-pt-only'''   ,    _lowerCamelCase       )       )




 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       # `get_file_from_repo` returns None if the file does not exist
       self.assertIsNone(get_file_from_repo('''bert-base-cased'''   ,    '''ahah.txt'''       )       )

       # The function raises if the repository does not exist.
       with self.assertRaisesRegex(_lowerCamelCase   ,    '''is not a valid model identifier'''       ):
             get_file_from_repo('''bert-base-case'''   ,    _lowerCamelCase       )

       # The function raises if the revision does not exist.
       with self.assertRaisesRegex(_lowerCamelCase   ,    '''is not a valid git identifier'''       ):
             get_file_from_repo('''bert-base-cased'''   ,    _lowerCamelCase   ,    revision='''ahaha'''       )

       a		:int									=			get_file_from_repo('''bert-base-cased'''   ,    _lowerCamelCase       )
       # The name is the cached name which is not very easy to test, so instead we load the content.
       a		:int									=			json.loads(open(_lowerCamelCase   ,    '''r'''       ).read()       )
       self.assertEqual(config['''hidden_size''']   ,    768       )




 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       with tempfile.TemporaryDirectory() as tmp_dir:
             a		:Union[str, Any]									=			Path(_lowerCamelCase       ) / '''a.txt'''
             filename.touch()
             self.assertEqual(get_file_from_repo(_lowerCamelCase   ,    '''a.txt'''       )   ,    str(_lowerCamelCase       )       )

             self.assertIsNone(get_file_from_repo(_lowerCamelCase   ,    '''b.txt'''       )       )









import qiskit
def 							__lowerCamelCase		(					UpperCAmelCase_		:						int					,    UpperCAmelCase_		:						int		):




      """simple docstring"""





      a		:Tuple									=			qiskit.Aer.get_backend('''aer_simulator'''		)

      # Create a Quantum Circuit acting on the q register
      a		:str									=			qiskit.QuantumCircuit(UpperCAmelCase_					,    UpperCAmelCase_		)

      # 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
      a		:Optional[Any]									=			qiskit.execute(UpperCAmelCase_					,    UpperCAmelCase_					,    shots=1000		)

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


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





