write_to_sdpa function fixed