'''simple docstring'''




import os
from pathlib import Path
from typing import Dict, List

import fire
import torch

from transformers import AutoModelForSeqaSeqLM, AutoTokenizer
from transformers.utils.logging import get_logger


snake_case  =			get_logger(__name__)







def 			A_   ( _lowerCamelCase			:							str  ,  _lowerCamelCase			:							str    ):
      if text.startswith(_lowerCamelCase    ):
            return text[len(_lowerCamelCase    ) :]
      return text  # or whatever







def 			A_   ( _lowerCamelCase			:							List[str]    ):
      return {remove_prefix(_lowerCamelCase  ,  'model.'    ): v for k, v in sd.items()}







def 			A_   ( _lowerCamelCase			:							List[Dict[str, torch.Tensor]]    ):
      _lowerCAmelCase		   =   {}
      for k in state_dicts[0].keys():
            _lowerCAmelCase		   =   [sd[k] for sd in state_dicts]
            _lowerCAmelCase		   =   sum(_lowerCamelCase    ) / len(_lowerCamelCase    )
            assert isinstance(_lowerCamelCase  ,  torch.Tensor    )
            _lowerCAmelCase		   =   new_t
      return new_sd







def 			A_   ( _lowerCamelCase			:							str  ,  _lowerCamelCase			:							str  ,  _lowerCamelCase			:							str    ):
      _lowerCAmelCase		   =   AutoModelForSeqaSeqLM.from_pretrained(_lowerCamelCase    )
      if os.path.isfile(_lowerCamelCase    ):
            _lowerCAmelCase		   =   [pl_ckpt_path]
      else:
            assert os.path.isdir(_lowerCamelCase    )
            _lowerCAmelCase		   =   list(Path(_lowerCamelCase    ).glob('*.ckpt'    )    )
            assert ckpt_files, F"could not find any ckpt files inside the {pl_ckpt_path} directory"

      if len(_lowerCamelCase    ) > 1:
            logger.info(F"averaging the weights of {ckpt_files}"    )

      _lowerCAmelCase		   =   [sanitize(torch.load(_lowerCamelCase  ,  map_location='cpu'    )['state_dict']    ) for x in ckpt_files]
      _lowerCAmelCase		   =   average_state_dicts(_lowerCamelCase    )

      _lowerCAmelCase   ,  _lowerCAmelCase		   =   hf_model.load_state_dict(_lowerCamelCase  ,  strict=_lowerCamelCase    )
      assert not missing, F"missing keys: {missing}"
      hf_model.save_pretrained(_lowerCamelCase    )
      try:
            _lowerCAmelCase		   =   AutoTokenizer.from_pretrained(_lowerCamelCase    )
            tok.save_pretrained(_lowerCamelCase    )
      except Exception:
            pass
            # dont copy tokenizer if cant


if __name__ == "__main__":
 fire.Fire(convert_pl_to_hf)






'''simple docstring'''




import numpy as np
import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute







def 			A_   ( _lowerCamelCase			:							float = np.pi / 2  ,  _lowerCamelCase			:							float = np.pi / 2  ,  _lowerCamelCase			:							float = np.pi / 2    ):
      _lowerCAmelCase		   =   QuantumRegister(3  ,  'qr'    )  # Define the number of quantum bits
      _lowerCAmelCase		   =   ClassicalRegister(1  ,  'cr'    )  # Define the number of classical bits

      _lowerCAmelCase		   =   QuantumCircuit(_lowerCamelCase  ,  _lowerCamelCase    )  # Define the quantum circuit.

      # Build the circuit
      quantum_circuit.u(_lowerCamelCase  ,  _lowerCamelCase  ,  _lowerCamelCase  ,  0    )  # Quantum State to teleport
      quantum_circuit.h(1    )  # add hadamard gate
      quantum_circuit.cx(
          1  ,  2    )  # add control gate with qubit 1 as control and 2 as target.
      quantum_circuit.cx(0  ,  1    )
      quantum_circuit.h(0    )
      quantum_circuit.cz(0  ,  2    )  # add control z gate.
      quantum_circuit.cx(1  ,  2    )

      quantum_circuit.measure([2]  ,  [0]    )  # measure the qubit.

      # Simulate the circuit using qasm simulator
      _lowerCAmelCase		   =   Aer.get_backend('aer_simulator'    )
      _lowerCAmelCase		   =   execute(_lowerCamelCase  ,  _lowerCamelCase  ,  shots=1_000    )

      return job.result().get_counts(_lowerCamelCase    )


if __name__ == "__main__":
 print(
     '''Total count for teleported state is: '''
     f'''{quantum_teleportation(np.pi/2, np.pi/2, np.pi/2)}'''
 )





