def get_relaxation(self, level, objective=None, inequalities=None,<EOL>equalities=None, substitutions=None,<EOL>momentinequalities=None, momentequalities=None,<EOL>momentsubstitutions=None,<EOL>removeequalities=False, extramonomials=None,<EOL>extramomentmatrices=None, extraobjexpr=None,<EOL>localizing_monomials=None, chordal_extension=False):
if self.level < -<NUM_LIT:1>:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>self.level = level<EOL>if substitutions is None:<EOL><INDENT>self.substitutions = {}<EOL><DEDENT>else:<EOL><INDENT>self.substitutions = substitutions<EOL>for lhs, rhs in substitutions.items():<EOL><INDENT>if not is_pure_substitution_rule(lhs, rhs):<EOL><INDENT>self.pure_substitution_rules = False<EOL><DEDENT>if iscomplex(lhs) or iscomplex(rhs):<EOL><INDENT>self.complex_matrix = True<EOL><DEDENT><DEDENT><DEDENT>if momentsubstitutions is not None:<EOL><INDENT>self.moment_substitutions = momentsubstitutions.copy()<EOL>if not self.complex_matrix:<EOL><INDENT>for key, val in self.moment_substitutions.copy().items():<EOL><INDENT>adjoint_monomial = apply_substitutions(key.adjoint(),<EOL>self.substitutions)<EOL>self.moment_substitutions[adjoint_monomial] = val<EOL><DEDENT><DEDENT><DEDENT>if chordal_extension:<EOL><INDENT>self.variables = find_variable_cliques(self.variables, objective,<EOL>inequalities, equalities,<EOL>momentinequalities,<EOL>momentequalities)<EOL><DEDENT>self.__generate_monomial_sets(extramonomials)<EOL>self.localizing_monomial_sets = localizing_monomials<EOL>self._calculate_block_structure(inequalities, equalities,<EOL>momentinequalities, momentequalities,<EOL>extramomentmatrices,<EOL>removeequalities)<EOL>self._estimate_n_vars()<EOL>if extramomentmatrices is not None:<EOL><INDENT>for parameters in extramomentmatrices:<EOL><INDENT>copy = False<EOL>for parameter in parameters:<EOL><INDENT>if parameter == "<STR_LIT>":<EOL><INDENT>copy = True<EOL><DEDENT><DEDENT>if copy:<EOL><INDENT>self.n_vars += self.n_vars + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>self.n_vars += (self.block_struct[<NUM_LIT:0>]**<NUM_LIT:2>)/<NUM_LIT:2><EOL><DEDENT><DEDENT><DEDENT>if self.complex_matrix:<EOL><INDENT>dtype = np.complex128<EOL><DEDENT>else:<EOL><INDENT>dtype = np.float64<EOL><DEDENT>self.F = lil_matrix((sum([bs**<NUM_LIT:2> for bs in self.block_struct]),<EOL>self.n_vars + <NUM_LIT:1>), dtype=dtype)<EOL>if self.verbose > <NUM_LIT:0>:<EOL><INDENT>print(('<STR_LIT>' % self.n_vars))<EOL>print('<STR_LIT>')<EOL><DEDENT>new_n_vars, block_index = self.__add_parameters()<EOL>self._time0 = time.time()<EOL>new_n_vars, block_index =self._generate_all_moment_matrix_blocks(new_n_vars, block_index)<EOL>if extramomentmatrices is not None:<EOL><INDENT>new_n_vars, block_index =self.__add_extra_momentmatrices(extramomentmatrices,<EOL>new_n_vars, block_index)<EOL><DEDENT>self.n_vars = new_n_vars<EOL>if self.verbose > <NUM_LIT:0>:<EOL><INDENT>print(('<STR_LIT>' % self.n_vars))<EOL><DEDENT>self.set_objective(objective, extraobjexpr)<EOL>self.constraint_starting_block = block_index<EOL>self.process_constraints(inequalities, equalities, momentinequalities,<EOL>momentequalities, block_index,<EOL>removeequalities)<EOL>
Get the SDP relaxation of a noncommutative polynomial optimization
        problem.

        :param level: The level of the relaxation. The value -1 will skip
                      automatic monomial generation and use only the monomials
                      supplied by the option `extramonomials`.
        :type level: int.
        :param obj: Optional parameter to describe the objective function.
        :type obj: :class:`sympy.core.exp.Expr`.
        :param inequalities: Optional parameter to list inequality constraints.
        :type inequalities: list of :class:`sympy.core.exp.Expr`.
        :param equalities: Optional parameter to list equality constraints.
        :type equalities: list of :class:`sympy.core.exp.Expr`.
        :param substitutions: Optional parameter containing monomials that can
                              be replaced (e.g., idempotent variables).
        :type substitutions: dict of :class:`sympy.core.exp.Expr`.
        :param momentinequalities: Optional parameter of inequalities defined
                                   on moments.
        :type momentinequalities: list of :class:`sympy.core.exp.Expr`.
        :param momentequalities: Optional parameter of equalities defined
                                 on moments.
        :type momentequalities: list of :class:`sympy.core.exp.Expr`.
        :param momentsubstitutions: Optional parameter containing moments that
                                    can be replaced.
        :type momentsubstitutions: dict of :class:`sympy.core.exp.Expr`.
        :param removeequalities: Optional parameter to attempt removing the
                                 equalities by solving the linear equations.
        :type removeequalities: bool.
        :param extramonomials: Optional paramter of monomials to be included,
                               on top of the requested level of relaxation.
        :type extramonomials: list of :class:`sympy.core.exp.Expr`.
        :param extramomentmatrices: Optional paramter of duplicating or adding
                               moment matrices.  A new moment matrix can be
                               unconstrained (""), a copy  of the first one
                               ("copy"), and satisfying a partial positivity
                               constraint ("ppt"). Each new moment matrix is
                               requested as a list of string of these options.
                               For instance, adding a single new moment matrix
                               as a copy of the first would be
                               ``extramomentmatrices=[["copy"]]``.
        :type extramomentmatrices: list of list of str.
        :param extraobjexpr: Optional parameter of a string expression of a
                             linear combination of moment matrix elements to be
                             included in the objective function.
        :type extraobjexpr: str.
        :param localizing_monomials: Optional parameter to specify sets of
                                     localizing monomials for each constraint.
                                     The internal order of constraints is
                                     inequalities first, followed by the
                                     equalities. If the parameter is specified,
                                     but for a certain constraint the automatic
                                     localization is requested, leave None in
                                     its place in this parameter.
        :type localizing_monomials: list of list of `sympy.core.exp.Expr`.
        :param chordal_extension: Optional parameter to request a sparse
                                  chordal extension.
        :type chordal_extension: bool.