Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Garcia committed Apr 9, 2020
1 parent 5cf56c9 commit 764ab6c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 69 deletions.
6 changes: 3 additions & 3 deletions test/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ def _wrapper(*args, **kwargs):
qe_token = kwargs.pop('qe_token')
qe_url = kwargs.pop('qe_url')

# Get the public provider.
# Get the open access project public provider.
public_provider = ibmq_factory.enable_account(qe_token, qe_url)
# Get the premium provider.
# Get a premium provider.
premium_provider = _get_custom_provider(ibmq_factory)

if premium_provider is None:
raise SkipTest('Requires both a public and premium provider.')
raise SkipTest('Requires both the public and premium provider.')

kwargs.update({
'providers': {'public_provider': public_provider,
Expand Down
112 changes: 46 additions & 66 deletions test/ibmq/test_basic_server_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@

"""Tests that hit all the basic server endpoints using both a public and premium provider."""

from datetime import datetime, timedelta

from qiskit.compiler import assemble, transpile
from qiskit.providers.jobstatus import JobStatus
from qiskit.test import slow_test
from qiskit.test.reference_circuits import ReferenceCircuits

from qiskit.providers.ibmq import least_busy
from ..decorators import requires_providers
from ..ibmqtestcase import IBMQTestCase
from ..utils import most_busy_backend, cancel_job
from ..utils import cancel_job


class TestBasicServerPaths(IBMQTestCase):
Expand All @@ -38,11 +36,14 @@ def setUpClass(cls, providers):
cls._qc = ReferenceCircuits.bell()
cls.seed = 73846087

@slow_test
def test_job_submission(self):
"""Test submitting a job."""
"""Test running a job against a device."""
for _desc, provider in self.providers.items():
with self.subTest(provider=provider):
backend = least_busy(provider.backends())
backend = least_busy(provider.backends(
simulator=False, filters=lambda b: b.configuration().n_qubits >= 5))
provider_backend = {'provider': provider, 'backend': backend}
with self.subTest(provider_backend=provider_backend):
circuit = transpile(self._qc, backend, seed_transpiler=self.seed)
qobj = assemble(circuit, backend, shots=1)
job = backend.run(qobj, validate_qobj=True)
Expand All @@ -55,75 +56,54 @@ def test_job_submission(self):
qobj_downloaded = job.qobj()
self.assertEqual(qobj_downloaded, qobj.to_dict())

def test_job_status_and_properties(self):
"""Test the status and properties of a job."""
def test_job_backend_properties_and_status(self):
"""Test the backend properties and status of a job."""
for _desc, provider in self.providers.items():
with self.subTest(provider=provider):
backend = most_busy_backend(provider)
backend = provider.backends(
simulator=False, filters=lambda b: b.configuration().n_qubits >= 5)
provider_backend = {'provider': provider, 'backend': backend}
with self.subTest(provider_backend=provider_backend):
circuit = transpile(self._qc, backend, seed_transpiler=self.seed)
qobj = assemble(circuit, backend, shots=1)
job = backend.run(qobj, validate_qobj=True)

self.assertTrue(job.status())
self.assertIsNotNone(job.properties())
self.assertTrue(job.status())
cancel_job(job, verify=True)

def test_retrieving_jobs(self):
"""Test retrieving jobs with filters."""
"""Test retrieving jobs."""
backend_name = 'ibmq_qasm_simulator'
past_month = datetime.now() - timedelta(days=30)
past_month_str = past_month.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
db_filter = {
'backend.name': backend_name,
'status': {'regexp': '^ERROR'}
}
for _desc, provider in self.providers.items():
jobs = provider.backends.jobs(limit=5, end_datetime=past_month, db_filter=db_filter)
# Ensure the jobs match the filter.
for job in jobs:
job_id = job.job_id()
provider_job = {'provider': provider, 'job': job_id}
job_backend_name = job.backend().name()
with self.subTest(provider_job=provider_job):
self.assertEqual(job_backend_name, backend_name,
'Job {} backend name should be "{}", but it is "{}".'
.format(job_id, job_backend_name, backend_name))
self.assertEqual(job.status(), JobStatus.ERROR,
'Job {} status should be "{}", but it is "{}".'
.format(job_id, JobStatus.ERROR, job.status()))
self.assertTrue(job.creation_date() <= past_month_str,
'Job {} creation date "{}" is not less than '
'or equal to the past month "{}".'
.format(job_id, job.creation_date(), past_month_str))

def test_devices_properties_and_defaults(self):
"""Test the properties and defaults for devices."""
with self.subTest(provider=provider):
job_list = provider.backends.jobs(backend_name=backend_name, limit=5, skip=0)
self.assertTrue(job_list)

def test_device_properties_and_defaults(self):
"""Test the properties and defaults for an open pulse device."""
for _desc, provider in self.providers.items():
for backend in provider.backends():
provider_backend = {'provider': provider, 'backend': backend}
with self.subTest(provider_backend=provider_backend):
properties = backend.properties()
if backend.configuration().simulator:
self.assertIsNone(properties)
else:
self.assertIsNotNone(properties)

defaults = backend.defaults()
if backend.configuration().open_pulse:
self.assertIsNotNone(defaults)
else:
self.assertIsNone(defaults)

def test_devices_status_and_job_limit(self):
"""Test the status and job limit for devices."""
pulse_backends = provider.backends(open_pulse=True, operational=True)
if not pulse_backends:
raise self.skipTest('Skipping pulse test since no pulse backend '
'found for provider "{}"'.format(provider))

pulse_backend = pulse_backends[0]
provider_backend = {'provider': provider, 'backend': pulse_backend}
with self.subTest(provider_backend=provider_backend):
properties = pulse_backend.properties()
self.assertIsNotNone(properties)
defaults = pulse_backend.defaults()
self.assertIsNotNone(defaults)

def test_device_status_and_job_limit(self):
"""Test the status and job limit for a device."""
for desc, provider in self.providers.items():
for backend in provider.backends():
provider_backend = {'provider': provider, 'backend': backend}
with self.subTest(provider_backend=provider_backend):
status = backend.status()
self.assertTrue(status)
self.assertTrue(status.operational)
job_limit = backend.job_limit()
if desc == 'public_provider':
self.assertEqual(job_limit.maximum_jobs, 5)
self.assertTrue(job_limit)
backend = provider.backends(simulator=False)[0]
provider_backend = {'provider': provider, 'backend': backend}
with self.subTest(provider_backend=provider_backend):
status = backend.status()
self.assertTrue(status)
job_limit = backend.job_limit()
if desc == 'public_provider':
self.assertEqual(job_limit.maximum_jobs, 5)
self.assertTrue(job_limit)

0 comments on commit 764ab6c

Please sign in to comment.