Legacy API Migration Guide¶
This chapter maps every construct from the original Irene API (SDPRelaxations,
Mom(), Probability=False, etc.) to the modern Irene pipeline
(OptimizationProblem + RelaxationEngine).
The legacy API remains available for backward compatibility — existing code will continue to run. However, new development should use the modern pipeline for its unified configuration, reduction pipeline integration, and consistent result types.
Problem Construction¶
Objective and Constraints¶
from sympy import symbols
x, y, z = symbols('x y z')
Rlx = SDPRelaxations([x, y, z])
Rlx.SetObjective(-2*x + y - z)
Rlx.AddConstraint(x + y + z <= 4)
Rlx.AddConstraint(x >= 0)
from Irene.grouprings import CommutativeSemigroup, SemigroupAlgebra
from Irene.program import OptimizationProblem
sg = CommutativeSemigroup(['x', 'y', 'z'])
sga = SemigroupAlgebra(sg)
x, y, z = sga['x'], sga['y'], sga['z']
prog = OptimizationProblem(sga)
prog.set_objective(-2*x + y - z)
prog.add_constraint(x + y + z <= 4)
prog.add_constraint(x >= 0)
Moment Constraints¶
Legacy API |
Modern API |
|---|---|
|
|
|
|
Solver Selection and Solving¶
Legacy API |
Modern API |
|---|---|
|
|
|
Automatic on |
|
|
|
|
|
Result object attributes — see |
Probability and Moment Settings¶
Legacy API |
Modern API |
|---|---|
|
Configured through |
|
Always True in modern API (PSD constraint is always enforced) |
|
Configured through solver-specific tolerance parameters (see CVXPY Solver Layer) |
SOS Decomposition¶
Rlx.Minimize()
V = Rlx.Decompose()
# V = {0: [a01, a02, ...], 1: [a11, ...], ...}
sos = expand(Rlx.ReduceExp(sum([p**2 for p in V[0]])))
result = engine.solve('sos')
# result.certificate contains the SOS decomposition
# result.certificate = {'f_sos': ..., 'f_sonc': ...}
Solution Extraction¶
Legacy API |
Modern API |
|---|---|
|
|
|
Configured through solver backend options |
|
|
Complete Example: Legacy vs Modern¶
from sympy import symbols
from Irene import SDPRelaxations, Mom
x, y, z = symbols('x y z')
Rlx = SDPRelaxations([x, y, z])
Rlx.SetObjective(-2*x + y - z)
Rlx.AddConstraint(24 - 20*x + 9*y - 13*z + 4*x**2
- 4*x*y + 4*x*z + 2*y**2 - 2*y*z + 2*z**2 >= 0)
Rlx.AddConstraint(x + y + z <= 4)
Rlx.AddConstraint(3*y + z <= 6)
Rlx.MomentsOrd(3)
Rlx.SetSDPSolver('dsdp')
Rlx.InitSDP()
Rlx.Minimize()
print(Rlx.Solution)
from Irene.grouprings import CommutativeSemigroup, SemigroupAlgebra
from Irene.program import OptimizationProblem
from Irene.relaxation_api import RelaxationEngine
from Irene.relaxations import RelaxationConfig
sg = CommutativeSemigroup(['x', 'y', 'z'])
sga = SemigroupAlgebra(sg)
x, y, z = sga['x'], sga['y'], sga['z']
prog = OptimizationProblem(sga)
prog.set_objective(-2*x + y - z)
prog.add_constraint(24 - 20*x + 9*y - 13*z + 4*x**2
- 4*x*y + 4*x*z + 2*y**2 - 2*y*z + 2*z**2 >= 0)
prog.add_constraint(x + y + z <= 4)
prog.add_constraint(3*y + z <= 6)
prog.add_constraint(x >= 0)
prog.add_constraint(x <= 2)
prog.add_constraint(y >= 0)
prog.add_constraint(z >= 0)
prog.add_constraint(z <= 3)
config = RelaxationConfig(
reduction_method="newton_polytope",
monomial_pruning=True,
)
engine = RelaxationEngine(prog, order=3, solver='dsdp', config=config)
result = engine.solve('sos')
print(f"Lower bound: {result.value:.8f}")
print(f"Status: {result.status}")