Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PACK] Rename cloud SDK package name when importing (#344) #71

Merged
merged 18 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish cloud-sdk 📦 to PyPI and TestPyPI
name: Publish pasqal-cloud 📦 to PyPI and TestPyPI
on:
push:
branches:
Expand Down Expand Up @@ -27,12 +27,13 @@ jobs:
--sdist
--wheel
--outdir dist/

- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
password: ${{ secrets.PASQAL_CLOUD_TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
password: ${{ secrets.PASQAL_CLOUD_PYPI_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/run-tests-and-mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:

- name: Perform unit tests
run: |
pytest -vvv --cov sdk tests
pytest -vvv --cov pasqal_cloud tests

- name: Mypy checks only for Python 3.8
if: ${{ matrix.python-version == 3.8 }}
run: |
mypy sdk
mypy pasqal_cloud
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build
venv
pipfile
pipfile.lock
.idea/
37 changes: 22 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,48 @@

All notable changes to this project will be documented in this file.

## [0.1.16] 2023-04-06
## [0.2.2] - 2023-04-19

### Changed

- `device_type` argument replace by `emulator` in sdk create_batch
- `DeviceType` replaced with `EmulatorType`
- Package renamed from **pasqal-sdk** to **pasqal-cloud**
- Import name renamed from **sdk** to **pasqal_cloud** (import sdk is now deprecated but still usable)

## [0.2.0] 2023-04-06

### Changed

- `device_type` argument replace by `emulator` in sdk create_batch
- `DeviceType` replaced with `EmulatorType`

### Deleted

- QPU device type and related logic
- QPU device type and related logic

## [0.1.15] 2023-03-27
## [0.1.15] - 2023-04-05

### Added

- Added tests to check the login behavior.
- Added tests to check the override Endpoints behavior.
- Added tests to check the login behavior.
- Added tests to check the override Endpoints behavior.

### Changed

- The authentication now directly connects to the Auth0 platform instead of connecting through PasqalCloud.
- Small refactor of files, with the authentication modules in the `authentication.py` file, instead of `client.py`.
- The authentication now directly connects to the Auth0 platform instead of connecting through PasqalCloud.
- Small refactor of files, with the authentication modules in the `authentication.py` file, instead of `client.py`.

### Deleted

- Account endpoint, we now use Auth0.
- Account endpoint, we now use Auth0.

## [0.1.14]
## [0.1.14] - 2023-03-27

### Changed

- Added a get_device_specs_dict function to the sdk
- Updated Readme for the device specs

## [0.1.13]
## [0.1.13] - 2023-03-02

### Changed

Expand All @@ -51,7 +58,7 @@ All notable changes to this project will be documented in this file.
### Changed

- The group_id field has been added to the Job schema which is now present in some services returning Job data.
- Pytest fixtures updated to accomodate this.
- Pytest fixtures updated to accommodate this.

## [0.1.11] - 2023-02-21

Expand Down Expand Up @@ -96,7 +103,7 @@ All notable changes to this project will be documented in this file.

### Changed

Reworked the `wait` logic when [creating a batch](https://github.com/pasqal-io/cloud-sdk/blob/dev/sdk/__init__.py#L46) or [declaring it as complete](<(https://github.com/pasqal-io/cloud-sdk/blob/dev/sdk/batch.py#L95)>). The old `wait` has been split into
Reworked the `wait` logic when [creating a batch](https://github.com/pasqal-io/pasqal-cloud/blob/dev/sdk/__init__.py#L46) or [declaring it as complete](<(https://github.com/pasqal-io/pasqal-cloud/blob/dev/sdk/batch.py#L95)>). The old `wait` has been split into
MatthieuMoreau0 marked this conversation as resolved.
Show resolved Hide resolved
two separate boolean kwargs `wait` and `fetch_results`. - `wait` when set to `True` still makes the python statement blocking until the batch gets assigned a termination status (e.g. `DONE`, `ERROR`, `TIMED_OUT`) but doesn't trigger fetching of results. - `fetch_results` is a boolean which when set to `True` makes the python statement blocking until the batch has a termination status and then fetches the results for all the jobs of the batch.

This enables the user to wait for the results and then implement its own custom logic to retrieve results (e.g. only fetch the results for the last job of the batch).
Expand All @@ -110,7 +117,7 @@ This is the last released version before the implementation of the changelog.

### Added

See commit history before [this commit](https://github.com/pasqal-io/cloud-sdk/commit/7c703534f55012489550f7df116f3f326e741de5).
See commit history before [this commit](https://github.com/pasqal-io/pasqal-cloud/commit/7c703534f55012489550f7df116f3f326e741de5).

### Changed

Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Cloud SDK
# PASQAL Cloud

SDK to be used to access Pasqal Cloud Services.

## Installation

To install the latest release of the `cloud-sdk`, have Python 3.8.0 or higher installed, then use pip:
To install the latest release of the `pasqal-cloud` (formerly pasqal-sdk), have Python 3.8.0 or higher installed, then use pip:

```bash
pip install pasqal-sdk
pip install pasqal-cloud
```

If you wish to **install the development version of the cloud_sdk from source** instead, do the following from within this repository after cloning it:
If you wish to **install the development version of the pasqal_cloud from source** instead, do the following from within this repository after cloning it:

```bash
git checkout develop
pip install -e .
```

Bear in mind that this installation will track the contents of your local
cloud_sdk repository folder, so if you checkout a different branch (e.g. `master`),
pasqal-cloud repository folder, so if you checkout a different branch (e.g. `master`),
your installation will change accordingly.

### Development Requirements (Optional)
Expand All @@ -34,7 +34,7 @@ pip install -e .[dev]
There are several ways to provide a correct authentication using the SDK.

```python
from sdk import SDK
from pasqal_cloud import SDK

group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
username="your_username" # Replace this value by your username or email on the PASQAL platform.
Expand Down Expand Up @@ -76,7 +76,7 @@ sdk = SDK(token_provider=NewTokenProvider, group_id=group_id)
If you want to redefine the APIs used by the SDK, please, do the following.

```python
from sdk import SDK, Endpoints, Auth0COnf
from pasqal_cloud import SDK, Endpoints, Auth0COnf

endpoints = Endpoints(core = "my_new_core_endpoint")
auth0 = Auth0Conf(
Expand Down Expand Up @@ -123,7 +123,7 @@ serialized_sequence = sequence.serialize()
Once you have serialized your sequence, you can send it with the SDK with the following code

```python
from sdk import SDK
from pasqal_cloud import SDK
from pulser import devices, Register, Sequence

group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
Expand All @@ -142,7 +142,7 @@ batch = sdk.create_batch(serialized_sequence, [job1,job2], wait=True)

# You can also choose to run your batch on an emulator using the optional argument 'emulator'
# For using a basic single-threaded QPU emulator that can go up to 10 qubits, you can specify the "EMU_FREE" emulator.
from sdk.device import EmulatorType
from pasqal_cloud.device import EmulatorType
batch = sdk.create_batch(serialized_sequence, [job1,job2], emulator=EmulatorType.EMU_FREE)

# Once the QPU has returned the results, you can access them with the following:
Expand All @@ -161,7 +161,7 @@ For EMU_TN you may add the integrator timestep in nanoseconds, the numerical acc
```python
# replace the corresponding section in the above code example with this to
# add further configuration
from sdk.device import EmulatorType, EmuTNConfig
from pasqal_cloud.device import EmulatorType, EmuTNConfig

configuration = EmuTNConfig(dt = 10.0, precision = "normal", max_bond_dim = 100)
batch = sdk.create_batch(serialized_sequence, [job1,job2], emulator=EmulatorType.EMU_TN, configuration=configuration)
Expand All @@ -172,7 +172,7 @@ For EMU_FREE you may add some default SPAM noise. Beware this makes your job tak
```python
# replace the corresponding section in the above code example with this to
# add further configuration
from sdk.device import EmulatorType, EmuFreeConfig
from pasqal_cloud.device import EmulatorType, EmuFreeConfig

configuration = EmuFreeConfig(with_noise=True)
batch = sdk.create_batch(serialized_sequence, [job1,job2], emulator=EmulatorType.EMU_FREE, configuration=configuration)
Expand Down
147 changes: 147 additions & 0 deletions pasqal_cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Copyright 2020 Pasqal Cloud Services development team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import time
from typing import Any, Dict, List, Optional
Mildophin marked this conversation as resolved.
Show resolved Hide resolved

from pasqal_cloud.authentication import TokenProvider
from pasqal_cloud.batch import Batch, RESULT_POLLING_INTERVAL
from pasqal_cloud.client import Client
from pasqal_cloud.device import BaseConfig
from pasqal_cloud.device import EmulatorType
from pasqal_cloud.endpoints import Auth0Conf, Endpoints
from pasqal_cloud.job import Job


class SDK:
_client: Client

def __init__(
self,
group_id: str,
username: Optional[str] = None,
password: Optional[str] = None,
token_provider: Optional[TokenProvider] = None,
endpoints: Optional[Endpoints] = None,
auth0: Optional[Auth0Conf] = None,
webhook: Optional[str] = None,
):
"""This class provides helper methods to call the PASQAL Cloud endpoints.

To authenticate to PASQAL Cloud, you have to provide either an
email/password combination or a TokenProvider instance.
You may omit the password, you will then be prompted to enter one.
"""
self._client = Client(
group_id=group_id,
username=username,
password=password,
token_provider=token_provider,
endpoints=endpoints,
auth0=auth0,
)
self.batches: Dict[str, Batch] = {}
self.webhook = webhook

def create_batch(
self,
serialized_sequence: str,
jobs: List[Dict[str, Any]],
emulator: Optional[EmulatorType] = None,
configuration: Optional[BaseConfig] = None,
wait: bool = False,
fetch_results: bool = False,
) -> Batch:
"""Create a new batch and send it to the API.
For Iroise MVP, the batch must contain at least one job and will be declared as
complete immediately.

Args:
serialized_sequence: Serialized pulser sequence.
jobs: List of jobs to be added to the batch at creation.
(#TODO: Make optional after Iroise MVP)
emulator: The type of emulator to use,
If set to None, the device_type will be set to the one
stored in the serialized sequence
configuration: A dictionary with extra configuration for the emulators
that accept it.
wait: Whether to wait for the batch to be done
fetch_results: Whether to download the results. Implies waiting
for the batch.


Returns:
Batch: The new batch that has been created in the database.
"""

req = {
"sequence_builder": serialized_sequence,
"webhook": self.webhook,
"jobs": jobs,
}

# the emulator field is only added in the case
# an emulator job is requested otherwise it's left empty
if emulator:
req.update({"emulator": emulator})

# The configuration field is only added in the case
# it's requested
if configuration:
req.update({"configuration": configuration.to_dict()}) # type: ignore

batch_rsp, jobs_rsp = self._client._send_batch(req)
batch_id = batch_rsp["id"]
if wait or fetch_results:
while batch_rsp["status"] in ["PENDING", "RUNNING"]:
time.sleep(RESULT_POLLING_INTERVAL)
batch_rsp, jobs_rsp = self._client._get_batch(batch_id)

if fetch_results:
batch_rsp, jobs_rsp = self._client._get_batch(
batch_id, fetch_results=True
)
batch = Batch(**batch_rsp, _client=self._client)
for job_rsp in jobs_rsp:
batch.jobs[job_rsp["id"]] = Job(**job_rsp)

self.batches[batch.id] = batch
return batch

def get_batch(self, id: str, fetch_results: bool = False) -> Batch:
"""Retrieve a batch's data and all its jobs.

Args:
id: Id of the batch.
fetch_results: whether to download job results

Returns:
Batch: the batch stored in the PCS database.
"""

batch_rsp, jobs_rsp = self._client._get_batch(id, fetch_results=fetch_results)
batch = Batch(**batch_rsp, _client=self._client)
for job_rsp in jobs_rsp:
batch.jobs[job_rsp["id"]] = Job(**job_rsp)
self.batches[batch.id] = batch
return batch

def get_device_specs_dict(self) -> Dict[str, str]:
"""Retrieve the list of available device specifications.

Returns:
DeviceSpecs: the list of available device specifications.
"""

return self._client.get_device_specs_dict()
2 changes: 1 addition & 1 deletion sdk/_version.py → pasqal_cloud/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "0.2.0"
__version__ = "0.2.2"
4 changes: 2 additions & 2 deletions sdk/authentication.py → pasqal_cloud/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from auth0.v3.exceptions import Auth0Error # type: ignore
from requests.auth import AuthBase

from sdk.endpoints import Auth0Conf
from sdk.errors import HTTPError
from pasqal_cloud.endpoints import Auth0Conf
from pasqal_cloud.errors import HTTPError


class HTTPBearerAuthenticator(AuthBase):
Expand Down
8 changes: 4 additions & 4 deletions sdk/batch.py → pasqal_cloud/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from dataclasses import dataclass, field
from typing import Any, Dict, Optional, Type, Union

from sdk.client import Client
from sdk.job import Job
from sdk.device.configuration import BaseConfig, EmuTNConfig, EmuFreeConfig
from sdk.device import EmulatorType
from pasqal_cloud.client import Client
from pasqal_cloud.job import Job
from pasqal_cloud.device.configuration import BaseConfig, EmuTNConfig, EmuFreeConfig
from pasqal_cloud.device import EmulatorType

RESULT_POLLING_INTERVAL = 2 # seconds

Expand Down
Loading