Skip to content

Commit

Permalink
Merge pull request #33 from qiboteam/upqiboclient
Browse files Browse the repository at this point in the history
updating qibo-client implementation
  • Loading branch information
scarrazza authored Aug 3, 2024
2 parents 9e67c7b + edc843f commit fd55dbd
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 389 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.9, '3.10', '3.11']
uses: qiboteam/workflows/.github/workflows/deploy-pip-poetry.yml@main
python-version: [3.9, '3.10', '3.11', '3.12']
uses: qiboteam/workflows/.github/workflows/deploy-pip-poetry.yml@v1
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
deploy-docs:
needs: [evaluate-label]
uses: qiboteam/workflows/.github/workflows/deploy-ghpages-latest-stable.yml@main
uses: qiboteam/workflows/.github/workflows/deploy-ghpages-latest-stable.yml@v1
with:
python-version: "3.10"
package-manager: "poetry"
Expand Down
799 changes: 421 additions & 378 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ packages = [{ include = "qibo_cloud_backends", from = "src" }]

[tool.poetry.dependencies]
python = ">=3.9,<3.13"
qibo = "^0.2.8"
qibo_client = "^0.0.7"
qibo = "^0.2.10"
qibo_client = "^0.0.9"
qiskit_ibm_runtime = ">=0.17"
qiskit_ibm_provider = ">=0.8.0"

Expand Down
7 changes: 5 additions & 2 deletions src/qibo_cloud_backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ class MetaBackend:
"""Meta-backend class which takes care of loading the qibo-cloud backends."""

@staticmethod
def load(client: str, token: str = None, platform: str = None) -> QibocloudBackend:
def load(
client: str, token: str = None, platform: str = None, verbosity: bool = False
) -> QibocloudBackend:
"""Loads the backend.
Args:
client (str): Name of the cloud client to load, one in ("qibo-client", "qiskit-client").
token (str): User token for the remote connection.
platform (str): Name of the platform to connect to on the provider's servers, e.g. `ibm_osaka`.
verbosity (bool): Enable verbose mode for the qibo-client. Default is False.
Returns:
qibo.backends.abstract.Backend: The loaded backend.
"""

if client == "qibo-client":
return QiboClientBackend(token, platform)
return QiboClientBackend(token, platform, verbosity)
elif client == "qiskit-client":
return QiskitClientBackend(token, platform)
else:
Expand Down
8 changes: 5 additions & 3 deletions src/qibo_cloud_backends/qibo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class QiboClientBackend(NumpyBackend):
Args:
token (str): User authentication token. By default this is read from the 'QIBO_CLIENT_TOKEN' environment variable.
provider (str): Name of the service provider. Defaults to `"TII"`.
platform (str): Name of the platform. Defaults to `"sim"`.
verbosity (str): Enable verbose mode for the client. Default is False.
"""

def __init__(self, token=None, platform=None):
def __init__(self, token=None, platform=None, verbosity=False):
super().__init__()
if token is None:
try:
Expand All @@ -28,6 +28,7 @@ def __init__(self, token=None, platform=None):
platform = "sim"
self.platform = platform
self.name = "qibo-client"
self.verbosity = verbosity
self.client = qibo_client.Client(token)

def execute_circuit(self, circuit, initial_state=None, nshots=1000):
Expand All @@ -46,4 +47,5 @@ def execute_circuit(self, circuit, initial_state=None, nshots=1000):
NotImplementedError,
"The use of an `initial_state` is not supported yet.",
)
return self.client.run_circuit(circuit, nshots=nshots, device=self.platform)
job = self.client.run_circuit(circuit, nshots=nshots, device=self.platform)
return job.result(verbose=self.verbosity)
1 change: 0 additions & 1 deletion src/qibo_cloud_backends/qiskit_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class QiskitClientBackend(NumpyBackend):
Args:
token (str): User authentication token. By default this is read from the 'IBMQ_TOKEN' environment variable.
provider (str): Name of the IBM service provider. Defaults to `"ibm-q"`.
platform (str): The IBM platform. Defaults to `"ibm_osaka"`.
"""

Expand Down
2 changes: 2 additions & 0 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def test_set_backend(backend, token):
assert GlobalBackend().name == backend


@pytest.mark.skip(reason="Requires bugfix in qibo.")
def test_list_available_backends():
available_backends = {
"numpy": True,
Expand All @@ -89,6 +90,7 @@ def test_list_available_backends():
"qibolab": False,
"qibo-cloud-backends": {"qibo-client": True, "qiskit-client": True},
"qibotn": False,
"qulacs": False,
}
assert list_available_backends() == available_backends

Expand Down

0 comments on commit fd55dbd

Please sign in to comment.