
'''simple docstring'''



from io import BytesIO
from typing import List, Union

import requests

from ..utils import add_end_docstrings, is_decord_available, is_torch_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_decord_available():
						import numpy as np
						from decord import VideoReader


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

_lowercase    =		logging.get_logger(__name__)




@add_end_docstrings(_SCREAMING_SNAKE_CASE			)
class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						def __init__( self   ,       *_lowercase   ,       **_lowercase				):

												"""simple docstring"""



												super().__init__(*_lowercase   ,       **_lowercase				)
												requires_backends(self   ,       """decord"""				)
												self.check_model_type(_lowercase				)




						def  _lowercase     ( self   ,       _lowercase=None   ,       _lowercase=None   ,       _lowercase=None				):

												"""simple docstring"""



												_lowerCAmelCase  						=			{}
												if frame_sampling_rate is not None:
																		_lowerCAmelCase  						=			frame_sampling_rate
												if num_frames is not None:
																		_lowerCAmelCase  						=			num_frames

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




						def __call__( self   ,       _lowercase   ,       **_lowercase				):

												"""simple docstring"""



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




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase=None   ,       _lowercase=1				):

												"""simple docstring"""



												if num_frames is None:
																		_lowerCAmelCase  						=			self.model.config.num_frames

												if video.startswith("""http://"""				) or video.startswith("""https://"""				):
																		_lowerCAmelCase  						=			BytesIO(requests.get(_lowercase				).content				)

												_lowerCAmelCase  						=			VideoReader(_lowercase				)
												videoreader.seek(0				)

												_lowerCAmelCase  						=			0
												_lowerCAmelCase  						=			num_frames * frame_sampling_rate - 1
												_lowerCAmelCase  						=			np.linspace(_lowercase   ,       _lowercase   ,       num=_lowercase   ,       dtype=np.intaa				)

												_lowerCAmelCase  						=			videoreader.get_batch(_lowercase				).asnumpy()
												_lowerCAmelCase  						=			list(_lowercase				)

												_lowerCAmelCase  						=			self.image_processor(_lowercase   ,       return_tensors=self.framework				)
												return model_inputs




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.model(**_lowercase				)
												return model_outputs




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase=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(_lowercase				)
												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(_lowercase   ,       _lowercase				)]


'''simple docstring'''



import numpy as np
import qiskit


def A				(__lowerCamelCase				:int = 8			,     __lowerCamelCase				:int | None = None		):
						_lowerCAmelCase  						=			np.random.default_rng(seed=__lowerCamelCase		)

						# 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=__lowerCamelCase		)
						# The set of states Alice will prepare.
						_lowerCAmelCase  						=			rng.integers(2			,     size=__lowerCamelCase		)
						# Measurement basis for Bob's qubits.
						_lowerCAmelCase  						=			rng.integers(2			,     size=__lowerCamelCase		)

						# Quantum Circuit to simulate BB84
						_lowerCAmelCase  						=			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.
						_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(__lowerCamelCase			,     __lowerCamelCase			,     shots=1			,     seed_simulator=__lowerCamelCase		)
						# Returns the result of measurement.
						_lowerCAmelCase  						=			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.
						_lowerCAmelCase  						=			"""""".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.
						_lowerCAmelCase  						=			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()
