pasqal-cloud 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pasqal-cloud-0.2.2/pasqal_cloud.egg-info → pasqal-cloud-0.2.4}/PKG-INFO +64 -77
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/README.md +63 -76
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/_version.py +1 -1
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/authentication.py +15 -10
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/client.py +2 -6
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4/pasqal_cloud.egg-info}/PKG-INFO +64 -77
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud.egg-info/requires.txt +7 -7
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/setup.py +4 -4
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/tests/test_client.py +17 -4
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/tests/test_doubles/authentication.py +4 -7
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/LICENSE +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/MANIFEST.in +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/__init__.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/batch.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/device/__init__.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/device/configuration/__init__.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/device/configuration/base_config.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/device/configuration/emu_free.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/device/configuration/emu_tn.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/device/emulator_types.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/endpoints.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/errors.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/job.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/py.typed +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/utils/__init__.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/utils/jsend.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud/utils/strenum.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud.egg-info/SOURCES.txt +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud.egg-info/dependency_links.txt +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pasqal_cloud.egg-info/top_level.txt +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/pyproject.toml +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/sdk/__init__.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/sdk/device/__init__.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/sdk/device/configuration/__init__.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/sdk/setup.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/sdk/utils/__init__.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/setup.cfg +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/tests/__init__.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/tests/conftest.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/tests/test_batch.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/tests/test_cloud_sdk_import.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/tests/test_config.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/tests/test_device_specs.py +0 -0
- {pasqal-cloud-0.2.2 → pasqal-cloud-0.2.4}/tests/test_doubles/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pasqal-cloud
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Software development kit for Pasqal cloud platform.
|
|
5
5
|
Home-page: https://github.com/pasqal-io/pasqal-cloud
|
|
6
6
|
Maintainer: Pasqal Cloud Services
|
|
@@ -44,65 +44,7 @@ To run the tutorials or the test suite locally, run the following to install the
|
|
|
44
44
|
pip install -e .[dev]
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
## Instanciation and Authentication
|
|
48
47
|
|
|
49
|
-
There are several ways to provide a correct authentication using the SDK.
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
from pasqal_cloud import SDK
|
|
53
|
-
|
|
54
|
-
group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
|
|
55
|
-
username="your_username" # Replace this value by your username or email on the PASQAL platform.
|
|
56
|
-
password="your_password" # Replace this value by your password on the PASQAL platform.
|
|
57
|
-
# Ideally, do not write this password in a script but provide in through the command-line or as a secret environment variable.
|
|
58
|
-
|
|
59
|
-
""" Method 1: Username + Password
|
|
60
|
-
If you know your credentials, you can pass them to the SDK instance on creation.
|
|
61
|
-
"""
|
|
62
|
-
sdk = SDK(username=username, password=password, group_id=group_id)
|
|
63
|
-
|
|
64
|
-
""" Method 2: Username only
|
|
65
|
-
If you only want to insert your username, but want a solution to have your password being secret
|
|
66
|
-
you can run the SDK without password. A prompt will then ask for your password
|
|
67
|
-
"""
|
|
68
|
-
sdk = SDK(username=username, group_id=group_id)
|
|
69
|
-
> Please, enter your password:
|
|
70
|
-
|
|
71
|
-
""" Method 3: Use a token
|
|
72
|
-
If you already know your token, you can directly pass it as an argument
|
|
73
|
-
using the following method.
|
|
74
|
-
"""
|
|
75
|
-
class NewTokenProvider(TokenProvider):
|
|
76
|
-
def _query_token(self):
|
|
77
|
-
# Custom token query that will be validated by the API Calls later.
|
|
78
|
-
return {
|
|
79
|
-
"access_token": "some_token",
|
|
80
|
-
"id_token": "id_token",
|
|
81
|
-
"scope": "openid profile email",
|
|
82
|
-
"expires_in": 86400,
|
|
83
|
-
"token_type": "Bearer"
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
sdk = SDK(token_provider=NewTokenProvider, group_id=group_id)
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
/!\ For developers /!\
|
|
90
|
-
|
|
91
|
-
If you want to redefine the APIs used by the SDK, please, do the following.
|
|
92
|
-
|
|
93
|
-
```python
|
|
94
|
-
from pasqal_cloud import SDK, Endpoints, Auth0COnf
|
|
95
|
-
|
|
96
|
-
endpoints = Endpoints(core = "my_new_core_endpoint")
|
|
97
|
-
auth0 = Auth0Conf(
|
|
98
|
-
domain="new_domain",
|
|
99
|
-
public_client_id="public_id",
|
|
100
|
-
audience="new_audience"
|
|
101
|
-
)
|
|
102
|
-
sdk = SDK(..., endpoints=endpoints, auth0=auth0)
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
This enables you to target backend services running locally on your machine, or other environment like preprod or dev.
|
|
106
48
|
|
|
107
49
|
## Basic usage
|
|
108
50
|
|
|
@@ -113,26 +55,11 @@ A `Batch` is a group of jobs with the same sequence that will run on the same QP
|
|
|
113
55
|
The batch sequence can be generated using [Pulser](https://github.com/pasqal-io/Pulser). See their [documentation](https://pulser.readthedocs.io/en/stable/),
|
|
114
56
|
for more information on how to install the library and create your own sequence.
|
|
115
57
|
|
|
116
|
-
|
|
58
|
+
Once you have created your sequence, you should serialize it as follows:
|
|
117
59
|
|
|
118
60
|
```python
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
# Define a register for your sequence
|
|
123
|
-
register = Register.square(2, spacing=5, prefix="q")
|
|
124
|
-
# Create a sequence for that register
|
|
125
|
-
sequence = Sequence(register, devices.IroiseMVP)
|
|
126
|
-
# Add a channel to your sequence
|
|
127
|
-
sequence.declare_channel("rydberg", "rydberg_global")
|
|
128
|
-
# Declare a variable
|
|
129
|
-
omega_max = sequence.declare_variable("omega_max")
|
|
130
|
-
# Add a pulse to that channel with the amplitude omega_max
|
|
131
|
-
generic_pulse = Pulse.ConstantPulse(100, omega_max, 2, 0.0)
|
|
132
|
-
sequence.add(generic_pulse, "rydberg")
|
|
133
|
-
|
|
134
|
-
# When you are done building your sequence, serialize it into a string
|
|
135
|
-
serialized_sequence = sequence.serialize()
|
|
61
|
+
# sequence should be a pulser Sequence object
|
|
62
|
+
serialized_sequence = sequence.to_abstract_repr()
|
|
136
63
|
```
|
|
137
64
|
|
|
138
65
|
Once you have serialized your sequence, you can send it with the SDK with the following code
|
|
@@ -166,6 +93,44 @@ for job in batch.jobs.values():
|
|
|
166
93
|
|
|
167
94
|
```
|
|
168
95
|
|
|
96
|
+
## Advanced usage
|
|
97
|
+
|
|
98
|
+
### Authentication
|
|
99
|
+
|
|
100
|
+
There are several ways to provide a correct authentication using the SDK.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from pasqal_cloud import SDK
|
|
104
|
+
|
|
105
|
+
group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
|
|
106
|
+
username="your_username" # Replace this value by your username or email on the PASQAL platform.
|
|
107
|
+
password="your_password" # Replace this value by your password on the PASQAL platform.
|
|
108
|
+
# Ideally, do not write this password in a script but provide in through the command-line or as a secret environment variable.
|
|
109
|
+
|
|
110
|
+
""" Method 1: Username + Password
|
|
111
|
+
If you know your credentials, you can pass them to the SDK instance on creation.
|
|
112
|
+
"""
|
|
113
|
+
sdk = SDK(username=username, password=password, group_id=group_id)
|
|
114
|
+
|
|
115
|
+
""" Method 2: Username only
|
|
116
|
+
If you only want to insert your username, but want a solution to have your password being secret
|
|
117
|
+
you can run the SDK without password. A prompt will then ask for your password
|
|
118
|
+
"""
|
|
119
|
+
sdk = SDK(username=username, group_id=group_id)
|
|
120
|
+
> Please, enter your password:
|
|
121
|
+
|
|
122
|
+
""" Method 3: Use a custom token provider
|
|
123
|
+
You can define a custom class to provide the token.
|
|
124
|
+
For example, if you know your token, you can use that token to authenticate directly to our APIs as follows.
|
|
125
|
+
"""
|
|
126
|
+
class CustomTokenProvider(TokenProvider):
|
|
127
|
+
def get_token(self):
|
|
128
|
+
return "your-token" # Replace this value with your token
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
sdk = SDK(token_provider=CustomTokenProvider(), group_id=group_id)
|
|
132
|
+
```
|
|
133
|
+
|
|
169
134
|
### Extra emulator configuration (Soon publicly available)
|
|
170
135
|
|
|
171
136
|
Some emulators, such as EMU_TN and EMU_FREE, accept further configuration to control the emulation.
|
|
@@ -205,3 +170,25 @@ sdk.get_device_specs_list()
|
|
|
205
170
|
|
|
206
171
|
The method returns a dict object mapping a device type to a serialized device specs. These specs can be used
|
|
207
172
|
to instantiate a `Device` instance in the `Pulser` library.
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
### Target different API endpoints
|
|
176
|
+
|
|
177
|
+
This is intended to the package developers.
|
|
178
|
+
|
|
179
|
+
If you want to redefine the APIs used by the SDK, please, do the following.
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from pasqal_cloud import SDK, Endpoints, Auth0COnf
|
|
183
|
+
|
|
184
|
+
endpoints = Endpoints(core = "my_new_core_endpoint")
|
|
185
|
+
auth0 = Auth0Conf(
|
|
186
|
+
domain="new_domain",
|
|
187
|
+
public_client_id="public_id",
|
|
188
|
+
audience="new_audience"
|
|
189
|
+
)
|
|
190
|
+
sdk = SDK(..., endpoints=endpoints, auth0=auth0)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
This enables you to target backend services running locally on your machine, or other environment like preprod or dev.
|
|
194
|
+
|
|
@@ -29,65 +29,7 @@ To run the tutorials or the test suite locally, run the following to install the
|
|
|
29
29
|
pip install -e .[dev]
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
## Instanciation and Authentication
|
|
33
32
|
|
|
34
|
-
There are several ways to provide a correct authentication using the SDK.
|
|
35
|
-
|
|
36
|
-
```python
|
|
37
|
-
from pasqal_cloud import SDK
|
|
38
|
-
|
|
39
|
-
group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
|
|
40
|
-
username="your_username" # Replace this value by your username or email on the PASQAL platform.
|
|
41
|
-
password="your_password" # Replace this value by your password on the PASQAL platform.
|
|
42
|
-
# Ideally, do not write this password in a script but provide in through the command-line or as a secret environment variable.
|
|
43
|
-
|
|
44
|
-
""" Method 1: Username + Password
|
|
45
|
-
If you know your credentials, you can pass them to the SDK instance on creation.
|
|
46
|
-
"""
|
|
47
|
-
sdk = SDK(username=username, password=password, group_id=group_id)
|
|
48
|
-
|
|
49
|
-
""" Method 2: Username only
|
|
50
|
-
If you only want to insert your username, but want a solution to have your password being secret
|
|
51
|
-
you can run the SDK without password. A prompt will then ask for your password
|
|
52
|
-
"""
|
|
53
|
-
sdk = SDK(username=username, group_id=group_id)
|
|
54
|
-
> Please, enter your password:
|
|
55
|
-
|
|
56
|
-
""" Method 3: Use a token
|
|
57
|
-
If you already know your token, you can directly pass it as an argument
|
|
58
|
-
using the following method.
|
|
59
|
-
"""
|
|
60
|
-
class NewTokenProvider(TokenProvider):
|
|
61
|
-
def _query_token(self):
|
|
62
|
-
# Custom token query that will be validated by the API Calls later.
|
|
63
|
-
return {
|
|
64
|
-
"access_token": "some_token",
|
|
65
|
-
"id_token": "id_token",
|
|
66
|
-
"scope": "openid profile email",
|
|
67
|
-
"expires_in": 86400,
|
|
68
|
-
"token_type": "Bearer"
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
sdk = SDK(token_provider=NewTokenProvider, group_id=group_id)
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
/!\ For developers /!\
|
|
75
|
-
|
|
76
|
-
If you want to redefine the APIs used by the SDK, please, do the following.
|
|
77
|
-
|
|
78
|
-
```python
|
|
79
|
-
from pasqal_cloud import SDK, Endpoints, Auth0COnf
|
|
80
|
-
|
|
81
|
-
endpoints = Endpoints(core = "my_new_core_endpoint")
|
|
82
|
-
auth0 = Auth0Conf(
|
|
83
|
-
domain="new_domain",
|
|
84
|
-
public_client_id="public_id",
|
|
85
|
-
audience="new_audience"
|
|
86
|
-
)
|
|
87
|
-
sdk = SDK(..., endpoints=endpoints, auth0=auth0)
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
This enables you to target backend services running locally on your machine, or other environment like preprod or dev.
|
|
91
33
|
|
|
92
34
|
## Basic usage
|
|
93
35
|
|
|
@@ -98,26 +40,11 @@ A `Batch` is a group of jobs with the same sequence that will run on the same QP
|
|
|
98
40
|
The batch sequence can be generated using [Pulser](https://github.com/pasqal-io/Pulser). See their [documentation](https://pulser.readthedocs.io/en/stable/),
|
|
99
41
|
for more information on how to install the library and create your own sequence.
|
|
100
42
|
|
|
101
|
-
|
|
43
|
+
Once you have created your sequence, you should serialize it as follows:
|
|
102
44
|
|
|
103
45
|
```python
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
# Define a register for your sequence
|
|
108
|
-
register = Register.square(2, spacing=5, prefix="q")
|
|
109
|
-
# Create a sequence for that register
|
|
110
|
-
sequence = Sequence(register, devices.IroiseMVP)
|
|
111
|
-
# Add a channel to your sequence
|
|
112
|
-
sequence.declare_channel("rydberg", "rydberg_global")
|
|
113
|
-
# Declare a variable
|
|
114
|
-
omega_max = sequence.declare_variable("omega_max")
|
|
115
|
-
# Add a pulse to that channel with the amplitude omega_max
|
|
116
|
-
generic_pulse = Pulse.ConstantPulse(100, omega_max, 2, 0.0)
|
|
117
|
-
sequence.add(generic_pulse, "rydberg")
|
|
118
|
-
|
|
119
|
-
# When you are done building your sequence, serialize it into a string
|
|
120
|
-
serialized_sequence = sequence.serialize()
|
|
46
|
+
# sequence should be a pulser Sequence object
|
|
47
|
+
serialized_sequence = sequence.to_abstract_repr()
|
|
121
48
|
```
|
|
122
49
|
|
|
123
50
|
Once you have serialized your sequence, you can send it with the SDK with the following code
|
|
@@ -151,6 +78,44 @@ for job in batch.jobs.values():
|
|
|
151
78
|
|
|
152
79
|
```
|
|
153
80
|
|
|
81
|
+
## Advanced usage
|
|
82
|
+
|
|
83
|
+
### Authentication
|
|
84
|
+
|
|
85
|
+
There are several ways to provide a correct authentication using the SDK.
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from pasqal_cloud import SDK
|
|
89
|
+
|
|
90
|
+
group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
|
|
91
|
+
username="your_username" # Replace this value by your username or email on the PASQAL platform.
|
|
92
|
+
password="your_password" # Replace this value by your password on the PASQAL platform.
|
|
93
|
+
# Ideally, do not write this password in a script but provide in through the command-line or as a secret environment variable.
|
|
94
|
+
|
|
95
|
+
""" Method 1: Username + Password
|
|
96
|
+
If you know your credentials, you can pass them to the SDK instance on creation.
|
|
97
|
+
"""
|
|
98
|
+
sdk = SDK(username=username, password=password, group_id=group_id)
|
|
99
|
+
|
|
100
|
+
""" Method 2: Username only
|
|
101
|
+
If you only want to insert your username, but want a solution to have your password being secret
|
|
102
|
+
you can run the SDK without password. A prompt will then ask for your password
|
|
103
|
+
"""
|
|
104
|
+
sdk = SDK(username=username, group_id=group_id)
|
|
105
|
+
> Please, enter your password:
|
|
106
|
+
|
|
107
|
+
""" Method 3: Use a custom token provider
|
|
108
|
+
You can define a custom class to provide the token.
|
|
109
|
+
For example, if you know your token, you can use that token to authenticate directly to our APIs as follows.
|
|
110
|
+
"""
|
|
111
|
+
class CustomTokenProvider(TokenProvider):
|
|
112
|
+
def get_token(self):
|
|
113
|
+
return "your-token" # Replace this value with your token
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
sdk = SDK(token_provider=CustomTokenProvider(), group_id=group_id)
|
|
117
|
+
```
|
|
118
|
+
|
|
154
119
|
### Extra emulator configuration (Soon publicly available)
|
|
155
120
|
|
|
156
121
|
Some emulators, such as EMU_TN and EMU_FREE, accept further configuration to control the emulation.
|
|
@@ -190,3 +155,25 @@ sdk.get_device_specs_list()
|
|
|
190
155
|
|
|
191
156
|
The method returns a dict object mapping a device type to a serialized device specs. These specs can be used
|
|
192
157
|
to instantiate a `Device` instance in the `Pulser` library.
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
### Target different API endpoints
|
|
161
|
+
|
|
162
|
+
This is intended to the package developers.
|
|
163
|
+
|
|
164
|
+
If you want to redefine the APIs used by the SDK, please, do the following.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from pasqal_cloud import SDK, Endpoints, Auth0COnf
|
|
168
|
+
|
|
169
|
+
endpoints = Endpoints(core = "my_new_core_endpoint")
|
|
170
|
+
auth0 = Auth0Conf(
|
|
171
|
+
domain="new_domain",
|
|
172
|
+
public_client_id="public_id",
|
|
173
|
+
audience="new_audience"
|
|
174
|
+
)
|
|
175
|
+
sdk = SDK(..., endpoints=endpoints, auth0=auth0)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
This enables you to target backend services running locally on your machine, or other environment like preprod or dev.
|
|
179
|
+
|
|
@@ -2,12 +2,11 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from abc import ABC, abstractmethod
|
|
4
4
|
from datetime import datetime, timedelta, timezone
|
|
5
|
-
from jwt import decode, DecodeError
|
|
6
|
-
from requests import PreparedRequest
|
|
7
5
|
from typing import Any, Optional
|
|
8
6
|
|
|
9
7
|
from auth0.v3.authentication import GetToken # type: ignore
|
|
10
|
-
from
|
|
8
|
+
from jwt import decode, DecodeError
|
|
9
|
+
from requests import PreparedRequest
|
|
11
10
|
from requests.auth import AuthBase
|
|
12
11
|
|
|
13
12
|
from pasqal_cloud.endpoints import Auth0Conf
|
|
@@ -30,14 +29,18 @@ class TokenProviderError(Exception):
|
|
|
30
29
|
|
|
31
30
|
|
|
32
31
|
class TokenProvider(ABC):
|
|
32
|
+
def __init__(self, *args: list[Any], **kwargs: dict):
|
|
33
|
+
...
|
|
34
|
+
|
|
35
|
+
@abstractmethod
|
|
36
|
+
def get_token(self) -> str:
|
|
37
|
+
raise NotImplementedError
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ExpiringTokenProvider(TokenProvider, ABC):
|
|
33
41
|
__token_cache: Optional[tuple[datetime, str]] = None
|
|
34
42
|
expiry_window: timedelta = timedelta(minutes=1.0)
|
|
35
43
|
|
|
36
|
-
def __init__(self, username: str, password: str, auth0: Auth0Conf):
|
|
37
|
-
self.username = username
|
|
38
|
-
self.password = password
|
|
39
|
-
self.auth0 = auth0
|
|
40
|
-
|
|
41
44
|
@abstractmethod
|
|
42
45
|
def _query_token(self) -> dict[str, Any]:
|
|
43
46
|
raise NotImplementedError
|
|
@@ -99,9 +102,11 @@ class TokenProvider(ABC):
|
|
|
99
102
|
return None
|
|
100
103
|
|
|
101
104
|
|
|
102
|
-
class Auth0TokenProvider(
|
|
105
|
+
class Auth0TokenProvider(ExpiringTokenProvider):
|
|
103
106
|
def __init__(self, username: str, password: str, auth0: Auth0Conf):
|
|
104
|
-
|
|
107
|
+
self.username = username
|
|
108
|
+
self.password = password
|
|
109
|
+
self.auth0 = auth0
|
|
105
110
|
|
|
106
111
|
# Makes a call in order to check the credentials at creation
|
|
107
112
|
self.get_token()
|
|
@@ -81,12 +81,8 @@ class Client:
|
|
|
81
81
|
|
|
82
82
|
@staticmethod
|
|
83
83
|
def _check_token_provider(token_provider: TokenProvider) -> None:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
# but the code should be correct, and is tested
|
|
87
|
-
issubclass(token_provider, TokenProvider) # type: ignore
|
|
88
|
-
except TypeError:
|
|
89
|
-
raise TypeError("token_provider must be a TokenProvider subclass")
|
|
84
|
+
if not isinstance(token_provider, TokenProvider):
|
|
85
|
+
raise TypeError("token_provider must be an instance of TokenProvider.")
|
|
90
86
|
|
|
91
87
|
def _credential_login(
|
|
92
88
|
self, username: str, password: Optional[str], auth0: Auth0Conf
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pasqal-cloud
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Software development kit for Pasqal cloud platform.
|
|
5
5
|
Home-page: https://github.com/pasqal-io/pasqal-cloud
|
|
6
6
|
Maintainer: Pasqal Cloud Services
|
|
@@ -44,65 +44,7 @@ To run the tutorials or the test suite locally, run the following to install the
|
|
|
44
44
|
pip install -e .[dev]
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
## Instanciation and Authentication
|
|
48
47
|
|
|
49
|
-
There are several ways to provide a correct authentication using the SDK.
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
from pasqal_cloud import SDK
|
|
53
|
-
|
|
54
|
-
group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
|
|
55
|
-
username="your_username" # Replace this value by your username or email on the PASQAL platform.
|
|
56
|
-
password="your_password" # Replace this value by your password on the PASQAL platform.
|
|
57
|
-
# Ideally, do not write this password in a script but provide in through the command-line or as a secret environment variable.
|
|
58
|
-
|
|
59
|
-
""" Method 1: Username + Password
|
|
60
|
-
If you know your credentials, you can pass them to the SDK instance on creation.
|
|
61
|
-
"""
|
|
62
|
-
sdk = SDK(username=username, password=password, group_id=group_id)
|
|
63
|
-
|
|
64
|
-
""" Method 2: Username only
|
|
65
|
-
If you only want to insert your username, but want a solution to have your password being secret
|
|
66
|
-
you can run the SDK without password. A prompt will then ask for your password
|
|
67
|
-
"""
|
|
68
|
-
sdk = SDK(username=username, group_id=group_id)
|
|
69
|
-
> Please, enter your password:
|
|
70
|
-
|
|
71
|
-
""" Method 3: Use a token
|
|
72
|
-
If you already know your token, you can directly pass it as an argument
|
|
73
|
-
using the following method.
|
|
74
|
-
"""
|
|
75
|
-
class NewTokenProvider(TokenProvider):
|
|
76
|
-
def _query_token(self):
|
|
77
|
-
# Custom token query that will be validated by the API Calls later.
|
|
78
|
-
return {
|
|
79
|
-
"access_token": "some_token",
|
|
80
|
-
"id_token": "id_token",
|
|
81
|
-
"scope": "openid profile email",
|
|
82
|
-
"expires_in": 86400,
|
|
83
|
-
"token_type": "Bearer"
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
sdk = SDK(token_provider=NewTokenProvider, group_id=group_id)
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
/!\ For developers /!\
|
|
90
|
-
|
|
91
|
-
If you want to redefine the APIs used by the SDK, please, do the following.
|
|
92
|
-
|
|
93
|
-
```python
|
|
94
|
-
from pasqal_cloud import SDK, Endpoints, Auth0COnf
|
|
95
|
-
|
|
96
|
-
endpoints = Endpoints(core = "my_new_core_endpoint")
|
|
97
|
-
auth0 = Auth0Conf(
|
|
98
|
-
domain="new_domain",
|
|
99
|
-
public_client_id="public_id",
|
|
100
|
-
audience="new_audience"
|
|
101
|
-
)
|
|
102
|
-
sdk = SDK(..., endpoints=endpoints, auth0=auth0)
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
This enables you to target backend services running locally on your machine, or other environment like preprod or dev.
|
|
106
48
|
|
|
107
49
|
## Basic usage
|
|
108
50
|
|
|
@@ -113,26 +55,11 @@ A `Batch` is a group of jobs with the same sequence that will run on the same QP
|
|
|
113
55
|
The batch sequence can be generated using [Pulser](https://github.com/pasqal-io/Pulser). See their [documentation](https://pulser.readthedocs.io/en/stable/),
|
|
114
56
|
for more information on how to install the library and create your own sequence.
|
|
115
57
|
|
|
116
|
-
|
|
58
|
+
Once you have created your sequence, you should serialize it as follows:
|
|
117
59
|
|
|
118
60
|
```python
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
# Define a register for your sequence
|
|
123
|
-
register = Register.square(2, spacing=5, prefix="q")
|
|
124
|
-
# Create a sequence for that register
|
|
125
|
-
sequence = Sequence(register, devices.IroiseMVP)
|
|
126
|
-
# Add a channel to your sequence
|
|
127
|
-
sequence.declare_channel("rydberg", "rydberg_global")
|
|
128
|
-
# Declare a variable
|
|
129
|
-
omega_max = sequence.declare_variable("omega_max")
|
|
130
|
-
# Add a pulse to that channel with the amplitude omega_max
|
|
131
|
-
generic_pulse = Pulse.ConstantPulse(100, omega_max, 2, 0.0)
|
|
132
|
-
sequence.add(generic_pulse, "rydberg")
|
|
133
|
-
|
|
134
|
-
# When you are done building your sequence, serialize it into a string
|
|
135
|
-
serialized_sequence = sequence.serialize()
|
|
61
|
+
# sequence should be a pulser Sequence object
|
|
62
|
+
serialized_sequence = sequence.to_abstract_repr()
|
|
136
63
|
```
|
|
137
64
|
|
|
138
65
|
Once you have serialized your sequence, you can send it with the SDK with the following code
|
|
@@ -166,6 +93,44 @@ for job in batch.jobs.values():
|
|
|
166
93
|
|
|
167
94
|
```
|
|
168
95
|
|
|
96
|
+
## Advanced usage
|
|
97
|
+
|
|
98
|
+
### Authentication
|
|
99
|
+
|
|
100
|
+
There are several ways to provide a correct authentication using the SDK.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from pasqal_cloud import SDK
|
|
104
|
+
|
|
105
|
+
group_id="your_group_id" # Replace this value by your group_id on the PASQAL platform.
|
|
106
|
+
username="your_username" # Replace this value by your username or email on the PASQAL platform.
|
|
107
|
+
password="your_password" # Replace this value by your password on the PASQAL platform.
|
|
108
|
+
# Ideally, do not write this password in a script but provide in through the command-line or as a secret environment variable.
|
|
109
|
+
|
|
110
|
+
""" Method 1: Username + Password
|
|
111
|
+
If you know your credentials, you can pass them to the SDK instance on creation.
|
|
112
|
+
"""
|
|
113
|
+
sdk = SDK(username=username, password=password, group_id=group_id)
|
|
114
|
+
|
|
115
|
+
""" Method 2: Username only
|
|
116
|
+
If you only want to insert your username, but want a solution to have your password being secret
|
|
117
|
+
you can run the SDK without password. A prompt will then ask for your password
|
|
118
|
+
"""
|
|
119
|
+
sdk = SDK(username=username, group_id=group_id)
|
|
120
|
+
> Please, enter your password:
|
|
121
|
+
|
|
122
|
+
""" Method 3: Use a custom token provider
|
|
123
|
+
You can define a custom class to provide the token.
|
|
124
|
+
For example, if you know your token, you can use that token to authenticate directly to our APIs as follows.
|
|
125
|
+
"""
|
|
126
|
+
class CustomTokenProvider(TokenProvider):
|
|
127
|
+
def get_token(self):
|
|
128
|
+
return "your-token" # Replace this value with your token
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
sdk = SDK(token_provider=CustomTokenProvider(), group_id=group_id)
|
|
132
|
+
```
|
|
133
|
+
|
|
169
134
|
### Extra emulator configuration (Soon publicly available)
|
|
170
135
|
|
|
171
136
|
Some emulators, such as EMU_TN and EMU_FREE, accept further configuration to control the emulation.
|
|
@@ -205,3 +170,25 @@ sdk.get_device_specs_list()
|
|
|
205
170
|
|
|
206
171
|
The method returns a dict object mapping a device type to a serialized device specs. These specs can be used
|
|
207
172
|
to instantiate a `Device` instance in the `Pulser` library.
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
### Target different API endpoints
|
|
176
|
+
|
|
177
|
+
This is intended to the package developers.
|
|
178
|
+
|
|
179
|
+
If you want to redefine the APIs used by the SDK, please, do the following.
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from pasqal_cloud import SDK, Endpoints, Auth0COnf
|
|
183
|
+
|
|
184
|
+
endpoints = Endpoints(core = "my_new_core_endpoint")
|
|
185
|
+
auth0 = Auth0Conf(
|
|
186
|
+
domain="new_domain",
|
|
187
|
+
public_client_id="public_id",
|
|
188
|
+
audience="new_audience"
|
|
189
|
+
)
|
|
190
|
+
sdk = SDK(..., endpoints=endpoints, auth0=auth0)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
This enables you to target backend services running locally on your machine, or other environment like preprod or dev.
|
|
194
|
+
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
auth0-python
|
|
2
|
-
requests
|
|
3
|
-
|
|
4
|
-
pyjwt[crypto]==2.5.0
|
|
1
|
+
auth0-python<4.0.0,>=3.23.1
|
|
2
|
+
requests<3.0.0,>=2.25.1
|
|
3
|
+
pyjwt[crypto]<3.0.0,>=2.5.0
|
|
5
4
|
|
|
6
5
|
[:python_version == '3.7']
|
|
7
6
|
typing-extensions==4.4.0
|
|
8
7
|
|
|
9
8
|
[dev]
|
|
10
|
-
|
|
9
|
+
flake8==3.9.0
|
|
11
10
|
types-requests==2.25.1
|
|
11
|
+
requests-mock==1.9.3
|
|
12
|
+
flake8-import-order==0.18.1
|
|
12
13
|
mypy==0.982
|
|
13
14
|
black==20.8b1
|
|
15
|
+
pytest-cov==2.11.1
|
|
14
16
|
pytest==6.2.5
|
|
15
|
-
flake8==3.9.0
|
|
16
|
-
flake8-import-order==0.18.1
|
|
@@ -37,10 +37,9 @@ setup(
|
|
|
37
37
|
],
|
|
38
38
|
url="https://github.com/pasqal-io/pasqal-cloud",
|
|
39
39
|
install_requires=[
|
|
40
|
-
"auth0-python
|
|
41
|
-
"requests
|
|
42
|
-
"
|
|
43
|
-
"pyjwt[crypto]==2.5.0",
|
|
40
|
+
"auth0-python >= 3.23.1, <4.0.0 ",
|
|
41
|
+
"requests>=2.25.1, <3.0.0",
|
|
42
|
+
"pyjwt[crypto]>=2.5.0, <3.0.0",
|
|
44
43
|
],
|
|
45
44
|
extras_require={
|
|
46
45
|
"dev": {
|
|
@@ -51,6 +50,7 @@ setup(
|
|
|
51
50
|
"pytest==6.2.5",
|
|
52
51
|
"pytest-cov==2.11.1",
|
|
53
52
|
"types-requests==2.25.1",
|
|
53
|
+
"requests-mock==1.9.3",
|
|
54
54
|
},
|
|
55
55
|
":python_version == '3.7'": [
|
|
56
56
|
"typing-extensions==4.4.0",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
from
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
|
|
2
3
|
import pytest
|
|
4
|
+
from auth0.v3.exceptions import Auth0Error # type: ignore
|
|
3
5
|
|
|
4
|
-
from
|
|
5
|
-
from pasqal_cloud import
|
|
6
|
+
from pasqal_cloud import Auth0Conf, Endpoints, SDK
|
|
7
|
+
from pasqal_cloud.authentication import TokenProvider
|
|
6
8
|
from tests.test_doubles.authentication import (
|
|
7
9
|
FakeAuth0AuthenticationFailure,
|
|
8
10
|
FakeAuth0AuthenticationSuccess,
|
|
@@ -26,7 +28,18 @@ class TestAuthSuccess:
|
|
|
26
28
|
SDK(group_id=self.group_id, username=self.username, password=self.password)
|
|
27
29
|
|
|
28
30
|
def test_good_token_provider(self):
|
|
29
|
-
SDK(
|
|
31
|
+
SDK(
|
|
32
|
+
group_id=self.group_id,
|
|
33
|
+
token_provider=FakeAuth0AuthenticationSuccess("username", "password", None),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def test_custom_token_provider(self):
|
|
37
|
+
"""Test that the custom provider suggested in the readme is working"""
|
|
38
|
+
class CustomTokenProvider(TokenProvider):
|
|
39
|
+
def get_token(self):
|
|
40
|
+
return "your-token" # Replace this value with your token
|
|
41
|
+
SDK(token_provider=CustomTokenProvider(), group_id="group_id")
|
|
42
|
+
|
|
30
43
|
|
|
31
44
|
def test_correct_endpoints(self):
|
|
32
45
|
sdk = SDK(
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
+
|
|
2
3
|
from typing import Any
|
|
3
4
|
|
|
4
5
|
from auth0.v3.exceptions import Auth0Error
|
|
5
6
|
|
|
6
|
-
from pasqal_cloud.authentication import
|
|
7
|
+
from pasqal_cloud.authentication import Auth0TokenProvider
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
class FakeAuth0AuthenticationSuccess(
|
|
10
|
+
class FakeAuth0AuthenticationSuccess(Auth0TokenProvider):
|
|
10
11
|
def _query_token(self) -> dict[str, Any]:
|
|
11
12
|
return {
|
|
12
13
|
"access_token": "some_token",
|
|
@@ -17,11 +18,7 @@ class FakeAuth0AuthenticationSuccess(TokenProvider):
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
class FakeAuth0AuthenticationFailure(
|
|
21
|
-
def __init__(self, *args: tuple, **kwargs: dict):
|
|
22
|
-
# Only to raise an error as the Authentication is failed.
|
|
23
|
-
self._query_token()
|
|
24
|
-
|
|
21
|
+
class FakeAuth0AuthenticationFailure(Auth0TokenProvider):
|
|
25
22
|
def _query_token(self) -> dict[str, Any]:
|
|
26
23
|
raise Auth0Error(
|
|
27
24
|
status_code=403, error_code=403, message="Wrong email/password"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|