Exemple #1
0
 def run_with_api(self, api):
     """Creates a new ``IBMQJob`` running with the provided API object."""
     backend = FakeRueschlikon()
     self._current_api = api
     self._current_qjob = IBMQJob(backend, None, api, qobj=new_fake_qobj())
     self._current_qjob.submit()
     return self._current_qjob
Exemple #2
0
 def run_with_api(self, api):
     """Creates a new ``IBMQJob`` running with the provided API object."""
     backend = IBMQBackend(mock.Mock(), mock.Mock(), mock.Mock(), api=api)
     self._current_api = api
     self._current_qjob = backend.run(qobj=new_fake_qobj())
     self._current_qjob.refresh = mock.Mock()
     return self._current_qjob
Exemple #3
0
 def run_with_api(self, api, job_class=IBMQJobPreQobj):
     """Creates a new ``IBMQJobPreQobj`` instance running with the provided API
     object.
     """
     backend = FakeRueschlikon()
     self._current_api = api
     self._current_qjob = job_class(backend,
                                    None,
                                    api,
                                    False,
                                    qobj=new_fake_qobj())
     self._current_qjob.submit()
     return self._current_qjob
    def test_cancel(self):
        # Again, cancelling jobs is beyond our responsibility. In this test
        # we only check if we delegate on the proper method of the underlaying
        # future object.

        job_id = str(uuid.uuid4())
        backend = FakeRueschlikon()
        with mocked_executor() as (BasicAerJob, executor):
            job = BasicAerJob(backend, job_id, lambda: None, new_fake_qobj())
            job.submit()
            job.cancel()

        self.assertCalledOnce(executor.submit)
        mocked_future = executor.submit.return_value
        self.assertCalledOnce(mocked_future.cancel)
Exemple #5
0
    def test_multiple_execution(self):
        # Notice that it is Python responsibility to test the executors
        # can run several tasks at the same time. It is our responsibility to
        # use the executor correctly. That is what this test checks.

        taskcount = 10
        target_tasks = [lambda: None for _ in range(taskcount)]

        job_id = str(uuid.uuid4())
        backend = FakeRueschlikon()
        # pylint: disable=invalid-name,redefined-outer-name
        with mocked_executor() as (SimulatorJob, executor):
            for index in range(taskcount):
                job = SimulatorJob(backend, job_id, target_tasks[index], new_fake_qobj())
                job.submit()

        self.assertEqual(executor.submit.call_count, taskcount)
        for index in range(taskcount):
            _, callargs, _ = executor.submit.mock_calls[index]
            submitted_task = callargs[0]
            target_task = target_tasks[index]
            self.assertEqual(submitted_task, target_task)