def test_set_mapping(): d = PUBO({('a', 'b'): 1, ('a', ): 2}) d.set_mapping({'a': 0, 'b': 2}) assert d.to_pubo() == {(0, 2): 1, (0, ): 2} d = PUBO({('a', 'b'): 1, ('a', ): 2}) d.set_reverse_mapping({0: 'a', 2: 'b'}) assert d.to_pubo() == {(0, 2): 1, (0, ): 2}
def test_pubo_on_qubo(): problem = PUBO({ ('a',): -1, ('b',): 2, ('a', 'b'): -3, ('b', 'c'): -4, (): -2 }) solution = {'c': 1, 'b': 1, 'a': 1} obj = -8 with assert_raises(ValueError): problem.to_pubo(deg=1) Problem(problem, solution, obj).runtests()
def test_to_enumerated(): d = PUBO({('a', 'b'): 1, ('a',): 2}) dt = d.to_enumerated() assert type(dt) == PUBOMatrix assert dt == d.to_pubo()