Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ disable=no-self-use, # disabled as it is too verbose
missing-yield-doc, # in coroutines, these checks can yield false
missing-yield-type-doc, # positives (pun intended)
import-outside-toplevel,
docstring-first-line-empty
docstring-first-line-empty,
R1732


[REPORTS]
Expand Down
31 changes: 26 additions & 5 deletions qiskit_ionq/ionq_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import dateutil.parser
from qiskit.providers import BackendV1 as Backend
from qiskit.providers.models import BackendConfiguration
from qiskit.providers.models.backendstatus import BackendStatus
from qiskit.providers import Options

from . import exceptions, ionq_client, ionq_job
Expand Down Expand Up @@ -175,13 +176,27 @@ def create_client(self):
def run(self, circuit, **kwargs):
"""Create and run a job on an IonQ Backend.

.. NOTE::

IonQ backends do not support multi-experiment jobs.
If ``circuit`` is provided as a list with more than one element
then this method will raise out with a RuntimeError.

Args:
circuit (:class:`QuantumCircuit <qiskit.circuit.QuantumCircuit>`):
A Qiskit QuantumCircuit object.

Returns:
IonQJob: A reference to the job that was submitted.

Raises:
RuntimeError: If a multi-experiment circuit was provided.
"""
if isinstance(circuit, (list, tuple)):
if len(circuit) > 1:
raise RuntimeError("Multi-experiment jobs are not supported!")
circuit = circuit[0]

for kwarg in kwargs:
if not hasattr(self.options, kwarg):
warnings.warn(
Expand All @@ -206,18 +221,24 @@ def retrieve_job(self, job_id):
return ionq_job.IonQJob(self, job_id, self.client)

def retrieve_jobs(self, job_ids):
"""get a list of jobs from a specific backend, job id """
"""get a list of jobs from a specific backend, job id"""

return [ionq_job.IonQJob(self, job_id, self.client) for job_id in job_ids]

# TODO: Implement backend status checks.
def status(self):
"""Not yet implemented.
"""Return a backend status object to the caller.

Raises:
NotImplementedError: This behavior is not currently supported.
Returns:
BackendStatus: the status of the backend.
"""
raise NotImplementedError("Backend status check is not supported.")
return BackendStatus(
backend_name=self.name(),
backend_version="1",
operational=True,
pending_jobs=0,
status_msg="",
)

def calibration(self):
"""Fetch the most recent calibration data for this backend.
Expand Down
47 changes: 39 additions & 8 deletions test/ionq_backend/test_base_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@

import pytest
from qiskit import QuantumCircuit
from qiskit.providers.models.backendstatus import BackendStatus

from qiskit_ionq import exceptions, ionq_client, ionq_job

from .. import conftest


def test_status_not_implemented(mock_backend):
"""Test that by default, `status` is not implemented.
def test_status_dummy_response(mock_backend):
"""Test that the IonQBackend returns an aribtrary backend status.

Args:
mock_backend (MockBackend): A fake/mock IonQBackend.
"""

with pytest.raises(NotImplementedError) as exc_info:
mock_backend.status()

assert str(exc_info.value) == "Backend status check is not supported."
status = mock_backend.status()
assert isinstance(status, BackendStatus)
assert status.operational is True


def test_client_property(mock_backend):
Expand Down Expand Up @@ -128,7 +127,7 @@ def test_create_client_exceptions(mock_backend, creds, msg):


def test_run(mock_backend, requests_mock):
"""Test that the backend `run` submits a job and returns that job.
"""Test that the backend `run` submits a circuit and returns its job.

Args:
mock_backend (MockBackend): A fake/mock IonQBackend.
Expand All @@ -145,3 +144,35 @@ def test_run(mock_backend, requests_mock):

assert isinstance(job, ionq_job.IonQJob)
assert job.job_id() == "fake_job"


def test_run_single_element_list(mock_backend, requests_mock):
"""Test that the backend `run` submits a circuit in a single-element list.

Args:
mock_backend (MockBackend): A fake/mock IonQBackend.
requests_mock (:class:`request_mock.Mocker`): A requests mocker.
"""
path = mock_backend.client.make_path("jobs")
dummy_response = conftest.dummy_job_response("fake_job")

# Mock the call to submit:
requests_mock.post(path, json=dummy_response, status_code=200)

# Run a dummy circuit.
job = mock_backend.run([QuantumCircuit(1, 1)])

assert isinstance(job, ionq_job.IonQJob)
assert job.job_id() == "fake_job"


def test_run_raises_multiexp_job(mock_backend):
"""Test that the backend `run` raises out if more than one circuit is provided.

Args:
mock_backend (MockBackend): A fake/mock IonQBackend.
"""
# Run a dummy circuit.
with pytest.raises(RuntimeError) as excinfo:
mock_backend.run([QuantumCircuit(1, 1), QuantumCircuit(1, 1)])
assert str(excinfo.value) == "Multi-experiment jobs are not supported!"