


'''simple docstring'''






import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from ...utils import logging
from ..auto import CONFIG_MAPPING


a_					:    int          =    logging.get_logger(__name__)

a_					:    str          =    {
    "salesforce/blip2-opt-2.7b": "https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json",
}




class  a     (     _SCREAMING_SNAKE_CASE       ):
 _lowerCAmelCase 					=	"""blip_2_vision_model"""
 def __init__( self      ,				__magic_name__=14_08      ,				__magic_name__=61_44      ,				__magic_name__=39      ,				__magic_name__=16      ,				__magic_name__=2_24      ,				__magic_name__=14      ,				__magic_name__="gelu"      ,				__magic_name__=0.0_0_0_0_1      ,				__magic_name__=0.0      ,				__magic_name__=1e-10      ,				__magic_name__=True      ,				**__magic_name__      ,				)					->							List[str]:
      super().__init__(**__magic_name__						)

      _a			      =							hidden_size
      _a			      =							intermediate_size
      _a			      =							num_hidden_layers
      _a			      =							num_attention_heads
      _a			      =							patch_size
      _a			      =							image_size
      _a			      =							initializer_range
      _a			      =							attention_dropout
      _a			      =							layer_norm_eps
      _a			      =							hidden_act
      _a			      =							qkv_bias




 @classmethod
 def 							__UpperCAmelCase		( cls      ,				__magic_name__      ,				**__magic_name__						)					->							"PretrainedConfig":
      cls._set_token_in_kwargs(__magic_name__						)

      _a      ,   _a			      =							cls.get_config_dict(__magic_name__      ,				**__magic_name__						)

      # get the vision config dict if we are loading from Blip2Config
      if config_dict.get('model_type'						) == "blip-2":
           _a			      =							config_dict['vision_config']

      if "model_type" in config_dict and hasattr(cls      ,				'model_type'						) and config_dict["model_type"] != cls.model_type:
           logger.warning(
               f'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
               f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'						)

      return cls.from_dict(__magic_name__      ,				**__magic_name__						)





class  a     (     _SCREAMING_SNAKE_CASE       ):
 _lowerCAmelCase 					=	"""blip_2_qformer"""
 def __init__( self      ,				__magic_name__=3_05_22      ,				__magic_name__=7_68      ,				__magic_name__=12      ,				__magic_name__=12      ,				__magic_name__=30_72      ,				__magic_name__="gelu"      ,				__magic_name__=0.1      ,				__magic_name__=0.1      ,				__magic_name__=5_12      ,				__magic_name__=0.0_2      ,				__magic_name__=1e-12      ,				__magic_name__=0      ,				__magic_name__="absolute"      ,				__magic_name__=2      ,				__magic_name__=14_08      ,				**__magic_name__      ,				)					->							Union[str, Any]:
      super().__init__(pad_token_id=__magic_name__      ,				**__magic_name__						)

      _a			      =							vocab_size
      _a			      =							hidden_size
      _a			      =							num_hidden_layers
      _a			      =							num_attention_heads
      _a			      =							hidden_act
      _a			      =							intermediate_size
      _a			      =							hidden_dropout_prob
      _a			      =							attention_probs_dropout_prob
      _a			      =							max_position_embeddings
      _a			      =							initializer_range
      _a			      =							layer_norm_eps
      _a			      =							position_embedding_type
      _a			      =							cross_attention_frequency
      _a			      =							encoder_hidden_size




 @classmethod
 def 							__UpperCAmelCase		( cls      ,				__magic_name__      ,				**__magic_name__						)					->							"PretrainedConfig":
      cls._set_token_in_kwargs(__magic_name__						)

      _a      ,   _a			      =							cls.get_config_dict(__magic_name__      ,				**__magic_name__						)

      # get the qformer config dict if we are loading from Blip2Config
      if config_dict.get('model_type'						) == "blip-2":
           _a			      =							config_dict['qformer_config']

      if "model_type" in config_dict and hasattr(cls      ,				'model_type'						) and config_dict["model_type"] != cls.model_type:
           logger.warning(
               f'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
               f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'						)

      return cls.from_dict(__magic_name__      ,				**__magic_name__						)





class  a     (     _SCREAMING_SNAKE_CASE       ):
 _lowerCAmelCase 					=	"""blip-2"""
 _lowerCAmelCase 					=	True
 def __init__( self      ,				__magic_name__=None      ,				__magic_name__=None      ,				__magic_name__=None      ,				__magic_name__=32      ,				**__magic_name__						)					->							Union[str, Any]:
      super().__init__(**__magic_name__						)

      if vision_config is None:
           _a			      =							{}
           logger.info('vision_config is None. initializing the Blip2VisionConfig with default values.'						)

      if qformer_config is None:
           _a			      =							{}
           logger.info('qformer_config is None. Initializing the Blip2QFormerConfig with default values.'						)

      if text_config is None:
           _a			      =							{}
           logger.info('text_config is None. Initializing the text config with default values (`OPTConfig`).'						)

      _a			      =							BlipaVisionConfig(**__magic_name__						)
      _a			      =							BlipaQFormerConfig(**__magic_name__						)
      _a			      =							text_config['model_type'] if 'model_type' in text_config else 'opt'
      _a			      =							CONFIG_MAPPING[text_model_type](**__magic_name__						)

      _a			      =							self.text_config.tie_word_embeddings
      _a			      =							self.text_config.is_encoder_decoder

      _a			      =							num_query_tokens
      _a			      =							self.vision_config.hidden_size
      _a			      =							self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
      _a			      =							1.0
      _a			      =							0.0_2
 @classmethod
 def 							__UpperCAmelCase		( cls      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__      ,				**__magic_name__      ,				)					->							List[Any]:
      return cls(
          vision_config=vision_config.to_dict()      ,				qformer_config=qformer_config.to_dict()      ,				text_config=text_config.to_dict()      ,				**__magic_name__      ,				)




 def 							__UpperCAmelCase		( self						)					->							List[str]:
      _a			      =							copy.deepcopy(self.__dict__						)
      _a			      =							self.vision_config.to_dict()
      _a			      =							self.qformer_config.to_dict()
      _a			      =							self.text_config.to_dict()
      _a			      =							self.__class__.model_type
      return output





'''simple docstring'''






import numpy as np
import qiskit






def 	_A				(lowerCAmelCase__  :int = 8				,						lowerCAmelCase__  :int | None = None		)   ->  str:




     '''simple docstring'''



     _a			      =							np.random.default_rng(seed=lowerCAmelCase__		)

     # Roughly 25% of the qubits will contribute to the key.
     # So we take more than we need.
     _a			      =							6 * key_len
     # Measurement basis for Alice's qubits.
     _a			      =							rng.integers(2				,						size=lowerCAmelCase__		)
     # The set of states Alice will prepare.
     _a			      =							rng.integers(2				,						size=lowerCAmelCase__		)
     # Measurement basis for Bob's qubits.
     _a			      =							rng.integers(2				,						size=lowerCAmelCase__		)

     # Quantum Circuit to simulate BB84
     _a			      =							qiskit.QuantumCircuit(lowerCAmelCase__				,						name='BB84'		)

     # Alice prepares her qubits according to rules above.
     for index, _ in enumerate(lowerCAmelCase__		):
          if alice_state[index] == 1:
               bbaa_circ.x(lowerCAmelCase__		)
          if alice_basis[index] == 1:
               bbaa_circ.h(lowerCAmelCase__		)
     bbaa_circ.barrier()

     # Bob measures the received qubits according to rules above.
     for index, _ in enumerate(lowerCAmelCase__		):
          if bob_basis[index] == 1:
               bbaa_circ.h(lowerCAmelCase__		)

     bbaa_circ.barrier()
     bbaa_circ.measure_all()

     # Simulate the quantum circuit.
     _a			      =							qiskit.Aer.get_backend('aer_simulator'		)
     # We only need to run one shot because the key is unique.
     # Multiple shots will produce the same key.
     _a			      =							qiskit.execute(lowerCAmelCase__				,						lowerCAmelCase__				,						shots=1				,						seed_simulator=lowerCAmelCase__		)
     # Returns the result of measurement.
     _a			      =							job.result().get_counts(lowerCAmelCase__		).most_frequent()

     # Extracting the generated key from the simulation results.
     # Only keep measurement results where Alice and Bob chose the same basis.
     _a			      =							''.join(
         [
             result_bit
             for alice_basis_bit, bob_basis_bit, result_bit in zip(
                 lowerCAmelCase__				,						lowerCAmelCase__				,						lowerCAmelCase__		)
             if alice_basis_bit == bob_basis_bit
         ]		)

     # Get final key. Pad with 0 if too short, otherwise truncate.
     _a			      =							gen_key[:key_len] if len(lowerCAmelCase__		) >= key_len else gen_key.ljust(lowerCAmelCase__				,						'0'		)
     return key


if __name__ == "__main__":
 print(f'''The generated key is : {bbaa(8, seed=0)}''')
 from doctest import testmod

 testmod()

