Skip to content

Commit

Permalink
Add Q-CTRL integration tests (#1173)
Browse files Browse the repository at this point in the history
* add initial qctrl test file

* add test & decorator

* add tests from Mirko

* Added assertness for preciseness of results

* remove print statements

* move into e2e folder

* setup ci

* Update q-ctrl-tests.yml

* add account test

* add more account tests

* Update test/qctrl/test_qctrl.py

Co-authored-by: Rathish Cholarajan <rathishc24@gmail.com>

* address comments

* update date to 2023

* Update test/qctrl/test_qctrl.py

Co-authored-by: Blake Johnson <blakejohnson04@gmail.com>

* Update test/qctrl/test_qctrl.py

Co-authored-by: Blake Johnson <blakejohnson04@gmail.com>

---------

Co-authored-by: merav-aharoni <merav@il.ibm.com>
Co-authored-by: Rathish Cholarajan <rathishc24@gmail.com>
Co-authored-by: Blake Johnson <blakejohnson04@gmail.com>
  • Loading branch information
4 people authored Dec 20, 2023
1 parent 86c41e0 commit e57edb3
Show file tree
Hide file tree
Showing 4 changed files with 477 additions and 3 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/q-ctrl-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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.

name: Q-CTRL Tests
on:
push:
tags:
- "*"
workflow_dispatch:
jobs:
integration-tests:
name: Run integration tests - ${{ matrix.environment }}
runs-on: ${{ matrix.os }}
strategy:
# avoid cancellation of in-progress jobs if any matrix job fails
fail-fast: false
matrix:
python-version: [ 3.9 ]
os: [ "ubuntu-latest" ]
environment: [ "ibm-cloud-staging" ]
environment: ${{ matrix.environment }}
env:
QISKIT_IBM_TOKEN: ${{ secrets.QISKIT_IBM_TOKEN_QCTRL }}
QISKIT_IBM_URL: ${{ secrets.QISKIT_IBM_URL }}
QISKIT_IBM_INSTANCE: ${{ secrets.QISKIT_IBM_INSTANCE_QCTRL }}
CHANNEL_STRATEGY: q-ctrl
LOG_LEVEL: DEBUG
STREAM_LOG: True
QISKIT_IN_PARALLEL: True
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install -c constraints.txt -r requirements-dev.txt
- name: Run q-ctrl tests
run: python -m unittest test/qctrl/test_qctrl.py
10 changes: 7 additions & 3 deletions test/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ def _wrapper(self, *args, **kwargs):


def _get_integration_test_config():
token, url, instance = (
token, url, instance, channel_strategy = (
os.getenv("QISKIT_IBM_TOKEN"),
os.getenv("QISKIT_IBM_URL"),
os.getenv("QISKIT_IBM_INSTANCE"),
os.getenv("CHANNEL_STRATEGY"),
)
channel: Any = "ibm_quantum" if url.find("quantum-computing.ibm.com") >= 0 else "ibm_cloud"
return channel, token, url, instance
return channel, token, url, instance, channel_strategy


def run_integration_test(func):
Expand Down Expand Up @@ -115,7 +116,7 @@ def _wrapper(self, *args, **kwargs):
["ibm_cloud", "ibm_quantum"] if supported_channel is None else supported_channel
)

channel, token, url, instance = _get_integration_test_config()
channel, token, url, instance, channel_strategy = _get_integration_test_config()
if not all([channel, token, url]):
raise Exception("Configuration Issue") # pylint: disable=broad-exception-raised

Expand All @@ -131,13 +132,15 @@ def _wrapper(self, *args, **kwargs):
channel=channel,
token=token,
url=url,
channel_strategy=channel_strategy,
)
dependencies = IntegrationTestDependencies(
channel=channel,
token=token,
url=url,
instance=instance,
service=service,
channel_strategy=channel_strategy,
)
kwargs["dependencies"] = dependencies
func(self, *args, **kwargs)
Expand All @@ -156,6 +159,7 @@ class IntegrationTestDependencies:
token: str
channel: str
url: str
channel_strategy: str


def integration_test_setup_with_backend(
Expand Down
23 changes: 23 additions & 0 deletions test/integration/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
get_resource_controller_api_url,
get_iam_api_url,
)
from qiskit_ibm_runtime.exceptions import IBMNotAuthorizedError
from ..ibm_test_case import IBMIntegrationTestCase
from ..decorators import IntegrationTestDependencies

Expand Down Expand Up @@ -51,6 +52,28 @@ def _skip_on_ibm_quantum(self):
if self.dependencies.channel == "ibm_quantum":
self.skipTest("Not supported on ibm_quantum")

def test_channel_strategy(self):
"""Test passing in a channel strategy."""
self._skip_on_ibm_quantum()
# test when channel strategy not supported by instance
with self.assertRaises(IBMNotAuthorizedError):
QiskitRuntimeService(
channel="ibm_cloud",
url=self.dependencies.url,
token=self.dependencies.token,
instance=self.dependencies.instance,
channel_strategy="q-ctrl",
)
# test passing in default
service = QiskitRuntimeService(
channel="ibm_cloud",
url=self.dependencies.url,
token=self.dependencies.token,
instance=self.dependencies.instance,
channel_strategy="default",
)
self.assertTrue(service)

def test_resolve_crn_for_valid_service_instance_name(self):
"""Verify if CRN is transparently resolved based for an existing service instance name."""
self._skip_on_ibm_quantum()
Expand Down
Loading

0 comments on commit e57edb3

Please sign in to comment.