MosekMonolithicSDP lifts a D=1 QcqpProblem into one positive-semidefinite matrix, solves it with the optional MOSEK Fusion backend, and recovers one QCQP vector per diagonal block.
QCQP vectors carry no homogenizing coordinate. Each PSD block is instead the lifted matrix of the keys it holds, with one constant entry; linear cost and constraint terms act on the lifted vector (row-0 slice).
import numpy as np
import gtsam
from gtsam.symbol_shorthand import XFormulation and lifecycle¶
For a QCQP with stacked vector , the relaxation replaces by one matrix . Quadratic costs and constraints become linear trace expressions in . The Python lifecycle is:
Construct
MosekMonolithicSDP(problem).Call
solve(mosek_params).Inspect
objectiveValue,problemStatus, andsolveTimeSeconds.Call the functional
qcqpValues()query and convert its matrix-valued result with the typed QCQP extraction helpers.Query
variableEVRs()independently when rank-one diagnostics are needed.
num_poses = 3
step = gtsam.Pose2(2.0, 0.0, 2.0 * np.pi / num_poses)
ground_truth = [gtsam.Pose2()]
for _ in range(1, num_poses):
ground_truth.append(ground_truth[-1].compose(step))
graph = gtsam.NonlinearFactorGraph()
graph.add(gtsam.FrobeniusPriorPose2(
X(0), ground_truth[0].matrix(), gtsam.noiseModel.Constrained.All(9)
))
for i in range(num_poses):
j = (i + 1) % num_poses
graph.add(gtsam.FrobeniusBetweenFactorPose2(
X(i), X(j), ground_truth[i].between(ground_truth[j])
))
problem = gtsam.QcqpProblem(graph)if not hasattr(gtsam, "MosekMonolithicSDP"):
print("This GTSAM build does not include the optional MOSEK backend.")
else:
solver = gtsam.MosekMonolithicSDP(problem)
if not solver.solve({"intpntCoTolRelGap": 1e-10}):
raise RuntimeError("MOSEK did not return a readable primal solution")
recovered = gtsam.extractQcqpValuesPose2(solver.qcqpValues())
errors = [
np.linalg.norm(ground_truth[i].localCoordinates(recovered.atPose2(X(i))))
for i in range(num_poses)
]
print("status:", solver.problemStatus())
print("objective:", solver.objectiveValue())
print("solve time (s):", solver.solveTimeSeconds())
print("ordered keys:", solver.orderedKeys())
print("ordered dimensions:", solver.orderedKeyDims())
print("eigenvalue ratios:", solver.variableEVRs())
print("maximum Pose2 error:", max(errors))status: ProblemStatus::PrimalAndDualFeasible
objective: 6.692513210282414e-11
solve time (s): 0.005703926086425781
ordered keys: [8646911284551352320, 8646911284551352321, 8646911284551352322]
ordered dimensions: {8646911284551352320: 6, 8646911284551352321: 6, 8646911284551352322: 6}
eigenvalue ratios: [1155389737259.924, 309355365080.9226, 154705479697.71225]
maximum Pose2 error: 5.832188596900567e-07
variableEVRs() reports the largest-to-second-largest eigenvalue ratio of each recovered diagonal block. A large ratio indicates a nearly rank-one block and makes vector recovery meaningful. This class is available in Python only when GTSAM is built with MOSEK.