





'''simple docstring'''






import qiskit
from qiskit.providers import Backend
def 				_lowerCamelCase(	UpperCamelCase__     :			int     ,							UpperCamelCase__     :			int		)		->	tuple[qiskit.QuantumCircuit, str, str]:
    A,						A							:							str				=    bin(UpperCamelCase_		)[2:], bin(UpperCamelCase_		)[2:]  # Remove leading '0b'

    # Ensure that both strings are of the same length
    if len(UpperCamelCase_		) > len(UpperCamelCase_		):
        A							:							Optional[int]				=    y.zfill(len(UpperCamelCase_		)		)
    else:
        A							:							Dict				=    x.zfill(len(UpperCamelCase_		)		)

    # We need (3 * number of bits in the larger number)+1 qBits
    # The second parameter is the number of classical registers, to measure the result
    A							:							Dict				=    qiskit.QuantumCircuit((len(UpperCamelCase_		) * 3) + 1     ,							len(UpperCamelCase_		) + 1		)

    # We are essentially "not-ing" the bits that are 1
    # Reversed because it's easier to perform ops on more significant bits
    for i in range(len(UpperCamelCase_		)		):
        if x[::-1][i] == "1":
            circuit.x(UpperCamelCase_		)
    for j in range(len(UpperCamelCase_		)		):
        if y[::-1][j] == "1":
            circuit.x(len(UpperCamelCase_		) + j		)

    return circuit, x, y
def 				_lowerCamelCase(	UpperCamelCase__     :			qiskit.QuantumCircuit     ,							UpperCamelCase__     :			int     ,							UpperCamelCase__     :			int     ,							UpperCamelCase__     :			int     ,							UpperCamelCase__     :			int     ,							)		->	int:
    circuit.ccx(UpperCamelCase_     ,							UpperCamelCase_     ,							UpperCamelCase_		)
    circuit.cx(UpperCamelCase_     ,							UpperCamelCase_		)
    circuit.ccx(UpperCamelCase_     ,							UpperCamelCase_     ,							UpperCamelCase_		)
    circuit.cx(UpperCamelCase_     ,							UpperCamelCase_		)
    circuit.cx(UpperCamelCase_     ,							UpperCamelCase_		)
def 				_lowerCamelCase(	UpperCamelCase__     :			int     ,							UpperCamelCase__     :			int     ,							UpperCamelCase__     :			Backend = qiskit.Aer.get_backend('''aer_simulator'''		)     ,							)		->	int:







    if vala < 0 or vala < 0:
        raise ValueError('''Both Integers must be positive!'''		)

    # Store the Integers
    A,						A,						A							:							int				=    store_two_classics(UpperCamelCase_     ,							UpperCamelCase_		)
    for i in range(len(UpperCamelCase_		)		):
        full_adder(UpperCamelCase_     ,							UpperCamelCase_     ,							len(UpperCamelCase_		) + i     ,							len(UpperCamelCase_		) + len(UpperCamelCase_		) + i     ,							len(UpperCamelCase_		) + len(UpperCamelCase_		) + i + 1		)
        circuit.barrier()  # Optional, just for aesthetics

    # Measure the resultant qBits
    for i in range(len(UpperCamelCase_		) + 1		):
        circuit.measure([(len(UpperCamelCase_		) * 2) + i]     ,							[i]		)

    A							:							Tuple				=    qiskit.execute(UpperCamelCase_     ,							UpperCamelCase_     ,							shots=1		).result()

    # The result is in binary. Convert it back to int
    return int(list(res.get_counts()		)[0]     ,							2		)


if __name__ == "__main__":
     import doctest

     doctest.testmod()








"""simple docstring"""




import argparse

import torch

from transformers import ImageGPTConfig, ImageGPTForCausalLM, load_tf_weights_in_imagegpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()






def 							lowerCAmelCase			(   UpperCamelCase_:				Dict  ,			UpperCamelCase_:				Dict  ,			UpperCamelCase_:				Any       )							->				Tuple:







  '''simple docstring'''







  _a					      =						{"small": (512, 8, 24), "medium": (1024, 8, 36), "large": (1536, 16, 48)}
  _a      ,						_a      ,						_a					      =						MODELS[model_size]  # set model hyperparameters
  _a					      =						ImageGPTConfig(n_embd=UpperCamelCase_  ,			n_layer=UpperCamelCase_  ,			n_head=UpperCamelCase_       )
  _a					      =						ImageGPTForCausalLM(UpperCamelCase_       )

  # Load weights from numpy
  load_tf_weights_in_imagegpt(UpperCamelCase_  ,			UpperCamelCase_  ,			UpperCamelCase_       )

  # Save pytorch-model
  _a					      =						pytorch_dump_folder_path + "/" + WEIGHTS_NAME
  _a					      =						pytorch_dump_folder_path + "/" + CONFIG_NAME
  print(f'''Save PyTorch model to {pytorch_weights_dump_path}'''       )
  torch.save(model.state_dict()  ,			UpperCamelCase_       )
  print(f'''Save configuration file to {pytorch_config_dump_path}'''       )
  with open(UpperCamelCase_  ,			"w"  ,			encoding="utf-8"       ) as f:
    f.write(config.to_json_string()       )


if __name__ == "__main__":
     UpperCamelCase											=     argparse.ArgumentParser()
     # Required parameters
     parser.add_argument(
         """--imagegpt_checkpoint_path""",
         default=None,
         type=str,
         required=True,
         help="""Path to the TensorFlow checkpoint path.""",
     )
     parser.add_argument(
         """--model_size""",
         default=None,
         type=str,
         required=True,
         help="""Size of the model (can be either 'small', 'medium' or 'large').""",
     )
     parser.add_argument(
         """--pytorch_dump_folder_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
     )
     UpperCamelCase											=     parser.parse_args()
     convert_imagegpt_checkpoint_to_pytorch(
         args.imagegpt_checkpoint_path, args.model_size, args.pytorch_dump_folder_path
     )


