



import numpy as np
import qiskit






def      _A				(UpperCamelCase		:      int = 8      ,			UpperCamelCase		:      int | None = None )  ->str:



			'''simple docstring'''







			lowerCamelCase__ :      Any								=		np.random.default_rng(seed=UpperCamelCase )

			# Roughly 25% of the qubits will contribute to the key.
			# So we take more than we need.
			lowerCamelCase__ :      Optional[int]								=		6 * key_len
			# Measurement basis for Alice's qubits.
			lowerCamelCase__ :      List[str]								=		rng.integers(2      ,			size=UpperCamelCase )
			# The set of states Alice will prepare.
			lowerCamelCase__ :      List[str]								=		rng.integers(2      ,			size=UpperCamelCase )
			# Measurement basis for Bob's qubits.
			lowerCamelCase__ :      str								=		rng.integers(2      ,			size=UpperCamelCase )

			# Quantum Circuit to simulate BB84
			lowerCamelCase__ :      Tuple								=		qiskit.QuantumCircuit(UpperCamelCase      ,			name="""BB84""" )

			# Alice prepares her qubits according to rules above.
			for index, _ in enumerate(UpperCamelCase ):
						if alice_state[index] == 1:
									bbaa_circ.x(UpperCamelCase )
						if alice_basis[index] == 1:
									bbaa_circ.h(UpperCamelCase )
			bbaa_circ.barrier()

			# Bob measures the received qubits according to rules above.
			for index, _ in enumerate(UpperCamelCase ):
						if bob_basis[index] == 1:
									bbaa_circ.h(UpperCamelCase )

			bbaa_circ.barrier()
			bbaa_circ.measure_all()

			# Simulate the quantum circuit.
			lowerCamelCase__ :      List[str]								=		qiskit.Aer.get_backend("""aer_simulator""" )
			# We only need to run one shot because the key is unique.
			# Multiple shots will produce the same key.
			lowerCamelCase__ :      str								=		qiskit.execute(UpperCamelCase      ,			UpperCamelCase      ,			shots=1      ,			seed_simulator=UpperCamelCase )
			# Returns the result of measurement.
			lowerCamelCase__ :      str								=		job.result().get_counts(UpperCamelCase ).most_frequent()

			# Extracting the generated key from the simulation results.
			# Only keep measurement results where Alice and Bob chose the same basis.
			lowerCamelCase__ :      Dict								=		"""""".join(
			    [
			        result_bit
			        for alice_basis_bit, bob_basis_bit, result_bit in zip(
			            UpperCamelCase      ,			UpperCamelCase      ,			UpperCamelCase )
			        if alice_basis_bit == bob_basis_bit
			    ] )

			# Get final key. Pad with 0 if too short, otherwise truncate.
			lowerCamelCase__ :      Tuple								=		gen_key[:key_len] if len(UpperCamelCase ) >= key_len else gen_key.ljust(UpperCamelCase      ,			"""0""" )
			return key


if __name__ == "__main__":
				print(F'''The generated key is : {bbaa(8, seed=0)}''')
				from doctest import testmod

				testmod()








import argparse

from transformers import TaConfig, TaForConditionalGeneration, load_tf_weights_in_ta
from transformers.utils import logging


logging.set_verbosity_info()






def      _A				(UpperCamelCase		:      Any      ,			UpperCamelCase		:      Union[str, Any]      ,			UpperCamelCase		:      Optional[Any] )  ->Any:



			'''simple docstring'''







			lowerCamelCase__ :      Optional[Any]								=		TaConfig.from_json_file(UpperCamelCase )
			print(f"Building PyTorch model from configuration: {config}" )
			lowerCamelCase__ :      Optional[int]								=		TaForConditionalGeneration(UpperCamelCase )

			# Load weights from tf checkpoint
			load_tf_weights_in_ta(UpperCamelCase      ,			UpperCamelCase      ,			UpperCamelCase )

			# Save pytorch-model
			print(f"Save PyTorch model to {pytorch_dump_path}" )
			model.save_pretrained(UpperCamelCase )


if __name__ == "__main__":
				_lowercase     							=						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(
				    '''--config_file''',
				    default=None,
				    type=str,
				    required=True,
				    help=(
				        '''The config json file corresponding to the pre-trained T5 model. \nThis specifies the model architecture.'''
				    ),
				)
				parser.add_argument(
				    '''--pytorch_dump_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
				)
				_lowercase     							=						parser.parse_args()
				convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)



