Exemplo n.º 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)
Exemplo n.º 2
0
    def test_SimulatedAnnealing_input_params(self):
        ws = self.create_workspace()

        good = SimulatedAnnealing(ws, timeout=1011, seed=4321)
        self.assertIsNotNone(good)
        self.assertEqual(
            "microsoft.simulatedannealing-parameterfree.cpu", good.target
        )
        self.assertEqual(
            {"timeout": 1011, "seed": 4321}, good.params["params"]
        )

        good = SimulatedAnnealing(
            ws, timeout=1011, seed=4321, platform=HardwarePlatform.FPGA
        )
        self.assertIsNotNone(good)
        self.assertEqual(
            "microsoft.simulatedannealing-parameterfree.fpga", good.target
        )
        self.assertEqual(
            {"timeout": 1011, "seed": 4321}, good.params["params"]
        )

        good = SimulatedAnnealing(ws, beta_start=21)
        self.assertIsNotNone(good)
        self.assertEqual("microsoft.simulatedannealing.cpu", good.target)
        self.assertEqual({"beta_start": 21}, good.params["params"])

        good = SimulatedAnnealing(
            ws, beta_start=21, platform=HardwarePlatform.FPGA
        )
        self.assertIsNotNone(good)
        self.assertEqual("microsoft.simulatedannealing.fpga", good.target)
        self.assertEqual({"beta_start": 21}, good.params["params"])
Exemplo n.º 3
0
    def test_input_params(self):
        ws = _init_ws_()

        s2_params = SimulatedAnnealing(ws).params
        self.assertEqual({ }, s2_params["params"])

        s2_params = SimulatedAnnealing(ws, timeout=1010).params
        self.assertEqual({ "timeout": 1010 }, s2_params["params"])

        p3_params = ParallelTempering(ws, sweeps=2024, all_betas=[3, 4, 5]).params
        self.assertEqual({ "all_betas": [3, 4, 5], "replicas": 3, "sweeps": 2024 }, p3_params["params"])
        
        s3_params = SimulatedAnnealing(ws, beta_start=3.2, sweeps=12).params
        self.assertEqual({ "beta_start": 3.2, "sweeps": 12 }, s3_params["params"])
Exemplo n.º 4
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()
Exemplo n.º 5
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())
Exemplo n.º 6
0
    def test_available_solvers(self):
        ws = self.create_workspace()

        self.assertIsNotNone(SimulatedAnnealing(ws))
        self.assertIsNotNone(ParallelTempering(ws))
Exemplo n.º 7
0
    def test_available_solvers(self):
        ws = _init_ws_()

        self.assertIsNotNone(SimulatedAnnealing(ws))
        self.assertIsNotNone(ParallelTempering(ws))