


import argparse

import torch
from torch import nn

from transformers import PLBartConfig, PLBartForConditionalGeneration, PLBartForSequenceClassification
def     UpperCAmelCase    (					_lowercase   :      Optional[Any]  )	->   Any:


	"""simple docstring"""




	lowerCAmelCase_			       = [
	    '''encoder.version''',
	    '''decoder.version''',
	    '''model.encoder.version''',
	    '''model.decoder.version''',
	    '''_float_tensor''',
	    '''decoder.output_projection.weight''',
	]
	for k in ignore_keys:
		state_dict.pop(lowercase_ ,      lowercase_  )
def     UpperCAmelCase    (					_lowercase   :      Tuple  )	->   Union[str, Any]:


	"""simple docstring"""




	lowerCAmelCase_			       = emb.weight.shape
	lowerCAmelCase_			       = nn.Linear(lowercase_ ,      lowercase_ ,      bias=lowercase_  )
	lowerCAmelCase_			       = emb.weight.data
	return lin_layer
def     UpperCAmelCase    (					_lowercase   :      int ,      _lowercase   :      Optional[Any]="uclanlp/plbart-base" ,      _lowercase   :      Dict=False ,      _lowercase   :      Optional[Any]=False  )	->   Tuple:


	"""simple docstring"""




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

	lowerCAmelCase_			       = PLBartConfig.from_pretrained(lowercase_ ,      vocab_size=lowercase_  )

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

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

	return model


if __name__ == "__main__":
		lowercase_							 =       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'
		)
		lowercase_							 =       parser.parse_args()
		lowercase_							 =       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     UpperCAmelCase    (					_lowercase   :      projectq.cengines._main.MainEngine  )	->   int:


	"""simple docstring"""




	lowerCAmelCase_			       = quantum_engine.allocate_qubit()
	H | qubit
	Measure | qubit
	return int(_lowercase  )


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

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

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

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

		print('Random numbers', random_numbers_list)