Пример #1
0
    def test_retrieve_active_jobs(self, provider):
        """Test retrieving jobs that are currently unfinished."""
        backend = most_busy_backend(provider)
        active_job_statuses = {
            api_status_to_job_status(status)
            for status in ApiJobStatus if status not in API_JOB_FINAL_STATES
        }

        qobj = bell_in_qobj(backend=backend)
        job = backend.run(qobj, validate_qobj=True)

        active_jobs = backend.active_jobs()
        if not job.in_final_state():
            # Assert `job_id` in the list of job id's (instead of the list of jobs),
            # because retrieved jobs might differ in attributes from the originally
            # submitted jobs or they might have changed status.
            self.assertIn(
                job.job_id(),
                [active_job.job_id() for active_job in active_jobs],
                "job {} is active but not retrieved when filtering for active jobs."
                .format(job.job_id()))

        for active_job in active_jobs:
            self.assertTrue(
                active_job._status in active_job_statuses,
                "status for job {} is '{}' but it should be '{}'.".format(
                    active_job.job_id(), active_job._status,
                    active_job_statuses))

        # Cancel job so it doesn't consume more resources.
        cancel_job(job)
Пример #2
0
    def test_retrieve_active_jobs(self):
        """Test retrieving jobs that are currently unfinished."""
        backend = most_busy_backend(self.provider)
        active_job_statuses = {
            api_status_to_job_status(status)
            for status in ApiJobStatus if status not in API_JOB_FINAL_STATES
        }

        qobj = bell_in_qobj(backend=backend)
        job = backend.run(qobj, validate_qobj=True)

        active_jobs = backend.active_jobs()
        if not job.in_final_state():  # Job is still active.
            self.assertIn(job.job_id(),
                          [active_job.job_id() for active_job in active_jobs])

        for active_job in active_jobs:
            self.assertTrue(
                active_job._status in active_job_statuses,
                "status for job {} is '{}' but it should be '{}'.".format(
                    active_job.job_id(), active_job._status,
                    active_job_statuses))

        # Cancel job so it doesn't consume more resources.
        cancel_job(job)