
"""simple docstring"""

import argparse

import torch
from torch import nn

from transformers import PLBartConfig, PLBartForConditionalGeneration, PLBartForSequenceClassification




def 			lowercase__  (    lowerCAmelCase :    Any       )       ->					List[str]:






    """simple docstring"""




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




def 			lowercase__  (    lowerCAmelCase :    Optional[int]       )       ->					List[str]:






    """simple docstring"""




    UpperCAmelCase	,							UpperCAmelCase  	=    emb.weight.shape
    UpperCAmelCase  	=    nn.Linear(lowerCAmelCase       , lowerCAmelCase       , bias=lowerCAmelCase       )
    UpperCAmelCase  	=    emb.weight.data
    return lin_layer




def 			lowercase__  (    lowerCAmelCase :    Optional[int]       , lowerCAmelCase :    Tuple="uclanlp/plbart-base"       , lowerCAmelCase :    Union[str, Any]=False       , lowerCAmelCase :    Union[str, Any]=False       )       ->					Tuple:






    """simple docstring"""




    UpperCAmelCase  	=    torch.load(lowerCAmelCase       , map_location='cpu'       )['model']
    remove_ignore_keys_(lowerCAmelCase       )
    UpperCAmelCase  	=    state_dict['encoder.embed_tokens.weight'].shape[0]

    UpperCAmelCase  	=    PLBartConfig.from_pretrained(lowerCAmelCase       , vocab_size=lowerCAmelCase       )

    UpperCAmelCase  	=    state_dict['decoder.embed_tokens.weight']
    if not classification:
        UpperCAmelCase  	=    PLBartForConditionalGeneration(lowerCAmelCase       )
        model.model.load_state_dict(lowerCAmelCase       )
        if finetuned:
            UpperCAmelCase  	=    make_linear_from_emb(model.model.shared       )

    else:
        UpperCAmelCase  	=    {}
        for key, value in state_dict.copy().items():
            if key.startswith('classification_heads.sentence_classification_head'       ):
                UpperCAmelCase  	=    value
                state_dict.pop(lowerCAmelCase       )
        UpperCAmelCase  	=    PLBartForSequenceClassification(lowerCAmelCase       )
        model.model.load_state_dict(lowerCAmelCase       )
        model.classification_head.load_state_dict(lowerCAmelCase       )

    return model


if __name__ == "__main__":
   SCREAMING_SNAKE_CASE_			    =  argparse.ArgumentParser()
   # Required parameters
   parser.add_argument('''fairseq_path''', type=str, help='''model.pt on local filesystem.''')
   parser.add_argument('''pytorch_dump_folder_path''', default=None, type=str, help='''Path to the output PyTorch model.''')
   parser.add_argument(
       '''--hf_config''',
       default='''uclanlp/plbart-base''',
       type=str,
       help='''Which huggingface architecture to use: plbart-base''',
   )
   parser.add_argument('''--finetuned''', action='''store_true''', help='''whether the model is a fine-tuned checkpoint''')
   parser.add_argument(
       '''--classification''', action='''store_true''', help='''whether the model is a classification checkpoint'''
   )
   SCREAMING_SNAKE_CASE_			    =  parser.parse_args()
   SCREAMING_SNAKE_CASE_			    =  convert_fairseq_plbart_checkpoint_from_disk(
       args.fairseq_path,
       hf_config_path=args.hf_config,
       finetuned=args.finetuned,
       classification=args.classification,
   )
   model.save_pretrained(args.pytorch_dump_folder_path)





"""simple docstring"""

import doctest

import projectq
from projectq.ops import H, Measure




def 			lowercase__  (    lowerCAmelCase :    projectq.cengines._main.MainEngine       )       ->					int:






    """simple docstring"""




    UpperCAmelCase  	=    quantum_engine.allocate_qubit()
    H | qubit
    Measure | qubit
    return int(lowerCAmelCase       )


if __name__ == "__main__":
   doctest.testmod()

   # initialises a new quantum backend
   SCREAMING_SNAKE_CASE_			    =  projectq.MainEngine()

   # Generate a list of 10 random numbers
   SCREAMING_SNAKE_CASE_			    =  [get_random_number(quantum_engine) for _ in range(10)]

   # Flushes the quantum engine from memory
   quantum_engine.flush()

   print('''Random numbers''', random_numbers_list)



