示例#1
0
def test_pubo_qubo_equal():

    random.seed(123)
    qubo = {(i, j): random.random() for i in range(7) for j in range(7)}
    qubo.update({(i, ): random.random() for i in range(7)})
    qubo[()] = random.random()
    for sol in itertools.product((0, 1), repeat=7):
        assert_allclose(pubo_value(sol, qubo), qubo_value(sol, qubo))
示例#2
0
def test_qubo_quso_equal():

    random.seed(815)
    qubo = {(i, j): random.random() for i in range(7) for j in range(7)}
    qubo.update({(i, ): random.random() for i in range(7)})
    qubo[()] = random.random()
    for sol in itertools.product((0, 1), repeat=7):
        assert_allclose(qubo_value(sol, qubo),
                        quso_value(boolean_to_spin(sol), qubo_to_quso(qubo)))
示例#3
0
def test_qubo_pubo_solve():

    e, sols = solve_pubo_bruteforce(problem.to_pubo())
    sol = problem.convert_solution(sols)
    assert problem.is_solution_valid(sol)
    assert problem.is_solution_valid(sols)
    assert sol == solution
    assert allclose(e, obj)

    assert (problem.value(sol) == qubo_value(sol, problem) == e)