


'''simple docstring'''






import math

import tensorflow as tf
from packaging import version





def      UpperCAmelCase      (		lowerCamelCase_  :Union[str, Any] ):







		'''simple docstring'''
		snake_case_		:							List[str]			       =						tf.convert_to_tensor(lowerCamelCase_ )
		snake_case_		:							int			       =						0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0 )				,      x.dtype ) ))

		return x * cdf





def      UpperCAmelCase      (		lowerCamelCase_  :Union[str, Any] ):







		'''simple docstring'''
		snake_case_		:							int			       =						tf.convert_to_tensor(lowerCamelCase_ )
		snake_case_		:							str			       =						tf.cast(math.pi				,      x.dtype )
		snake_case_		:							Dict			       =						tf.cast(0.044_715				,      x.dtype )
		snake_case_		:							Any			       =						0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi ) * (x + coeff * tf.pow(lowerCamelCase_				,      3 )) ))

		return x * cdf





def      UpperCAmelCase      (		lowerCamelCase_  :Union[str, Any] ):







		'''simple docstring'''
		snake_case_		:							Optional[int]			       =						tf.convert_to_tensor(lowerCamelCase_ )

		return x * tf.tanh(tf.math.softplus(lowerCamelCase_ ) )





def      UpperCAmelCase      (		lowerCamelCase_  :Optional[int] ):







		'''simple docstring'''
		snake_case_		:							int			       =						tf.convert_to_tensor(lowerCamelCase_ )
		snake_case_		:							Tuple			       =						tf.cast(0.044_715				,      x.dtype )
		snake_case_		:							List[str]			       =						tf.cast(0.7_978_845_608				,      x.dtype )

		return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x) ))





def      UpperCAmelCase      (		lowerCamelCase_  :Optional[int] ):







		'''simple docstring'''
		snake_case_		:							Optional[int]			       =						tf.convert_to_tensor(lowerCamelCase_ )
		snake_case_		:							Any			       =						tf.cast(1.702				,      x.dtype )
		return x * tf.math.sigmoid(coeff * x )





def      UpperCAmelCase      (		lowerCamelCase_  :Optional[Any] ):







		'''simple docstring'''
		return tf.clip_by_value(_gelu(lowerCamelCase_ )				,      -10				,      10 )





def      UpperCAmelCase      (		lowerCamelCase_  :Tuple				,      lowerCamelCase_  :List[Any]=-1 ):







		'''simple docstring'''
		snake_case_       ,      snake_case_		:							List[Any]			       =						tf.split(lowerCamelCase_				,      2				,      axis=lowerCamelCase_ )
		return a * tf.math.sigmoid(lowerCamelCase_ )


if version.parse(tf.version.VERSION) >= version.parse('2.4'):





							def      UpperCAmelCase      (		lowerCamelCase_  :Dict ):







									'''simple docstring'''
									return tf.keras.activations.gelu(lowerCamelCase_				,      approximate=lowerCamelCase_ )

							__A	:	int     =     tf.keras.activations.gelu






							__A	:	Any     =     approximate_gelu_wrap
else:
							__A	:	str     =     _gelu
							__A	:	Dict     =     _gelu_new


__A	:	Tuple     =     {
    'gelu': gelu,
    'gelu_10': gelu_aa,
    'gelu_fast': gelu_fast,
    'gelu_new': gelu_new,
    'glu': glu,
    'mish': mish,
    'quick_gelu': quick_gelu,
    'relu': tf.keras.activations.relu,
    'sigmoid': tf.keras.activations.sigmoid,
    'silu': tf.keras.activations.swish,
    'swish': tf.keras.activations.swish,
    'tanh': tf.keras.activations.tanh,
}






def      UpperCAmelCase      (		lowerCamelCase_  :Union[str, Any] ):







		'''simple docstring'''
		if activation_string in ACTaFN:
				return ACTaFN[activation_string]
		else:
				raise KeyError(F'''function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys() )}''' )



'''simple docstring'''






import numpy as np
import qiskit





def      UpperCAmelCase      (		lowerCamelCase_  :int = 8				,      lowerCamelCase_  :int | None = None ):







		'''simple docstring'''
		snake_case_		:							Tuple			       =						np.random.default_rng(seed=lowerCamelCase_ )

		# Roughly 25% of the qubits will contribute to the key.
		# So we take more than we need.
		snake_case_		:							Union[str, Any]			       =						6 * key_len
		# Measurement basis for Alice's qubits.
		snake_case_		:							Tuple			       =						rng.integers(2				,      size=lowerCamelCase_ )
		# The set of states Alice will prepare.
		snake_case_		:							Tuple			       =						rng.integers(2				,      size=lowerCamelCase_ )
		# Measurement basis for Bob's qubits.
		snake_case_		:							List[Any]			       =						rng.integers(2				,      size=lowerCamelCase_ )

		# Quantum Circuit to simulate BB84
		snake_case_		:							Optional[int]			       =						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.
		snake_case_		:							Union[str, Any]			       =						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.
		snake_case_		:							Tuple			       =						qiskit.execute(lowerCamelCase_				,      lowerCamelCase_				,      shots=1				,      seed_simulator=lowerCamelCase_ )
		# Returns the result of measurement.
		snake_case_		:							Tuple			       =						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.
		snake_case_		:							Optional[Any]			       =						"""""".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.
		snake_case_		:							str			       =						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()