
from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
					from PIL import Image

					from ..image_utils import load_image

if is_tf_available():
					import tensorflow as tf

					from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
					from ..tf_utils import stable_softmax

if is_torch_available():
					from ..models.auto.modeling_auto import MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING

UpperCamelCase_   	=	logging.get_logger(__name__)

@add_end_docstrings(__UpperCAmelCase					)
class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Optional[Any]      ,				*snake_case__  :  Tuple      ,				**snake_case__  :  Any ):
								"""simple docstring"""







								super().__init__(*snake_case__      ,				**snake_case__ )
								requires_backends(self      ,				"vision" )
								self.check_model_type(
								    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
								    if self.framework == "tf"
								    else MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING )







							def       UpperCAmelCase__					(						self  :  List[Any]      ,				snake_case__  :  int=None ):
								"""simple docstring"""







								__lowerCAmelCase         =							{}
								if top_k is not None:
									__lowerCAmelCase         =							top_k
								return {}, {}, postprocess_params







							def __call__(						self  :  int      ,				snake_case__  :  Union[str, List[str], "Image.Image", List["Image.Image"]]      ,				**snake_case__  :  List[str] ):
								"""simple docstring"""







								return super().__call__(snake_case__      ,				**snake_case__ )







							def       UpperCAmelCase__					(						self  :  int      ,				snake_case__  :  Any ):
								"""simple docstring"""







								__lowerCAmelCase         =							load_image(snake_case__ )
								__lowerCAmelCase         =							self.image_processor(images=snake_case__      ,				return_tensors=self.framework )
								return model_inputs







							def       UpperCAmelCase__					(						self  :  str      ,				snake_case__  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model(**snake_case__ )
								return model_outputs







							def       UpperCAmelCase__					(						self  :  str      ,				snake_case__  :  List[str]      ,				snake_case__  :  Optional[Any]=5 ):
								"""simple docstring"""







								if top_k > self.model.config.num_labels:
									__lowerCAmelCase         =							self.model.config.num_labels

								if self.framework == "pt":
									__lowerCAmelCase         =							model_outputs.logits.softmax(-1 )[0]
									__lowerCAmelCase   ,						__lowerCAmelCase         =							probs.topk(snake_case__ )
								elif self.framework == "tf":
									__lowerCAmelCase         =							stable_softmax(model_outputs.logits      ,				axis=-1 )[0]
									__lowerCAmelCase         =							tf.math.top_k(snake_case__      ,				k=snake_case__ )
									__lowerCAmelCase   ,						__lowerCAmelCase         =							topk.values.numpy(), topk.indices.numpy()
								else:
									raise ValueError(F"Unsupported framework: {self.framework}" )

								__lowerCAmelCase         =							scores.tolist()
								__lowerCAmelCase         =							ids.tolist()
								return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(snake_case__      ,				snake_case__ )]








import numpy as np
import qiskit






def 		_UpperCAmelCase   (	UpperCamelCase:     int = 8			,							UpperCamelCase:     int | None = None  ):






	"""simple docstring"""


	__lowerCAmelCase         =							np.random.default_rng(seed=UpperCamelCase  )

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

	# Quantum Circuit to simulate BB84
	__lowerCAmelCase         =							qiskit.QuantumCircuit(UpperCamelCase			,							name="BB84"  )

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

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

	bbaa_circ.barrier()
	bbaa_circ.measure_all()

	# Simulate the quantum circuit.
	__lowerCAmelCase         =							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.
	__lowerCAmelCase         =							qiskit.execute(UpperCamelCase			,							UpperCamelCase			,							shots=1			,							seed_simulator=UpperCamelCase  )
	# Returns the result of measurement.
	__lowerCAmelCase         =							job.result().get_counts(UpperCamelCase  ).most_frequent()

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

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


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

					testmod()






