async def __test_upload_problem(
            self,
            count: int,
            terms_thresh: int,
            size_thresh: int,
            compress: bool,
            problem_type: ProblemType = ProblemType.ising,
            initial_terms: List[Term] = [],
            **kwargs):
        if not (self.in_recording or self.is_live):
            # Temporarily disabling this test in playback mode
            # due to multiple calls to the storage API
            # that need to have a request id to distinguish
            # them while playing back
            print("Skipping this test in playback mode")
            return

        ws = self.create_async_workspace()

        sProblem = await StreamingProblem.create(ws,
                                                 name="test",
                                                 problem_type=problem_type,
                                                 terms=initial_terms)
        rProblem = Problem("test",
                           problem_type=problem_type,
                           terms=initial_terms)
        sProblem.upload_terms_threshold = terms_thresh
        sProblem.upload_size_threshold = size_thresh
        sProblem.compress = compress

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

        self.assertEqual(problem_type, sProblem.problem_type)
        self.assertEqual(problem_type.name, sProblem.stats["type"])
        self.assertEqual(count + len(initial_terms),
                         sProblem.stats["num_terms"])
        self.assertEqual(
            self.__kwarg_or_value(kwargs, "avg_coupling", 2),
            sProblem.stats["avg_coupling"],
        )
        self.assertEqual(
            self.__kwarg_or_value(kwargs, "max_coupling", 2),
            sProblem.stats["max_coupling"],
        )
        self.assertEqual(
            self.__kwarg_or_value(kwargs, "min_coupling", 2),
            sProblem.stats["min_coupling"],
        )

        uri = await sProblem.upload(ws)
        data = await sProblem.download()
        uploaded = json.loads(data.serialize())
        local = json.loads(rProblem.serialize())
        self.assertEqual(uploaded, local)
Пример #2
0
    def test_problem_large(self):
        problem = Problem(name="test", terms=[], problem_type=ProblemType.pubo)
        self.assertTrue(not problem.is_large())

        problem.add_term(5.0, [])
        self.assertTrue(not problem.is_large())

        problem.add_term(6.0, list(range(3000)))
        self.assertTrue(not problem.is_large())

        problem.add_terms([Term(indices=[9999], c=1.0)] *
                          int(1e6))  # create 1mil dummy terms
        self.assertTrue(problem.is_large())
Пример #3
0
    def test_add_terms_cterms(self):
        problem = Problem(name="test")
        count = 4

        for i in range(count):
            problem.add_term(c=i, indices=[i, i + 1])
        self.assertEqual(ProblemType.ising, problem.problem_type)
        self.assertEqual(count, len(problem.terms))
        self.assertEqual(Term(c=1, indices=[1, 2]), problem.terms[1])

        more = []
        for i in range(count + 1):
            more.append(Term(c=i, indices=[i, i - 1]))
        problem.add_terms(more)
        self.assertEqual((count * 2) + 1, len(problem.terms))
        self.assertEqual(Term(c=count, indices=[count, count - 1]),
                         problem.terms[count * 2])