





"""simple docstring"""



from __future__ import annotations

import numpy as np
from numpy import floataa
from numpy.typing import NDArray







def 		__lowercase					(       snake_case_  :  NDArray[floataa]    ,snake_case_  :  NDArray[floataa]    ,snake_case_  :  list[int]    ,snake_case_  :  int    ,)       ->list[float]:



    '''simple docstring'''







    __A			,	__A   :						List[Any]									=					coefficient_matrix.shape
    __A			,	__A   :						int									=					constant_matrix.shape

    if rowsa != colsa:
        __A   :						Union[str, Any]									=					F"""Coefficient matrix dimensions must be nxn but received {rowsa}x{colsa}"""
        raise ValueError(snake_case_						)

    if colsa != 1:
        __A   :						List[Any]									=					F"""Constant matrix must be nx1 but received {rowsa}x{colsa}"""
        raise ValueError(snake_case_						)

    if rowsa != rowsa:
        __A   :						Any									=					(
            '''Coefficient and constant matrices dimensions must be nxn and nx1 but '''
            F"""received {rowsa}x{colsa} and {rowsa}x{colsa}"""
        )
        raise ValueError(snake_case_						)

    if len(snake_case_						) != rowsa:
        __A   :						int									=					(
            '''Number of initial values must be equal to number of rows in coefficient '''
            F"""matrix but received {len(snake_case_						)} and {rowsa}"""
        )
        raise ValueError(snake_case_						)

    if iterations <= 0:
        raise ValueError('''Iterations must be at least 1'''						)

    __A   :						NDArray[floataa]									=					np.concatenate(
        (coefficient_matrix, constant_matrix)    ,axis=1						)

    __A			,	__A   :						Union[str, Any]									=					table.shape

    strictly_diagonally_dominant(snake_case_						)

    # Iterates the whole matrix for given number of times
    for _ in range(snake_case_						):
        __A   :						Union[str, Any]									=					[]
        for row in range(snake_case_						):
            __A   :						Optional[Any]									=					0
            for col in range(snake_case_						):
                if col == row:
                    __A   :						str									=					table[row][col]
                elif col == cols - 1:
                    __A   :						List[str]									=					table[row][col]
                else:
                    temp += (-1) * table[row][col] * init_val[col]
            __A   :						List[Any]									=					(temp + val) / denom
            new_val.append(snake_case_						)
        __A   :						List[str]									=					new_val

    return [float(snake_case_						) for i in new_val]







def 		__lowercase					(       snake_case_  :  NDArray[floataa]						)       ->bool:



    '''simple docstring'''







    __A			,	__A   :						Any									=					table.shape

    __A   :						Optional[int]									=					True

    for i in range(0    ,snake_case_						):
        __A   :						str									=					0
        for j in range(0    ,cols - 1						):
            if i == j:
                continue
            else:
                total += table[i][j]

        if table[i][i] <= total:
            raise ValueError('''Coefficient matrix is not strictly diagonally dominant'''						)

    return is_diagonally_dominant


# Test Cases
if __name__ == "__main__":
       import doctest

       doctest.testmod()











"""simple docstring"""



import numpy as np
import qiskit







def 		__lowercase					(       snake_case_  :  int = 8    ,snake_case_  :  int | None = None						)       ->str:



    '''simple docstring'''







    __A   :						str									=					np.random.default_rng(seed=snake_case_						)

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

    # Quantum Circuit to simulate BB84
    __A   :						Dict									=					qiskit.QuantumCircuit(snake_case_    ,name='''BB84'''						)

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

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

    bbaa_circ.barrier()
    bbaa_circ.measure_all()

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

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

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


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

       testmod()




