Exemple #1
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=FakeQobj(), validate_qobj=True)
     self._current_qjob.refresh = mock.Mock()
     return self._current_qjob
 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_client=api)
     self._current_api = api
     self._current_qjob = backend.run(qobj=FakeQobj())  # pylint: disable=no-value-for-parameter
     self._current_qjob.refresh = mock.Mock()
     return self._current_qjob
Exemple #3
0
    def test_wait_for_final_state_timeout(self):
        """Test timeout waiting for job to reach a final state."""
        job_id = str(uuid.uuid4())
        backend = FakeRueschlikon()
        with mocked_executor() as (BasicAerJob, executor):
            job = BasicAerJob(backend, job_id, lambda: None, FakeQobj())
            job.submit()

        mocked_future = executor.submit.return_value
        mocked_future.running.return_value = True
        mocked_future.cancelled.return_value = False
        mocked_future.done.return_value = False
        self.assertRaises(JobTimeoutError,
                          job.wait_for_final_state,
                          timeout=0.5)
Exemple #4
0
    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, FakeQobj())
            job.submit()
            job.cancel()

        self.assertCalledOnce(executor.submit)
        mocked_future = executor.submit.return_value
        self.assertCalledOnce(mocked_future.cancel)
Exemple #5
0
    def test_wait_for_final_state(self):
        """Test waiting for job to reach a final state."""
        def _job_call_back(c_job_id, c_job_status, c_job):
            """Job status query callback function."""
            self.assertEqual(c_job_id, job_id)
            self.assertEqual(c_job_status, JobStatus.RUNNING)
            self.assertEqual(c_job, job)
            mocked_future.running.return_value = False
            mocked_future.done.return_value = True

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

        mocked_future = executor.submit.return_value
        mocked_future.running.return_value = True
        mocked_future.cancelled.return_value = False
        mocked_future.done.return_value = False
        job.wait_for_final_state(callback=_job_call_back)
Exemple #6
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()
        with mocked_executor() as (SimulatorJob, executor):
            for index in range(taskcount):
                job = SimulatorJob(backend, job_id, target_tasks[index],
                                   FakeQobj())
                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)