





'''simple docstring'''


import argparse

import torch

from transformers import ChineseCLIPConfig, ChineseCLIPModel




def       A							(      _UpperCAmelCase   :				int						,_UpperCAmelCase   :				Union[str, Any]						,_UpperCAmelCase   :				Dict					)  ->				List[str]:


  '''simple docstring'''




  __lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase		:    List[str]			     =  pt_weights[F"""{prefix}.in_proj_weight"""].chunk(3						,dim=0					)
  __lowerCAmelCase     ,					__lowerCAmelCase     ,					__lowerCAmelCase		:    Optional[Any]			     =  pt_weights[F"""{prefix}.in_proj_bias"""].chunk(3						,dim=0					)

  __lowerCAmelCase		:    Optional[Any]			     =  pt_weights[F"""{prefix}.out_proj.weight"""]
  __lowerCAmelCase		:    List[Any]			     =  pt_weights[F"""{prefix}.out_proj.bias"""]

  __lowerCAmelCase		:    Optional[Any]			     =  q_proj
  __lowerCAmelCase		:    List[Any]			     =  q_proj_bias

  __lowerCAmelCase		:    Any			     =  k_proj
  __lowerCAmelCase		:    Dict			     =  k_proj_bias

  __lowerCAmelCase		:    Any			     =  v_proj
  __lowerCAmelCase		:    Union[str, Any]			     =  v_proj_bias

  __lowerCAmelCase		:    Optional[Any]			     =  out_proj_weights
  __lowerCAmelCase		:    List[str]			     =  out_proj_bias




def       A							(      _UpperCAmelCase   :				Optional[Any]						,_UpperCAmelCase   :				List[str]						,_UpperCAmelCase   :				List[str]					)  ->				Any:


  '''simple docstring'''




  copy_linear(hf_mlp.fca						,_UpperCAmelCase						,F"""{prefix}.c_fc"""					)
  copy_linear(hf_mlp.fca						,_UpperCAmelCase						,F"""{prefix}.c_proj"""					)




def       A							(      _UpperCAmelCase   :				List[str]						,_UpperCAmelCase   :				Union[str, Any]						,_UpperCAmelCase   :				int					)  ->				Optional[int]:


  '''simple docstring'''




  __lowerCAmelCase		:    Union[str, Any]			     =  pt_weights[F"""{prefix}.weight"""].data
  __lowerCAmelCase		:    Optional[Any]			     =  pt_weights[F"""{prefix}.bias"""].data




def       A							(      _UpperCAmelCase   :				List[str]						,_UpperCAmelCase   :				Optional[int]						,_UpperCAmelCase   :				int					)  ->				Any:


  '''simple docstring'''




  copy_linear(hf_layer.layer_norma						,_UpperCAmelCase						,F"""{prefix}.ln_1"""					)
  copy_linear(hf_layer.layer_norma						,_UpperCAmelCase						,F"""{prefix}.ln_2"""					)

  # copy MLP
  copy_mlp(hf_layer.mlp						,_UpperCAmelCase						,F"""{prefix}.mlp"""					)

  # copy attn
  copy_attn_layer(hf_layer.self_attn						,_UpperCAmelCase						,F"""{prefix}.attn"""					)




def       A							(      _UpperCAmelCase   :				List[Any]						,_UpperCAmelCase   :				Optional[int]						,_UpperCAmelCase   :				List[str]					)  ->				Optional[int]:


  '''simple docstring'''




  for layer_id, hf_layer in enumerate(_UpperCAmelCase					):
    copy_layer(_UpperCAmelCase						,_UpperCAmelCase						,F"""{prefix}.{layer_id}"""					)




def       A							(      _UpperCAmelCase   :				List[Any]						,_UpperCAmelCase   :				Union[str, Any]					)  ->				Dict:


  '''simple docstring'''




  __lowerCAmelCase		:    Any			     =  pt_weights['text_projection'].data.T

  # copy text encoder
  for name, param in hf_model.text_model.named_parameters():
    __lowerCAmelCase		:    Any			     =  pt_weights[F"""bert.{name}"""].data




