Function Reference¶
SdpRelaxation Class¶
- class ncpol2sdpa.SdpRelaxation(variables, nonrelaxed=None, verbose=0, hierarchy='npa', normalized=True)¶
Class for obtaining sparse SDP relaxation.
Parameters: - variables (list of sympy.physics.quantum.operator.Operator or sympy.physics.quantum.operator.HermitianOperator or a list of list.) – Commutative or noncommutative, Hermitian or nonhermiatian variables, possibly a list of list of variables if the hierarchy is not NPA.
- nonrelaxed (list of sympy.physics.quantum.operator.Operator or sympy.physics.quantum.operator.HermitianOperator or a list of list.) – Optional variables which are not to be relaxed.
- verbose (int.) –
Optional parameter for level of verbosity:
- 0: quiet
- 1: verbose
- 2: debug level
- hierarchy (str.) –
Optional parameter for defining the type of hierarchy (default: “npa”):
- “npa”: the standard NPA hierarchy (doi:10.1137/090760155). When the variables are commutative, this formulation is identical to the Lasserre hierarchy.
- “npa_chordal”: chordal graph extension to improve sparsity (doi:10.1137/050623802)
- “nieto-silleras”: doi:10.1088/1367-2630/16/1/013035
- “moroder”: doi:10.1103/PhysRevLett.111.030501
- normalized (bool.) – Optional parameter for changing the normalization of states over which the optimization happens. Turn it off if further processing is done on the SDP matrix before solving it.
- get_relaxation(level, objective=None, inequalities=None, equalities=None, substitutions=None, bounds=None, removeequalities=False, extramonomials=None, nsextraobjvars=None)¶
Get the SDP relaxation of a noncommutative polynomial optimization problem.
Parameters: - level (int.) – The level of the relaxation
- obj (sympy.core.exp.Expr.) – Optional parameter to describe the objective function.
- inequalities (list of sympy.core.exp.Expr.) – Optional parameter to list inequality constraints.
- equalities (list of sympy.core.exp.Expr.) – Optional parameter to list equality constraints.
- substitutions (dict of sympy.core.exp.Expr.) – Optional parameter containing monomials that can be replaced (e.g., idempotent variables).
- bounds (list of sympy.core.exp.Expr.) – Optional parameter of bounds on variables which will not be relaxed by localizing matrices.
- removeequalities (bool.) – Optional parameter to attempt removing the equalities by solving the linear equations.
- extramonomials (list of sympy.core.exp.Expr.) – Optional paramter of monomials to be included, on top of the requested level of relaxation.
- nsextraobjvars (list of float.) – Optional parameter of the coefficients of unnormalized top left elements of the moment matrices of the Nieto-Silleras hierarchy that should be included in the objective function.
- set_objective(objective, nsextraobjvars=None)¶
Set or change the objective function of the polynomial optimization problem.
Parameters: - objective (sympy.core.expr.Expr) – Describes the objective function.
- nsextraobjvars (list of float.) – Optional parameter of the coefficients of unnormalized top left elements of the moment matrices of the Nieto-Silleras hierarchy that should be included in the objective function.
Functions to Work with SDPA, PICOS, and MOSEK¶
- ncpol2sdpa.solve_sdp(sdpRelaxation, solverexecutable='sdpa')¶
Helper function to write out the SDP problem to a temporary file, call the solver, and parse the output.
Parameters: - sdpRelaxation (ncpol2sdpa.SdpRelaxation.) – The SDP relaxation to be solved.
- solverexecutable (str.) – Optional paramater to specify the name of the executable if sdpa is not in the path or has a different name.
Returns: tuple of float – the primal and dual solution of the SDP, respectively.
- ncpol2sdpa.write_to_sdpa(sdpRelaxation, filename)¶
Write the SDP relaxation to SDPA format.
Parameters: - sdpRelaxation (ncpol2sdpa.SdpRelaxation.) – The SDP relaxation to write.
- filename (str.) – The name of the file. It must have the suffix ”.dat-s”
- ncpol2sdpa.convert_to_mosek(sdpRelaxation)¶
Convert an SDP relaxation to a MOSEK task.
Parameters: sdpRelaxation (ncpol2sdpa.SdpRelaxation.) – The SDP relaxation to convert. Returns: mosek.Task.
- ncpol2sdpa.convert_to_picos(sdpRelaxation)¶
Convert an SDP relaxation to a PICOS problem.
Parameters: sdpRelaxation (ncpol2sdpa.SdpRelaxation.) – The SDP relaxation to convert. Returns: picos.Problem.
Functions to Help Define Polynomial Optimization Problems¶
- ncpol2sdpa.generate_variables(n_vars, hermitian=False, commutative=False, name='x')¶
Generates a number of commutative or noncommutative variables
Parameters: n_vars (int.) – The number of variables. Returns: list of sympy.physics.quantum.operator.Operator or sympy.physics.quantum.operator.HermitianOperator variables
- ncpol2sdpa.get_ncmonomials(variables, degree)¶
Generates all noncommutative monomials up to a degree
Parameters: - variables (list of sympy.physics.quantum.operator.Operator or sympy.physics.quantum.operator.) – The noncommutative variables to generate monomials from
- degree (int.) – The maximum degree.
Returns: list of monomials.
- ncpol2sdpa.ncdegree(polynomial)¶
Returns the degree of a noncommutative polynomial.
Parameters: polynomial (sympy.core.expr.Expr.) – Polynomial of noncommutive variables. Returns: int – the degree of the polynomial.
- ncpol2sdpa.flatten(lol)¶
Flatten a list of lists to a list.
Parameters: lol (list of list.) – A list of lists in arbitrary depth. Returns: flat list of elements.
Functions to Define Physics Problems¶
- ncpol2sdpa.bosonic_constraints(a)¶
Return a set of constraints that define bosonic ladder operators.
Parameters: a (list of sympy.physics.quantum.operator.Operator.) – The non-Hermitian variables. Returns: tuple of dict of substitutions and list of equalities.
- ncpol2sdpa.fermionic_constraints(a)¶
Return a set of constraints that define fermionic ladder operators.
Parameters: a (list of sympy.physics.quantum.operator.Operator.) – The non-Hermitian variables. Returns: tuple of dict of substitutions and list of equalities and inequalities.
- ncpol2sdpa.pauli_constraints(X, Y, Z)¶
Return a set of constraints that define Pauli spin operators.
Parameters: - X (list of sympy.physics.quantum.operator.HermitianOperator.) – List of Pauli X operator on sites.
- Y (list of sympy.physics.quantum.operator.HermitianOperator.) – List of Pauli Y operator on sites.
- Z (list of sympy.physics.quantum.operator.HermitianOperator.) – List of Pauli Z operator on sites.
Returns: tuple of substitutions and equalities.
- ncpol2sdpa.get_neighbors(index, lattice_length, width=0, periodic=False)¶
Get the neighbors of an operator in a lattice.
Parameters: - index (int.) – Linear index of operator.
- lattice_length (int.) – The size of the 2D lattice in either dimension
- width (int.) – Optional parameter to define width.
- periodic (bool) – Optional parameter to indicate periodic boundary conditions.
Returns: list of int – the neighbors in linear index.
- ncpol2sdpa.correlator(A, B)¶
Correlators between the probabilities of two parties.
Parameters: - A (list of list of sympy.physics.quantum.operator.HermitianOperator.) – Measurements of Alice.
- B (list of list of sympy.physics.quantum.operator.HermitianOperator.) – Measurements of Bob.
Returns: list of correlators.
- ncpol2sdpa.generate_measurements(party, label)¶
Generate variables that behave like measurements.
Parameters: - party (list of int.) – The list of number of measurement outputs a party has.
- label (str.) – The label to be given to the symbolic variables.
Returns: list of list of sympy.physics.quantum.operator.HermitianOperator.
- ncpol2sdpa.projective_measurement_constraints(*parties)¶
Return a set of constraints that define projective measurements.
Parameters: parties – Measurements of different parties. Returns: substitutions containing idempotency, orthogonality and commutation relations.
- ncpol2sdpa.maximum_violation(A_configuration, B_configuration, I, level)¶
Get the maximum violation of a Bell inequality.
Parameters: - A_configuration (list of int.) – Measurement settings of Alice.
- B_configuration (list of int.) – Measurement settings of Bob.
- I (list of list of int.) – The I matrix of a Bell inequality in the Collins-Gisin notation.
- level (int.) – Level of relaxation.
Returns: tuple of primal and dual solutions of the SDP relaxation.
- ncpol2sdpa.define_objective_with_I(I, A, B)¶
Define a polynomial using measurements and an I matrix describing a Bell inequality.
Parameters: - I (list of list of int.) – The I matrix of a Bell inequality in the Collins-Gisin notation.
- A (list of list of sympy.physics.quantum.operator.HermitianOperator.) – Measurements of Alice.
- B (list of list of sympy.physics.quantum.operator.HermitianOperator.) – Measurements of Bob.
Returns: sympy.core.expr.Expr – the objective function to be solved by SDPA as minimization problem to find the maximum quantum violation.