
'''simple docstring'''



import pytest

import datasets


# Import fixture modules as plugins
_lowercase    =		["""tests.fixtures.files""", """tests.fixtures.hub""", """tests.fixtures.fsspec"""]


def A				(__lowerCamelCase				:Dict			,     __lowerCamelCase				:Tuple		):
						# Mark tests as "unit" by default if not marked as "integration" (or already marked as "unit")
						for item in items:
												if any(marker in item.keywords for marker in ["""integration""", """unit"""]		):
																		continue
												item.add_marker(pytest.mark.unit		)


def A				(__lowerCamelCase				:Optional[int]		):
						config.addinivalue_line("""markers"""			,     """torchaudio_latest: mark test to run with torchaudio>=0.12"""		)


@pytest.fixture(autouse=__lowerCamelCase		)
def A				(__lowerCamelCase				:Optional[Any]			,     __lowerCamelCase				:List[Any]		):
						# test_hf_cache_home = tmp_path_factory.mktemp("cache")  # TODO: why a cache dir per test function does not work?
						_lowerCAmelCase  						=			tmp_path_factory.getbasetemp() / """cache"""
						_lowerCAmelCase  						=			test_hf_cache_home / """datasets"""
						_lowerCAmelCase  						=			test_hf_cache_home / """metrics"""
						_lowerCAmelCase  						=			test_hf_cache_home / """modules"""
						monkeypatch.setattr("""datasets.config.HF_DATASETS_CACHE"""			,     str(__lowerCamelCase		)		)
						monkeypatch.setattr("""datasets.config.HF_METRICS_CACHE"""			,     str(__lowerCamelCase		)		)
						monkeypatch.setattr("""datasets.config.HF_MODULES_CACHE"""			,     str(__lowerCamelCase		)		)
						_lowerCAmelCase  						=			test_hf_datasets_cache / """downloads"""
						monkeypatch.setattr("""datasets.config.DOWNLOADED_DATASETS_PATH"""			,     str(__lowerCamelCase		)		)
						_lowerCAmelCase  						=			test_hf_datasets_cache / """downloads""" / """extracted"""
						monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_PATH"""			,     str(__lowerCamelCase		)		)


@pytest.fixture(autouse=__lowerCamelCase			,     scope="""session"""		)
def A				():
						datasets.disable_progress_bar()


@pytest.fixture(autouse=__lowerCamelCase		)
def A				(__lowerCamelCase				:List[str]		):
						# don't take tests into account when counting downloads
						monkeypatch.setattr("""datasets.config.HF_UPDATE_DOWNLOAD_COUNTS"""			,     __lowerCamelCase		)





@pytest.fixture
def A				(__lowerCamelCase				:Union[str, Any]		):
						# Required to suppress RemovedIn20Warning when feature(s) are not compatible with SQLAlchemy 2.0
						# To be removed once SQLAlchemy 2.0 supported
						monkeypatch.setattr("""sqlalchemy.util.deprecations.SILENCE_UBER_WARNING"""			,     __lowerCamelCase		)


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