Example #1
0
def test_qubo_solver_ising_interactions_from_qubo_is_symmetric():
    solver = BaseSolver()
    qubo = random_symmetric_matrix()
    solver.qubo = qubo.copy()
    solver.build_ising_interactions()
    ising = solver.ising_interactions.copy()
    assert check_symmetric(ising)
Example #2
0
def test_qubo_solver_qubo_from_ising_interactions_is_symmetric():
    solver = BaseSolver()
    ising = random_symmetric_matrix()
    solver.ising_interactions = ising.copy()
    solver.build_qubo()
    qubo = solver.qubo.copy()
    assert check_symmetric(qubo)
Example #3
0
def test_qubo_solver_ising_qubo_ising_reconstructs_original():
    solver = BaseSolver()
    ising = random_symmetric_matrix()
    solver.ising_interactions = ising.copy()
    solver.build_qubo()
    solver.build_ising_interactions()
    reconstructed_ising = solver.ising_interactions
    assert np.allclose(ising, reconstructed_ising)
Example #4
0
def test_hamiltonian_solver_response_is_spin():
    solver = QuboSolver(qubo=random_symmetric_matrix())

    def callback(result):
        assert not (result is None)
        assert ((result == 1) | (result == 0)).all()

    future = solver.solve(callback)
    assert (future.result().status_code == 200)
Example #5
0
def test_qubo_solver_response_is_binary():
    solver = QuboSolver(qubo=random_symmetric_matrix())

    def callback(result):
        assert not (result is None)
        assert (result >= 0).all() and (result <= 1).all()

    future = solver.solve(callback)
    assert (future.result().status_code == 200)
Example #6
0
    def test_can_calculate_qubo_energy(self):
        solver = QuboSolver(qubo=random_symmetric_matrix())

        def callback(result):
            e = solver.qubo_energy(result)
            print(e)
            # assert (e > 0)

        future = solver.solve(callback)
        response = future.result()
Example #7
0
    def test_can_calculate_hamiltonian_energy(self):
        solver = IsingHamiltonianSolver(
            ising_interactions=random_symmetric_matrix())

        def callback(result):
            e = solver.hamiltonian_energy(result)
            print(e)
            # assert (e > 0)

        future = solver.solve(callback)
        response = future.result()
Example #8
0
    def test_solver_solve_callback_called(self):
        solver = QuboSolver(qubo=random_symmetric_matrix())

        def callback(result):
            print(result)
            assert not (result is None)
            assert len(result) == solver.qubo.shape[0]

        def iterative_callback(q):
            print(solver.qubo_energy(spin_to_zero_one(q)))
            pass

        future = solver.solve(callback, endpoint=LocalEndpoint())
        # future = solver.solve(callback,endpoint=Endpoint(host="http://localhost:3001"))
        response = future.result()
Example #9
0
def test_simulated_annealer_annealing():
    annealer = SimulatedAnnealer(strategy=SingleSpinFlipStrategy(repetition=1))
    hamiltonian = random_symmetric_matrix(1000)
    annealer.callback = lambda q: print(hamiltonian_energy(q, hamiltonian))
    annealer.anneal(hamiltonian)
    assert annealer.q.shape[0] == hamiltonian.shape[0]
Example #10
0
def test_base_solver_build_qubo_with_ising_interactions():
    solver = BaseSolver()
    solver.ising_interactions = random_symmetric_matrix()
    callback = lambda result: None
    solver.solve(callback, endpoint=LocalEndpoint())
    assert solver.qubo.shape[0] > 0
Example #11
0
def test_ising_hamiltonian_solver():
    Jij = random_symmetric_matrix()
    solver = IsingHamiltonianSolver(ising_interactions=Jij)
    assert not (solver is None)
    assert solver.qubo.shape[0] == Jij.shape[0]
Example #12
0
def test_qubo_solver():
    qubo = random_symmetric_matrix()
    solver = QuboSolver(qubo=qubo)
    solver.build_ising_interactions()
    assert not (solver is None)
    assert solver.ising_interactions.shape[0] == qubo.shape[0]
Example #13
0
 def test_solver_solve_success(self):
     solver = QuboSolver()
     solver.ising_interactions = random_symmetric_matrix()
     callback = lambda result: None
     solver.build_qubo()
     solver.solve(callback)
Example #14
0
 def test_dispatch_success(self):
     endpoint = LocalEndpoint()
     solver = QuboSolver()
     solver.ising_interactions = random_symmetric_matrix()
     endpoint.dispatch(solver)