def find_solution_ranks(sdp, xmat=None, baselevel=<NUM_LIT:0>):
if sdp.status == "<STR_LIT>" and xmat is None:<EOL><INDENT>raise Exception("<STR_LIT>" +<EOL>"<STR_LIT>")<EOL><DEDENT>elif sdp.status != "<STR_LIT>" and xmat is None:<EOL><INDENT>xmat = sdp.x_mat[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>xmat = sdp.x_mat[<NUM_LIT:0>]<EOL><DEDENT>if sdp.status == "<STR_LIT>":<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>ranks = []<EOL>from numpy.linalg import matrix_rank<EOL>if baselevel == <NUM_LIT:0>:<EOL><INDENT>levels = range(<NUM_LIT:1>, sdp.level + <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>levels = [baselevel]<EOL><DEDENT>for level in levels:<EOL><INDENT>base_monomials =pick_monomials_up_to_degree(sdp.monomial_sets[<NUM_LIT:0>], level)<EOL>ranks.append(matrix_rank(xmat[:len(base_monomials),<EOL>:len(base_monomials)]))<EOL><DEDENT>if xmat.shape != (len(base_monomials), len(base_monomials)):<EOL><INDENT>ranks.append(matrix_rank(xmat))<EOL><DEDENT>return ranks<EOL>
Helper function to detect rank loop in the solution matrix.

    :param sdp: The SDP relaxation.
    :type sdp: :class:`ncpol2sdpa.sdp`.
    :param x_mat: Optional parameter providing the primal solution of the
                  moment matrix. If not provided, the solution is extracted
                  from the sdp object.
    :type x_mat: :class:`numpy.array`.
    :param base_level: Optional parameter for specifying the lower level
                       relaxation for which the rank loop should be tested
                       against.
    :type base_level: int.
    :returns: list of int -- the ranks of the solution matrix with in the
              order of increasing degree.