





import argparse
import json

import numpy
import torch

from transformers.models.xlm.tokenization_xlm import VOCAB_FILES_NAMES
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()







def       A__							(   SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__)       ->   Any:
  # Load checkpoint
  __snake_case:						Tuple			  =						torch.load(__SCREAMING_SNAKE_CASE , map_location="""cpu""")

  __snake_case:						int			  =						chkpt["model"]

  # We have the base model one level deeper than the original XLM repository
  __snake_case:						Optional[int]			  =						{}
  for k, v in state_dict.items():
    if "pred_layer" in k:
      __snake_case:						Any			  =						v
    else:
      __snake_case:						List[str]			  =						v

  __snake_case:						Optional[Any]			  =						chkpt["params"]
  __snake_case:						Union[str, Any]			  =						{n: v for n, v in config.items() if not isinstance(__SCREAMING_SNAKE_CASE , (torch.FloatTensor, numpy.ndarray))}

  __snake_case:						Optional[Any]			  =						chkpt["dico_word2id"]
  __snake_case:						Optional[int]			  =						{s + "</w>" if s.find("""@@""") == -1 and i > 13 else s.replace("""@@""" , """"""): i for s, i in vocab.items()}

  # Save pytorch-model
  __snake_case:						Union[str, Any]			  =						pytorch_dump_folder_path + "/" + WEIGHTS_NAME
  __snake_case:						List[Any]			  =						pytorch_dump_folder_path + "/" + CONFIG_NAME
  __snake_case:						Dict			  =						pytorch_dump_folder_path + "/" + VOCAB_FILES_NAMES["vocab_file"]

  print(F'''Save PyTorch model to {pytorch_weights_dump_path}''')
  torch.save(__SCREAMING_SNAKE_CASE , __SCREAMING_SNAKE_CASE)

  print(F'''Save configuration file to {pytorch_config_dump_path}''')
  with open(__SCREAMING_SNAKE_CASE , """w""" , encoding="""utf-8""") as f:
    f.write(json.dumps(__SCREAMING_SNAKE_CASE , indent=2) + """\n""")

  print(F'''Save vocab file to {pytorch_config_dump_path}''')
  with open(__SCREAMING_SNAKE_CASE , """w""" , encoding="""utf-8""") as f:
    f.write(json.dumps(__SCREAMING_SNAKE_CASE , indent=2) + """\n""")


if __name__ == "__main__":
      __UpperCAmelCase	:       Dict    	=							argparse.ArgumentParser()
      # Required parameters
      parser.add_argument(
          "--xlm_checkpoint_path", default=None, type=str, required=True, help="Path the official PyTorch dump."
      )
      parser.add_argument(
          "--pytorch_dump_folder_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
      )
      __UpperCAmelCase	:       List[str]    	=							parser.parse_args()
      convert_xlm_checkpoint_to_pytorch(args.xlm_checkpoint_path, args.pytorch_dump_folder_path)








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






