





import json
import logging
import os
import sys
from time import time
from unittest.mock import patch

from transformers.testing_utils import TestCasePlus, require_torch_tpu


logging.basicConfig(level=logging.DEBUG)

__UpperCAmelCase	:       int    	=							logging.getLogger()







def       A__							(   SCREAMING_SNAKE_CASE__)       ->   Dict:
  __snake_case:						int			  =						{}
  __snake_case:						List[str]			  =						os.path.join(SCREAMING_SNAKE_CASE__ , """all_results.json""")
  if os.path.exists(SCREAMING_SNAKE_CASE__):
    with open(SCREAMING_SNAKE_CASE__ , """r""") as f:
      __snake_case:						List[Any]			  =						json.load(SCREAMING_SNAKE_CASE__)
  else:
    raise ValueError(F'''can\'t find {path}''')
  return results


__UpperCAmelCase	:       int    	=							logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)







@require_torch_tpu
class    __snake_case	(							__lowerCamelCase      ):





       '''simple docstring'''







       def 							UpperCAmelCase__			(  self			:   Union[str, Any]		):
         import xla_spawn

         __snake_case:						Optional[Any]			  =						self.get_auto_remove_tmp_dir()
         __snake_case:						List[Any]			  =						f'''
            ./examples/pytorch/text-classification/run_glue.py
            --num_cores=8
            ./examples/pytorch/text-classification/run_glue.py
            --model_name_or_path distilbert-base-uncased
            --output_dir {tmp_dir}
            --overwrite_output_dir
            --train_file ./tests/fixtures/tests_samples/MRPC/train.csv
            --validation_file ./tests/fixtures/tests_samples/MRPC/dev.csv
            --do_train
            --do_eval
            --debug tpu_metrics_debug
            --per_device_train_batch_size=2
            --per_device_eval_batch_size=1
            --learning_rate=1e-4
            --max_steps=10
            --warmup_steps=2
            --seed=42
            --max_seq_length=128
            '''.split()

         with patch.object(A							,    """argv"""							,    A		):
           __snake_case:						Any			  =						time()
           xla_spawn.main()
           __snake_case:						str			  =						time()

           __snake_case:						str			  =						get_results(A		)
           self.assertGreaterEqual(result["""eval_accuracy"""]							,    0.75		)

           # Assert that the script takes less than 500 seconds to make sure it doesn't hang.
           self.assertLess(end - start							,    500		)






       def 							UpperCAmelCase__			(  self			:   Union[str, Any]		):
         import xla_spawn

         __snake_case:						Optional[int]			  =						"""
            ./tests/test_trainer_tpu.py
            --num_cores=8
            ./tests/test_trainer_tpu.py
            """.split()
         with patch.object(A							,    """argv"""							,    A		):
           xla_spawn.main()













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)}'
      )






