def convert_to_picos(sdp, duplicate_moment_matrix=False):
import picos as pic<EOL>import cvxopt as cvx<EOL>P = pic.Problem(verbose=sdp.verbose)<EOL>block_size = sdp.block_struct[<NUM_LIT:0>]<EOL>if sdp.F.dtype == np.float64:<EOL><INDENT>X = P.add_variable('<STR_LIT:X>', (block_size, block_size), vtype="<STR_LIT>")<EOL>if duplicate_moment_matrix:<EOL><INDENT>Y = P.add_variable('<STR_LIT:Y>', (block_size, block_size), vtype="<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>X = P.add_variable('<STR_LIT:X>', (block_size, block_size), vtype="<STR_LIT>")<EOL>if duplicate_moment_matrix:<EOL><INDENT>Y = P.add_variable('<STR_LIT:X>', (block_size, block_size), vtype="<STR_LIT>")<EOL><DEDENT><DEDENT>row_offset = <NUM_LIT:0><EOL>theoretical_n_vars = sdp.block_struct[<NUM_LIT:0>]**<NUM_LIT:2><EOL>eq_block_start = sdp.constraint_starting_block+sdp._n_inequalities<EOL>block_idx = <NUM_LIT:0><EOL>while (block_idx < len(sdp.block_struct)):<EOL><INDENT>block_size = sdp.block_struct[block_idx]<EOL>x, Ix, Jx = [], [], []<EOL>c, Ic, Jc = [], [], []<EOL>for i, row in enumerate(sdp.F.rows[row_offset:row_offset +<EOL>block_size**<NUM_LIT:2>]):<EOL><INDENT>for j, column in enumerate(row):<EOL><INDENT>if column > <NUM_LIT:0>:<EOL><INDENT>x.append(sdp.F.data[row_offset+i][j])<EOL>Ix.append(i)<EOL>Jx.append(column-<NUM_LIT:1>)<EOL>i0 = (i//block_size)+(i % block_size)*block_size<EOL>if i != i0:<EOL><INDENT>x.append(sdp.F.data[row_offset+i][j])<EOL>Ix.append(i0)<EOL>Jx.append(column-<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>c.append(sdp.F.data[row_offset+i][j])<EOL>Ic.append(i%block_size)<EOL>Jc.append(i//block_size)<EOL><DEDENT><DEDENT><DEDENT>permutation = cvx.spmatrix(x, Ix, Jx, (block_size**<NUM_LIT:2>,<EOL>theoretical_n_vars))<EOL>constant = cvx.spmatrix(c, Ic, Jc, (block_size, block_size))<EOL>if duplicate_moment_matrix:<EOL><INDENT>constraint = X<EOL><DEDENT>else:<EOL><INDENT>constraint = X.copy()<EOL><DEDENT>for k in constraint.factors:<EOL><INDENT>constraint.factors[k] = permutation<EOL><DEDENT>constraint._size = (block_size, block_size)<EOL>if block_idx < eq_block_start:<EOL><INDENT>P.add_constraint(constant + constraint >> <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>P.add_constraint(constant + constraint == <NUM_LIT:0>)<EOL>row_offset += block_size**<NUM_LIT:2><EOL>block_idx += <NUM_LIT:1><EOL><DEDENT>if duplicate_moment_matrix andblock_size == sdp.block_struct[<NUM_LIT:0>]:<EOL><INDENT>for k in Y.factors:<EOL><INDENT>Y.factors[k] = permutation<EOL><DEDENT><DEDENT>row_offset += block_size**<NUM_LIT:2><EOL>block_idx += <NUM_LIT:1><EOL><DEDENT>if len(np.nonzero(sdp.obj_facvar)[<NUM_LIT:0>]) > <NUM_LIT:0>:<EOL><INDENT>x, Ix, Jx = [], [], []<EOL>for k, val in enumerate(sdp.obj_facvar):<EOL><INDENT>if val != <NUM_LIT:0>:<EOL><INDENT>x.append(val)<EOL>Ix.append(<NUM_LIT:0>)<EOL>Jx.append(k)<EOL><DEDENT><DEDENT>permutation = cvx.spmatrix(x, Ix, Jx)<EOL>objective = X.copy()<EOL>for k in objective.factors:<EOL><INDENT>objective.factors[k] = permutation<EOL><DEDENT>objective._size = (<NUM_LIT:1>, <NUM_LIT:1>)<EOL>P.set_objective('<STR_LIT>', objective)<EOL><DEDENT>return P<EOL>
Convert an SDP relaxation to a PICOS problem such that the exported
    .dat-s file is extremely sparse, there is not penalty imposed in terms of
    SDP variables or number of constraints. This conversion can be used for
    imposing extra constraints on the moment matrix, such as partial transpose.

    :param sdp: The SDP relaxation to convert.
    :type sdp: :class:`ncpol2sdpa.sdp`.
    :param duplicate_moment_matrix: Optional parameter to add an unconstrained
                                    moment matrix to the problem with the same
                                    structure as the moment matrix with the PSD
                                    constraint.
    :type duplicate_moment_matrix: bool.

    :returns: :class:`picos.Problem`.