Skip to content

Commit 037e374

Browse files
committed
Uniformize solver output status between LP and SDP
1 parent 30fad11 commit 037e374

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

inflation/sdp/InflationSDP.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ def solve(self,
824824
self.solution_object = solveSDP_MosekFUSION(**args)
825825

826826
self.status = self.solution_object["status"]
827-
if self.status == "feasible":
827+
if self.status == "optimal":
828828
self.success = True
829829
self.primal_objective = self.solution_object["primal_value"]
830830
self.objective_value = self.solution_object["primal_value"]

inflation/sdp/sdp_utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,14 @@ def constraint_dicts_to_sparse(constraints: List[dict]) -> (coo_array, coo_array
462462

463463
status = M.getProblemStatus()
464464
if status == ProblemStatus.PrimalAndDualFeasible:
465-
status_str = "feasible"
465+
status_str = "optimal"
466466
primal = M.primalObjValue()
467467
dual = M.dualObjValue()
468468

469-
elif status in [ProblemStatus.DualInfeasible,
470-
ProblemStatus.PrimalInfeasible]:
471-
status_str = "infeasible"
469+
elif status == ProblemStatus.DualInfeasible:
470+
status_str = "dual_infeas_cer"
471+
elif status == ProblemStatus.PrimalInfeasible:
472+
status_str = "primal_infeas_cer",
472473
elif status == ProblemStatus.Unknown:
473474
status_str = "unknown"
474475
code, desc = mosek.Env.getcodedesc(
@@ -495,11 +496,11 @@ def constraint_dicts_to_sparse(constraints: List[dict]) -> (coo_array, coo_array
495496
return {"status": status_str, "error": error_message}
496497
except Exception as e:
497498
status_str = "other"
498-
error_message = "Unexpected error: {0}".format(e)
499+
error_message = f"Unexpected error: {e}"
499500
print(error_message)
500501
return {"status": status_str, "error": error_message}
501502

502-
if status_str in ["feasible", "infeasible"]:
503+
if status_str in ["optimal", "primal_infeas_cer", "dual_infeas_cer"]:
503504
certificate = {x: 0 for x in known_vars}
504505

505506
# c0(P(a...|x...))
@@ -533,7 +534,7 @@ def constraint_dicts_to_sparse(constraints: List[dict]) -> (coo_array, coo_array
533534
del certificate[x]
534535

535536
# For debugging purposes
536-
if status_str == "feasible" and verbose > 1:
537+
if status_str == "optimal" and verbose > 1:
537538
TOL = 1e-8 # Constraint tolerance
538539
if var_inequalities:
539540
x = A.todense() \

test/test_pipeline.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def test_GHZ_commuting(self):
452452

453453
sdp.set_distribution(self.GHZ(0.5 + 1e-2))
454454
sdp.solve()
455-
self.assertEqual(sdp.status, "infeasible",
455+
self.assertEqual(sdp.status, "dual_infeas_cer",
456456
"The commuting SDP is not identifying incompatible " +
457457
"distributions.")
458458
lp_fanout = InflationLP(self.cutInflation_c)
@@ -473,7 +473,7 @@ def test_GHZ_commuting(self):
473473
"is not identifying incompatible distributions.")
474474
sdp.set_distribution(self.GHZ(0.5 - 1e-2))
475475
sdp.solve()
476-
self.assertEqual(sdp.status, "feasible",
476+
self.assertEqual(sdp.status, "optimal",
477477
"The commuting SDP is not recognizing compatible " +
478478
"distributions.")
479479
lp_fanout.set_distribution(self.GHZ(0.5 - 1e-2))
@@ -506,7 +506,7 @@ def test_GHZ_NC(self):
506506
(0.5+1e-2) / 2 + (0.5-1e-2) / 8),
507507
"Setting the distribution is failing.")
508508
sdp.solve()
509-
self.assertTrue(sdp.status in ["infeasible", "unknown"],
509+
self.assertTrue(sdp.status in ["dual_infeas_cer", "unknown"],
510510
"The non-commuting SDP is not identifying " +
511511
"incompatible distributions.")
512512
sdp.solve(feas_as_optim=True)
@@ -518,7 +518,7 @@ def test_GHZ_NC(self):
518518
(0.5-1e-2) / 2 + (0.5+1e-2) / 8),
519519
"Re-setting the distribution is failing.")
520520
sdp.solve()
521-
self.assertEqual(sdp.status, "feasible",
521+
self.assertEqual(sdp.status, "optimal",
522522
"The non-commuting SDP is not recognizing " +
523523
"compatible distributions.")
524524
sdp.solve(feas_as_optim=True)
@@ -531,20 +531,20 @@ def test_instrumental(self):
531531
sdp.generate_relaxation("local1")
532532
sdp.set_distribution(self.incompatible_dist)
533533
sdp.solve(feas_as_optim=False)
534-
self.assertEqual(sdp.status, "infeasible",
534+
self.assertEqual(sdp.status, "dual_infeas_cer",
535535
"Failing to detect the infeasibility of the " +
536536
"distribution that maximally violates Bonet's " +
537537
"inequalty.")
538538
unnormalized_dist = np.ones((2, 2, 3, 1), dtype=float)
539539
sdp.set_distribution(unnormalized_dist)
540540
sdp.solve(feas_as_optim=False)
541-
self.assertEqual(sdp.status, "infeasible",
541+
self.assertEqual(sdp.status, "dual_infeas_cer",
542542
"Failing to detect the infeasibility of an " +
543543
"distribution that violates normalization.")
544544
compat_dist = unnormalized_dist / 4
545545
sdp.set_distribution(compat_dist)
546546
sdp.solve(feas_as_optim=False)
547-
self.assertEqual(sdp.status, "feasible",
547+
self.assertEqual(sdp.status, "optimal",
548548
"A feasible distribution for the instrumental " +
549549
"scenario is not being recognized as such.")
550550

@@ -615,13 +615,13 @@ def test_supports(self):
615615
pr_support[a, b, x, y] = np.random.randn()
616616
sdp.set_distribution(pr_support)
617617
sdp.solve(feas_as_optim=False)
618-
self.assertEqual(sdp.status, "infeasible",
618+
self.assertEqual(sdp.status, "dual_infeas_cer",
619619
"Failing to detect the infeasibility of a support "
620620
+ "known to be incompatible.")
621621
compatible_support = np.ones((2, 2, 2, 2), dtype=float)
622622
sdp.set_distribution(compatible_support)
623623
sdp.solve(feas_as_optim=False)
624-
self.assertEqual(sdp.status, "feasible",
624+
self.assertEqual(sdp.status, "optimal",
625625
"A feasible support for the Bell scenario is not " +
626626
"being recognized as such.")
627627

0 commit comments

Comments
 (0)