


'''simple docstring'''



import numpy as np
import qiskit


def    lowerCamelCase__   ( A     :    int = 8   ,     A     :    int | None = None  ):




						'''simple docstring'''






						UpperCAmelCase         =			np.random.default_rng(seed=A  )

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

						# Quantum Circuit to simulate BB84
						UpperCAmelCase         =			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.
						UpperCAmelCase         =			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.
						UpperCAmelCase         =			qiskit.execute(A   ,     A   ,     shots=1   ,     seed_simulator=A  )
						# Returns the result of measurement.
						UpperCAmelCase         =			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.
						UpperCAmelCase         =			''''''.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.
						UpperCAmelCase         =			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()









'''simple docstring'''



# Copyright 2022 The HuggingFace Team and The OpenBMB Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


_lowercase    :    Any			     =  {
    """configuration_cpmant""": ["""CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """CpmAntConfig"""],
    """tokenization_cpmant""": ["""CpmAntTokenizer"""],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowercase    :    int			     =  [
	    """CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """CpmAntForCausalLM""",
	    """CpmAntModel""",
	    """CpmAntPreTrainedModel""",
	]


if TYPE_CHECKING:
	from .configuration_cpmant import CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP, CpmAntConfig
	from .tokenization_cpmant import CpmAntTokenizer

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_cpmant import (
		    CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    CpmAntForCausalLM,
		    CpmAntModel,
		    CpmAntPreTrainedModel,
		)


else:
	import sys

	_lowercase    :    Dict			     =  _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





