def write_to_sdpa(sdp, filename):
<EOL>row_offsets = [<NUM_LIT:0>]<EOL>cumulative_sum = <NUM_LIT:0><EOL>for block_size in sdp.block_struct:<EOL><INDENT>cumulative_sum += block_size ** <NUM_LIT:2><EOL>row_offsets.append(cumulative_sum)<EOL><DEDENT>multiplier = <NUM_LIT:1><EOL>if sdp.F.dtype == np.complex128:<EOL><INDENT>multiplier = <NUM_LIT:2><EOL><DEDENT>lines = [[] for _ in range(multiplier*sdp.n_vars+<NUM_LIT:1>)]<EOL>for row in range(len(sdp.F.rows)):<EOL><INDENT>if len(sdp.F.rows[row]) > <NUM_LIT:0>:<EOL><INDENT>col_index = <NUM_LIT:0><EOL>block_index, i, j = convert_row_to_sdpa_index(sdp.block_struct,<EOL>row_offsets, row)<EOL>for k in sdp.F.rows[row]:<EOL><INDENT>value = sdp.F.data[row][col_index]<EOL>col_index += <NUM_LIT:1><EOL>if k == <NUM_LIT:0>:<EOL><INDENT>value *= -<NUM_LIT:1><EOL><DEDENT>if sdp.F.dtype == np.float64:<EOL><INDENT>lines[k].append('<STR_LIT>'.format(<EOL>block_index + <NUM_LIT:1>, i + <NUM_LIT:1>, j + <NUM_LIT:1>, value))<EOL><DEDENT>else:<EOL><INDENT>bs = sdp.block_struct[block_index]<EOL>if value.real != <NUM_LIT:0>:<EOL><INDENT>lines[k].append('<STR_LIT>'.format(<EOL>block_index + <NUM_LIT:1>, i + <NUM_LIT:1>, j + <NUM_LIT:1>, value.real))<EOL>lines[k].append('<STR_LIT>'.format(<EOL>block_index + <NUM_LIT:1>, i + bs + <NUM_LIT:1>, j + bs + <NUM_LIT:1>,<EOL>value.real))<EOL><DEDENT>if value.imag != <NUM_LIT:0>:<EOL><INDENT>lines[k + sdp.n_vars].append(<EOL>'<STR_LIT>'.format(<EOL>block_index + <NUM_LIT:1>, i + <NUM_LIT:1>, j + bs + <NUM_LIT:1>,<EOL>value.imag))<EOL>lines[k + sdp.n_vars].append(<EOL>'<STR_LIT>'.format(<EOL>block_index + <NUM_LIT:1>, j + <NUM_LIT:1>, i + bs + <NUM_LIT:1>,<EOL>-value.imag))<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>file_ = open(filename, '<STR_LIT:w>')<EOL>file_.write('<STR_LIT>' + filename + '<STR_LIT>')<EOL>file_.write(str(multiplier*sdp.n_vars) + '<STR_LIT>')<EOL>block_struct = [multiplier*blk_size<EOL>for blk_size in sdp.block_struct]<EOL>file_.write(str(len(block_struct)) + '<STR_LIT>')<EOL>file_.write(str(block_struct).replace('<STR_LIT:[>', '<STR_LIT:(>')<EOL>.replace('<STR_LIT:]>', '<STR_LIT:)>'))<EOL>file_.write('<STR_LIT>')<EOL>objective =str(list(sdp.obj_facvar)).replace('<STR_LIT:[>', '<STR_LIT>').replace('<STR_LIT:]>', '<STR_LIT>')<EOL>if multiplier == <NUM_LIT:2>:<EOL><INDENT>objective += '<STR_LIT:U+002CU+0020>' + objective<EOL><DEDENT>file_.write('<STR_LIT:{>'+objective+'<STR_LIT>')<EOL>for k, line in enumerate(lines):<EOL><INDENT>if line == []:<EOL><INDENT>continue<EOL><DEDENT>for item in line:<EOL><INDENT>file_.write('<STR_LIT>'.format(k)+item)<EOL><DEDENT><DEDENT>file_.close()<EOL>
Write the SDP relaxation to SDPA format.

    :param sdp: The SDP relaxation to write.
    :type sdp: :class:`ncpol2sdpa.sdp`.
    :param filename: The name of the file. It must have the suffix ".dat-s"
    :type filename: str.