


'''simple docstring'''






import argparse

import torch
from torch import nn

from transformers import SpeechaTextConfig, SpeechaTextForConditionalGeneration






def 	_A				(lowerCAmelCase__  :Any		)   ->  Optional[Any]:




     '''simple docstring'''



     _a			      =							[
         'encoder.version',
         'decoder.version',
         'model.encoder.version',
         'model.decoder.version',
         'decoder.output_projection.weight',
         '_float_tensor',
         'encoder.embed_positions._float_tensor',
         'decoder.embed_positions._float_tensor',
     ]
     for k in ignore_keys:
          state_dict.pop(lowerCAmelCase__				,						lowerCAmelCase__		)






def 	_A				(lowerCAmelCase__  :List[Any]		)   ->  Tuple:




     '''simple docstring'''



     _a			      =							list(s_dict.keys()		)
     for key in keys:
          if "transformer_layers" in key:
               _a			      =							s_dict.pop(lowerCAmelCase__		)
          elif "subsample" in key:
               _a			      =							s_dict.pop(lowerCAmelCase__		)






def 	_A				(lowerCAmelCase__  :int		)   ->  Any:




     '''simple docstring'''



     _a      ,   _a			      =							emb.weight.shape
     _a			      =							nn.Linear(lowerCAmelCase__				,						lowerCAmelCase__				,						bias=lowerCAmelCase__		)
     _a			      =							emb.weight.data
     return lin_layer






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




     '''simple docstring'''



     _a			      =							torch.load(lowerCAmelCase__				,						map_location='cpu'		)
     _a			      =							mam_aaa['args']
     _a			      =							mam_aaa['model']
     _a			      =							state_dict['decoder.output_projection.weight']

     remove_ignore_keys_(lowerCAmelCase__		)
     rename_keys(lowerCAmelCase__		)

     _a			      =							state_dict['decoder.embed_tokens.weight'].shape[0]

     _a			      =							args.share_decoder_input_output_embed

     _a			      =							[int(lowerCAmelCase__		) for i in args.conv_kernel_sizes.split(','		)]
     _a			      =							SpeechaTextConfig(
         vocab_size=lowerCAmelCase__				,						max_source_positions=args.max_source_positions				,						max_target_positions=args.max_target_positions				,						encoder_layers=args.encoder_layers				,						decoder_layers=args.decoder_layers				,						encoder_attention_heads=args.encoder_attention_heads				,						decoder_attention_heads=args.decoder_attention_heads				,						encoder_ffn_dim=args.encoder_ffn_embed_dim				,						decoder_ffn_dim=args.decoder_ffn_embed_dim				,						d_model=args.encoder_embed_dim				,						dropout=args.dropout				,						attention_dropout=args.attention_dropout				,						activation_dropout=args.activation_dropout				,						activation_function='relu'				,						num_conv_layers=len(lowerCAmelCase__		)				,						conv_channels=args.conv_channels				,						conv_kernel_sizes=lowerCAmelCase__				,						input_feat_per_channel=args.input_feat_per_channel				,						input_channels=args.input_channels				,						tie_word_embeddings=lowerCAmelCase__				,						num_beams=5				,						max_length=2_00				,						use_cache=lowerCAmelCase__				,						decoder_start_token_id=2				,						early_stopping=lowerCAmelCase__				,						)

     _a			      =							SpeechaTextForConditionalGeneration(lowerCAmelCase__		)
     _a      ,   _a			      =							model.model.load_state_dict(lowerCAmelCase__				,						strict=lowerCAmelCase__		)
     if len(lowerCAmelCase__		) > 0 and not set(lowerCAmelCase__		) <= {
         "encoder.embed_positions.weights",
         "decoder.embed_positions.weights",
     }:
          raise ValueError(
              'Only `encoder.embed_positions.weights` and `decoder.embed_positions.weights`  are allowed to be missing,'
              f' but all the following weights are missing {missing}'		)

     if tie_embeds:
          _a			      =							make_linear_from_emb(model.model.decoder.embed_tokens		)
     else:
          _a			      =							lm_head_weights

     model.save_pretrained(lowerCAmelCase__		)


if __name__ == "__main__":
 a_					:    List[Any]          =    argparse.ArgumentParser()
 # Required parameters
 parser.add_argument("--fairseq_path", type=str, help="Path to the fairseq model (.pt) file.")
 parser.add_argument("--pytorch_dump_folder_path", default=None, type=str, help="Path to the output PyTorch model.")
 a_					:    str          =    parser.parse_args()
 convert_fairseq_sat_checkpoint_to_tfms(args.fairseq_path, args.pytorch_dump_folder_path)





'''simple docstring'''






import numpy as np
import qiskit






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




     '''simple docstring'''



     _a			      =							np.random.default_rng(seed=lowerCAmelCase__		)

     # Roughly 25% of the qubits will contribute to the key.
     # So we take more than we need.
     _a			      =							6 * key_len
     # Measurement basis for Alice's qubits.
     _a			      =							rng.integers(2				,						size=lowerCAmelCase__		)
     # The set of states Alice will prepare.
     _a			      =							rng.integers(2				,						size=lowerCAmelCase__		)
     # Measurement basis for Bob's qubits.
     _a			      =							rng.integers(2				,						size=lowerCAmelCase__		)

     # Quantum Circuit to simulate BB84
     _a			      =							qiskit.QuantumCircuit(lowerCAmelCase__				,						name='BB84'		)

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

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

     bbaa_circ.barrier()
     bbaa_circ.measure_all()

     # Simulate the quantum circuit.
     _a			      =							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.
     _a			      =							qiskit.execute(lowerCAmelCase__				,						lowerCAmelCase__				,						shots=1				,						seed_simulator=lowerCAmelCase__		)
     # Returns the result of measurement.
     _a			      =							job.result().get_counts(lowerCAmelCase__		).most_frequent()

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

     # Get final key. Pad with 0 if too short, otherwise truncate.
     _a			      =							gen_key[:key_len] if len(lowerCAmelCase__		) >= key_len else gen_key.ljust(lowerCAmelCase__				,						'0'		)
     return key


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

 testmod()

