
import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
					import jax.numpy as jnp

					from transformers.models.albert.modeling_flax_albert import (
					    FlaxAlbertForMaskedLM,
					    FlaxAlbertForMultipleChoice,
					    FlaxAlbertForPreTraining,
					    FlaxAlbertForQuestionAnswering,
					    FlaxAlbertForSequenceClassification,
					    FlaxAlbertForTokenClassification,
					    FlaxAlbertModel,
					)

class       a		(   unittest.TestCase					):







							def __init__(						self  :  Any      ,				snake_case__  :  Union[str, Any]      ,				snake_case__  :  Union[str, Any]=13      ,				snake_case__  :  List[Any]=7      ,				snake_case__  :  Dict=True      ,				snake_case__  :  Optional[int]=True      ,				snake_case__  :  Any=True      ,				snake_case__  :  Optional[int]=True      ,				snake_case__  :  List[str]=99      ,				snake_case__  :  Tuple=32      ,				snake_case__  :  List[Any]=5      ,				snake_case__  :  Union[str, Any]=4      ,				snake_case__  :  List[str]=37      ,				snake_case__  :  List[Any]="gelu"      ,				snake_case__  :  Optional[Any]=0.1      ,				snake_case__  :  Any=0.1      ,				snake_case__  :  List[str]=512      ,				snake_case__  :  Dict=16      ,				snake_case__  :  Tuple=2      ,				snake_case__  :  Union[str, Any]=0.0_2      ,				snake_case__  :  Any=4      ,				):
								"""simple docstring"""







								__lowerCAmelCase         =							parent
								__lowerCAmelCase         =							batch_size
								__lowerCAmelCase         =							seq_length
								__lowerCAmelCase         =							is_training
								__lowerCAmelCase         =							use_attention_mask
								__lowerCAmelCase         =							use_token_type_ids
								__lowerCAmelCase         =							use_labels
								__lowerCAmelCase         =							vocab_size
								__lowerCAmelCase         =							hidden_size
								__lowerCAmelCase         =							num_hidden_layers
								__lowerCAmelCase         =							num_attention_heads
								__lowerCAmelCase         =							intermediate_size
								__lowerCAmelCase         =							hidden_act
								__lowerCAmelCase         =							hidden_dropout_prob
								__lowerCAmelCase         =							attention_probs_dropout_prob
								__lowerCAmelCase         =							max_position_embeddings
								__lowerCAmelCase         =							type_vocab_size
								__lowerCAmelCase         =							type_sequence_label_size
								__lowerCAmelCase         =							initializer_range
								__lowerCAmelCase         =							num_choices







							def       UpperCAmelCase__					(						self  :  Optional[int] ):
								"""simple docstring"""







								__lowerCAmelCase         =							ids_tensor([self.batch_size, self.seq_length]      ,				self.vocab_size )

								__lowerCAmelCase         =							None
								if self.use_attention_mask:
									__lowerCAmelCase         =							random_attention_mask([self.batch_size, self.seq_length] )

								__lowerCAmelCase         =							None
								if self.use_token_type_ids:
									__lowerCAmelCase         =							ids_tensor([self.batch_size, self.seq_length]      ,				self.type_vocab_size )

								__lowerCAmelCase         =							AlbertConfig(
								    vocab_size=self.vocab_size      ,				hidden_size=self.hidden_size      ,				num_hidden_layers=self.num_hidden_layers      ,				num_attention_heads=self.num_attention_heads      ,				intermediate_size=self.intermediate_size      ,				hidden_act=self.hidden_act      ,				hidden_dropout_prob=self.hidden_dropout_prob      ,				attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,				max_position_embeddings=self.max_position_embeddings      ,				type_vocab_size=self.type_vocab_size      ,				is_decoder=snake_case__      ,				initializer_range=self.initializer_range      ,				)

								return config, input_ids, token_type_ids, attention_mask







							def       UpperCAmelCase__					(						self  :  Any ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.prepare_config_and_inputs()
								__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase   ,						__lowerCAmelCase         =							config_and_inputs
								__lowerCAmelCase         =							{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
								return config, inputs_dict

@require_flax
class       a		(   __UpperCAmelCase      ,	unittest.TestCase					):
							lowercase_		:						Tuple   							=  (
							    (
							        FlaxAlbertModel,
							        FlaxAlbertForPreTraining,
							        FlaxAlbertForMaskedLM,
							        FlaxAlbertForMultipleChoice,
							        FlaxAlbertForQuestionAnswering,
							        FlaxAlbertForSequenceClassification,
							        FlaxAlbertForTokenClassification,
							        FlaxAlbertForQuestionAnswering,
							    )
							    if is_flax_available()
							    else ()
							)







							def       UpperCAmelCase__					(						self  :  int ):
								"""simple docstring"""







								__lowerCAmelCase         =							FlaxAlbertModelTester(self )







							@slow
							def       UpperCAmelCase__					(						self  :  Optional[int] ):
								"""simple docstring"""







								for model_class_name in self.all_model_classes:
									__lowerCAmelCase         =							model_class_name.from_pretrained("albert-base-v2" )
									__lowerCAmelCase         =							model(np.ones((1, 1) ) )
									self.assertIsNotNone(snake_case__ )

@require_flax
class       a		(   unittest.TestCase					):







							@slow
							def       UpperCAmelCase__					(						self  :  str ):
								"""simple docstring"""







								__lowerCAmelCase         =							FlaxAlbertModel.from_pretrained("albert-base-v2" )
								__lowerCAmelCase         =							np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]] )
								__lowerCAmelCase         =							np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
								__lowerCAmelCase         =							model(snake_case__      ,				attention_mask=snake_case__ )[0]
								__lowerCAmelCase         =							(1, 11, 768)
								self.assertEqual(output.shape      ,				snake_case__ )
								__lowerCAmelCase         =							np.array(
								    [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]] )

								self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]      ,				snake_case__      ,				atol=1E-4 ) )








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()






