def test_set_mapping(): d = QUBO({('a', 'b'): 1, ('a', ): 2}) d.set_mapping({'a': 0, 'b': 2}) assert d.to_qubo() == {(0, 2): 1, (0, ): 2} d = QUBO({('a', 'b'): 1, ('a', ): 2}) d.set_reverse_mapping({0: 'a', 2: 'b'}) assert d.to_qubo() == {(0, 2): 1, (0, ): 2}
def test_properties(): temp = QUBO({('0', '0'): 1, ('0', 1): 2}) assert not temp.offset d = QUBO() d[(0, )] += 1 d[(1, )] += 2 assert d == d.to_qubo() == {(0, ): 1, (1, ): 2} assert d.mapping == d.reverse_mapping == {0: 0, 1: 1} d.set_mapping({1: 0, 0: 1}) assert d.to_qubo() == {(1, ): 1, (0, ): 2} assert d.mapping == d.reverse_mapping == {0: 1, 1: 0}
def test_properties(): temp = QUBO({('0', '0'): 1, ('0', 1): 2}) assert not temp.offset d = QUBO() d[(0, )] += 1 d[(1, )] += 2 assert d == d.to_qubo() == {(0, ): 1, (1, ): 2} assert d.mapping == d.reverse_mapping == {0: 0, 1: 1} d.set_mapping({1: 0, 0: 1}) assert d.to_qubo() == {(1, ): 1, (0, ): 2} assert d.mapping == d.reverse_mapping == {0: 1, 1: 0} # an old bug d = QUBO() d.set_mapping({0: 0}) d[(0, )] += 1 assert d.num_binary_variables == 1 assert d.variables == {0}
def test_to_enumerated(): d = QUBO({('a', 'b'): 1, ('a', ): 2}) dt = d.to_enumerated() assert type(dt) == QUBOMatrix assert dt == d.to_qubo()