Skip to content

Commit

Permalink
Create batch class (#1183)
Browse files Browse the repository at this point in the history
* Create batch class

* add simple reno and test
  • Loading branch information
kt474 authored Nov 2, 2023
1 parent c15763a commit a8dc25d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions qiskit_ibm_runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def result_callback(job_id, result):
from .runtime_options import RuntimeOptions
from .utils.json import RuntimeEncoder, RuntimeDecoder
from .session import Session # pylint: disable=cyclic-import
from .batch import Batch # pylint: disable=cyclic-import

from .exceptions import *
from .utils.utils import setup_logger
Expand Down
21 changes: 21 additions & 0 deletions qiskit_ibm_runtime/batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Qiskit Runtime batch mode."""

from .session import Session


class Batch(Session):
"""Class for creating a batch mode in Qiskit Runtime."""

pass
6 changes: 6 additions & 0 deletions releasenotes/notes/batch-class-b7a3befcfce8860e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
There is a new class, :class:`qiskit_ibm_runtime.Batch` that currently works
the same way as :class:`qiskit_ibm_runtime.Session` but will later be updated
to better support submitting multiple jobs at once.
35 changes: 35 additions & 0 deletions test/unit/test_batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Tests for Batch class."""

from unittest.mock import patch

from qiskit_ibm_runtime import Batch
import qiskit_ibm_runtime.session as session_pkg
from ..ibm_test_case import IBMTestCase


class TestBatch(IBMTestCase):
"""Class for testing the Session class."""

def tearDown(self) -> None:
super().tearDown()
session_pkg._DEFAULT_SESSION.set(None)

@patch("qiskit_ibm_runtime.session.QiskitRuntimeService", autospec=True)
def test_default_batch(self, mock_service):
"""Test using default batch mode."""
mock_service.global_service = None
batch = Batch(backend="ibm_gotham")
self.assertIsNotNone(batch.service)
mock_service.assert_called_once()

0 comments on commit a8dc25d

Please sign in to comment.