def inner_product(vec0: QubitVector, vec1: QubitVector) -> bk.BKTensor:
    """ Hilbert-Schmidt inner product between qubit vectors

    The tensor rank and qubits must match.
    """
    if vec0.rank != vec1.rank or vec0.qubit_nb != vec1.qubit_nb:
        raise ValueError('Incompatibly vectors. Qubits and rank must match')

    vec1 = vec1.permute(vec0.qubits)  # Make sure qubits in same order
    return bk.inner(vec0.tensor, vec1.tensor)