Exemple #1
0
    def test_job_get_results(self):
        ws = self.create_workspace()

        problem = Problem(name="test")
        count = 4

        for i in range(count):
            problem.add_term(c=i, indices=[i, i + 1])

        with unittest.mock.patch.object(Job,
                                        self.mock_create_job_id_name,
                                        return_value=self.get_dummy_job_id()):
            solver = SimulatedAnnealing(ws)
            job = solver.submit(problem)
            actual = job.get_results()

        expected = {
            'version': '1.0',
            'configuration': {
                '0': 1,
                '1': 1,
                '2': -1,
                '3': 1,
                '4': -1
            },
            'cost': -6.0,
            'parameters': {
                'beta_start': 0.2,
                'beta_stop': 1.9307236000000003,
                'restarts': 360,
                'sweeps': 50
            }
        }

        self.assertEqual(expected, actual)
Exemple #2
0
    def test_job_refresh(self):
        ws = self.create_workspace()

        problem = Problem(name="test")
        count = 4

        for i in range(count):
            problem.add_term(c=i, indices=[i, i + 1])

        with unittest.mock.patch.object(Job,
                                        self.mock_create_job_id_name,
                                        return_value=self.get_dummy_job_id()):
            solver = SimulatedAnnealing(ws)
            job = solver.submit(problem)
            job.refresh()
Exemple #3
0
    def test_job_wait_unit_completed(self):
        ws = self.create_workspace()

        problem = Problem(name="test")
        count = 4

        for i in range(count):
            problem.add_term(c=i, indices=[i, i + 1])

        with unittest.mock.patch.object(Job,
                                        self.mock_create_job_id_name,
                                        return_value=self.get_dummy_job_id()):
            solver = SimulatedAnnealing(ws)
            job = solver.submit(problem)
            job.wait_until_completed()
            self.assertEqual(True, job.has_completed())