
import numpy as np
import qiskit
def        __lowercase(							__snake_case				:		str    ,__snake_case				:		int					)       ->   qiskit.QuantumCircuit:
       __snake_case						       =   qiskit.QuantumCircuit(num_qubits + 1					)

       # First, let's deal with the case in which oracle is balanced
       if case == "balanced":
              # First generate a random number that tells us which CNOTs to
              # wrap in X-gates:
              __snake_case						       =   np.random.randint(1    ,2**num_qubits					)
              # Next, format 'b' as a binary string of length 'n', padded with zeros:
              __snake_case						       =   format(__snake_case    ,f'''0{num_qubits}b'''					)
              # Next, we place the first X-gates. Each digit in our binary string
              # corresponds to a qubit, if the digit is 0, we do nothing, if it's 1
              # we apply an X-gate to that qubit:
              for index, bit in enumerate(__snake_case					):
                     if bit == "1":
                            oracle_qc.x(__snake_case					)
        # Do the controlled-NOT gates for each qubit, using the output qubit
        # as the target:
              for index in range(__snake_case					):
                     oracle_qc.cx(__snake_case    ,__snake_case					)
              # Next, place the final X-gates
              for index, bit in enumerate(__snake_case					):
                     if bit == "1":
                            oracle_qc.x(__snake_case					)

    # Case in which oracle is constant
       if case == "constant":
              # First decide what the fixed output of the oracle will be
              # (either always 0 or always 1)
              __snake_case						       =   np.random.randint(2					)
              if output == 1:
                     oracle_qc.x(__snake_case					)

       __snake_case						       =   oracle_qc.to_gate()
       __snake_case						       =   'Oracle'  # To show when we display the circuit
       return oracle_gate
def        __lowercase(							__snake_case				:		qiskit.QuantumCircuit    ,__snake_case				:		int					)       ->   qiskit.QuantumCircuit:
       __snake_case						       =   qiskit.QuantumCircuit(num_qubits + 1    ,__snake_case					)
       # Set up the output qubit:
       dj_circuit.x(__snake_case					)
       dj_circuit.h(__snake_case					)
       # And set up the input register:
       for qubit in range(__snake_case					):
              dj_circuit.h(__snake_case					)
       # Let's append the oracle gate to our circuit:
       dj_circuit.append(__snake_case    ,range(num_qubits + 1					)					)
       # Finally, perform the H-gates again and measure:
       for qubit in range(__snake_case					):
              dj_circuit.h(__snake_case					)

       for i in range(__snake_case					):
              dj_circuit.measure(__snake_case    ,__snake_case					)

       return dj_circuit
def        __lowercase(							__snake_case				:		str    ,__snake_case				:		int					)       ->   qiskit.result.counts.Counts:
       __snake_case						       =   qiskit.Aer.get_backend('aer_simulator'					)

       __snake_case						       =   dj_oracle(__snake_case    ,__snake_case					)
       __snake_case						       =   dj_algorithm(__snake_case    ,__snake_case					)

       # Execute the circuit on the simulator
       __snake_case						       =   qiskit.execute(__snake_case    ,__snake_case    ,shots=10_00					)

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


if __name__ == "__main__":
 print(f"""Deutsch Jozsa - Constant Oracle: {deutsch_jozsa('constant', 3)}""")
 print(f"""Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa('balanced', 3)}""")


import argparse

from transformers import ConvBertConfig, ConvBertModel, TFConvBertModel, load_tf_weights_in_convbert
from transformers.utils import logging


logging.set_verbosity_info()
def        __lowercase(							__snake_case				:		Dict    ,__snake_case				:		List[str]    ,__snake_case				:		List[Any]					)       ->   str:
       __snake_case						       =   ConvBertConfig.from_json_file(__snake_case					)
       __snake_case						       =   ConvBertModel(__snake_case					)

       __snake_case						       =   load_tf_weights_in_convbert(__snake_case    ,__snake_case    ,__snake_case					)
       model.save_pretrained(__snake_case					)

       __snake_case						       =   TFConvBertModel.from_pretrained(__snake_case    ,from_pt=__snake_case					)
       tf_model.save_pretrained(__snake_case					)


if __name__ == "__main__":
 lowerCamelCase_				:							List[Any]       =    argparse.ArgumentParser()
 # Required parameters
 parser.add_argument(
     "--tf_checkpoint_path", default=None, type=str, required=True, help="Path to the TensorFlow checkpoint path."
 )
 parser.add_argument(
     "--convbert_config_file",
     default=None,
     type=str,
     required=True,
     help=(
         "The config json file corresponding to the pre-trained ConvBERT model. \n"
         "This specifies the model architecture."
     ),
 )
 parser.add_argument(
     "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
 )
 lowerCamelCase_				:							Union[str, Any]       =    parser.parse_args()
 convert_orig_tfa_checkpoint_to_pytorch(args.tf_checkpoint_path, args.convbert_config_file, args.pytorch_dump_path)
