Skip to content

Commit

Permalink
Feature/base qcvv framework (#992)
Browse files Browse the repository at this point in the history
In preparation for the XEB/IRB benchmarking routines, this PR implements
some common functionality that can form the basis of a wide QCVV framework within
superstaq.
  • Loading branch information
cdbf1 authored Aug 13, 2024
1 parent 9f68cf5 commit ab0802d
Show file tree
Hide file tree
Showing 10 changed files with 1,642 additions and 2 deletions.
14 changes: 14 additions & 0 deletions cirq-superstaq/cirq_superstaq/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,20 @@ def __repr__(self) -> str:
def _value_equality_values_(self) -> tuple[str, dict[str, Any]]:
return self._job_id, self._job

def __getitem__(self, index: int) -> css.Job:
"""Args:
idx: The index of the sub-job to return. Each sub-job corresponds to the a single
circuit.
Returns:
A sub-job at the given index.
"""
job_id = self._job_id.split(",")[index]
sub_job = css.Job(self._client, job_id)
if job_id in self._job:
sub_job._job[job_id] = self._job[job_id]
return sub_job


def _get_marginal_counts(counts: dict[str, int], indices: Sequence[int]) -> dict[str, int]:
"""Compute a marginal distribution, accumulating total counts on specific bits (by index).
Expand Down
28 changes: 28 additions & 0 deletions cirq-superstaq/cirq_superstaq/job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ def new_job() -> css.Job:
return css.Job(client, "new_job_id")


@pytest.fixture
def multi_circuit_job() -> css.Job:
"""Fixture for a job with multiple circuits submitted
Returns:
A job with multiple subjobs
"""
client = gss.superstaq_client._SuperstaqClient(
client_name="cirq-superstaq",
remote_host="http://example.com",
api_key="to_my_heart",
)
job = css.Job(client, "job_id1,job_id2,job_id3")
job._job = {
"job_id1": {"status": "Done"},
"job_id2": {"status": "Running"},
"job_id3": {"status": "Submitted"},
}
return job


def _mocked_request_response(content: object) -> requests.Response:
response = requests.Response()
response.status_code = requests.codes.OK
Expand Down Expand Up @@ -452,6 +473,13 @@ def test_job_results_poll_failure(mock_sleep: mock.MagicMock, job: css.job.Job)
assert mock_sleep.call_count == 5


def test_job_getitem(multi_circuit_job: css.job.Job) -> None:
job_1 = multi_circuit_job[0]
assert isinstance(job_1, css.Job)
assert job_1.job_id() == "job_id1"
assert job_1.status() == "Done"


def test_get_marginal_counts() -> None:
counts_dict = {"10": 50, "11": 50}
indices = [0]
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Superstaq Documentation
=======================
Welcome! Here you can find more about Infleqtion's state-of-the-art quantum software platform that uses proprietary cross-layer optimization techniques to deliver unmatched performance.

.. raw:: html

<div class="container-index">
Expand Down
12 changes: 12 additions & 0 deletions supermarq-benchmarks/examples/qcvv/qcvv.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
QCVV: Quantum Characterisation, Validation and Verification
===========================================================

The Supermarq QCVV library provides a customizable toolkit for testing and characterizing
quantum devices. The toolkit can either be used with simulators or on live devices.

For a demonstration of how to implement a new experiment take a look at the following notebook

.. toctree::
:maxdepth: 1

qcvv_css
360 changes: 360 additions & 0 deletions supermarq-benchmarks/examples/qcvv/qcvv_css.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions supermarq-benchmarks/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cirq-superstaq~=0.5.23
qiskit-superstaq~=0.5.23
scikit-learn>=1.0
seaborn>=0.13.2
3 changes: 2 additions & 1 deletion supermarq-benchmarks/supermarq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import benchmark, converters, features, plotting, simulation, stabilizers
from . import benchmark, converters, features, plotting, qcvv, simulation, stabilizers
from ._version import __version__
from .benchmarks import (
bit_code,
Expand Down Expand Up @@ -27,4 +27,5 @@
"simulation",
"stabilizers",
"vqe_proxy",
"qcvv",
]
5 changes: 5 additions & 0 deletions supermarq-benchmarks/supermarq/qcvv/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""A toolkit of QCVV routines."""

from .base_experiment import BenchmarkingExperiment, BenchmarkingResults, Sample

__all__ = ["BenchmarkingExperiment", "BenchmarkingResults", "Sample"]
Loading

0 comments on commit ab0802d

Please sign in to comment.