From d8f092dc783e9a7a41e497d9e19b905f2becb0d5 Mon Sep 17 00:00:00 2001 From: Bharath Date: Fri, 22 Sep 2023 19:29:43 -0500 Subject: [PATCH 01/50] initial commit --- cirq-superstaq/cirq_superstaq/service.py | 17 +++++++++++---- .../qiskit_superstaq/superstaq_provider.py | 21 +++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/service.py b/cirq-superstaq/cirq_superstaq/service.py index 71095d983..76708ebcf 100644 --- a/cirq-superstaq/cirq_superstaq/service.py +++ b/cirq-superstaq/cirq_superstaq/service.py @@ -331,13 +331,22 @@ def get_balance(self, pretty_output: bool = True) -> Union[str, float]: return f"${balance:,.2f}" return balance - def get_targets(self) -> Dict[str, List[str]]: - """Gets a list of available, unavailable, and retired targets. + def get_targets(self, simulator: Optional[bool], **kwargs) -> Dict[str, List[str]]: + """Gets a list of Superstaq targets along with their status information. + + Args: + simulator: Optional flag to restrict the list of targets to simulators. + kwargs: Optional desired target filters. + - supports_submit: Boolean flag to only return targets that (don't) allow circuit submissions. + - supports_submit_qubo: Boolean flag to only return targets that (don't) allow qubo submissions. + - supports_compile: Boolean flag to return targets that (don't) support circuit compilation. + - available: Boolean flag to only return targets that are (not) available to use. + - retired: Boolean flag to only return targets that are or are not retired. Returns: - A list of Superstaq targets. + A list of Superstaq targets (or filterd targets based on `kwargs`). """ - return self._client.get_targets()["superstaq_targets"] + return self._client.get_targets(simulator, **kwargs) def resource_estimate( self, circuits: Union[cirq.Circuit, Sequence[cirq.Circuit]], target: Optional[str] = None diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py index 8580baef1..b214babd1 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py @@ -134,8 +134,8 @@ def resource_estimate( target: A string containing the name of a target backend. Returns: - ResourceEstimate(s) containing resource costs (after compilation) for running circuit(s) - on a backend. + `ResourceEstimate`(s) containing resource costs (after compilation) for running + circuit(s) on a backend. """ return self.get_backend(target).resource_estimate(circuits) @@ -500,10 +500,19 @@ def process_dfe(self, ids: List[str]) -> float: """ return self._client.process_dfe(ids) - def get_targets(self) -> Dict[str, Any]: - """Gets list of targets. + def get_targets(self, simulator: Optional[bool], **kwargs) -> Dict[str, Any]: + """Gets a list of Superstaq targets along with their status information. + + Args: + simulator: Optional flag to restrict the list of targets to simulators. + kwargs: Optional desired target filters. + - supports_submit: Boolean flag to only return targets that (don't) allow circuit submissions. + - supports_submit_qubo: Boolean flag to only return targets that (don't) allow qubo submissions. + - supports_compile: Boolean flag to return targets that (don't) support circuit compilation. + - available: Boolean flag to only return targets that are (not) available to use. + - retired: Boolean flag to only return targets that are or are not retired. Returns: - A dictionary sorted by "compile-only", "compile-and-run", "unavailable", and "retired". + A list of Superstaq targets (or filterd targets based on `kwargs`). """ - return self._client.get_targets()["superstaq_targets"] + return self._client.get_targets(simulator, **kwargs) From 88c69f610dd106579572f6aa22809948a636296e Mon Sep 17 00:00:00 2001 From: Bharath Date: Fri, 22 Sep 2023 19:30:15 -0500 Subject: [PATCH 02/50] filtering + dataclass for /get_targets --- .../general_superstaq/superstaq_client.py | 61 +++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index d1036cdc5..596f1f46a 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -19,6 +19,7 @@ import time import urllib import warnings +from dataclasses import dataclass from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Union import qubovert as qv @@ -217,15 +218,53 @@ def _accept_terms_of_use(self, user_input: str) -> str: """ return self.post_request("/accept_terms_of_use", {"user_input": user_input}) - def get_targets(self) -> Dict[str, Dict[str, List[str]]]: + def get_targets(self, simulator: Optional[bool], **kwargs) -> Dict[str, Dict[str, List[str]]]: """Makes a GET request to retrieve targets from the Superstaq API. - Gets a list of available, unavailable, and retired targets. + Args: + simulator: Optional flag to restrict the list of targets to simulators. + kwargs: Optional desired target filters. + + Raises: + ValueError: If `kwargs` is not a valid keyword inquiry on the target. Returns: - A dictionary listing the targets. + A list of Superstaq targets (or filterd targets based on `kwargs`). """ - return self.get_request("/targets") + superstaq_targets = self.get_request("/targets")["superstaq_targets"] + target_list = [ + TargetInfo(target_name, properties) + for target_name, properties in superstaq_targets.items() + ] + + if simulator is not None: + target_list = [ + target_info + for target_info in target_list + if ("simulator" in target_info.target) == simulator + ] + + if kwargs: + filtered_targets = [] + for target in target_list: + for key in kwargs.keys(): + if key not in target.properties: + raise ValueError( + f"{key} is not a valid keyword inquiry on the target. Alternatively, " + "please use the /target_info endpoint to retrieve more information on " + "the target." + ) + if all( + target.properties.get(key) == value + for key, value in kwargs.items() + if key in target.properties + ): + filtered_targets.append(target) + + if filtered_targets == []: + print("No targets match the specified criteria.") + return filtered_targets + return target_list def add_new_user(self, json_dict: Dict[str, str]) -> str: """Makes a POST request to Superstaq API to add a new user. @@ -755,3 +794,17 @@ def find_api_key() -> str: "Try passing an 'api_key' variable, or setting your API key in the command line " "with SUPERSTAQ_API_KEY=..." ) + + +@dataclass +class TargetInfo: + """A class to store data returned from a /get_targets request.""" + + target: str + properties: Dict[str, bool] + + def __repr__(self) -> str: + properties_str = ",\n ".join( + f"{property}={value}" for property, value in self.properties.items() + ) + return f"TargetInfo(\n target={self.target},\n {properties_str}\n)" From d3dc507565c9e3d354675bd26d737c3155d25d3b Mon Sep 17 00:00:00 2001 From: Bharath Date: Fri, 29 Sep 2023 12:02:10 -0500 Subject: [PATCH 03/50] missing types + flake8 fix --- cirq-superstaq/cirq_superstaq/service.py | 13 +++++++--- .../general_superstaq/superstaq_client.py | 4 ++- .../qiskit_superstaq/superstaq_provider.py | 26 ++++++++++++------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/service.py b/cirq-superstaq/cirq_superstaq/service.py index 76708ebcf..e9153c816 100644 --- a/cirq-superstaq/cirq_superstaq/service.py +++ b/cirq-superstaq/cirq_superstaq/service.py @@ -331,15 +331,20 @@ def get_balance(self, pretty_output: bool = True) -> Union[str, float]: return f"${balance:,.2f}" return balance - def get_targets(self, simulator: Optional[bool], **kwargs) -> Dict[str, List[str]]: + def get_targets( + self, simulator: Optional[bool] = None, **kwargs: Any + ) -> List[gss.superstaq_client.TargetInfo]: """Gets a list of Superstaq targets along with their status information. Args: simulator: Optional flag to restrict the list of targets to simulators. kwargs: Optional desired target filters. - - supports_submit: Boolean flag to only return targets that (don't) allow circuit submissions. - - supports_submit_qubo: Boolean flag to only return targets that (don't) allow qubo submissions. - - supports_compile: Boolean flag to return targets that (don't) support circuit compilation. + - supports_submit: Boolean flag to only return targets that (don't) allow circuit + submissions. + - supports_submit_qubo: Boolean flag to only return targets that (don't) allow qubo + submissions. + - supports_compile: Boolean flag to return targets that (don't) support circuit + compilation. - available: Boolean flag to only return targets that are (not) available to use. - retired: Boolean flag to only return targets that are or are not retired. diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index 596f1f46a..47ca88f09 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. """Client for making requests to Superstaq's API.""" +from __future__ import annotations + import json import os import pathlib @@ -218,7 +220,7 @@ def _accept_terms_of_use(self, user_input: str) -> str: """ return self.post_request("/accept_terms_of_use", {"user_input": user_input}) - def get_targets(self, simulator: Optional[bool], **kwargs) -> Dict[str, Dict[str, List[str]]]: + def get_targets(self, simulator: Optional[bool] = None, **kwargs: Any) -> List[TargetInfo]: """Makes a GET request to retrieve targets from the Superstaq API. Args: diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py index b214babd1..9795c267d 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py @@ -14,7 +14,7 @@ from __future__ import annotations import warnings -from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union +from typing import TYPE_CHECKING, Any, List, Mapping, Optional, Sequence, Tuple, Union import general_superstaq as gss import numpy as np @@ -118,11 +118,12 @@ def backends(self) -> List[qss.SuperstaqBackend]: Returns: A list of Superstaq backends. """ - targets = self._client.get_targets()["superstaq_targets"] - backends = [] - for target in targets["compile-and-run"]: - backends.append(self.get_backend(target)) - return backends + submit_targets = self._client.get_targets() + superstaq_backends = [] + for backend in submit_targets: + if backend.properties["supports_submit"]: + superstaq_backends.append(self.get_backend(backend.target)) + return superstaq_backends def resource_estimate( self, circuits: Union[qiskit.QuantumCircuit, Sequence[qiskit.QuantumCircuit]], target: str @@ -500,15 +501,20 @@ def process_dfe(self, ids: List[str]) -> float: """ return self._client.process_dfe(ids) - def get_targets(self, simulator: Optional[bool], **kwargs) -> Dict[str, Any]: + def get_targets( + self, simulator: Optional[bool] = None, **kwargs: Any + ) -> List[gss.superstaq_client.TargetInfo]: """Gets a list of Superstaq targets along with their status information. Args: simulator: Optional flag to restrict the list of targets to simulators. kwargs: Optional desired target filters. - - supports_submit: Boolean flag to only return targets that (don't) allow circuit submissions. - - supports_submit_qubo: Boolean flag to only return targets that (don't) allow qubo submissions. - - supports_compile: Boolean flag to return targets that (don't) support circuit compilation. + - supports_submit: Boolean flag to only return targets that (don't) allow circuit + submissions. + - supports_submit_qubo: Boolean flag to only return targets that (don't) allow qubo + submissions. + - supports_compile: Boolean flag to return targets that (don't) support circuit + compilation. - available: Boolean flag to only return targets that are (not) available to use. - retired: Boolean flag to only return targets that are or are not retired. From 5b1efbd4e8cbb851e6425f9c6dffa59446d67a75 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 00:35:24 -0500 Subject: [PATCH 04/50] store get_targets output store TargetInfo list --- .../general_superstaq/superstaq_client.py | 52 ++-- .../superstaq_client_test.py | 83 ++++-- general-superstaq/general_superstaq/typing.py | 247 ++++++++++++++++++ 3 files changed, 337 insertions(+), 45 deletions(-) diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index 47ca88f09..d201eb396 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -21,9 +21,9 @@ import time import urllib import warnings -from dataclasses import dataclass from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Union +import pydantic import qubovert as qv import requests @@ -235,7 +235,7 @@ def get_targets(self, simulator: Optional[bool] = None, **kwargs: Any) -> List[T """ superstaq_targets = self.get_request("/targets")["superstaq_targets"] target_list = [ - TargetInfo(target_name, properties) + TargetInfo(target=target_name, **properties) for target_name, properties in superstaq_targets.items() ] @@ -243,28 +243,26 @@ def get_targets(self, simulator: Optional[bool] = None, **kwargs: Any) -> List[T target_list = [ target_info for target_info in target_list - if ("simulator" in target_info.target) == simulator + if (target_info.target.endswith("simulator")) == simulator ] if kwargs: filtered_targets = [] for target in target_list: for key in kwargs.keys(): - if key not in target.properties: + if key not in target.__fields__: raise ValueError( f"{key} is not a valid keyword inquiry on the target. Alternatively, " "please use the /target_info endpoint to retrieve more information on " "the target." ) if all( - target.properties.get(key) == value - for key, value in kwargs.items() - if key in target.properties + getattr(target, filter) == filter_value + for filter, filter_value in kwargs.items() ): filtered_targets.append(target) - if filtered_targets == []: - print("No targets match the specified criteria.") + print("No targets matched the specified criteria.") return filtered_targets return target_list @@ -798,15 +796,37 @@ def find_api_key() -> str: ) -@dataclass -class TargetInfo: - """A class to store data returned from a /get_targets request.""" +class TargetInfo(pydantic.BaseModel): + """A class to store data returned from a `/get_targets` request.""" target: str - properties: Dict[str, bool] + supports_submit: bool = False + supports_submit_qubo: bool = False + supports_compile: bool = False + available: bool = False + retired: bool = False def __repr__(self) -> str: - properties_str = ",\n ".join( - f"{property}={value}" for property, value in self.properties.items() + return textwrap.dedent( + f"""\ + TargetInfo( + target={self.target!r}, + supports_submit={self.supports_submit!r}, + supports_submit_qubo={self.supports_submit_qubo!r}, + supports_compile={self.supports_compile!r}, + available={self.available!r}, + retired={self.retired!r}, + )""" ) - return f"TargetInfo(\n target={self.target},\n {properties_str}\n)" + + def __eq__(self, other: object) -> bool: + if isinstance(other, TargetInfo): + return ( + self.target == other.target + and self.supports_submit == other.supports_submit + and self.supports_submit_qubo == other.supports_submit_qubo + and self.supports_compile == other.supports_compile + and self.available == other.available + and self.retired == other.retired + ) + return False diff --git a/general-superstaq/general_superstaq/superstaq_client_test.py b/general-superstaq/general_superstaq/superstaq_client_test.py index 54b217ed9..bb179a589 100644 --- a/general-superstaq/general_superstaq/superstaq_client_test.py +++ b/general-superstaq/general_superstaq/superstaq_client_test.py @@ -464,46 +464,51 @@ def test_superstaq_client_resource_estimate(mock_post: mock.MagicMock) -> None: @mock.patch("requests.get") def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: mock_get.return_value.ok = True - targets = { - "superstaq_targets:": { - "compile-and-run": [ - "ibmq_qasm_simulator", - "ibmq_armonk_qpu", - "ibmq_santiago_qpu", - "ibmq_bogota_qpu", - "ibmq_lima_qpu", - "ibmq_belem_qpu", - "ibmq_quito_qpu", - "ibmq_statevector_simulator", - "ibmq_mps_simulator", - "ibmq_extended-stabilizer_simulator", - "ibmq_stabilizer_simulator", - "ibmq_manila_qpu", - "aws_dm1_simulator", - "aws_sv1_simulator", - "d-wave_advantage-system4.1_qpu", - "d-wave_dw-2000q-6_qpu", - "aws_tn1_simulator", - "rigetti_aspen-9_qpu", - "d-wave_advantage-system1.1_qpu", - "ionq_ion_qpu", - ], - "compile-only": ["aqt_keysight_qpu", "sandia_qscout_qpu"], - } - } - mock_get.return_value.json.return_value = targets + mock_get.return_value.json.return_value = {"superstaq_targets": gss.typing.TARGET_LIST} client = gss.superstaq_client._SuperstaqClient( client_name="general-superstaq", remote_host="http://example.com", api_key="to_my_heart", ) response = client.get_targets() - assert response == targets + assert response == gss.typing.RETURNED_TARGETS mock_get.assert_called_with( f"http://example.com/{API_VERSION}/targets", headers=EXPECTED_HEADERS, verify=False ) + # test simulator only return + response = client.get_targets(simulator=True) + simulator_targets = [ + target_info + for target_info in gss.typing.RETURNED_TARGETS + if target_info.target.endswith("simulator") + ] + assert response == simulator_targets + + # test kwargs return + response = client.get_targets(simulator=True, supports_submit_qubo=True, available=True) + assert response == [ + gss.superstaq_client.TargetInfo( + target="toshiba_bifurcation_simulator", + **{ + "supports_submit": False, + "supports_submit_qubo": True, + "supports_compile": False, + "available": True, + "retired": False, + }, + ) + ] + + # test empty return + response = client.get_targets(simulator=False, supports_submit_qubo=True, available=True) + assert response == [] + + # invalid kwarg test + with pytest.raises(ValueError, match="a valid keyword inquiry on the target"): + _ = client.get_targets(invalid_key=True) + @mock.patch("requests.post") def test_superstaq_client_get_job_unauthorized(mock_post: mock.MagicMock) -> None: @@ -822,3 +827,23 @@ def test_find_api_key() -> None: with mock.patch.dict(os.environ, SUPERSTAQ_API_KEY=""): with mock.patch("pathlib.Path.is_file", return_value=False): gss.superstaq_client.find_api_key() + + +def test_target_info_repr_and_eq() -> None: + sample_target_info = gss.superstaq_client.TargetInfo( + target="example_target", + **{ + "supports_submit": False, + "supports_submit_qubo": True, + "supports_compile": False, + "available": True, + "retired": False, + }, + ) + assert ( + repr(sample_target_info) + == "TargetInfo(\n target='example_target',\n supports_submit=False,\n " + "supports_submit_qubo=True,\n supports_compile=False,\n " + "available=True,\n retired=False,\n)" + ) + assert sample_target_info != {"superstaq_target": "example_target"} diff --git a/general-superstaq/general_superstaq/typing.py b/general-superstaq/general_superstaq/typing.py index c1ef940c7..3327feec8 100644 --- a/general-superstaq/general_superstaq/typing.py +++ b/general-superstaq/general_superstaq/typing.py @@ -1,5 +1,7 @@ from typing import Any, Dict, Optional, TypedDict +from general_superstaq.superstaq_client import TargetInfo + Job = TypedDict( "Job", { @@ -16,3 +18,248 @@ "state_vector": Optional[str], }, ) + +TARGET_LIST = { + "aqt_keysight_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "aqt_zurich_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "aws_dm1_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "aws_sv1_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "aws_tn1_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "cq_hilbert_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "cq_hilbert_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_extended-stabilizer_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_guadalupe_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_lagos_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_mps_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_nairobi_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_perth_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_qasm_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_stabilizer_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_statevector_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ionq_aria-1_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": False, + }, + "ionq_aria-2_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": False, + }, + "ionq_harmony_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ionq_ion_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "oxford_lucy_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": False, + }, + "qtm_h1-1_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "qtm_h1-1e_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "qtm_h2-1_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "rigetti_aspen-10_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-11_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-8_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-9_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-m-1_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-m-2_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-m-3_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "sandia_qscout_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ss_unconstrained_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "toshiba_bifurcation_simulator": { + "supports_submit": False, + "supports_submit_qubo": True, + "supports_compile": False, + "available": True, + "retired": False, + }, +} + +RETURNED_TARGETS = [ + TargetInfo(target=target_name, **properties) for target_name, properties in TARGET_LIST.items() +] From c9e2ae9b768673bd9937aeb1a8de75ebcc1338ba Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 00:48:24 -0500 Subject: [PATCH 05/50] update with BaseModel + code clean-up --- qiskit-superstaq/qiskit_superstaq/superstaq_provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py index 9795c267d..65b7eb13c 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py @@ -121,7 +121,7 @@ def backends(self) -> List[qss.SuperstaqBackend]: submit_targets = self._client.get_targets() superstaq_backends = [] for backend in submit_targets: - if backend.properties["supports_submit"]: + if backend.supports_submit: superstaq_backends.append(self.get_backend(backend.target)) return superstaq_backends From 89cb8217ceb4b29a39648b033b7015dae887f4c2 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 00:49:47 -0500 Subject: [PATCH 06/50] updated tests --- .../cirq_superstaq/daily_integration_test.py | 20 +++++++++- cirq-superstaq/cirq_superstaq/service_test.py | 39 +++--------------- qiskit-superstaq/qiskit_superstaq/conftest.py | 36 ++++------------- .../superstaq_provider_test.py | 40 +++---------------- 4 files changed, 36 insertions(+), 99 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/daily_integration_test.py b/cirq-superstaq/cirq_superstaq/daily_integration_test.py index a61f6a262..c2da48c82 100644 --- a/cirq-superstaq/cirq_superstaq/daily_integration_test.py +++ b/cirq-superstaq/cirq_superstaq/daily_integration_test.py @@ -137,8 +137,24 @@ def test_get_resource_estimate(service: css.Service) -> None: def test_get_targets(service: css.Service) -> None: result = service.get_targets() - assert "ibmq_qasm_simulator" in result["compile-and-run"] - assert "aqt_keysight_qpu" in result["compile-only"] + ibmq_properties = { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + } + aqt_properties = { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + } + assert ( + gss.superstaq_client.TargetInfo(target="ibmq_qasm_simulator", **ibmq_properties) in result + ) + assert gss.superstaq_client.TargetInfo(target="aqt_keysight_qpu", **aqt_properties) in result def test_qscout_compile(service: css.Service) -> None: diff --git a/cirq-superstaq/cirq_superstaq/service_test.py b/cirq-superstaq/cirq_superstaq/service_test.py index 9751f86ea..6b4454631 100644 --- a/cirq-superstaq/cirq_superstaq/service_test.py +++ b/cirq-superstaq/cirq_superstaq/service_test.py @@ -228,40 +228,13 @@ def test_service_get_balance() -> None: assert service.get_balance(pretty_output=False) == 12345.6789 -def test_service_get_targets() -> None: +@mock.patch( + "general_superstaq.superstaq_client._SuperstaqClient.get_request", + return_value={"superstaq_targets": gss.typing.TARGET_LIST}, +) +def test_service_get_targets(mock_get_request: mock.MagicMock) -> None: service = css.Service(api_key="key", remote_host="http://example.com") - mock_client = mock.MagicMock() - targets = { - "superstaq_targets": { - "compile-and-run": [ - "ibmq_qasm_simulator", - "ibmq_armonk_qpu", - "ibmq_santiago_qpu", - "ibmq_bogota_qpu", - "ibmq_lima_qpu", - "ibmq_belem_qpu", - "ibmq_quito_qpu", - "ibmq_statevector_simulator", - "ibmq_mps_simulator", - "ibmq_extended-stabilizer_simulator", - "ibmq_stabilizer_simulator", - "ibmq_manila_qpu", - "aws_dm1_simulator", - "aws_sv1_simulator", - "d-wave_advantage-system4.1_qpu", - "d-wave_dw-2000q-6_qpu", - "aws_tn1_simulator", - "rigetti_aspen-9_qpu", - "d-wave_advantage-system1.1_qpu", - "ionq_ion_qpu", - ], - "compile-only": ["aqt_keysight_qpu", "aqt_zurich_qpu", "sandia_qscout_qpu"], - } - } - mock_client.get_targets.return_value = targets - service._client = mock_client - - assert service.get_targets() == targets["superstaq_targets"] + assert service.get_targets() == gss.typing.RETURNED_TARGETS @mock.patch( diff --git a/qiskit-superstaq/qiskit_superstaq/conftest.py b/qiskit-superstaq/qiskit_superstaq/conftest.py index 367b135ea..30d1faa15 100644 --- a/qiskit-superstaq/qiskit_superstaq/conftest.py +++ b/qiskit-superstaq/qiskit_superstaq/conftest.py @@ -1,4 +1,4 @@ -from typing import Dict, List, Optional +from typing import Any, List, Optional import general_superstaq as gss import pytest @@ -32,7 +32,6 @@ def __init__(self, provider: qss.SuperstaqProvider, target: str) -> None: "max_shots": -1, "coupling_map": None, } - gss.validation.validate_target(target) qiskit.providers.BackendV1.__init__( @@ -47,38 +46,17 @@ def __init__(self, provider: qss.SuperstaqProvider, target: str) -> None: class MockSuperstaqClient(gss.superstaq_client._SuperstaqClient): """Stand-in for `_SuperstaqClient` that the tests can call.""" - def get_targets(self) -> Dict[str, Dict[str, List[str]]]: + def get_targets( + self, simulator: Optional[bool] = None, **kwargs: Any + ) -> List[gss.superstaq_client.TargetInfo]: """Makes a GET request to retrieve targets from the Superstaq API. - Gets a list of available, unavailable, and retired targets. + Gets all targets supported by Superstaq (available, unavailable, and retired targets). Returns: - A dictionary listing the targets. + A dictionary listing the Superstaq targets. """ - return { - "superstaq_targets": { - "compile-and-run": [ - "ibmq_qasm_simulator", - "ibmq_armonk_qpu", - "ibmq_santiago_qpu", - "ibmq_bogota_qpu", - "ibmq_lima_qpu", - "ibmq_belem_qpu", - "ibmq_quito_qpu", - "ibmq_statevector_simulator", - "ibmq_mps_simulator", - "ibmq_extended-stabilizer_simulator", - "ibmq_stabilizer_simulator", - "ibmq_manila_qpu", - "aws_dm1_simulator", - "aws_tn1_simulator", - "ionq_ion_qpu", - "aws_sv1_simulator", - "rigetti_aspen-9_qpu", - ], - "compile-only": ["aqt_keysight_qpu", "sandia_qscout_qpu"], - } - } + return gss.typing.RETURNED_TARGETS class MockSuperstaqProvider(qss.SuperstaqProvider): diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py index dcb6357e3..8a43490e4 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py @@ -29,7 +29,7 @@ def test_provider(fake_superstaq_provider: MockSuperstaqProvider) -> None: == "" ) - assert str(fake_superstaq_provider.backends()[0]) == "ibmq_qasm_simulator" + assert str(fake_superstaq_provider.backends()[0]) == "aws_dm1_simulator" @patch.dict(os.environ, {"SUPERSTAQ_API_KEY": ""}) @@ -412,37 +412,7 @@ def test_dfe(mock_post: MagicMock, fake_superstaq_provider: MockSuperstaqProvide assert fake_superstaq_provider.process_dfe(["1", "2"]) == 1 -def test_get_targets() -> None: - provider = qss.SuperstaqProvider(api_key="key", remote_host="http://example.com") - mock_client = mock.MagicMock() - targets = { - "superstaq_targets": { - "compile-and-run": [ - "ibmq_qasm_simulator", - "ibmq_armonk_qpu", - "ibmq_santiago_qpu", - "ibmq_bogota_qpu", - "ibmq_lima_qpu", - "ibmq_belem_qpu", - "ibmq_quito_qpu", - "ibmq_statevector_simulator", - "ibmq_mps_simulator", - "ibmq_extended-stabilizer_simulator", - "ibmq_stabilizer_simulator", - "ibmq_manila_qpu", - "aws_dm1_simulator", - "aws_sv1_simulator", - "d-wave_advantage-system4.1_qpu", - "d-wave_dw-2000q-6_qpu", - "aws_tn1_simulator", - "rigetti_aspen-9_qpu", - "d-wave_advantage-system1.1_qpu", - "ionq_ion_qpu", - ], - "compile-only": ["aqt_keysight_qpu", "aqt_zurich_qpu", "sandia_qscout_qpu"], - } - } - mock_client.get_targets.return_value = targets - provider._client = mock_client - - assert provider.get_targets() == targets["superstaq_targets"] +@patch("requests.get") +def test_get_targets(mock_get: MagicMock, fake_superstaq_provider: MockSuperstaqProvider) -> None: + mock_get.return_value.json = {"superstaq_targets": gss.typing.TARGET_LIST} + assert fake_superstaq_provider.get_targets() == gss.typing.RETURNED_TARGETS From 8a260637228f0c1c63fce5ea5bcbb93d7eab186a Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 01:11:45 -0500 Subject: [PATCH 07/50] update in supermarq --- .../supermarq/run_benchmarks.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/supermarq-benchmarks/supermarq/run_benchmarks.py b/supermarq-benchmarks/supermarq/run_benchmarks.py index 121648039..de8413a50 100644 --- a/supermarq-benchmarks/supermarq/run_benchmarks.py +++ b/supermarq-benchmarks/supermarq/run_benchmarks.py @@ -1,11 +1,15 @@ from datetime import datetime -from typing import Dict, List, Tuple +from typing import TYPE_CHECKING, List, Tuple import cirq import cirq_superstaq as css import supermarq +if TYPE_CHECKING: + from general_superstaq.superstaq_client import TargetInfo + + BENCHMARKS: List[Tuple[supermarq.benchmark.Benchmark, str]] = [ (supermarq.ghz.GHZ(5), "ghz5"), (supermarq.hamiltonian_simulation.HamiltonianSimulation(4), "hsim4"), @@ -14,21 +18,22 @@ ] -def get_qpu_targets(targets: Dict[str, List[str]]) -> List[str]: - """Get real device targets. +def get_qpu_targets(target_list: List[TargetInfo]) -> List[TargetInfo]: + """Gets real device targets. Args: - targets: Output from `service.get_targets()`. + target_list: Output from `service.get_targets()`. Returns: A list with the targets corresponding to real devices. """ - qpu_targets: List[str] = [] - run_targets = targets.get("compile-and-run", []) - - for t in run_targets: - if t.endswith("qpu") and not t.startswith("ionq") and not t.startswith("rigetti"): - qpu_targets.append(t) + qpu_targets = [ + target_info + for target_info in target_list + if target_info.target.endswith("qpu") + and not target_info.target.startswith("ionq") + and not target_info.target.startswith("rigetti") + ] return qpu_targets From 29c7519ad194b28caa96aba2ed5819ed393d4355 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 01:16:14 -0500 Subject: [PATCH 08/50] extract target name --- supermarq-benchmarks/supermarq/run_benchmarks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/supermarq-benchmarks/supermarq/run_benchmarks.py b/supermarq-benchmarks/supermarq/run_benchmarks.py index de8413a50..9831a0fc7 100644 --- a/supermarq-benchmarks/supermarq/run_benchmarks.py +++ b/supermarq-benchmarks/supermarq/run_benchmarks.py @@ -47,7 +47,7 @@ def get_qpu_targets(target_list: List[TargetInfo]) -> List[TargetInfo]: date = datetime.today().strftime("%Y-%m-%d") tag = f"{date}-{label}-{target}" - target_info = service.target_info(target) + target_info = service.target_info(target.target) if label == "bitcode3" and not target_info.get("supports_midcircuit_measurement"): continue @@ -57,9 +57,9 @@ def get_qpu_targets(target_list: List[TargetInfo]) -> List[TargetInfo]: job = service.create_job( circuit, repetitions=1000, - target=target, + target=target.target, tag=tag, lifespan=3653, ) except Exception: - print(f"{label} on {target} failed.") + print(f"{label} on {target.target} failed.") From 79fe2bd75ed507d98ecfe925daee1271d477a521 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 17:44:57 -0500 Subject: [PATCH 09/50] add pydantic req --- checks-superstaq/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/checks-superstaq/requirements.txt b/checks-superstaq/requirements.txt index 60400ca90..db55526c5 100644 --- a/checks-superstaq/requirements.txt +++ b/checks-superstaq/requirements.txt @@ -11,4 +11,5 @@ pytest>=6.2.5 pytest-cov>=2.11.1 pytest-randomly>=3.10.1 pytest-socket>=0.4.1 +pydantic>=2.4.2 sphinx-rtd-theme>=1.0.0 From 4dddff8d417ba967283de0857ff8a695a9228061 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 17:45:22 -0500 Subject: [PATCH 10/50] remove print statement --- .../general_superstaq/superstaq_client.py | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index 6d6973d17..794252caa 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -280,8 +280,6 @@ def get_targets(self, simulator: Optional[bool] = None, **kwargs: Any) -> List[T for filter, filter_value in kwargs.items() ): filtered_targets.append(target) - if filtered_targets == []: - print("No targets matched the specified criteria.") return filtered_targets return target_list @@ -824,28 +822,3 @@ class TargetInfo(pydantic.BaseModel): supports_compile: bool = False available: bool = False retired: bool = False - - def __repr__(self) -> str: - return textwrap.dedent( - f"""\ - TargetInfo( - target={self.target!r}, - supports_submit={self.supports_submit!r}, - supports_submit_qubo={self.supports_submit_qubo!r}, - supports_compile={self.supports_compile!r}, - available={self.available!r}, - retired={self.retired!r}, - )""" - ) - - def __eq__(self, other: object) -> bool: - if isinstance(other, TargetInfo): - return ( - self.target == other.target - and self.supports_submit == other.supports_submit - and self.supports_submit_qubo == other.supports_submit_qubo - and self.supports_compile == other.supports_compile - and self.available == other.available - and self.retired == other.retired - ) - return False From b0f3d26b06951dff3f65b0bc61bcc435a753e285 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 17:45:52 -0500 Subject: [PATCH 11/50] remove __repr__ and __eq__ test --- .../superstaq_client_test.py | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/general-superstaq/general_superstaq/superstaq_client_test.py b/general-superstaq/general_superstaq/superstaq_client_test.py index 3fd914b84..0970d287f 100644 --- a/general-superstaq/general_superstaq/superstaq_client_test.py +++ b/general-superstaq/general_superstaq/superstaq_client_test.py @@ -490,14 +490,14 @@ def test_superstaq_client_resource_estimate(mock_post: mock.MagicMock) -> None: @mock.patch("requests.get") def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: mock_get.return_value.ok = True - mock_get.return_value.json.return_value = {"superstaq_targets": gss.typing.TARGET_LIST} + mock_get.return_value.json.return_value = {"superstaq_targets": gss.testing.TARGET_LIST} client = gss.superstaq_client._SuperstaqClient( client_name="general-superstaq", remote_host="http://example.com", api_key="to_my_heart", ) response = client.get_targets() - assert response == gss.typing.RETURNED_TARGETS + assert response == gss.testing.RETURNED_TARGETS mock_get.assert_called_with( f"http://example.com/{API_VERSION}/targets", headers=EXPECTED_HEADERS, verify=False @@ -507,7 +507,7 @@ def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: response = client.get_targets(simulator=True) simulator_targets = [ target_info - for target_info in gss.typing.RETURNED_TARGETS + for target_info in gss.testing.RETURNED_TARGETS if target_info.target.endswith("simulator") ] assert response == simulator_targets @@ -853,23 +853,3 @@ def test_find_api_key() -> None: with mock.patch.dict(os.environ, SUPERSTAQ_API_KEY=""): with mock.patch("pathlib.Path.is_file", return_value=False): gss.superstaq_client.find_api_key() - - -def test_target_info_repr_and_eq() -> None: - sample_target_info = gss.superstaq_client.TargetInfo( - target="example_target", - **{ - "supports_submit": False, - "supports_submit_qubo": True, - "supports_compile": False, - "available": True, - "retired": False, - }, - ) - assert ( - repr(sample_target_info) - == "TargetInfo(\n target='example_target',\n supports_submit=False,\n " - "supports_submit_qubo=True,\n supports_compile=False,\n " - "available=True,\n retired=False,\n)" - ) - assert sample_target_info != {"superstaq_target": "example_target"} From e7617377eed147d9cec21bc5d08741a4872248dc Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 17:46:10 -0500 Subject: [PATCH 12/50] create testing.py --- .../general_superstaq/__init__.py | 2 + .../general_superstaq/testing.py | 246 +++++++++++++++++ general-superstaq/general_superstaq/typing.py | 247 ------------------ 3 files changed, 248 insertions(+), 247 deletions(-) create mode 100644 general-superstaq/general_superstaq/testing.py diff --git a/general-superstaq/general_superstaq/__init__.py b/general-superstaq/general_superstaq/__init__.py index f4eb98e37..a279ad398 100644 --- a/general-superstaq/general_superstaq/__init__.py +++ b/general-superstaq/general_superstaq/__init__.py @@ -14,6 +14,7 @@ service, superstaq_client, superstaq_exceptions, + testing, typing, validation, ) @@ -33,5 +34,6 @@ "superstaq_client", "superstaq_exceptions", "typing", + "testing", "validation", ] diff --git a/general-superstaq/general_superstaq/testing.py b/general-superstaq/general_superstaq/testing.py new file mode 100644 index 000000000..a702b1825 --- /dev/null +++ b/general-superstaq/general_superstaq/testing.py @@ -0,0 +1,246 @@ +from general_superstaq.superstaq_client import TargetInfo + +TARGET_LIST = { + "aqt_keysight_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "aqt_zurich_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "aws_dm1_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "aws_sv1_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "aws_tn1_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "cq_hilbert_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "cq_hilbert_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_extended-stabilizer_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_guadalupe_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_lagos_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_mps_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_nairobi_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_perth_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_qasm_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_stabilizer_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ibmq_statevector_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ionq_aria-1_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": False, + }, + "ionq_aria-2_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": False, + }, + "ionq_harmony_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ionq_ion_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "oxford_lucy_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": False, + }, + "qtm_h1-1_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "qtm_h1-1e_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "qtm_h2-1_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "rigetti_aspen-10_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-11_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-8_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-9_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-m-1_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-m-2_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": False, + "retired": True, + }, + "rigetti_aspen-m-3_qpu": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "sandia_qscout_qpu": { + "supports_submit": False, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "ss_unconstrained_simulator": { + "supports_submit": True, + "supports_submit_qubo": False, + "supports_compile": True, + "available": True, + "retired": False, + }, + "toshiba_bifurcation_simulator": { + "supports_submit": False, + "supports_submit_qubo": True, + "supports_compile": False, + "available": True, + "retired": False, + }, +} + +RETURNED_TARGETS = [ + TargetInfo(target=target_name, **properties) for target_name, properties in TARGET_LIST.items() +] diff --git a/general-superstaq/general_superstaq/typing.py b/general-superstaq/general_superstaq/typing.py index 3327feec8..c1ef940c7 100644 --- a/general-superstaq/general_superstaq/typing.py +++ b/general-superstaq/general_superstaq/typing.py @@ -1,7 +1,5 @@ from typing import Any, Dict, Optional, TypedDict -from general_superstaq.superstaq_client import TargetInfo - Job = TypedDict( "Job", { @@ -18,248 +16,3 @@ "state_vector": Optional[str], }, ) - -TARGET_LIST = { - "aqt_keysight_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "aqt_zurich_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "aws_dm1_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "aws_sv1_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "aws_tn1_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "cq_hilbert_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "cq_hilbert_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ibmq_extended-stabilizer_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ibmq_guadalupe_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ibmq_lagos_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ibmq_mps_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ibmq_nairobi_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ibmq_perth_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ibmq_qasm_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ibmq_stabilizer_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ibmq_statevector_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ionq_aria-1_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": False, - "retired": False, - }, - "ionq_aria-2_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": False, - "retired": False, - }, - "ionq_harmony_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ionq_ion_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "oxford_lucy_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": False, - "retired": False, - }, - "qtm_h1-1_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "qtm_h1-1e_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "qtm_h2-1_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "rigetti_aspen-10_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": False, - "retired": True, - }, - "rigetti_aspen-11_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": False, - "retired": True, - }, - "rigetti_aspen-8_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": False, - "retired": True, - }, - "rigetti_aspen-9_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": False, - "retired": True, - }, - "rigetti_aspen-m-1_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": False, - "retired": True, - }, - "rigetti_aspen-m-2_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": False, - "retired": True, - }, - "rigetti_aspen-m-3_qpu": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "sandia_qscout_qpu": { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "ss_unconstrained_simulator": { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - }, - "toshiba_bifurcation_simulator": { - "supports_submit": False, - "supports_submit_qubo": True, - "supports_compile": False, - "available": True, - "retired": False, - }, -} - -RETURNED_TARGETS = [ - TargetInfo(target=target_name, **properties) for target_name, properties in TARGET_LIST.items() -] From 9c146b670fb5844939cc178539dc8588c68c7940 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 17:46:41 -0500 Subject: [PATCH 13/50] extension rename --- cirq-superstaq/cirq_superstaq/service_test.py | 4 ++-- qiskit-superstaq/qiskit_superstaq/conftest.py | 2 +- qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/service_test.py b/cirq-superstaq/cirq_superstaq/service_test.py index b40c52dfc..2275465b4 100644 --- a/cirq-superstaq/cirq_superstaq/service_test.py +++ b/cirq-superstaq/cirq_superstaq/service_test.py @@ -251,11 +251,11 @@ def test_service_get_balance() -> None: @mock.patch( "general_superstaq.superstaq_client._SuperstaqClient.get_request", - return_value={"superstaq_targets": gss.typing.TARGET_LIST}, + return_value={"superstaq_targets": gss.testing.TARGET_LIST}, ) def test_service_get_targets(mock_get_request: mock.MagicMock) -> None: service = css.Service(api_key="key", remote_host="http://example.com") - assert service.get_targets() == gss.typing.RETURNED_TARGETS + assert service.get_targets() == gss.testing.RETURNED_TARGETS @mock.patch( diff --git a/qiskit-superstaq/qiskit_superstaq/conftest.py b/qiskit-superstaq/qiskit_superstaq/conftest.py index 30d1faa15..c3b8285a0 100644 --- a/qiskit-superstaq/qiskit_superstaq/conftest.py +++ b/qiskit-superstaq/qiskit_superstaq/conftest.py @@ -56,7 +56,7 @@ def get_targets( Returns: A dictionary listing the Superstaq targets. """ - return gss.typing.RETURNED_TARGETS + return gss.testing.RETURNED_TARGETS class MockSuperstaqProvider(qss.SuperstaqProvider): diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py index 5291140c7..5fad3cb70 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py @@ -426,5 +426,5 @@ def test_dfe(mock_post: MagicMock, fake_superstaq_provider: MockSuperstaqProvide @patch("requests.get") def test_get_targets(mock_get: MagicMock, fake_superstaq_provider: MockSuperstaqProvider) -> None: - mock_get.return_value.json = {"superstaq_targets": gss.typing.TARGET_LIST} - assert fake_superstaq_provider.get_targets() == gss.typing.RETURNED_TARGETS + mock_get.return_value.json = {"superstaq_targets": gss.testing.TARGET_LIST} + assert fake_superstaq_provider.get_targets() == gss.testing.RETURNED_TARGETS From 42534d580cf98623dbb735aa5a461295c57fd69e Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 18:32:06 -0500 Subject: [PATCH 14/50] update req version --- checks-superstaq/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks-superstaq/requirements.txt b/checks-superstaq/requirements.txt index db55526c5..0333206d4 100644 --- a/checks-superstaq/requirements.txt +++ b/checks-superstaq/requirements.txt @@ -11,5 +11,5 @@ pytest>=6.2.5 pytest-cov>=2.11.1 pytest-randomly>=3.10.1 pytest-socket>=0.4.1 -pydantic>=2.4.2 +pydantic>=1.10.7,<2.0.0 sphinx-rtd-theme>=1.0.0 From bdde587c713afb7a57d74b808c9036e464c2e85b Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 5 Oct 2023 18:36:06 -0500 Subject: [PATCH 15/50] apply requirements --- checks-superstaq/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks-superstaq/requirements.txt b/checks-superstaq/requirements.txt index 0333206d4..d4960ecaf 100644 --- a/checks-superstaq/requirements.txt +++ b/checks-superstaq/requirements.txt @@ -6,10 +6,10 @@ isort[colors]>=5.10.1 mypy>=1.0.0 nbmake>=1.3.0 nbsphinx>=0.9.0 +pydantic>=1.10.7,<2.0.0 pylint>=2.15.0 pytest>=6.2.5 pytest-cov>=2.11.1 pytest-randomly>=3.10.1 pytest-socket>=0.4.1 -pydantic>=1.10.7,<2.0.0 sphinx-rtd-theme>=1.0.0 From 85e0687511d7ae8024b01cc368797b3b1ea6ebcc Mon Sep 17 00:00:00 2001 From: Bharath Date: Fri, 6 Oct 2023 13:02:24 -0500 Subject: [PATCH 16/50] kwargs -> explicit args --- cirq-superstaq/cirq_superstaq/service.py | 33 ++++++----- .../general_superstaq/superstaq_client.py | 56 +++++++++++-------- .../superstaq_client_test.py | 6 +- qiskit-superstaq/qiskit_superstaq/conftest.py | 24 ++++++-- .../qiskit_superstaq/superstaq_provider.py | 33 ++++++----- 5 files changed, 94 insertions(+), 58 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/service.py b/cirq-superstaq/cirq_superstaq/service.py index 5cb4a2b42..8a9e0cade 100644 --- a/cirq-superstaq/cirq_superstaq/service.py +++ b/cirq-superstaq/cirq_superstaq/service.py @@ -405,26 +405,33 @@ def get_balance(self, pretty_output: bool = True) -> Union[str, float]: return balance def get_targets( - self, simulator: Optional[bool] = None, **kwargs: Any + self, + simulator: Optional[bool] = None, + supports_submit: Optional[bool] = None, + supports_submit_qubo: Optional[bool] = None, + supports_compile: Optional[bool] = None, + available: Optional[bool] = None, + retired: Optional[bool] = None, ) -> List[gss.superstaq_client.TargetInfo]: """Gets a list of Superstaq targets along with their status information. Args: - simulator: Optional flag to restrict the list of targets to simulators. - kwargs: Optional desired target filters. - - supports_submit: Boolean flag to only return targets that (don't) allow circuit - submissions. - - supports_submit_qubo: Boolean flag to only return targets that (don't) allow qubo - submissions. - - supports_compile: Boolean flag to return targets that (don't) support circuit - compilation. - - available: Boolean flag to only return targets that are (not) available to use. - - retired: Boolean flag to only return targets that are or are not retired. + simulator: Optional flag to restrict the list of targets to (non-) simulators. + supports_submit: Optional boolean flag to only return targets that (don't) allow + circuit submissions. + supports_submit_qubo: Optional boolean flag to only return targets that (don't) + allow qubo submissions. + supports_compile: Optional boolean flag to return targets that (don't) support + circuit compilation. + available: Optional boolean flag to only return targets that are (not) available + to use. + retired: Optional boolean flag to only return targets that are or are not retired. Returns: - A list of Superstaq targets (or filterd targets based on `kwargs`). + A list of Superstaq targets (or a filtered set of targets). """ - return self._client.get_targets(simulator, **kwargs) + filters = {key: value for key, value in locals().items() if key != "self"} + return self._client.get_targets(**filters) def resource_estimate( self, circuits: Union[cirq.Circuit, Sequence[cirq.Circuit]], target: Optional[str] = None diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index 794252caa..370720c0f 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -239,47 +239,57 @@ def _accept_terms_of_use(self, user_input: str) -> str: """ return self.post_request("/accept_terms_of_use", {"user_input": user_input}) - def get_targets(self, simulator: Optional[bool] = None, **kwargs: Any) -> List[TargetInfo]: + def get_targets( + self, + simulator: Optional[bool] = None, + supports_submit: Optional[bool] = None, + supports_submit_qubo: Optional[bool] = None, + supports_compile: Optional[bool] = None, + available: Optional[bool] = None, + retired: Optional[bool] = None, + ) -> List[TargetInfo]: """Makes a GET request to retrieve targets from the Superstaq API. Args: - simulator: Optional flag to restrict the list of targets to simulators. - kwargs: Optional desired target filters. - - Raises: - ValueError: If `kwargs` is not a valid keyword inquiry on the target. + simulator: Optional flag to restrict the list of targets to (non-) simulators. + supports_submit: Optional boolean flag to only return targets that (don't) allow + circuit submissions. + supports_submit_qubo: Optional boolean flag to only return targets that (don't) + allow qubo submissions. + supports_compile: Optional boolean flag to return targets that (don't) support + circuit compilation. + available: Optional boolean flag to only return targets that are (not) available + to use. + retired: Optional boolean flag to only return targets that are or are not retired. Returns: - A list of Superstaq targets (or filterd targets based on `kwargs`). + A list of Superstaq targets (or a filtered set of targets). """ + filters = { + key: value + for key, value in locals().items() + if key not in ("self", "simulator") and value is not None + } superstaq_targets = self.get_request("/targets")["superstaq_targets"] target_list = [ TargetInfo(target=target_name, **properties) for target_name, properties in superstaq_targets.items() ] - if simulator is not None: target_list = [ target_info for target_info in target_list if (target_info.target.endswith("simulator")) == simulator ] - - if kwargs: - filtered_targets = [] - for target in target_list: - for key in kwargs.keys(): - if key not in target.__fields__: - raise ValueError( - f"{key} is not a valid keyword inquiry on the target. Alternatively, " - "please use the /target_info endpoint to retrieve more information on " - "the target." - ) + if filters: + filtered_targets = [ + target_info + for target_info in target_list if all( - getattr(target, filter) == filter_value - for filter, filter_value in kwargs.items() - ): - filtered_targets.append(target) + getattr(target_info, filter) == filter_value + for filter, filter_value in filters.items() + ) + ] return filtered_targets return target_list diff --git a/general-superstaq/general_superstaq/superstaq_client_test.py b/general-superstaq/general_superstaq/superstaq_client_test.py index 0970d287f..9fa56d1bc 100644 --- a/general-superstaq/general_superstaq/superstaq_client_test.py +++ b/general-superstaq/general_superstaq/superstaq_client_test.py @@ -512,7 +512,7 @@ def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: ] assert response == simulator_targets - # test kwargs return + # test filtered return response = client.get_targets(simulator=True, supports_submit_qubo=True, available=True) assert response == [ gss.superstaq_client.TargetInfo( @@ -531,10 +531,6 @@ def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: response = client.get_targets(simulator=False, supports_submit_qubo=True, available=True) assert response == [] - # invalid kwarg test - with pytest.raises(ValueError, match="a valid keyword inquiry on the target"): - _ = client.get_targets(invalid_key=True) - @mock.patch("requests.post") def test_superstaq_client_get_job_unauthorized(mock_post: mock.MagicMock) -> None: diff --git a/qiskit-superstaq/qiskit_superstaq/conftest.py b/qiskit-superstaq/qiskit_superstaq/conftest.py index c3b8285a0..005de0d72 100644 --- a/qiskit-superstaq/qiskit_superstaq/conftest.py +++ b/qiskit-superstaq/qiskit_superstaq/conftest.py @@ -1,4 +1,4 @@ -from typing import Any, List, Optional +from typing import List, Optional import general_superstaq as gss import pytest @@ -47,14 +47,30 @@ class MockSuperstaqClient(gss.superstaq_client._SuperstaqClient): """Stand-in for `_SuperstaqClient` that the tests can call.""" def get_targets( - self, simulator: Optional[bool] = None, **kwargs: Any + self, + simulator: Optional[bool] = None, + supports_submit: Optional[bool] = None, + supports_submit_qubo: Optional[bool] = None, + supports_compile: Optional[bool] = None, + available: Optional[bool] = None, + retired: Optional[bool] = None, ) -> List[gss.superstaq_client.TargetInfo]: """Makes a GET request to retrieve targets from the Superstaq API. - Gets all targets supported by Superstaq (available, unavailable, and retired targets). + Args: + simulator: Optional flag to restrict the list of targets to (non-) simulators. + supports_submit: Optional boolean flag to only return targets that (don't) allow + circuit submissions. + supports_submit_qubo: Optional boolean flag to only return targets that (don't) + allow qubo submissions. + supports_compile: Optional boolean flag to return targets that (don't) support + circuit compilation. + available: Optional boolean flag to only return targets that are (not) available + to use. + retired: Optional boolean flag to only return targets that are or are not retired. Returns: - A dictionary listing the Superstaq targets. + A list of Superstaq targets (or a filtered set of targets). """ return gss.testing.RETURNED_TARGETS diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py index 41d9f8157..aa6201d7d 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py @@ -512,23 +512,30 @@ def process_dfe(self, ids: List[str]) -> float: return self._client.process_dfe(ids) def get_targets( - self, simulator: Optional[bool] = None, **kwargs: Any + self, + simulator: Optional[bool] = None, + supports_submit: Optional[bool] = None, + supports_submit_qubo: Optional[bool] = None, + supports_compile: Optional[bool] = None, + available: Optional[bool] = None, + retired: Optional[bool] = None, ) -> List[gss.superstaq_client.TargetInfo]: """Gets a list of Superstaq targets along with their status information. Args: - simulator: Optional flag to restrict the list of targets to simulators. - kwargs: Optional desired target filters. - - supports_submit: Boolean flag to only return targets that (don't) allow circuit - submissions. - - supports_submit_qubo: Boolean flag to only return targets that (don't) allow qubo - submissions. - - supports_compile: Boolean flag to return targets that (don't) support circuit - compilation. - - available: Boolean flag to only return targets that are (not) available to use. - - retired: Boolean flag to only return targets that are or are not retired. + simulator: Optional flag to restrict the list of targets to (non-) simulators. + supports_submit: Optional boolean flag to only return targets that (don't) allow + circuit submissions. + supports_submit_qubo: Optional boolean flag to only return targets that (don't) + allow qubo submissions. + supports_compile: Optional boolean flag to return targets that (don't) support + circuit compilation. + available: Optional boolean flag to only return targets that are (not) available + to use. + retired: Optional boolean flag to only return targets that are or are not retired. Returns: - A list of Superstaq targets (or filterd targets based on `kwargs`). + A list of all Superstaq targets (or a filtered set of Superstaq targets). """ - return self._client.get_targets(simulator, **kwargs) + filters = {key: value for key, value in locals().items() if key != "self"} + return self._client.get_targets(**filters) From 20e617ae5d91408fcb5056f13cbc64a3b99cf17a Mon Sep 17 00:00:00 2001 From: Bharath Date: Fri, 6 Oct 2023 18:18:44 -0500 Subject: [PATCH 17/50] move filtering --- .../general_superstaq/superstaq_client.py | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index 370720c0f..fe11abce1 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -265,32 +265,14 @@ def get_targets( Returns: A list of Superstaq targets (or a filtered set of targets). """ - filters = { - key: value - for key, value in locals().items() - if key not in ("self", "simulator") and value is not None + target_filters = { + key: value for key, value in locals().items() if key != "self" and value is not None } - superstaq_targets = self.get_request("/targets")["superstaq_targets"] + superstaq_targets = self.get_request("/targets", target_filters)["superstaq_targets"] target_list = [ TargetInfo(target=target_name, **properties) for target_name, properties in superstaq_targets.items() ] - if simulator is not None: - target_list = [ - target_info - for target_info in target_list - if (target_info.target.endswith("simulator")) == simulator - ] - if filters: - filtered_targets = [ - target_info - for target_info in target_list - if all( - getattr(target_info, filter) == filter_value - for filter, filter_value in filters.items() - ) - ] - return filtered_targets return target_list def add_new_user(self, json_dict: Dict[str, str]) -> str: @@ -615,11 +597,12 @@ def aqt_get_configs(self) -> Dict[str, str]: """ return self.get_request("/get_aqt_configs") - def get_request(self, endpoint: str) -> Any: + def get_request(self, endpoint: str, json_dict: Optional[Mapping[str, object]] = None) -> Any: """Performs a GET request on a given endpoint. Args: endpoint: The endpoint to perform the GET request on. + json_dict: Optional dictionary of relevant options. Returns: The response of the GET request. @@ -631,6 +614,13 @@ def request() -> requests.Response: Returns: The Flask GET request object. """ + if json_dict: + return requests.get( + f"{self.url}{endpoint}", + json=json_dict, + headers=self.headers, + verify=self.verify_https, + ) return requests.get( f"{self.url}{endpoint}", headers=self.headers, From 5f4c1b511688c96dcdd98981a057cdb4f0ec0c6a Mon Sep 17 00:00:00 2001 From: Bharath Date: Fri, 6 Oct 2023 18:18:56 -0500 Subject: [PATCH 18/50] remove filtering tests --- .../superstaq_client_test.py | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/general-superstaq/general_superstaq/superstaq_client_test.py b/general-superstaq/general_superstaq/superstaq_client_test.py index 9fa56d1bc..7c7022a65 100644 --- a/general-superstaq/general_superstaq/superstaq_client_test.py +++ b/general-superstaq/general_superstaq/superstaq_client_test.py @@ -496,6 +496,7 @@ def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: remote_host="http://example.com", api_key="to_my_heart", ) + client.get_request("/targets", json_dict={"simulator": None}) response = client.get_targets() assert response == gss.testing.RETURNED_TARGETS @@ -503,34 +504,6 @@ def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: f"http://example.com/{API_VERSION}/targets", headers=EXPECTED_HEADERS, verify=False ) - # test simulator only return - response = client.get_targets(simulator=True) - simulator_targets = [ - target_info - for target_info in gss.testing.RETURNED_TARGETS - if target_info.target.endswith("simulator") - ] - assert response == simulator_targets - - # test filtered return - response = client.get_targets(simulator=True, supports_submit_qubo=True, available=True) - assert response == [ - gss.superstaq_client.TargetInfo( - target="toshiba_bifurcation_simulator", - **{ - "supports_submit": False, - "supports_submit_qubo": True, - "supports_compile": False, - "available": True, - "retired": False, - }, - ) - ] - - # test empty return - response = client.get_targets(simulator=False, supports_submit_qubo=True, available=True) - assert response == [] - @mock.patch("requests.post") def test_superstaq_client_get_job_unauthorized(mock_post: mock.MagicMock) -> None: From c78510f7ba6f13202689655328f57a1ea1e155da Mon Sep 17 00:00:00 2001 From: Bharath Thotakura <113555655+bharat-thotakura@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:13:41 -0500 Subject: [PATCH 19/50] Use kwargs in `gss` `get_targets()` Co-authored-by: richrines1 <85512171+richrines1@users.noreply.github.com> --- .../general_superstaq/superstaq_client.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index fe11abce1..bbd823b71 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -239,15 +239,7 @@ def _accept_terms_of_use(self, user_input: str) -> str: """ return self.post_request("/accept_terms_of_use", {"user_input": user_input}) - def get_targets( - self, - simulator: Optional[bool] = None, - supports_submit: Optional[bool] = None, - supports_submit_qubo: Optional[bool] = None, - supports_compile: Optional[bool] = None, - available: Optional[bool] = None, - retired: Optional[bool] = None, - ) -> List[TargetInfo]: + def get_targets(self, **kwargs: Optional[bool]) -> List[TargetInfo]: """Makes a GET request to retrieve targets from the Superstaq API. Args: From 635ecd14298386a0b36fbbe2a10606c948637042 Mon Sep 17 00:00:00 2001 From: Bharath Thotakura <113555655+bharat-thotakura@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:14:18 -0500 Subject: [PATCH 20/50] `locals()` -> `kwargs` in `gss` Co-authored-by: richrines1 <85512171+richrines1@users.noreply.github.com> --- general-superstaq/general_superstaq/superstaq_client.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index bbd823b71..73844cc96 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -257,9 +257,7 @@ def get_targets(self, **kwargs: Optional[bool]) -> List[TargetInfo]: Returns: A list of Superstaq targets (or a filtered set of targets). """ - target_filters = { - key: value for key, value in locals().items() if key != "self" and value is not None - } + target_filters = {key: value for key, value in kwargs.items() if value is not None} superstaq_targets = self.get_request("/targets", target_filters)["superstaq_targets"] target_list = [ TargetInfo(target=target_name, **properties) From f22ea53302614c6c34dcd1a018769e669a82a97a Mon Sep 17 00:00:00 2001 From: Bharath Date: Tue, 10 Oct 2023 14:06:07 -0500 Subject: [PATCH 21/50] move to gss.typing --- .../cirq_superstaq/daily_integration_test.py | 6 ++--- cirq-superstaq/cirq_superstaq/service.py | 2 +- .../general_superstaq/superstaq_client.py | 27 +++---------------- .../general_superstaq/testing.py | 2 +- general-superstaq/general_superstaq/typing.py | 13 +++++++++ qiskit-superstaq/qiskit_superstaq/conftest.py | 2 +- .../qiskit_superstaq/superstaq_provider.py | 2 +- .../supermarq/run_benchmarks.py | 2 +- 8 files changed, 23 insertions(+), 33 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/daily_integration_test.py b/cirq-superstaq/cirq_superstaq/daily_integration_test.py index 6b5711e92..aeedb0f0a 100644 --- a/cirq-superstaq/cirq_superstaq/daily_integration_test.py +++ b/cirq-superstaq/cirq_superstaq/daily_integration_test.py @@ -150,10 +150,8 @@ def test_get_targets(service: css.Service) -> None: "available": True, "retired": False, } - assert ( - gss.superstaq_client.TargetInfo(target="ibmq_qasm_simulator", **ibmq_properties) in result - ) - assert gss.superstaq_client.TargetInfo(target="aqt_keysight_qpu", **aqt_properties) in result + assert gss.typing.TargetInfo(target="ibmq_qasm_simulator", **ibmq_properties) in result + assert gss.typing.TargetInfo(target="aqt_keysight_qpu", **aqt_properties) in result def test_qscout_compile(service: css.Service) -> None: diff --git a/cirq-superstaq/cirq_superstaq/service.py b/cirq-superstaq/cirq_superstaq/service.py index 8a9e0cade..807ec34d4 100644 --- a/cirq-superstaq/cirq_superstaq/service.py +++ b/cirq-superstaq/cirq_superstaq/service.py @@ -412,7 +412,7 @@ def get_targets( supports_compile: Optional[bool] = None, available: Optional[bool] = None, retired: Optional[bool] = None, - ) -> List[gss.superstaq_client.TargetInfo]: + ) -> List[gss.typing.TargetInfo]: """Gets a list of Superstaq targets along with their status information. Args: diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index 73844cc96..3c08d7273 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -23,7 +23,6 @@ import warnings from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Union -import pydantic import qubovert as qv import requests @@ -239,20 +238,11 @@ def _accept_terms_of_use(self, user_input: str) -> str: """ return self.post_request("/accept_terms_of_use", {"user_input": user_input}) - def get_targets(self, **kwargs: Optional[bool]) -> List[TargetInfo]: + def get_targets(self, **kwargs: Optional[bool]) -> List[gss.typing.TargetInfo]: """Makes a GET request to retrieve targets from the Superstaq API. Args: - simulator: Optional flag to restrict the list of targets to (non-) simulators. - supports_submit: Optional boolean flag to only return targets that (don't) allow - circuit submissions. - supports_submit_qubo: Optional boolean flag to only return targets that (don't) - allow qubo submissions. - supports_compile: Optional boolean flag to return targets that (don't) support - circuit compilation. - available: Optional boolean flag to only return targets that are (not) available - to use. - retired: Optional boolean flag to only return targets that are or are not retired. + kwargs: Optional flags to restrict/filter returned targets. Returns: A list of Superstaq targets (or a filtered set of targets). @@ -260,7 +250,7 @@ def get_targets(self, **kwargs: Optional[bool]) -> List[TargetInfo]: target_filters = {key: value for key, value in kwargs.items() if value is not None} superstaq_targets = self.get_request("/targets", target_filters)["superstaq_targets"] target_list = [ - TargetInfo(target=target_name, **properties) + gss.typing.TargetInfo(target=target_name, **properties) for target_name, properties in superstaq_targets.items() ] return target_list @@ -801,14 +791,3 @@ def find_api_key() -> str: "Try passing an 'api_key' variable, or setting your API key in the command line " "with SUPERSTAQ_API_KEY=..." ) - - -class TargetInfo(pydantic.BaseModel): - """A class to store data returned from a `/get_targets` request.""" - - target: str - supports_submit: bool = False - supports_submit_qubo: bool = False - supports_compile: bool = False - available: bool = False - retired: bool = False diff --git a/general-superstaq/general_superstaq/testing.py b/general-superstaq/general_superstaq/testing.py index a702b1825..bc2a8f43a 100644 --- a/general-superstaq/general_superstaq/testing.py +++ b/general-superstaq/general_superstaq/testing.py @@ -1,4 +1,4 @@ -from general_superstaq.superstaq_client import TargetInfo +from general_superstaq.typing import TargetInfo TARGET_LIST = { "aqt_keysight_qpu": { diff --git a/general-superstaq/general_superstaq/typing.py b/general-superstaq/general_superstaq/typing.py index c1ef940c7..bfb3f462f 100644 --- a/general-superstaq/general_superstaq/typing.py +++ b/general-superstaq/general_superstaq/typing.py @@ -1,5 +1,7 @@ from typing import Any, Dict, Optional, TypedDict +import pydantic + Job = TypedDict( "Job", { @@ -16,3 +18,14 @@ "state_vector": Optional[str], }, ) + + +class TargetInfo(pydantic.BaseModel): + """A data class to store data returned from a `/get_targets` request.""" + + target: str + supports_submit: bool = False + supports_submit_qubo: bool = False + supports_compile: bool = False + available: bool = False + retired: bool = False diff --git a/qiskit-superstaq/qiskit_superstaq/conftest.py b/qiskit-superstaq/qiskit_superstaq/conftest.py index 005de0d72..5c08c0f46 100644 --- a/qiskit-superstaq/qiskit_superstaq/conftest.py +++ b/qiskit-superstaq/qiskit_superstaq/conftest.py @@ -54,7 +54,7 @@ def get_targets( supports_compile: Optional[bool] = None, available: Optional[bool] = None, retired: Optional[bool] = None, - ) -> List[gss.superstaq_client.TargetInfo]: + ) -> List[gss.typing.TargetInfo]: """Makes a GET request to retrieve targets from the Superstaq API. Args: diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py index aa6201d7d..b0f4ad234 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py @@ -519,7 +519,7 @@ def get_targets( supports_compile: Optional[bool] = None, available: Optional[bool] = None, retired: Optional[bool] = None, - ) -> List[gss.superstaq_client.TargetInfo]: + ) -> List[gss.typing.TargetInfo]: """Gets a list of Superstaq targets along with their status information. Args: diff --git a/supermarq-benchmarks/supermarq/run_benchmarks.py b/supermarq-benchmarks/supermarq/run_benchmarks.py index 9831a0fc7..de79ae285 100644 --- a/supermarq-benchmarks/supermarq/run_benchmarks.py +++ b/supermarq-benchmarks/supermarq/run_benchmarks.py @@ -7,7 +7,7 @@ import supermarq if TYPE_CHECKING: - from general_superstaq.superstaq_client import TargetInfo + from general_superstaq.typing import TargetInfo BENCHMARKS: List[Tuple[supermarq.benchmark.Benchmark, str]] = [ From 59a5c2f1d08a406218f0d1720d9946341adb8be4 Mon Sep 17 00:00:00 2001 From: Bharath Date: Tue, 10 Oct 2023 14:11:53 -0500 Subject: [PATCH 22/50] comment out notebook get_targets() temp commit to pass notebook check; will be reverted --- docs/source/get_started/access_info/access_info_css.ipynb | 2 +- docs/source/get_started/access_info/access_info_qss.ipynb | 2 +- supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/get_started/access_info/access_info_css.ipynb b/docs/source/get_started/access_info/access_info_css.ipynb index e1b2f7d81..ea3535eea 100644 --- a/docs/source/get_started/access_info/access_info_css.ipynb +++ b/docs/source/get_started/access_info/access_info_css.ipynb @@ -169,7 +169,7 @@ } ], "source": [ - "service.get_targets()" + "# service.get_targets()" ] }, { diff --git a/docs/source/get_started/access_info/access_info_qss.ipynb b/docs/source/get_started/access_info/access_info_qss.ipynb index e74d4a948..2e19caaad 100644 --- a/docs/source/get_started/access_info/access_info_qss.ipynb +++ b/docs/source/get_started/access_info/access_info_qss.ipynb @@ -160,7 +160,7 @@ } ], "source": [ - "provider.backends()" + "# provider.backends()" ] }, { diff --git a/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb b/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb index cfaa0c85b..deb0305e1 100644 --- a/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb +++ b/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb @@ -150,7 +150,7 @@ ], "source": [ "# See which backends are available\n", - "service.get_targets()" + "# service.get_targets()" ] }, { From b9f80c94a03b897f3d916fc030f958db6185561c Mon Sep 17 00:00:00 2001 From: Bharath Date: Tue, 10 Oct 2023 14:25:13 -0500 Subject: [PATCH 23/50] conftest typing + docstring fix --- qiskit-superstaq/qiskit_superstaq/conftest.py | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/qiskit-superstaq/qiskit_superstaq/conftest.py b/qiskit-superstaq/qiskit_superstaq/conftest.py index 5c08c0f46..d39d57f20 100644 --- a/qiskit-superstaq/qiskit_superstaq/conftest.py +++ b/qiskit-superstaq/qiskit_superstaq/conftest.py @@ -46,28 +46,21 @@ def __init__(self, provider: qss.SuperstaqProvider, target: str) -> None: class MockSuperstaqClient(gss.superstaq_client._SuperstaqClient): """Stand-in for `_SuperstaqClient` that the tests can call.""" - def get_targets( - self, - simulator: Optional[bool] = None, - supports_submit: Optional[bool] = None, - supports_submit_qubo: Optional[bool] = None, - supports_compile: Optional[bool] = None, - available: Optional[bool] = None, - retired: Optional[bool] = None, - ) -> List[gss.typing.TargetInfo]: + def get_targets(self, **kwargs: Optional[bool]) -> List[gss.typing.TargetInfo]: """Makes a GET request to retrieve targets from the Superstaq API. Args: - simulator: Optional flag to restrict the list of targets to (non-) simulators. - supports_submit: Optional boolean flag to only return targets that (don't) allow - circuit submissions. - supports_submit_qubo: Optional boolean flag to only return targets that (don't) - allow qubo submissions. - supports_compile: Optional boolean flag to return targets that (don't) support - circuit compilation. - available: Optional boolean flag to only return targets that are (not) available - to use. - retired: Optional boolean flag to only return targets that are or are not retired. + kwargs: Optional flags to restrict/filter returned targets. + - simulator: Optional flag to restrict the list of targets to (non-) simulators. + - supports_submit: Optional boolean flag to only return targets that (don't) allow + circuit submissions. + - supports_submit_qubo: Optional boolean flag to only return targets that (don't) + allow qubo submissions. + - supports_compile: Optional boolean flag to return targets that (don't) support + circuit compilation. + - available: Optional boolean flag to only return targets that are (not) available + to use. + - retired: Optional boolean flag to only return targets that are or are not retired. Returns: A list of Superstaq targets (or a filtered set of targets). From 2ade62273739ffe15c1dd146c892e3e0fb8ec76d Mon Sep 17 00:00:00 2001 From: Bharath Date: Wed, 11 Oct 2023 11:35:18 -0500 Subject: [PATCH 24/50] remove get_targets --- cirq-superstaq/cirq_superstaq/service.py | 29 ------------------- .../qiskit_superstaq/superstaq_provider.py | 29 ------------------- 2 files changed, 58 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/service.py b/cirq-superstaq/cirq_superstaq/service.py index 807ec34d4..d92cc786f 100644 --- a/cirq-superstaq/cirq_superstaq/service.py +++ b/cirq-superstaq/cirq_superstaq/service.py @@ -404,35 +404,6 @@ def get_balance(self, pretty_output: bool = True) -> Union[str, float]: return f"${balance:,.2f}" return balance - def get_targets( - self, - simulator: Optional[bool] = None, - supports_submit: Optional[bool] = None, - supports_submit_qubo: Optional[bool] = None, - supports_compile: Optional[bool] = None, - available: Optional[bool] = None, - retired: Optional[bool] = None, - ) -> List[gss.typing.TargetInfo]: - """Gets a list of Superstaq targets along with their status information. - - Args: - simulator: Optional flag to restrict the list of targets to (non-) simulators. - supports_submit: Optional boolean flag to only return targets that (don't) allow - circuit submissions. - supports_submit_qubo: Optional boolean flag to only return targets that (don't) - allow qubo submissions. - supports_compile: Optional boolean flag to return targets that (don't) support - circuit compilation. - available: Optional boolean flag to only return targets that are (not) available - to use. - retired: Optional boolean flag to only return targets that are or are not retired. - - Returns: - A list of Superstaq targets (or a filtered set of targets). - """ - filters = {key: value for key, value in locals().items() if key != "self"} - return self._client.get_targets(**filters) - def resource_estimate( self, circuits: Union[cirq.Circuit, Sequence[cirq.Circuit]], target: Optional[str] = None ) -> Union[ResourceEstimate, List[ResourceEstimate]]: diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py index b0f4ad234..45ffb0b76 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py @@ -510,32 +510,3 @@ def process_dfe(self, ids: List[str]) -> float: through `submit_dfe` have not finished running. """ return self._client.process_dfe(ids) - - def get_targets( - self, - simulator: Optional[bool] = None, - supports_submit: Optional[bool] = None, - supports_submit_qubo: Optional[bool] = None, - supports_compile: Optional[bool] = None, - available: Optional[bool] = None, - retired: Optional[bool] = None, - ) -> List[gss.typing.TargetInfo]: - """Gets a list of Superstaq targets along with their status information. - - Args: - simulator: Optional flag to restrict the list of targets to (non-) simulators. - supports_submit: Optional boolean flag to only return targets that (don't) allow - circuit submissions. - supports_submit_qubo: Optional boolean flag to only return targets that (don't) - allow qubo submissions. - supports_compile: Optional boolean flag to return targets that (don't) support - circuit compilation. - available: Optional boolean flag to only return targets that are (not) available - to use. - retired: Optional boolean flag to only return targets that are or are not retired. - - Returns: - A list of all Superstaq targets (or a filtered set of Superstaq targets). - """ - filters = {key: value for key, value in locals().items() if key != "self"} - return self._client.get_targets(**filters) From b3e8b21214bfe4f5aaaad602aa8dc66687357f5a Mon Sep 17 00:00:00 2001 From: Bharath Date: Wed, 11 Oct 2023 11:36:10 -0500 Subject: [PATCH 25/50] move clients get_targets to gss.service --- .../general_superstaq/service.py | 62 +++++++++++++++---- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/general-superstaq/general_superstaq/service.py b/general-superstaq/general_superstaq/service.py index 783721794..eccbd2f9c 100644 --- a/general-superstaq/general_superstaq/service.py +++ b/general-superstaq/general_superstaq/service.py @@ -5,7 +5,7 @@ import qubovert as qv import general_superstaq as gss -from general_superstaq import superstaq_client +from general_superstaq import superstaq_client, typing class Service: @@ -87,7 +87,7 @@ def update_user_balance(self, email: str, balance: float) -> str: balance: The new balance. Returns: - String containing status of update (whether or not it failed). + String containing status of update (whether or not it failed). """ limit = 2000.0 # If limit modified, must update in server-superstaq if balance > limit: @@ -109,7 +109,7 @@ def update_user_role(self, email: str, role: int) -> str: role: The new role. Returns: - String containing status of update (whether or not it failed). + String containing status of update (whether or not it failed). """ return self._client.update_user_role( { @@ -118,6 +118,45 @@ def update_user_role(self, email: str, role: int) -> str: } ) + def get_targets( + self, + simulator: Optional[bool] = None, + supports_submit: Optional[bool] = None, + supports_submit_qubo: Optional[bool] = None, + supports_compile: Optional[bool] = None, + available: Optional[bool] = None, + retired: Optional[bool] = None, + **kwargs: bool, + ) -> List[typing.TargetInfo]: + """Gets a list of Superstaq targets along with their status information. + + Args: + simulator: Optional flag to restrict the list of targets to (non-) simulators. + supports_submit: Optional boolean flag to only return targets that (don't) allow + circuit submissions. + supports_submit_qubo: Optional boolean flag to only return targets that (don't) + allow qubo submissions. + supports_compile: Optional boolean flag to return targets that (don't) support + circuit compilation. + available: Optional boolean flag to only return targets that are (not) available + to use. + retired: Optional boolean flag to only return targets that are or are not retired. + kwargs: Any addtional, supported flags to restrict/filter returned targets. + + Returns: + A list of Superstaq targets (or a filtered set of targets). + """ + filters = dict( + simulator=simulator, + supports_submit=supports_submit, + supports_submit_qubo=supports_submit_qubo, + supports_compile=supports_compile, + available=available, + retired=retired, + **kwargs, + ) + return self._client.get_targets(**filters) + def submit_qubo( self, qubo: qv.QUBO, @@ -126,9 +165,10 @@ def submit_qubo( method: Optional[str] = None, max_solutions: int = 1000, ) -> Dict[str, str]: - """Solves the QUBO given via the submit_qubo function in superstaq_client, and returns any - number of specified dictionaries that seek the minimum of the energy landscape from the - given objective function known as output solutions. + """Solves a submitted QUBO problem via annealing. + + This method returns any number of specified dictionaries that seek the minimum of + the energy landscape from the given objective function known as output solutions. Args: qubo: A `qv.QUBO` object. @@ -140,7 +180,7 @@ def submit_qubo( max_solutions: A parameter that specifies the max number of output solutions. Returns: - A dictionary returned by the submit_qubo function. + A dictionary containing the output solutions. """ return self._client.submit_qubo(qubo, target, repetitions, method, max_solutions) @@ -150,8 +190,8 @@ def aqt_upload_configs(self, pulses: Any, variables: Any) -> str: Arguments can be either file paths (in .yaml format) or qtrl Manager instances. Args: - pulses: PulseManager or file path for pulse configuration. - variables: VariableManager or file path for variable configuration. + pulses: `PulseManager` or file path for pulse configuration. + variables: `VariableManager` or file path for variable configuration. Returns: A status of the update (whether or not it failed). @@ -210,8 +250,8 @@ def aqt_download_configs( is required to read the downloaded configs. Args: - pulses_file_path (optional): Where to write the pulse configuration. - variables_file_path (optional): Where to write the variable configuration. + pulses_file_path: Where to write the pulse configuration. + variables_file_path: Where to write the variable configuration. overwrite: Whether or not to overwrite existing files. Returns: From 281c6d9152f95264af7881571dce89967ec4c1bd Mon Sep 17 00:00:00 2001 From: Bharath Date: Wed, 11 Oct 2023 11:40:42 -0500 Subject: [PATCH 26/50] relocate get_targets test --- cirq-superstaq/cirq_superstaq/service_test.py | 9 --------- general-superstaq/general_superstaq/service_test.py | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/service_test.py b/cirq-superstaq/cirq_superstaq/service_test.py index 2275465b4..c8635a91b 100644 --- a/cirq-superstaq/cirq_superstaq/service_test.py +++ b/cirq-superstaq/cirq_superstaq/service_test.py @@ -249,15 +249,6 @@ def test_service_get_balance() -> None: assert service.get_balance(pretty_output=False) == 12345.6789 -@mock.patch( - "general_superstaq.superstaq_client._SuperstaqClient.get_request", - return_value={"superstaq_targets": gss.testing.TARGET_LIST}, -) -def test_service_get_targets(mock_get_request: mock.MagicMock) -> None: - service = css.Service(api_key="key", remote_host="http://example.com") - assert service.get_targets() == gss.testing.RETURNED_TARGETS - - @mock.patch( "general_superstaq.superstaq_client._SuperstaqClient.post_request", return_value={ diff --git a/general-superstaq/general_superstaq/service_test.py b/general-superstaq/general_superstaq/service_test.py index 15ccb36ff..23cf3e433 100644 --- a/general-superstaq/general_superstaq/service_test.py +++ b/general-superstaq/general_superstaq/service_test.py @@ -156,6 +156,15 @@ def test_service_aqt_upload_configs( _ = service.aqt_upload_configs({}, {}) +@mock.patch( + "general_superstaq.superstaq_client._SuperstaqClient.get_request", + return_value={"superstaq_targets": gss.testing.TARGET_LIST}, +) +def test_service_get_targets(mock_get_request: mock.MagicMock) -> None: + service = gss.service.Service(api_key="key", remote_host="http://example.com") + assert service.get_targets() == gss.testing.RETURNED_TARGETS + + @mock.patch( "general_superstaq.superstaq_client._SuperstaqClient.aqt_get_configs", return_value={"pulses": "Hello", "variables": "World"}, From bfe4a775ac3530ede05b36e659bb714ce1e8e773 Mon Sep 17 00:00:00 2001 From: Bharath Date: Wed, 11 Oct 2023 11:41:18 -0500 Subject: [PATCH 27/50] use post_request + kwargs + docstring nits --- .../general_superstaq/superstaq_client.py | 12 ++---------- .../general_superstaq/superstaq_client_test.py | 1 - 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index 3c08d7273..7debb2b88 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -248,7 +248,7 @@ def get_targets(self, **kwargs: Optional[bool]) -> List[gss.typing.TargetInfo]: A list of Superstaq targets (or a filtered set of targets). """ target_filters = {key: value for key, value in kwargs.items() if value is not None} - superstaq_targets = self.get_request("/targets", target_filters)["superstaq_targets"] + superstaq_targets = self.post_request("/targets", target_filters)["superstaq_targets"] target_list = [ gss.typing.TargetInfo(target=target_name, **properties) for target_name, properties in superstaq_targets.items() @@ -577,12 +577,11 @@ def aqt_get_configs(self) -> Dict[str, str]: """ return self.get_request("/get_aqt_configs") - def get_request(self, endpoint: str, json_dict: Optional[Mapping[str, object]] = None) -> Any: + def get_request(self, endpoint: str) -> Any: """Performs a GET request on a given endpoint. Args: endpoint: The endpoint to perform the GET request on. - json_dict: Optional dictionary of relevant options. Returns: The response of the GET request. @@ -594,13 +593,6 @@ def request() -> requests.Response: Returns: The Flask GET request object. """ - if json_dict: - return requests.get( - f"{self.url}{endpoint}", - json=json_dict, - headers=self.headers, - verify=self.verify_https, - ) return requests.get( f"{self.url}{endpoint}", headers=self.headers, diff --git a/general-superstaq/general_superstaq/superstaq_client_test.py b/general-superstaq/general_superstaq/superstaq_client_test.py index 7c7022a65..2e8fc9b78 100644 --- a/general-superstaq/general_superstaq/superstaq_client_test.py +++ b/general-superstaq/general_superstaq/superstaq_client_test.py @@ -496,7 +496,6 @@ def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: remote_host="http://example.com", api_key="to_my_heart", ) - client.get_request("/targets", json_dict={"simulator": None}) response = client.get_targets() assert response == gss.testing.RETURNED_TARGETS From bc03723fce03fee086ab054abf1cc2a55ccd94aa Mon Sep 17 00:00:00 2001 From: Bharath Date: Wed, 11 Oct 2023 11:54:02 -0500 Subject: [PATCH 28/50] change to post request in tests --- general-superstaq/general_superstaq/service_test.py | 2 +- .../general_superstaq/superstaq_client_test.py | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/general-superstaq/general_superstaq/service_test.py b/general-superstaq/general_superstaq/service_test.py index 23cf3e433..af58cfa3e 100644 --- a/general-superstaq/general_superstaq/service_test.py +++ b/general-superstaq/general_superstaq/service_test.py @@ -157,7 +157,7 @@ def test_service_aqt_upload_configs( @mock.patch( - "general_superstaq.superstaq_client._SuperstaqClient.get_request", + "general_superstaq.superstaq_client._SuperstaqClient.post_request", return_value={"superstaq_targets": gss.testing.TARGET_LIST}, ) def test_service_get_targets(mock_get_request: mock.MagicMock) -> None: diff --git a/general-superstaq/general_superstaq/superstaq_client_test.py b/general-superstaq/general_superstaq/superstaq_client_test.py index 2e8fc9b78..dd8006e01 100644 --- a/general-superstaq/general_superstaq/superstaq_client_test.py +++ b/general-superstaq/general_superstaq/superstaq_client_test.py @@ -487,10 +487,10 @@ def test_superstaq_client_resource_estimate(mock_post: mock.MagicMock) -> None: assert mock_post.call_args[0][0] == f"http://example.com/{API_VERSION}/resource_estimate" -@mock.patch("requests.get") -def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: - mock_get.return_value.ok = True - mock_get.return_value.json.return_value = {"superstaq_targets": gss.testing.TARGET_LIST} +@mock.patch("requests.post") +def test_superstaq_client_get_targets(mock_post: mock.MagicMock) -> None: + mock_post.return_value.ok = True + mock_post.return_value.json.return_value = {"superstaq_targets": gss.testing.TARGET_LIST} client = gss.superstaq_client._SuperstaqClient( client_name="general-superstaq", remote_host="http://example.com", @@ -499,10 +499,6 @@ def test_superstaq_client_get_targets(mock_get: mock.MagicMock) -> None: response = client.get_targets() assert response == gss.testing.RETURNED_TARGETS - mock_get.assert_called_with( - f"http://example.com/{API_VERSION}/targets", headers=EXPECTED_HEADERS, verify=False - ) - @mock.patch("requests.post") def test_superstaq_client_get_job_unauthorized(mock_post: mock.MagicMock) -> None: From f175de3e7a0ebd5544939f423e4b21937c998867 Mon Sep 17 00:00:00 2001 From: Bharath Date: Tue, 24 Oct 2023 16:31:17 -0500 Subject: [PATCH 29/50] remove merge conflict test _ --- cirq-superstaq/cirq_superstaq/service.py | 16 ---------------- cirq-superstaq/cirq_superstaq/service_test.py | 10 ---------- 2 files changed, 26 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/service.py b/cirq-superstaq/cirq_superstaq/service.py index 6f734fc20..625ec01a9 100644 --- a/cirq-superstaq/cirq_superstaq/service.py +++ b/cirq-superstaq/cirq_superstaq/service.py @@ -388,22 +388,6 @@ def get_job(self, job_id: str) -> css.job.Job: """ return css.job.Job(client=self._client, job_id=job_id) - def get_balance(self, pretty_output: bool = True) -> Union[str, float]: - """Get the querying user's account balance in USD. - - Args: - pretty_output: Whether to return a pretty string or a float of the balance. - - Returns: - If `pretty_output` is `True`, returns the balance as a nicely formatted string - ($-prefix, commas on LHS every three digits, and two digits after period). Otherwise, - simply returns a float of the balance. - """ - balance = self._client.get_balance()["balance"] - if pretty_output: - return f"${balance:,.2f}" - return balance - def resource_estimate( self, circuits: Union[cirq.Circuit, Sequence[cirq.Circuit]], target: Optional[str] = None ) -> Union[ResourceEstimate, List[ResourceEstimate]]: diff --git a/cirq-superstaq/cirq_superstaq/service_test.py b/cirq-superstaq/cirq_superstaq/service_test.py index ae37f9506..28500a95a 100644 --- a/cirq-superstaq/cirq_superstaq/service_test.py +++ b/cirq-superstaq/cirq_superstaq/service_test.py @@ -239,16 +239,6 @@ def test_service_create_job() -> None: assert create_job_kwargs["fake_data"] == "" -def test_service_get_balance() -> None: - service = css.Service(api_key="key", remote_host="http://example.com") - mock_client = mock.MagicMock() - mock_client.get_balance.return_value = {"balance": 12345.6789} - service._client = mock_client - - assert service.get_balance() == "12,345.68 credits" - assert service.get_balance(pretty_output=False) == 12345.6789 - - @mock.patch( "general_superstaq.superstaq_client._SuperstaqClient.post_request", return_value={ From fbd0b1c71873f9442e1151c541567b2c12ef1b16 Mon Sep 17 00:00:00 2001 From: Bharath Thotakura <113555655+bharat-thotakura@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:31:33 -0500 Subject: [PATCH 30/50] docstring update (1) Co-authored-by: richrines1 <85512171+richrines1@users.noreply.github.com> --- general-superstaq/general_superstaq/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/general-superstaq/general_superstaq/service.py b/general-superstaq/general_superstaq/service.py index 59591cc1e..3588703b6 100644 --- a/general-superstaq/general_superstaq/service.py +++ b/general-superstaq/general_superstaq/service.py @@ -144,7 +144,7 @@ def get_targets( kwargs: Any addtional, supported flags to restrict/filter returned targets. Returns: - A list of Superstaq targets (or a filtered set of targets). + A list of Superstaq targets matching all provided criteria. """ filters = dict( simulator=simulator, From 707f4f9259a8dea22cd0b2e62283179168a1579e Mon Sep 17 00:00:00 2001 From: Bharath Thotakura <113555655+bharat-thotakura@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:31:50 -0500 Subject: [PATCH 31/50] docstring update (2) Co-authored-by: richrines1 <85512171+richrines1@users.noreply.github.com> --- general-superstaq/general_superstaq/superstaq_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index 7debb2b88..55120c8fb 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -245,7 +245,7 @@ def get_targets(self, **kwargs: Optional[bool]) -> List[gss.typing.TargetInfo]: kwargs: Optional flags to restrict/filter returned targets. Returns: - A list of Superstaq targets (or a filtered set of targets). + A list of Superstaq targets matching all provided criteria. """ target_filters = {key: value for key, value in kwargs.items() if value is not None} superstaq_targets = self.post_request("/targets", target_filters)["superstaq_targets"] From 71613843741b488d4851dd5df43e8b299cecd4df Mon Sep 17 00:00:00 2001 From: Bharath Thotakura <113555655+bharat-thotakura@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:32:13 -0500 Subject: [PATCH 32/50] docstring update (3) Co-authored-by: richrines1 <85512171+richrines1@users.noreply.github.com> --- qiskit-superstaq/qiskit_superstaq/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit-superstaq/qiskit_superstaq/conftest.py b/qiskit-superstaq/qiskit_superstaq/conftest.py index d39d57f20..41e785eae 100644 --- a/qiskit-superstaq/qiskit_superstaq/conftest.py +++ b/qiskit-superstaq/qiskit_superstaq/conftest.py @@ -63,7 +63,7 @@ def get_targets(self, **kwargs: Optional[bool]) -> List[gss.typing.TargetInfo]: - retired: Optional boolean flag to only return targets that are or are not retired. Returns: - A list of Superstaq targets (or a filtered set of targets). + A list of Superstaq targets matching all provided criteria. """ return gss.testing.RETURNED_TARGETS From 082b0705eddab96b7864e4d2dab880b90f74b2f8 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 26 Oct 2023 13:14:38 -0500 Subject: [PATCH 33/50] update requirements --- cirq-superstaq/dev-requirements.txt | 2 +- cirq-superstaq/example-requirements.txt | 2 +- cirq-superstaq/requirements.txt | 2 +- docs/requirements.txt | 4 ++-- general-superstaq/dev-requirements.txt | 2 +- qiskit-superstaq/dev-requirements.txt | 2 +- qiskit-superstaq/requirements.txt | 2 +- supermarq-benchmarks/dev-requirements.txt | 2 +- supermarq-benchmarks/requirements.txt | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cirq-superstaq/dev-requirements.txt b/cirq-superstaq/dev-requirements.txt index a14958861..6774b8e02 100644 --- a/cirq-superstaq/dev-requirements.txt +++ b/cirq-superstaq/dev-requirements.txt @@ -1 +1 @@ -checks-superstaq~=0.4.28 +checks-superstaq~=0.4.29 diff --git a/cirq-superstaq/example-requirements.txt b/cirq-superstaq/example-requirements.txt index 5c902cdd0..c201ab211 100644 --- a/cirq-superstaq/example-requirements.txt +++ b/cirq-superstaq/example-requirements.txt @@ -1,2 +1,2 @@ notebook~=6.5.5 -qiskit-superstaq~=0.4.28 +qiskit-superstaq~=0.4.29 diff --git a/cirq-superstaq/requirements.txt b/cirq-superstaq/requirements.txt index 4a83cc434..85ec798da 100644 --- a/cirq-superstaq/requirements.txt +++ b/cirq-superstaq/requirements.txt @@ -1,3 +1,3 @@ cirq>=1.0.0 -general-superstaq~=0.4.28 +general-superstaq~=0.4.29 qubovert>=1.2.3 diff --git a/docs/requirements.txt b/docs/requirements.txt index b0d0c1156..465c7a931 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,5 @@ -cirq-superstaq[dev]~=0.4.28 +cirq-superstaq[dev]~=0.4.29 ipywidgets>=8.0.0 nbsphinx>=0.9.0 -qiskit-superstaq[dev]~=0.4.28 +qiskit-superstaq[dev]~=0.4.29 sphinx-rtd-theme>=1.0.0 diff --git a/general-superstaq/dev-requirements.txt b/general-superstaq/dev-requirements.txt index 0cf93f4e2..3b5028a50 100644 --- a/general-superstaq/dev-requirements.txt +++ b/general-superstaq/dev-requirements.txt @@ -1,2 +1,2 @@ -checks-superstaq~=0.4.28 +checks-superstaq~=0.4.29 pyyaml>=6.0 diff --git a/qiskit-superstaq/dev-requirements.txt b/qiskit-superstaq/dev-requirements.txt index a14958861..6774b8e02 100644 --- a/qiskit-superstaq/dev-requirements.txt +++ b/qiskit-superstaq/dev-requirements.txt @@ -1 +1 @@ -checks-superstaq~=0.4.28 +checks-superstaq~=0.4.29 diff --git a/qiskit-superstaq/requirements.txt b/qiskit-superstaq/requirements.txt index d4715443f..785924487 100644 --- a/qiskit-superstaq/requirements.txt +++ b/qiskit-superstaq/requirements.txt @@ -1,3 +1,3 @@ -general-superstaq~=0.4.28 +general-superstaq~=0.4.29 matplotlib~=3.0 qiskit>=0.43.3 diff --git a/supermarq-benchmarks/dev-requirements.txt b/supermarq-benchmarks/dev-requirements.txt index a14958861..6774b8e02 100644 --- a/supermarq-benchmarks/dev-requirements.txt +++ b/supermarq-benchmarks/dev-requirements.txt @@ -1 +1 @@ -checks-superstaq~=0.4.28 +checks-superstaq~=0.4.29 diff --git a/supermarq-benchmarks/requirements.txt b/supermarq-benchmarks/requirements.txt index 1b8fec69e..f354a681b 100644 --- a/supermarq-benchmarks/requirements.txt +++ b/supermarq-benchmarks/requirements.txt @@ -1,4 +1,4 @@ -cirq-superstaq~=0.4.28 +cirq-superstaq~=0.4.29 matplotlib<=3.5.2 -qiskit-superstaq~=0.4.28 +qiskit-superstaq~=0.4.29 scikit-learn>=1.0 From b6d1470a5ea92239e142b3af3e8766c2f5c07598 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 26 Oct 2023 13:33:58 -0500 Subject: [PATCH 34/50] use gss.TargetInfo --- general-superstaq/general_superstaq/service.py | 5 ++--- general-superstaq/general_superstaq/superstaq_client.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/general-superstaq/general_superstaq/service.py b/general-superstaq/general_superstaq/service.py index 3588703b6..36afd6fc2 100644 --- a/general-superstaq/general_superstaq/service.py +++ b/general-superstaq/general_superstaq/service.py @@ -5,7 +5,6 @@ import qubovert as qv import general_superstaq as gss -from general_superstaq import superstaq_client, typing class Service: @@ -25,7 +24,7 @@ def __init__( client: The Superstaq client to use. """ - self._client = superstaq_client._SuperstaqClient( + self._client = gss.superstaq_client._SuperstaqClient( client_name="general-superstaq", remote_host=remote_host, api_key=api_key, @@ -127,7 +126,7 @@ def get_targets( available: Optional[bool] = None, retired: Optional[bool] = None, **kwargs: bool, - ) -> List[typing.TargetInfo]: + ) -> List[gss.TargetInfo]: """Gets a list of Superstaq targets along with their status information. Args: diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index 55120c8fb..dff513345 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -238,7 +238,7 @@ def _accept_terms_of_use(self, user_input: str) -> str: """ return self.post_request("/accept_terms_of_use", {"user_input": user_input}) - def get_targets(self, **kwargs: Optional[bool]) -> List[gss.typing.TargetInfo]: + def get_targets(self, **kwargs: Optional[bool]) -> List[gss.TargetInfo]: """Makes a GET request to retrieve targets from the Superstaq API. Args: @@ -250,7 +250,7 @@ def get_targets(self, **kwargs: Optional[bool]) -> List[gss.typing.TargetInfo]: target_filters = {key: value for key, value in kwargs.items() if value is not None} superstaq_targets = self.post_request("/targets", target_filters)["superstaq_targets"] target_list = [ - gss.typing.TargetInfo(target=target_name, **properties) + gss.TargetInfo(target=target_name, **properties) for target_name, properties in superstaq_targets.items() ] return target_list From 47cabd51568640a4d501adac7320c826cad907a0 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 26 Oct 2023 13:33:39 -0500 Subject: [PATCH 35/50] remove testing import use gss.TargetInfo import fix updated gss.testing import --- general-superstaq/general_superstaq/__init__.py | 4 ++-- general-superstaq/general_superstaq/service_test.py | 5 +++-- general-superstaq/general_superstaq/superstaq_client_test.py | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/general-superstaq/general_superstaq/__init__.py b/general-superstaq/general_superstaq/__init__.py index a279ad398..1694efd9d 100644 --- a/general-superstaq/general_superstaq/__init__.py +++ b/general-superstaq/general_superstaq/__init__.py @@ -7,6 +7,7 @@ SuperstaqUnsuccessfulJobException, SuperstaqWarning, ) +from general_superstaq.typing import TargetInfo from . import ( qubo, @@ -14,7 +15,6 @@ service, superstaq_client, superstaq_exceptions, - testing, typing, validation, ) @@ -34,6 +34,6 @@ "superstaq_client", "superstaq_exceptions", "typing", - "testing", + "TargetInfo", "validation", ] diff --git a/general-superstaq/general_superstaq/service_test.py b/general-superstaq/general_superstaq/service_test.py index f58b57788..52e2ae4b2 100644 --- a/general-superstaq/general_superstaq/service_test.py +++ b/general-superstaq/general_superstaq/service_test.py @@ -8,6 +8,7 @@ import qubovert as qv import general_superstaq as gss +from general_superstaq.testing import RETURNED_TARGETS, TARGET_LIST def test_service_get_balance() -> None: @@ -158,11 +159,11 @@ def test_service_aqt_upload_configs( @mock.patch( "general_superstaq.superstaq_client._SuperstaqClient.post_request", - return_value={"superstaq_targets": gss.testing.TARGET_LIST}, + return_value={"superstaq_targets": TARGET_LIST}, ) def test_service_get_targets(mock_get_request: mock.MagicMock) -> None: service = gss.service.Service(api_key="key", remote_host="http://example.com") - assert service.get_targets() == gss.testing.RETURNED_TARGETS + assert service.get_targets() == RETURNED_TARGETS @mock.patch( diff --git a/general-superstaq/general_superstaq/superstaq_client_test.py b/general-superstaq/general_superstaq/superstaq_client_test.py index dd8006e01..be8e2781a 100644 --- a/general-superstaq/general_superstaq/superstaq_client_test.py +++ b/general-superstaq/general_superstaq/superstaq_client_test.py @@ -22,6 +22,7 @@ import requests import general_superstaq as gss +from general_superstaq.testing import RETURNED_TARGETS, TARGET_LIST API_VERSION = gss.API_VERSION EXPECTED_HEADERS = { @@ -490,14 +491,14 @@ def test_superstaq_client_resource_estimate(mock_post: mock.MagicMock) -> None: @mock.patch("requests.post") def test_superstaq_client_get_targets(mock_post: mock.MagicMock) -> None: mock_post.return_value.ok = True - mock_post.return_value.json.return_value = {"superstaq_targets": gss.testing.TARGET_LIST} + mock_post.return_value.json.return_value = {"superstaq_targets": TARGET_LIST} client = gss.superstaq_client._SuperstaqClient( client_name="general-superstaq", remote_host="http://example.com", api_key="to_my_heart", ) response = client.get_targets() - assert response == gss.testing.RETURNED_TARGETS + assert response == RETURNED_TARGETS @mock.patch("requests.post") From 5f4460a4c1d34a3f6159615123d6afa78fc6f909 Mon Sep 17 00:00:00 2001 From: Bharath Thotakura <113555655+bharat-thotakura@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:32:48 -0500 Subject: [PATCH 36/50] remove submission restriction Co-authored-by: richrines1 <85512171+richrines1@users.noreply.github.com> --- qiskit-superstaq/qiskit_superstaq/superstaq_provider.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py index f36e04df7..829c29a9d 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py @@ -128,11 +128,10 @@ def backends(self) -> List[qss.SuperstaqBackend]: Returns: A list of Superstaq backends. """ - submit_targets = self._client.get_targets() + targets = self._client.get_targets() superstaq_backends = [] - for backend in submit_targets: - if backend.supports_submit: - superstaq_backends.append(self.get_backend(backend.target)) + for backend in targets: + superstaq_backends.append(self.get_backend(backend.target)) return superstaq_backends def resource_estimate( From 601545328d3edc68076cc3ca602953032535ee66 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 26 Oct 2023 13:58:39 -0500 Subject: [PATCH 37/50] update test from allowed backends update --- .../qiskit_superstaq/superstaq_provider_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py index 3045675f0..4b24e1239 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py @@ -23,13 +23,13 @@ @patch.dict(os.environ, {"SUPERSTAQ_API_KEY": ""}) def test_provider(fake_superstaq_provider: MockSuperstaqProvider) -> None: assert str(fake_superstaq_provider) == "" - assert ( repr(fake_superstaq_provider) == "" ) - - assert str(fake_superstaq_provider.backends()[0]) == "aws_dm1_simulator" + assert ( + str(fake_superstaq_provider.backends()[0]) == "aqt_keysight_qpu" + ) # First backend alphabetically. def test_provider_args() -> None: From 0a82700619f76c80a5de5ae1883452e6e7480f77 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 26 Oct 2023 14:29:42 -0500 Subject: [PATCH 38/50] update testing import in qss --- qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py index 4b24e1239..5aeed6eb5 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py @@ -13,6 +13,7 @@ import pytest import qiskit from general_superstaq import ResourceEstimate +from general_supertaq.testing import RETURNED_TARGETS, TARGET_LIST import qiskit_superstaq as qss @@ -435,5 +436,5 @@ def test_dfe(mock_post: MagicMock, fake_superstaq_provider: MockSuperstaqProvide @patch("requests.get") def test_get_targets(mock_get: MagicMock, fake_superstaq_provider: MockSuperstaqProvider) -> None: - mock_get.return_value.json = {"superstaq_targets": gss.testing.TARGET_LIST} - assert fake_superstaq_provider.get_targets() == gss.testing.RETURNED_TARGETS + mock_get.return_value.json = {"superstaq_targets": TARGET_LIST} + assert fake_superstaq_provider.get_targets() == RETURNED_TARGETS From 31b8d82ca0f0f5a8c9050ffb0f1de6776ff21bee Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 26 Oct 2023 14:45:37 -0500 Subject: [PATCH 39/50] gss.testing import fix in qss --- .../qiskit_superstaq/superstaq_provider_test.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py index 5aeed6eb5..9065981bd 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider_test.py @@ -12,8 +12,7 @@ import numpy as np import pytest import qiskit -from general_superstaq import ResourceEstimate -from general_supertaq.testing import RETURNED_TARGETS, TARGET_LIST +from general_superstaq import ResourceEstimate, testing import qiskit_superstaq as qss @@ -436,5 +435,5 @@ def test_dfe(mock_post: MagicMock, fake_superstaq_provider: MockSuperstaqProvide @patch("requests.get") def test_get_targets(mock_get: MagicMock, fake_superstaq_provider: MockSuperstaqProvider) -> None: - mock_get.return_value.json = {"superstaq_targets": TARGET_LIST} - assert fake_superstaq_provider.get_targets() == RETURNED_TARGETS + mock_get.return_value.json = {"superstaq_targets": testing.TARGET_LIST} + assert fake_superstaq_provider.get_targets() == testing.RETURNED_TARGETS From 4dfaf8918d6feba8ca53f11ead436d1df1aac1c4 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 26 Oct 2023 14:53:13 -0500 Subject: [PATCH 40/50] clearer TargetInfo in integration test --- .../cirq_superstaq/daily_integration_test.py | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/daily_integration_test.py b/cirq-superstaq/cirq_superstaq/daily_integration_test.py index 46306f585..807afe7b5 100644 --- a/cirq-superstaq/cirq_superstaq/daily_integration_test.py +++ b/cirq-superstaq/cirq_superstaq/daily_integration_test.py @@ -136,22 +136,25 @@ def test_get_resource_estimate(service: css.Service) -> None: def test_get_targets(service: css.Service) -> None: result = service.get_targets() - ibmq_properties = { - "supports_submit": True, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - } - aqt_properties = { - "supports_submit": False, - "supports_submit_qubo": False, - "supports_compile": True, - "available": True, - "retired": False, - } - assert gss.typing.TargetInfo(target="ibmq_qasm_simulator", **ibmq_properties) in result - assert gss.typing.TargetInfo(target="aqt_keysight_qpu", **aqt_properties) in result + ibmq_target_info = gss.typing.TargetInfo( + target="ibmq_qasm_simulator", + supports_submit=True, + supports_submit_qubo=False, + supports_compile=True, + available=True, + retired=False, + ) + aqt_target_info = gss.typing.TargetInfo( + target="aqt_keysight_qpu", + supports_submit=False, + supports_submit_qubo=False, + supports_compile=True, + available=True, + retired=False, + ) + + assert ibmq_target_info in result + assert aqt_target_info in result def test_qscout_compile(service: css.Service) -> None: From d4f6f966833a1d67ced5a5a03f89bad793a408b5 Mon Sep 17 00:00:00 2001 From: Bharath Date: Fri, 3 Nov 2023 16:49:22 -0500 Subject: [PATCH 41/50] Revert "MIS notebook update" This reverts commit c6c686c97558b8329f9e9dab193e4dccc8afb843. --- docs/source/apps/max_sharpe_ratio_optimization.ipynb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/source/apps/max_sharpe_ratio_optimization.ipynb b/docs/source/apps/max_sharpe_ratio_optimization.ipynb index 24f483192..fd52e2522 100644 --- a/docs/source/apps/max_sharpe_ratio_optimization.ipynb +++ b/docs/source/apps/max_sharpe_ratio_optimization.ipynb @@ -94,8 +94,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Run this to use token as an environment variable\n", - "# os.environ[\"SUPERSTAQ_API_KEY\"] = \"key\"" + "os.environ[\"SUPERSTAQ_API_KEY\"] = \"key\"" ] }, { @@ -1024,8 +1023,8 @@ "source": [ "from qubovert.sim import anneal_qubo\n", "\n", - "res = client.submit_qubo(obj_QUBO, target=\"toshiba_bifurcation_simulator\", method=\"dry-run\")\n", - "# res = client.submit_qubo(obj_QUBO, target=\"toshiba_bifurcation_simulator\")\n", + "res = client.submit_qubo(obj_QUBO, target=\"toshiba_bifurcation_qpu\", method=\"dry-run\")\n", + "# res = client.submit_qubo(obj_QUBO, target=\"toshiba_bifurcation_qpu\")\n", "res = gss.qubo.read_json_qubo_result(res)" ] }, @@ -1267,7 +1266,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, From 9aeba903b926f0b3818c2a1e32b68e4a97571aa5 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 9 Nov 2023 17:28:48 -0600 Subject: [PATCH 42/50] renaming TargetInfo -> Target --- cirq-superstaq/cirq_superstaq/daily_integration_test.py | 4 ++-- general-superstaq/general_superstaq/__init__.py | 4 ++-- general-superstaq/general_superstaq/service.py | 2 +- general-superstaq/general_superstaq/superstaq_client.py | 4 ++-- general-superstaq/general_superstaq/testing.py | 4 ++-- general-superstaq/general_superstaq/typing.py | 2 +- qiskit-superstaq/qiskit_superstaq/conftest.py | 2 +- supermarq-benchmarks/supermarq/run_benchmarks.py | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cirq-superstaq/cirq_superstaq/daily_integration_test.py b/cirq-superstaq/cirq_superstaq/daily_integration_test.py index 807afe7b5..4ed71cd05 100644 --- a/cirq-superstaq/cirq_superstaq/daily_integration_test.py +++ b/cirq-superstaq/cirq_superstaq/daily_integration_test.py @@ -136,7 +136,7 @@ def test_get_resource_estimate(service: css.Service) -> None: def test_get_targets(service: css.Service) -> None: result = service.get_targets() - ibmq_target_info = gss.typing.TargetInfo( + ibmq_target_info = gss.typing.Target( target="ibmq_qasm_simulator", supports_submit=True, supports_submit_qubo=False, @@ -144,7 +144,7 @@ def test_get_targets(service: css.Service) -> None: available=True, retired=False, ) - aqt_target_info = gss.typing.TargetInfo( + aqt_target_info = gss.typing.Target( target="aqt_keysight_qpu", supports_submit=False, supports_submit_qubo=False, diff --git a/general-superstaq/general_superstaq/__init__.py b/general-superstaq/general_superstaq/__init__.py index 1694efd9d..20799ff66 100644 --- a/general-superstaq/general_superstaq/__init__.py +++ b/general-superstaq/general_superstaq/__init__.py @@ -7,7 +7,7 @@ SuperstaqUnsuccessfulJobException, SuperstaqWarning, ) -from general_superstaq.typing import TargetInfo +from general_superstaq.typing import Target from . import ( qubo, @@ -34,6 +34,6 @@ "superstaq_client", "superstaq_exceptions", "typing", - "TargetInfo", + "Target", "validation", ] diff --git a/general-superstaq/general_superstaq/service.py b/general-superstaq/general_superstaq/service.py index 2d37c67dd..25d126f21 100644 --- a/general-superstaq/general_superstaq/service.py +++ b/general-superstaq/general_superstaq/service.py @@ -126,7 +126,7 @@ def get_targets( available: Optional[bool] = None, retired: Optional[bool] = None, **kwargs: bool, - ) -> List[gss.TargetInfo]: + ) -> List[gss.Target]: """Gets a list of Superstaq targets along with their status information. Args: diff --git a/general-superstaq/general_superstaq/superstaq_client.py b/general-superstaq/general_superstaq/superstaq_client.py index df4f8faea..dcf0126a3 100644 --- a/general-superstaq/general_superstaq/superstaq_client.py +++ b/general-superstaq/general_superstaq/superstaq_client.py @@ -239,7 +239,7 @@ def _accept_terms_of_use(self, user_input: str) -> str: """ return self.post_request("/accept_terms_of_use", {"user_input": user_input}) - def get_targets(self, **kwargs: Optional[bool]) -> List[gss.TargetInfo]: + def get_targets(self, **kwargs: Optional[bool]) -> List[gss.Target]: """Makes a GET request to retrieve targets from the Superstaq API. Args: @@ -251,7 +251,7 @@ def get_targets(self, **kwargs: Optional[bool]) -> List[gss.TargetInfo]: target_filters = {key: value for key, value in kwargs.items() if value is not None} superstaq_targets = self.post_request("/targets", target_filters)["superstaq_targets"] target_list = [ - gss.TargetInfo(target=target_name, **properties) + gss.Target(target=target_name, **properties) for target_name, properties in superstaq_targets.items() ] return target_list diff --git a/general-superstaq/general_superstaq/testing.py b/general-superstaq/general_superstaq/testing.py index bc2a8f43a..36a3629d4 100644 --- a/general-superstaq/general_superstaq/testing.py +++ b/general-superstaq/general_superstaq/testing.py @@ -1,4 +1,4 @@ -from general_superstaq.typing import TargetInfo +from general_superstaq.typing import Target TARGET_LIST = { "aqt_keysight_qpu": { @@ -242,5 +242,5 @@ } RETURNED_TARGETS = [ - TargetInfo(target=target_name, **properties) for target_name, properties in TARGET_LIST.items() + Target(target=target_name, **properties) for target_name, properties in TARGET_LIST.items() ] diff --git a/general-superstaq/general_superstaq/typing.py b/general-superstaq/general_superstaq/typing.py index bfb3f462f..fd3ebdbc5 100644 --- a/general-superstaq/general_superstaq/typing.py +++ b/general-superstaq/general_superstaq/typing.py @@ -20,7 +20,7 @@ ) -class TargetInfo(pydantic.BaseModel): +class Target(pydantic.BaseModel): """A data class to store data returned from a `/get_targets` request.""" target: str diff --git a/qiskit-superstaq/qiskit_superstaq/conftest.py b/qiskit-superstaq/qiskit_superstaq/conftest.py index 41e785eae..ca32f19a3 100644 --- a/qiskit-superstaq/qiskit_superstaq/conftest.py +++ b/qiskit-superstaq/qiskit_superstaq/conftest.py @@ -46,7 +46,7 @@ def __init__(self, provider: qss.SuperstaqProvider, target: str) -> None: class MockSuperstaqClient(gss.superstaq_client._SuperstaqClient): """Stand-in for `_SuperstaqClient` that the tests can call.""" - def get_targets(self, **kwargs: Optional[bool]) -> List[gss.typing.TargetInfo]: + def get_targets(self, **kwargs: Optional[bool]) -> List[gss.typing.Target]: """Makes a GET request to retrieve targets from the Superstaq API. Args: diff --git a/supermarq-benchmarks/supermarq/run_benchmarks.py b/supermarq-benchmarks/supermarq/run_benchmarks.py index de79ae285..18ba5c936 100644 --- a/supermarq-benchmarks/supermarq/run_benchmarks.py +++ b/supermarq-benchmarks/supermarq/run_benchmarks.py @@ -7,7 +7,7 @@ import supermarq if TYPE_CHECKING: - from general_superstaq.typing import TargetInfo + from general_superstaq.typing import Target BENCHMARKS: List[Tuple[supermarq.benchmark.Benchmark, str]] = [ @@ -18,7 +18,7 @@ ] -def get_qpu_targets(target_list: List[TargetInfo]) -> List[TargetInfo]: +def get_qpu_targets(target_list: List[Target]) -> List[Target]: """Gets real device targets. Args: From 38bdb83737eb1c647fcbef6f7eacebd84b2a187b Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 9 Nov 2023 19:02:42 -0600 Subject: [PATCH 43/50] Revert "comment out notebook get_targets()" This reverts commit 59a5c2f1d08a406218f0d1720d9946341adb8be4. --- docs/source/get_started/access_info/access_info_css.ipynb | 2 +- docs/source/get_started/access_info/access_info_qss.ipynb | 2 +- supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/get_started/access_info/access_info_css.ipynb b/docs/source/get_started/access_info/access_info_css.ipynb index 3ef1e7263..2787528ba 100644 --- a/docs/source/get_started/access_info/access_info_css.ipynb +++ b/docs/source/get_started/access_info/access_info_css.ipynb @@ -169,7 +169,7 @@ } ], "source": [ - "# service.get_targets()" + "service.get_targets()" ] }, { diff --git a/docs/source/get_started/access_info/access_info_qss.ipynb b/docs/source/get_started/access_info/access_info_qss.ipynb index 1ecbf78e7..db64aa1f9 100644 --- a/docs/source/get_started/access_info/access_info_qss.ipynb +++ b/docs/source/get_started/access_info/access_info_qss.ipynb @@ -158,7 +158,7 @@ } ], "source": [ - "# provider.backends()" + "provider.backends()" ] }, { diff --git a/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb b/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb index deb0305e1..cfaa0c85b 100644 --- a/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb +++ b/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb @@ -150,7 +150,7 @@ ], "source": [ "# See which backends are available\n", - "# service.get_targets()" + "service.get_targets()" ] }, { From 421b636c25de41054baeafb7bf0e536c35d38530 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 9 Nov 2023 19:12:13 -0600 Subject: [PATCH 44/50] filter to backend() --- qiskit-superstaq/qiskit_superstaq/superstaq_provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py index 829c29a9d..0afdadf7e 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py @@ -128,7 +128,7 @@ def backends(self) -> List[qss.SuperstaqBackend]: Returns: A list of Superstaq backends. """ - targets = self._client.get_targets() + targets = self._client.get_targets(supports_submit_qubo=False) superstaq_backends = [] for backend in targets: superstaq_backends.append(self.get_backend(backend.target)) From 8972ef8f6206ceb1ab8b8e958a871f4762d41f80 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 9 Nov 2023 20:05:48 -0600 Subject: [PATCH 45/50] add filters to backends() --- .../qiskit_superstaq/superstaq_provider.py | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py index 0afdadf7e..fd6692908 100644 --- a/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py +++ b/qiskit-superstaq/qiskit_superstaq/superstaq_provider.py @@ -122,13 +122,41 @@ def get_backend(self, target: str) -> qss.SuperstaqBackend: """ return qss.SuperstaqBackend(provider=self, target=target) - def backends(self) -> List[qss.SuperstaqBackend]: + def backends( + self, + simulator: Optional[bool] = None, + supports_submit: Optional[bool] = None, + supports_compile: Optional[bool] = None, + available: Optional[bool] = None, + retired: Optional[bool] = None, + **kwargs: bool, + ) -> List[qss.SuperstaqBackend]: """Lists the backends available from this provider. + Args: + simulator: Optional flag to restrict the list of targets to (non-) simulators. + supports_submit: Optional boolean flag to only return targets that (don't) allow + circuit submissions. + supports_compile: Optional boolean flag to return targets that (don't) support + circuit compilation. + available: Optional boolean flag to only return targets that are (not) available + to use. + retired: Optional boolean flag to only return targets that are or are not retired. + kwargs: Any additional, supported flags to restrict/filter returned targets. + Returns: A list of Superstaq backends. """ - targets = self._client.get_targets(supports_submit_qubo=False) + filters = dict( + simulator=simulator, + supports_submit=supports_submit, + supports_submit_qubo=False, + supports_compile=supports_compile, + available=available, + retired=retired, + **kwargs, + ) + targets = self._client.get_targets(**filters) superstaq_backends = [] for backend in targets: superstaq_backends.append(self.get_backend(backend.target)) From 8926de32249f0f37dbeded45454e1b52fb126171 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 9 Nov 2023 20:06:12 -0600 Subject: [PATCH 46/50] docstring typo fix --- general-superstaq/general_superstaq/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/general-superstaq/general_superstaq/service.py b/general-superstaq/general_superstaq/service.py index 25d126f21..59d030904 100644 --- a/general-superstaq/general_superstaq/service.py +++ b/general-superstaq/general_superstaq/service.py @@ -140,7 +140,7 @@ def get_targets( available: Optional boolean flag to only return targets that are (not) available to use. retired: Optional boolean flag to only return targets that are or are not retired. - kwargs: Any addtional, supported flags to restrict/filter returned targets. + kwargs: Any additional, supported flags to restrict/filter returned targets. Returns: A list of Superstaq targets matching all provided criteria. From c4182ea410bda790b4358247e4e44a23330a747f Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 9 Nov 2023 20:06:30 -0600 Subject: [PATCH 47/50] rerun supermarq notebook --- .../examples/Supermarq_HPCA_Tutorial.ipynb | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb b/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb index cfaa0c85b..99e1a586e 100644 --- a/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb +++ b/supermarq-benchmarks/examples/Supermarq_HPCA_Tutorial.ipynb @@ -62,7 +62,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "$145.05\n" + "20 credits\n" ] } ], @@ -85,7 +85,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "$145.05\n" + "20 credits\n" ] } ], @@ -107,40 +107,42 @@ { "data": { "text/plain": [ - "{'compile-only': ['aqt_keysight_qpu', 'aqt_zurich_qpu', 'sandia_qscout_qpu'],\n", - " 'compile-and-run': ['aws_dm1_simulator',\n", - " 'aws_sv1_simulator',\n", - " 'aws_tn1_simulator',\n", - " 'cq_hilbert_qpu',\n", - " 'cq_hilbert_simulator',\n", - " 'ibmq_belem_qpu',\n", - " 'ibmq_extended-stabilizer_simulator',\n", - " 'ibmq_guadalupe_qpu',\n", - " 'ibmq_jakarta_qpu',\n", - " 'ibmq_lagos_qpu',\n", - " 'ibmq_lima_qpu',\n", - " 'ibmq_manila_qpu',\n", - " 'ibmq_mps_simulator',\n", - " 'ibmq_nairobi_qpu',\n", - " 'ibmq_perth_qpu',\n", - " 'ibmq_qasm_simulator',\n", - " 'ibmq_quito_qpu',\n", - " 'ibmq_stabilizer_simulator',\n", - " 'ibmq_statevector_simulator',\n", - " 'ionq_aria-1_qpu',\n", - " 'ionq_harmony_qpu',\n", - " 'ionq_ion_simulator',\n", - " 'qtm_h1-1_qpu',\n", - " 'qtm_h1-1e_simulator',\n", - " 'qtm_h2-1_qpu',\n", - " 'ss_unconstrained_simulator'],\n", - " 'unavailable': ['oxford_lucy_qpu', 'rigetti_aspen-m-3_qpu'],\n", - " 'retired': ['rigetti_aspen-10_qpu',\n", - " 'rigetti_aspen-11_qpu',\n", - " 'rigetti_aspen-8_qpu',\n", - " 'rigetti_aspen-9_qpu',\n", - " 'rigetti_aspen-m-1_qpu',\n", - " 'rigetti_aspen-m-2_qpu']}" + "[Target(target='aqt_keysight_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='aqt_zurich_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='aws_dm1_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='aws_sv1_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='aws_tn1_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='cq_hilbert_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='cq_hilbert_simulator', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_brisbane_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_extended-stabilizer_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_fake-athens_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_fake-lima_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_lagos_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_mps_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_nairobi_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_perth_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_qasm_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_stabilizer_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_statevector_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ionq_aria-1_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='ionq_aria-2_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='ionq_harmony_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='ionq_ion_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='oxford_lucy_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='qtm_h1-1_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='qtm_h1-1e_simulator', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='qtm_h2-1_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='rigetti_aspen-10_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-11_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-8_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-9_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-m-1_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-m-2_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-m-3_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='sandia_qscout_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ss_unconstrained_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='toshiba_bifurcation_simulator', supports_submit=False, supports_submit_qubo=True, supports_compile=False, available=True, retired=False)]" ] }, "execution_count": 4, From f85fc62f90ed40d323e5cb1d6bbe19f0b8ec98d2 Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 9 Nov 2023 20:11:08 -0600 Subject: [PATCH 48/50] re-run get_started notebooks + nits --- .../access_info/access_info_css.ipynb | 82 ++++++++++--------- .../access_info/access_info_qss.ipynb | 28 +++++-- 2 files changed, 62 insertions(+), 48 deletions(-) diff --git a/docs/source/get_started/access_info/access_info_css.ipynb b/docs/source/get_started/access_info/access_info_css.ipynb index 2787528ba..15931bb33 100644 --- a/docs/source/get_started/access_info/access_info_css.ipynb +++ b/docs/source/get_started/access_info/access_info_css.ipynb @@ -84,7 +84,7 @@ { "data": { "text/plain": [ - "'135.75 credits'" + "'20 credits'" ] }, "execution_count": 3, @@ -110,9 +110,9 @@ "metadata": {}, "source": [ "## Backend Information\n", - "In addition to account information, the`Service` object also gives you a list of all the devices and simulators to which you have access, as well as additional information about those backends.\n", + "In addition to account information, the ``Service`` object also gives you a list of all the devices and simulators to which you have access, as well as additional information about those backends.\n", "\n", - "* `get_targets()`: Retrieves a list of available backends\n", + "* `get_targets()`: Retrieves a list of available backends. This method also accepts the following boolean keyword arguments to filter the targets returned: `simulator`, `supports_submit`, `supports_submit_qubo`, `supports_compile`, `available`, and `retired`.\n", "* `target_info(\"\")`: Retrieve information on your selected backend, such as number of qubits, native gate set, where `` is the name of the desired backend" ] }, @@ -127,40 +127,42 @@ { "data": { "text/plain": [ - "{'compile-only': ['aqt_keysight_qpu', 'aqt_zurich_qpu', 'sandia_qscout_qpu'],\n", - " 'compile-and-run': ['aws_dm1_simulator',\n", - " 'aws_sv1_simulator',\n", - " 'aws_tn1_simulator',\n", - " 'cq_hilbert_qpu',\n", - " 'cq_hilbert_simulator',\n", - " 'ibmq_brisbane_qpu',\n", - " 'ibmq_extended-stabilizer_simulator',\n", - " 'ibmq_fake-athens_qpu',\n", - " 'ibmq_fake-lima_qpu',\n", - " 'ibmq_guadalupe_qpu',\n", - " 'ibmq_lagos_qpu',\n", - " 'ibmq_mps_simulator',\n", - " 'ibmq_nairobi_qpu',\n", - " 'ibmq_perth_qpu',\n", - " 'ibmq_qasm_simulator',\n", - " 'ibmq_stabilizer_simulator',\n", - " 'ibmq_statevector_simulator',\n", - " 'ionq_aria-1_qpu',\n", - " 'ionq_harmony_qpu',\n", - " 'ionq_ion_simulator',\n", - " 'qtm_h1-1_qpu',\n", - " 'qtm_h1-1e_simulator',\n", - " 'qtm_h2-1_qpu',\n", - " 'ss_unconstrained_simulator'],\n", - " 'unavailable': ['ionq_aria-2_qpu',\n", - " 'oxford_lucy_qpu',\n", - " 'rigetti_aspen-m-3_qpu'],\n", - " 'retired': ['rigetti_aspen-10_qpu',\n", - " 'rigetti_aspen-11_qpu',\n", - " 'rigetti_aspen-8_qpu',\n", - " 'rigetti_aspen-9_qpu',\n", - " 'rigetti_aspen-m-1_qpu',\n", - " 'rigetti_aspen-m-2_qpu']}" + "[Target(target='aqt_keysight_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='aqt_zurich_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='aws_dm1_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='aws_sv1_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='aws_tn1_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='cq_hilbert_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='cq_hilbert_simulator', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_brisbane_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_extended-stabilizer_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_fake-athens_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_fake-lima_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_lagos_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_mps_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_nairobi_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_perth_qpu', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_qasm_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_stabilizer_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ibmq_statevector_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ionq_aria-1_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='ionq_aria-2_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='ionq_harmony_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='ionq_ion_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='oxford_lucy_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='qtm_h1-1_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='qtm_h1-1e_simulator', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='qtm_h2-1_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='rigetti_aspen-10_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-11_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-8_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-9_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-m-1_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-m-2_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=True),\n", + " Target(target='rigetti_aspen-m-3_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=False, retired=False),\n", + " Target(target='sandia_qscout_qpu', supports_submit=False, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='ss_unconstrained_simulator', supports_submit=True, supports_submit_qubo=False, supports_compile=True, available=True, retired=False),\n", + " Target(target='toshiba_bifurcation_simulator', supports_submit=False, supports_submit_qubo=True, supports_compile=False, available=True, retired=False)]" ] }, "execution_count": 4, @@ -266,7 +268,7 @@ { "data": { "text/plain": [ - "'49cbea8a-9aa8-4b09-ada1-8d7476287794'" + "'5af79d5b-fc6b-4183-aee5-61dd90df834a'" ] }, "execution_count": 7, @@ -331,7 +333,7 @@ { "data": { "text/plain": [ - "{'00': 51, '11': 49}" + "{'00': 56, '11': 44}" ] }, "execution_count": 10, @@ -496,7 +498,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.2" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/docs/source/get_started/access_info/access_info_qss.ipynb b/docs/source/get_started/access_info/access_info_qss.ipynb index db64aa1f9..c92946278 100644 --- a/docs/source/get_started/access_info/access_info_qss.ipynb +++ b/docs/source/get_started/access_info/access_info_qss.ipynb @@ -82,7 +82,7 @@ { "data": { "text/plain": [ - "'136.30 credits'" + "'20 credits'" ] }, "execution_count": 3, @@ -108,9 +108,9 @@ "metadata": {}, "source": [ "## Backend Information\n", - "In addition to account information, the`SuperstaqProvider` object also gives you a list of all the devices and simulators to which you have access, as well as additional information about those backends.\n", + "In addition to account information, the ``SuperstaqProvider`` object also gives you a list of all the devices and simulators to which you have access, as well as additional information about those backends.\n", "\n", - "* `backends()`: Retrieves a list of available backends\n", + "* `backends()`: Retrieves a list of available backends. This method also accepts the following boolean keyword arguments to filter the backends returned: `simulator`, `supports_submit`, `supports_compile`, `available`, and `retired`.\n", "* `get_backend(\"\")`: Select your target backend, where `` is the name of the desired backend\n", "* `get_backend(\"\").target_info()`: Retrieve information on your selected backend, such as number of qubits, native gate set" ] @@ -126,7 +126,9 @@ { "data": { "text/plain": [ - "[,\n", + "[,\n", + " ,\n", + " ,\n", " ,\n", " ,\n", " ,\n", @@ -135,7 +137,6 @@ " ,\n", " ,\n", " ,\n", - " ,\n", " ,\n", " ,\n", " ,\n", @@ -144,11 +145,21 @@ " ,\n", " ,\n", " ,\n", + " ,\n", " ,\n", " ,\n", + " ,\n", " ,\n", " ,\n", " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", " ]" ] }, @@ -195,6 +206,7 @@ " [5, 4],\n", " [5, 6],\n", " [6, 5]],\n", + " 'description': '7 qubit device',\n", " 'supports_midcircuit_measurement': True,\n", " 'max_experiments': 900,\n", " 'processor_type': {'family': 'Falcon', 'revision': '5.11', 'segment': 'H'}}" @@ -257,7 +269,7 @@ { "data": { "text/plain": [ - "'9a840187-f7d9-4cd3-952f-bdae5c70b1cb'" + "'d9f6df78-749d-4748-92e5-030571d72b31'" ] }, "execution_count": 7, @@ -322,7 +334,7 @@ { "data": { "text/plain": [ - "{'00': 46, '11': 54}" + "{'00': 40, '11': 60}" ] }, "execution_count": 10, @@ -408,7 +420,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.2" + "version": "3.9.16" } }, "nbformat": 4, From ceae28e0790aa242396c7fbaaa07130dd9683e6b Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 9 Nov 2023 20:15:43 -0600 Subject: [PATCH 49/50] wording: backends -> targets --- docs/source/get_started/access_info/access_info_css.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/get_started/access_info/access_info_css.ipynb b/docs/source/get_started/access_info/access_info_css.ipynb index 15931bb33..1118b873a 100644 --- a/docs/source/get_started/access_info/access_info_css.ipynb +++ b/docs/source/get_started/access_info/access_info_css.ipynb @@ -6,7 +6,7 @@ "metadata": {}, "source": [ "# Accessing info with `cirq-superstaq`\n", - "This tutorial will cover the information you can access on your account and related jobs and backends using `cirq-superstaq`." + "This tutorial will cover the information you can access on your account and related jobs and targets using `cirq-superstaq`." ] }, { @@ -110,9 +110,9 @@ "metadata": {}, "source": [ "## Backend Information\n", - "In addition to account information, the ``Service`` object also gives you a list of all the devices and simulators to which you have access, as well as additional information about those backends.\n", + "In addition to account information, the ``Service`` object also gives you a list of all the devices and simulators to which you have access, as well as additional information about those targets.\n", "\n", - "* `get_targets()`: Retrieves a list of available backends. This method also accepts the following boolean keyword arguments to filter the targets returned: `simulator`, `supports_submit`, `supports_submit_qubo`, `supports_compile`, `available`, and `retired`.\n", + "* `get_targets()`: Retrieves a list of available targets. This method also accepts the following boolean keyword arguments to filter the targets returned: `simulator`, `supports_submit`, `supports_submit_qubo`, `supports_compile`, `available`, and `retired`.\n", "* `target_info(\"\")`: Retrieve information on your selected backend, such as number of qubits, native gate set, where `` is the name of the desired backend" ] }, From 5b11ed707696f606527aea8d1261253e66f7779e Mon Sep 17 00:00:00 2001 From: Bharath Date: Thu, 9 Nov 2023 20:32:15 -0600 Subject: [PATCH 50/50] Revert "Revert "MIS notebook update"" This reverts commit d4f6f966833a1d67ced5a5a03f89bad793a408b5. --- docs/source/apps/max_sharpe_ratio_optimization.ipynb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/source/apps/max_sharpe_ratio_optimization.ipynb b/docs/source/apps/max_sharpe_ratio_optimization.ipynb index fd52e2522..24f483192 100644 --- a/docs/source/apps/max_sharpe_ratio_optimization.ipynb +++ b/docs/source/apps/max_sharpe_ratio_optimization.ipynb @@ -94,7 +94,8 @@ "metadata": {}, "outputs": [], "source": [ - "os.environ[\"SUPERSTAQ_API_KEY\"] = \"key\"" + "# Run this to use token as an environment variable\n", + "# os.environ[\"SUPERSTAQ_API_KEY\"] = \"key\"" ] }, { @@ -1023,8 +1024,8 @@ "source": [ "from qubovert.sim import anneal_qubo\n", "\n", - "res = client.submit_qubo(obj_QUBO, target=\"toshiba_bifurcation_qpu\", method=\"dry-run\")\n", - "# res = client.submit_qubo(obj_QUBO, target=\"toshiba_bifurcation_qpu\")\n", + "res = client.submit_qubo(obj_QUBO, target=\"toshiba_bifurcation_simulator\", method=\"dry-run\")\n", + "# res = client.submit_qubo(obj_QUBO, target=\"toshiba_bifurcation_simulator\")\n", "res = gss.qubo.read_json_qubo_result(res)" ] }, @@ -1266,7 +1267,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" },