import numpy as np
import qiskit







def 						A__  (					__A = 8   , __A = None	):







    '''simple docstring'''
    _lowerCamelCase     :		Any 						=						np.random.default_rng(seed=__A	)

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

    # Quantum Circuit to simulate BB84
    _lowerCamelCase     :		List[Any] 						=						qiskit.QuantumCircuit(__A   , name="""BB84"""	)

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

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

    bbaa_circ.barrier()
    bbaa_circ.measure_all()

    # Simulate the quantum circuit.
    _lowerCamelCase     :		str 						=						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     :		int 						=						qiskit.execute(__A   , __A   , shots=1   , seed_simulator=__A	)
    # Returns the result of measurement.
    _lowerCamelCase     :		Optional[Any] 						=						job.result().get_counts(__A	).most_frequent()

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

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


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

    testmod()





from math import log

from scipy.constants import Boltzmann, physical_constants

lowerCAmelCase			:							List[Any]     =300  # TEMPERATURE (unit = K)







def 						A__  (					__A   , __A   , __A   , ):







    '''simple docstring'''

    if donor_conc <= 0:
        raise ValueError("""Donor concentration should be positive"""	)
    elif acceptor_conc <= 0:
        raise ValueError("""Acceptor concentration should be positive"""	)
    elif intrinsic_conc <= 0:
        raise ValueError("""Intrinsic concentration should be positive"""	)
    elif donor_conc <= intrinsic_conc:
        raise ValueError(
            """Donor concentration should be greater than intrinsic concentration"""	)
    elif acceptor_conc <= intrinsic_conc:
        raise ValueError(
            """Acceptor concentration should be greater than intrinsic concentration"""	)
    else:
        return (
            Boltzmann
            * T
            * log((donor_conc * acceptor_conc) / intrinsic_conc**2	)
            / physical_constants["electron volt"][0]
        )


if __name__ == "__main__":
    import doctest

    doctest.testmod()




