import math

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

def 							UpperCamelCase				(    lowerCAmelCase_ = 3   )		->						qiskit.result.counts.Counts:




       '''simple docstring'''






       if isinstance(lowerCAmelCase_       ,					lowerCAmelCase_   ):
              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(lowerCAmelCase_   ) != 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).'   )

       _A=	QuantumRegister(lowerCAmelCase_       ,					'qr'   )
       _A=	ClassicalRegister(lowerCAmelCase_       ,					'cr'   )

       _A=	QuantumCircuit(lowerCAmelCase_       ,					lowerCAmelCase_   )

       _A=	number_of_qubits

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

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

       # measure all the qubits
       quantum_circuit.measure(lowerCAmelCase_       ,					lowerCAmelCase_   )
       # simulate with 10000 shots
       _A=	Aer.get_backend('qasm_simulator'   )
       _A=	execute(lowerCAmelCase_       ,					lowerCAmelCase_       ,					shots=1_00_00   )

       return job.result().get_counts(lowerCAmelCase_   )


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

import torch

from transformers import BertForMaskedLM


if __name__ == "__main__":
      UpperCAmelCase_								=							argparse.ArgumentParser(
          description=(
              '''Extraction some layers of the full BertForMaskedLM or RObertaForMaskedLM for Transfer Learned'''
              ''' Distillation'''
          )
      )
      parser.add_argument('''--model_type''', default='''bert''', choices=['''bert'''])
      parser.add_argument('''--model_name''', default='''bert-base-uncased''', type=str)
      parser.add_argument('''--dump_checkpoint''', default='''serialization_dir/tf_bert-base-uncased_0247911.pth''', type=str)
      parser.add_argument('''--vocab_transform''', action='''store_true''')
      UpperCAmelCase_								=							parser.parse_args()

      if args.model_type == "bert":
            UpperCAmelCase_								=							BertForMaskedLM.from_pretrained(args.model_name)
            UpperCAmelCase_								=							'''bert'''
      else:
            raise ValueError('''args.model_type should be "bert".''')

      UpperCAmelCase_								=							model.state_dict()
      UpperCAmelCase_								=							{}

      for w in ["word_embeddings", "position_embeddings"]:
            UpperCAmelCase_								=							state_dict[F"{prefix}.embeddings.{w}.weight"]
      for w in ["weight", "bias"]:
            UpperCAmelCase_								=							state_dict[F"{prefix}.embeddings.LayerNorm.{w}"]

      UpperCAmelCase_								=							0
      for teacher_idx in [0, 2, 4, 7, 9, 11]:
            for w in ["weight", "bias"]:
                  UpperCAmelCase_								=							state_dict[
                      F"{prefix}.encoder.layer.{teacher_idx}.attention.self.query.{w}"
                  ]
                  UpperCAmelCase_								=							state_dict[
                      F"{prefix}.encoder.layer.{teacher_idx}.attention.self.key.{w}"
                  ]
                  UpperCAmelCase_								=							state_dict[
                      F"{prefix}.encoder.layer.{teacher_idx}.attention.self.value.{w}"
                  ]

                  UpperCAmelCase_								=							state_dict[
                      F"{prefix}.encoder.layer.{teacher_idx}.attention.output.dense.{w}"
                  ]
                  UpperCAmelCase_								=							state_dict[
                      F"{prefix}.encoder.layer.{teacher_idx}.attention.output.LayerNorm.{w}"
                  ]

                  UpperCAmelCase_								=							state_dict[
                      F"{prefix}.encoder.layer.{teacher_idx}.intermediate.dense.{w}"
                  ]
                  UpperCAmelCase_								=							state_dict[
                      F"{prefix}.encoder.layer.{teacher_idx}.output.dense.{w}"
                  ]
                  UpperCAmelCase_								=							state_dict[
                      F"{prefix}.encoder.layer.{teacher_idx}.output.LayerNorm.{w}"
                  ]
            std_idx += 1

      UpperCAmelCase_								=							state_dict['''cls.predictions.decoder.weight''']
      UpperCAmelCase_								=							state_dict['''cls.predictions.bias''']
      if args.vocab_transform:
            for w in ["weight", "bias"]:
                  UpperCAmelCase_								=							state_dict[F"cls.predictions.transform.dense.{w}"]
                  UpperCAmelCase_								=							state_dict[F"cls.predictions.transform.LayerNorm.{w}"]

      print(F"N layers selected for distillation: {std_idx}")
      print(F"Number of params transferred for distillation: {len(compressed_sd.keys())}")

      print(F"Save transferred checkpoint to {args.dump_checkpoint}.")
      torch.save(compressed_sd, args.dump_checkpoint)