def test_functional(self): cqm = CQM() bqm = BQM({'a': -1}, {'ab': 1}, 1.5, 'SPIN') cqm.add_constraint(bqm, '<=') cqm.add_constraint(bqm, '>=') cqm.set_objective(BQM({'c': -1}, {}, 'SPIN')) cqm.add_constraint(Spin('a')*Integer('d')*5 <= 3) new = CQM.from_file(cqm.to_file()) self.assertTrue(cqm.objective.is_equal(new.objective)) self.assertEqual(set(cqm.constraints), set(new.constraints)) for label, constraint in cqm.constraints.items(): self.assertTrue(constraint.lhs.is_equal(new.constraints[label].lhs)) self.assertEqual(constraint.rhs, new.constraints[label].rhs) self.assertEqual(constraint.sense, new.constraints[label].sense)
def test_functional_empty(self): new = CQM.from_file(CQM().to_file())