def       A							(      _UpperCAmelCase   :				Dict						,_UpperCAmelCase   :				Tuple					)  ->				List[Any]:


  '''simple docstring'''




  __lowerCAmelCase		:    str			     =  pt_weights['visual.proj'].data.T

  # copy layer norms
  copy_linear(hf_model.vision_model.pre_layrnorm						,_UpperCAmelCase						,'visual.ln_pre'					)
  copy_linear(hf_model.vision_model.post_layernorm						,_UpperCAmelCase						,'visual.ln_post'					)

  # copy embeddings
  __lowerCAmelCase		:    Optional[Any]			     =  pt_weights['visual.conv1.weight'].data
  __lowerCAmelCase		:    List[Any]			     =  pt_weights['visual.class_embedding'].data
  __lowerCAmelCase		:    str			     =  pt_weights['visual.positional_embedding'].data

  # copy encoder
  copy_layers(hf_model.vision_model.encoder.layers						,_UpperCAmelCase						,'visual.transformer.resblocks'					)




@torch.no_grad()
def       A							(      _UpperCAmelCase   :				str						,_UpperCAmelCase   :				Tuple						,_UpperCAmelCase   :				Any=None					)  ->				str:


  '''simple docstring'''




  assert config_path is not None, "Please specify the ChineseCLIP model config of the corresponding model size."
  __lowerCAmelCase		:    str			     =  ChineseCLIPConfig.from_pretrained(_UpperCAmelCase					)

  __lowerCAmelCase		:    List[Any]			     =  ChineseCLIPModel(_UpperCAmelCase					).eval()

  __lowerCAmelCase		:    List[str]			     =  torch.load(_UpperCAmelCase						,map_location='cpu'					)['state_dict']
  __lowerCAmelCase		:    str			     =  {(name[7:] if name.startswith('module.'					) else name): value for name, value in pt_weights.items()}

  copy_text_model_and_projection(_UpperCAmelCase						,_UpperCAmelCase					)
  copy_vision_model_and_projection(_UpperCAmelCase						,_UpperCAmelCase					)
  __lowerCAmelCase		:    List[Any]			     =  pt_weights['logit_scale'].data

  hf_model.save_pretrained(_UpperCAmelCase					)


if __name__ == "__main__":
    A_				     =							argparse.ArgumentParser()
    parser.add_argument(
        "--pytorch_dump_folder_path",
        default=None,
        type=str,
        help="Path to the output folder storing converted hf PyTorch model.",
    )
    parser.add_argument(
        "--checkpoint_path", default=None, type=str, help="Path to original github format ChineseCLIP checkpoint."
    )
    parser.add_argument(
        "--config_path", default=None, required=True, type=str, help="Path to hf config.json of model to convert."
    )
    A_				     =							parser.parse_args()

    convert_chinese_clip_checkpoint(args.checkpoint_path, args.pytorch_dump_folder_path, args.config_path)
    print("The conversion is finished!")












'''simple docstring'''


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




def       A							(      _UpperCAmelCase   :				float = np.pi / 2						,_UpperCAmelCase   :				float = np.pi / 2						,_UpperCAmelCase   :				float = np.pi / 2					)  ->				qiskit.result.counts.Counts:


  '''simple docstring'''




  __lowerCAmelCase		:    Optional[int]			     =  QuantumRegister(3						,'qr'					)  # Define the number of quantum bits
  __lowerCAmelCase		:    Optional[int]			     =  ClassicalRegister(1						,'cr'					)  # Define the number of classical bits

  __lowerCAmelCase		:    List[Any]			     =  QuantumCircuit(_UpperCAmelCase						,_UpperCAmelCase					)  # Define the quantum circuit.

  # Build the circuit
  quantum_circuit.u(_UpperCAmelCase						,_UpperCAmelCase						,_UpperCAmelCase						,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		:    List[str]			     =  Aer.get_backend('aer_simulator'					)
  __lowerCAmelCase		:    Optional[Any]			     =  execute(_UpperCAmelCase						,_UpperCAmelCase						,shots=1_0_0_0					)

  return job.result().get_counts(_UpperCAmelCase					)


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





