luna-quantum 0.0.16__py3-none-any.whl → 0.0.33__py3-none-any.whl

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.

Potentially problematic release.


This version of luna-quantum might be problematic. Click here for more details.

Files changed (66) hide show
  1. {luna_quantum-0.0.16.dist-info → luna_quantum-0.0.33.dist-info}/METADATA +2 -1
  2. {luna_quantum-0.0.16.dist-info → luna_quantum-0.0.33.dist-info}/RECORD +64 -58
  3. luna_sdk/controllers/luna_http_client.py +27 -0
  4. luna_sdk/controllers/luna_platform_client.py +41 -23
  5. luna_sdk/controllers/luna_q.py +11 -16
  6. luna_sdk/controllers/luna_solve.py +12 -17
  7. luna_sdk/controllers/luna_transform.py +14 -15
  8. luna_sdk/error/http_error_utils.py +10 -3
  9. luna_sdk/interfaces/circuit_repo_i.py +18 -12
  10. luna_sdk/interfaces/cplex_repo_i.py +25 -10
  11. luna_sdk/interfaces/info_repo_i.py +10 -3
  12. luna_sdk/interfaces/lp_repo_i.py +20 -8
  13. luna_sdk/interfaces/optimization_repo_i.py +35 -60
  14. luna_sdk/interfaces/qpu_token_repo_i.py +40 -38
  15. luna_sdk/interfaces/solutions_repo_i.py +44 -24
  16. luna_sdk/repositories/circuit_repo.py +11 -44
  17. luna_sdk/repositories/cplex_repo.py +32 -20
  18. luna_sdk/repositories/info_repo.py +4 -7
  19. luna_sdk/repositories/lp_repo.py +21 -15
  20. luna_sdk/repositories/optimization_repo.py +36 -210
  21. luna_sdk/repositories/qpu_token_repo.py +52 -128
  22. luna_sdk/repositories/solutions_repo.py +109 -181
  23. luna_sdk/schemas/create/solution.py +2 -2
  24. luna_sdk/schemas/enums/optimization.py +8 -7
  25. luna_sdk/schemas/enums/qpu_token_type.py +1 -1
  26. luna_sdk/schemas/optimization.py +15 -24
  27. luna_sdk/schemas/optimization_formats/qubo.py +8 -0
  28. luna_sdk/schemas/pretty_base.py +10 -3
  29. luna_sdk/schemas/qpu_token.py +4 -5
  30. luna_sdk/schemas/rest/qpu_token/qpu_token_source.py +18 -0
  31. luna_sdk/schemas/rest/qpu_token/token_provider.py +47 -15
  32. luna_sdk/schemas/solution.py +7 -6
  33. luna_sdk/schemas/solver_info.py +31 -1
  34. luna_sdk/schemas/solver_parameters/aws/optimizer_params.py +40 -0
  35. luna_sdk/schemas/solver_parameters/aws/qaoa.py +36 -4
  36. luna_sdk/schemas/solver_parameters/base_parameter.py +5 -0
  37. luna_sdk/schemas/solver_parameters/dwave/base.py +15 -14
  38. luna_sdk/schemas/solver_parameters/dwave/dialectic_search.py +3 -2
  39. luna_sdk/schemas/solver_parameters/dwave/kerberos.py +2 -3
  40. luna_sdk/schemas/solver_parameters/dwave/leap_hybrid_bqm.py +2 -2
  41. luna_sdk/schemas/solver_parameters/dwave/leap_hybrid_cqm.py +2 -2
  42. luna_sdk/schemas/solver_parameters/dwave/parallel_tempering.py +2 -3
  43. luna_sdk/schemas/solver_parameters/dwave/parallel_tempering_qpu.py +2 -3
  44. luna_sdk/schemas/solver_parameters/dwave/population_annealing.py +2 -3
  45. luna_sdk/schemas/solver_parameters/dwave/population_annealing_qpu.py +2 -1
  46. luna_sdk/schemas/solver_parameters/dwave/qaga.py +4 -2
  47. luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_qpu.py +2 -3
  48. luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_simulated_annealing.py +2 -3
  49. luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_tabu_search.py +2 -3
  50. luna_sdk/schemas/solver_parameters/dwave/quantum_annealing.py +2 -3
  51. luna_sdk/schemas/solver_parameters/dwave/repeated_reverse_quantum_annealing.py +4 -2
  52. luna_sdk/schemas/solver_parameters/dwave/repeated_reverse_simulated_annealing.py +3 -2
  53. luna_sdk/schemas/solver_parameters/dwave/saga.py +1 -1
  54. luna_sdk/schemas/solver_parameters/dwave/tabu_search.py +3 -1
  55. luna_sdk/schemas/solver_parameters/fujitsu/base.py +5 -4
  56. luna_sdk/schemas/solver_parameters/fujitsu/partial_config.py +7 -5
  57. luna_sdk/schemas/solver_parameters/ibm/standard_parameters.py +121 -7
  58. luna_sdk/schemas/solver_parameters/qctrl/qaoa.py +2 -2
  59. luna_sdk/schemas/wrappers/__init__.py +1 -0
  60. luna_sdk/schemas/wrappers/datetime_wrapper.py +31 -0
  61. luna_sdk/utils/parameter_finder.py +90 -0
  62. luna_sdk/utils/qpu_tokens.py +14 -13
  63. luna_sdk/constants.py +0 -1
  64. luna_sdk/controllers/custom_login_client.py +0 -61
  65. {luna_quantum-0.0.16.dist-info → luna_quantum-0.0.33.dist-info}/LICENSE +0 -0
  66. {luna_quantum-0.0.16.dist-info → luna_quantum-0.0.33.dist-info}/WHEEL +0 -0
@@ -9,7 +9,7 @@ from luna_sdk.interfaces.optimization_repo_i import IOptimizationRepo
9
9
  from luna_sdk.schemas import UseCase
10
10
  from luna_sdk.schemas.create import QUBOIn
11
11
  from luna_sdk.schemas.create.optimization import OptimizationUseCaseIn
12
- from luna_sdk.schemas.enums.optimization import InputType
12
+ from luna_sdk.schemas.enums.optimization import OptFormat
13
13
  from luna_sdk.schemas.enums.timeframe import TimeframeEnum
14
14
  from luna_sdk.schemas.optimization import (
15
15
  Optimization,
@@ -17,6 +17,7 @@ from luna_sdk.schemas.optimization import (
17
17
  OptimizationCQM,
18
18
  OptimizationLP,
19
19
  OptimizationUseCase,
20
+ OptimizationQubo,
20
21
  )
21
22
  from luna_sdk.schemas.optimization_formats.bqm import BQMSchema
22
23
  from luna_sdk.schemas.optimization_formats.cqm import CQMSchema
@@ -30,35 +31,17 @@ class OptimizationRepo(IOptimizationRepo):
30
31
  def get_all(
31
32
  self,
32
33
  timeframe: Optional[TimeframeEnum] = None,
33
- input_type: Optional[InputType] = None,
34
+ input_type: Optional[OptFormat] = None,
34
35
  limit: int = 50,
35
36
  offset: int = 0,
37
+ **kwargs,
36
38
  ) -> List[Optimization]:
37
- """
38
- Get a list of all available Models.
39
-
40
- Parameters
41
- ----------
42
- timeframe: Optional[TimeframeEnum]
43
- Only return QUBOs created within a specified timeframe. Default None.
44
- input_type: Optional[InputType]
45
- Only return optimizations of a specified input type. Default None.
46
- limit: int
47
- Limit the number of Optimizations to be returned. Default value 50.
48
- offset: int
49
- Offset the list of optimizations by this amount. Default value 0.
50
-
51
- Returns
52
- -------
53
- List[Model]
54
- List of Model instances.
55
- """
56
39
  params = {}
57
40
  if timeframe and timeframe != TimeframeEnum.all_time: # no value == all_time
58
41
  params["timeframe"] = timeframe.value
59
42
 
60
43
  if input_type:
61
- params["input_type"] = input_type.value
44
+ params["original_format"] = input_type.value
62
45
 
63
46
  if limit < 1:
64
47
  # set the minimum limit to 1
@@ -66,12 +49,14 @@ class OptimizationRepo(IOptimizationRepo):
66
49
 
67
50
  params["limit"] = str(limit)
68
51
  params["offset"] = str(offset)
69
- response: Response = self._client.get(self._endpoint, params=params)
52
+ response: Response = self._client.get(self._endpoint, params=params, **kwargs)
70
53
  response.raise_for_status()
71
54
  return [Optimization.model_validate(item) for item in response.json()]
72
55
 
73
- def get(self, optimization_id: str) -> Optimization:
74
- response: Response = self._client.get(f"{self._endpoint}/{optimization_id}")
56
+ def get(self, optimization_id: str, **kwargs) -> Optimization:
57
+ response: Response = self._client.get(
58
+ f"{self._endpoint}/{optimization_id}", **kwargs
59
+ )
75
60
  response.raise_for_status()
76
61
  response_data = response.json()
77
62
 
@@ -79,57 +64,33 @@ class OptimizationRepo(IOptimizationRepo):
79
64
 
80
65
  optimization_data = response_data.pop("optimization_data", None)
81
66
  if optimization_data:
82
- input_type = response_data["input_type"]
67
+ original_format = response_data["original_format"]
83
68
 
84
- if input_type in (InputType.bqm_spin, InputType.bqm_binary):
69
+ if original_format == OptFormat.BQM:
85
70
  model = OptimizationBQM
86
- elif input_type == InputType.cqm:
71
+ elif original_format == OptFormat.CQM:
87
72
  model = OptimizationCQM
88
- elif input_type == InputType.lp:
73
+ elif original_format == OptFormat.LP:
89
74
  model = OptimizationLP
90
- elif input_type == InputType.qubo:
75
+ elif original_format == OptFormat.QUBO:
91
76
  if response_data.get("use_case_name"):
92
77
  model = OptimizationUseCase
93
78
  else:
94
- model = OptimizationBQM
79
+ model = OptimizationQubo
95
80
  else:
96
- model = OptimizationBQM
81
+ raise ValueError("Unknown optimization format")
97
82
 
98
83
  response_data.update(optimization_data)
99
84
 
100
- return model.validate(response_data)
85
+ return model.model_validate(response_data)
101
86
 
102
87
  def create_from_qubo(
103
- self,
104
- name: str,
105
- matrix: List[List[float]],
106
- timeout: Optional[float] = 10800.0,
88
+ self, name: str, matrix: List[List[float]], **kwargs
107
89
  ) -> Optimization:
108
- """
109
- Create an optimization from a QUBO matrix.
110
-
111
- Parameters
112
- ----------
113
- name: str
114
- Name of the optimization to be created.
115
- matrix: List[List[float]]
116
- QUBO matrix.
117
- timeout: Optional[float]
118
- Default = 10800. Timeout for the api request. If set to None,
119
- there won't be any timeout. Increase or disable the timeout if you face
120
- issues uploading big QUBO matrices.
121
-
122
- Returns
123
- -------
124
- Optimization:
125
- Created optimization.
126
- """
127
90
  data_in: Dict[str, Any] = QUBOIn(name=name, matrix=matrix).model_dump()
128
91
 
129
92
  response: Response = self._client.post(
130
- f"{self._endpoint}/qubo",
131
- json=data_in,
132
- timeout=timeout,
93
+ f"{self._endpoint}/qubo", json=data_in, **kwargs
133
94
  )
134
95
 
135
96
  response.raise_for_status()
@@ -137,30 +98,8 @@ class OptimizationRepo(IOptimizationRepo):
137
98
  return Optimization.model_validate_json(response.text)
138
99
 
139
100
  def create_from_use_case(
140
- self,
141
- name: str,
142
- use_case: UseCase,
143
- timeout: Optional[float] = 10800.0,
101
+ self, name: str, use_case: UseCase, **kwargs
144
102
  ) -> Optimization:
145
- """
146
- Create an optimization from a use case.
147
-
148
- Parameters
149
- ----------
150
- name: str
151
- Name of the optimization to be created.
152
- use_case: UseCase
153
- Use case.
154
- timeout: Optional[float]
155
- Default = 10800.0. Timeout for the api request. If set to None,
156
- there won't be any timeout. Increase or disable the timeout if you face
157
- issues uploading big Problems.
158
-
159
- Returns
160
- -------
161
- Optimization:
162
- Created optimization.
163
- """
164
103
  optimization_in = OptimizationUseCaseIn(
165
104
  name=name, use_case=use_case, params=None
166
105
  )
@@ -168,7 +107,7 @@ class OptimizationRepo(IOptimizationRepo):
168
107
  response: Response = self._client.post(
169
108
  f"{self._endpoint}/use_case",
170
109
  content=optimization_in.model_dump_json(),
171
- timeout=timeout,
110
+ **kwargs,
172
111
  )
173
112
 
174
113
  response.raise_for_status()
@@ -176,33 +115,12 @@ class OptimizationRepo(IOptimizationRepo):
176
115
  return Optimization.model_validate_json(response.text)
177
116
 
178
117
  def create_from_bqm(
179
- self,
180
- name: str,
181
- bqm: BinaryQuadraticModel,
182
- timeout: Optional[float] = 10800.0,
118
+ self, name: str, bqm: BinaryQuadraticModel, **kwargs
183
119
  ) -> Optimization:
184
- """
185
- Create an optimization from BQM.
186
-
187
- Parameters
188
- ----------
189
- name: str
190
- Name of the optimization to be created.
191
- bqm: BinaryQuadraticModel
192
- QUBO in dimod BQM format.
193
- timeout: Optional[float]
194
-
195
- Returns
196
- -------
197
- Optimization:
198
- Created optimization.
199
- """
200
120
  data_in = {"name": name, **BQMSchema.from_bqm(bqm).model_dump()}
201
121
 
202
122
  response: Response = self._client.post(
203
- f"{self._endpoint}/bqm",
204
- json=data_in,
205
- timeout=timeout,
123
+ f"{self._endpoint}/bqm", json=data_in, **kwargs
206
124
  )
207
125
 
208
126
  response.raise_for_status()
@@ -210,34 +128,12 @@ class OptimizationRepo(IOptimizationRepo):
210
128
  return Optimization.model_validate_json(response.text)
211
129
 
212
130
  def create_from_cqm(
213
- self,
214
- name: str,
215
- cqm: ConstrainedQuadraticModel,
216
- timeout: Optional[float] = 10800.0,
131
+ self, name: str, cqm: ConstrainedQuadraticModel, **kwargs
217
132
  ) -> Optimization:
218
- """
219
- Create an optimization from CQM.
220
-
221
- Parameters
222
- ----------
223
- name: str
224
- Name of the optimization to be created.
225
- cqm: ConstrainedQuadraticModel
226
- in dimod CQM format.
227
- timeout: Optional[float]
228
-
229
- Returns
230
- -------
231
- Optimization:
232
- Created optimization.
233
- """
234
-
235
133
  data_in = {"name": name, **CQMSchema.from_cqm(cqm).model_dump()}
236
134
 
237
135
  response: Response = self._client.post(
238
- f"{self._endpoint}/cqm",
239
- json=data_in,
240
- timeout=timeout,
136
+ f"{self._endpoint}/cqm", json=data_in, **kwargs
241
137
  )
242
138
 
243
139
  response.raise_for_status()
@@ -245,35 +141,13 @@ class OptimizationRepo(IOptimizationRepo):
245
141
  return Optimization.model_validate_json(response.text)
246
142
 
247
143
  def create_from_lp_file(
248
- self,
249
- name: str,
250
- lp_file: BufferedReader,
251
- timeout: Optional[float] = 10800.0,
144
+ self, name: str, lp_file: BufferedReader, **kwargs
252
145
  ) -> Optimization:
253
- """
254
- Create an optimization from LP file.
255
-
256
- Parameters
257
- ----------
258
- name: str
259
- Name of the optimization to be created.
260
- lp_file: buffer reader.
261
- timeout: Optional[float]
262
- Default = 10800. Timeout for the api request. If set to None,
263
- there won't be any timeout. Increase or disable the timeout if you face
264
- issues uploading big QUBO matrices.
265
-
266
- Returns
267
- -------
268
- Optimization:
269
- Created optimization.
270
- """
271
-
272
146
  response: Response = self._client.post(
273
147
  f"{self._endpoint}/lp-file",
274
148
  data={"optimization_in": json.dumps({"name": name})},
275
149
  files={"lp_file": lp_file},
276
- timeout=timeout,
150
+ **kwargs,
277
151
  )
278
152
 
279
153
  response.raise_for_status()
@@ -281,78 +155,30 @@ class OptimizationRepo(IOptimizationRepo):
281
155
  return Optimization.model_validate_json(response.text)
282
156
 
283
157
  def create_from_lp_string(
284
- self,
285
- name: str,
286
- lp_string: str,
287
- timeout: Optional[float] = 10800.0,
158
+ self, name: str, lp_string: str, **kwargs
288
159
  ) -> Optimization:
289
- """
290
- Create an optimization from LP string.
291
-
292
- Parameters
293
- ----------
294
- name: str
295
- Name of the optimization to be created.
296
- lp_string: string.
297
- timeout: Optional[float]
298
- Default = 10800. Timeout for the api request. If set to None,
299
- there won't be any timeout. Increase or disable the timeout if you face
300
- issues uploading big QUBO matrices.
301
-
302
- Returns
303
- -------
304
- Optimization:
305
- Created optimization.
306
- """
307
160
  data_in = {"name": name, "lp_string": lp_string}
308
161
 
309
162
  response: Response = self._client.post(
310
- f"{self._endpoint}/lp-string",
311
- json=data_in,
312
- timeout=timeout,
163
+ f"{self._endpoint}/lp-string", json=data_in, **kwargs
313
164
  )
314
165
 
315
166
  response.raise_for_status()
316
167
 
317
168
  return Optimization.model_validate_json(response.text)
318
169
 
319
- def rename(self, optimization_id: str, name: str) -> Optimization:
320
- """
321
- Update the name of the optimization
322
-
323
- Parameters
324
- ----------
325
- optimization_id: str
326
- Id of the optimization to be updated.
327
- name: str
328
- New name of the optimization
329
-
330
- Returns
331
- -------
332
- Optimization:
333
- Updated optimization.
334
- """
170
+ def rename(self, optimization_id: str, name: str, **kwargs) -> Optimization:
335
171
  data: Dict[str, str] = {"name": name}
336
172
 
337
173
  response: Response = self._client.put(
338
- f"{self._endpoint}/{optimization_id}",
339
- content=json.dumps(data),
174
+ f"{self._endpoint}/{optimization_id}", content=json.dumps(data), **kwargs
340
175
  )
341
176
  response.raise_for_status()
342
177
 
343
178
  return Optimization.model_validate_json(response.text)
344
179
 
345
- def delete(self, optimization_id: str) -> None:
346
- """
347
- Delete one QUBO by id.
348
-
349
- Parameters
350
- ----------
351
- optimization_id: str
352
- Id of the Model that should be deleted
353
-
354
- Returns
355
- -------
356
- """
357
- response: Response = self._client.delete(f"{self._endpoint}/{optimization_id}")
180
+ def delete(self, optimization_id: str, **kwargs) -> None:
181
+ response: Response = self._client.delete(
182
+ f"{self._endpoint}/{optimization_id}", **kwargs
183
+ )
358
184
  response.raise_for_status()
@@ -22,17 +22,20 @@ class QpuTokenRepo(IQpuTokenRepo):
22
22
  if token_type is None:
23
23
  return f"{self._endpoint}"
24
24
  elif token_type == QpuTokenTypeEnum.PERSONAL:
25
- return f"{self._endpoint}/users"
25
+ return f"{self._endpoint}/private"
26
26
  else:
27
- return f"{self._endpoint}/organization"
27
+ return f"{self._endpoint}/shared"
28
28
 
29
- def _get_by_name(self, name: str, token_type: QpuTokenTypeEnum) -> QpuTokenOut:
29
+ def _get_by_name(
30
+ self, name: str, token_type: QpuTokenTypeEnum, **kwargs
31
+ ) -> QpuTokenOut:
30
32
  response: Response = self._client.get(
31
- f"{self._get_endpoint_by_type(token_type)}/by_name/{name}"
33
+ f"{self._get_endpoint_by_type(token_type)}/{name}", **kwargs
32
34
  )
33
35
  response.raise_for_status()
34
36
 
35
37
  qpu_token_data = response.json()
38
+ qpu_token_data["token_type"] = token_type
36
39
  return QpuTokenOut.model_validate(qpu_token_data)
37
40
 
38
41
  def create(
@@ -40,32 +43,10 @@ class QpuTokenRepo(IQpuTokenRepo):
40
43
  name: str,
41
44
  provider: str,
42
45
  token: str,
43
- token_type: QpuTokenTypeEnum = QpuTokenTypeEnum.PERSONAL,
46
+ token_type: QpuTokenTypeEnum,
44
47
  encryption_key: Optional[str] = None,
48
+ **kwargs,
45
49
  ) -> QpuTokenOut:
46
- """
47
- Create user QPU token
48
-
49
- Parameters
50
- ----------
51
- name: str
52
- Name of the QPU token
53
- provider: str
54
- Name of provider
55
- token: str
56
- Token
57
- token_type: QpuTokenTypeEnum
58
- There are two types of QPU tokens: PERSONAL and ORGANIZATION.
59
- The default value is PERSONAL.
60
- All users of an organization can use organization QPU tokens.
61
- User QPU tokens can only be used by the user who created them.
62
- encryption_key: Optional[str]
63
- Encryption key to be used for encryption of QPU tokens.
64
- Returns
65
- -------
66
- QpuTokenOut
67
- QpuTokenOut instances.
68
- """
69
50
  encryption_key = encryption_key or os.environ.get("LUNA_ENCRYPTION_KEY")
70
51
  if encryption_key is None:
71
52
  raise EncryptionNotSetException
@@ -77,10 +58,13 @@ class QpuTokenRepo(IQpuTokenRepo):
77
58
  )
78
59
 
79
60
  response: Response = self._client.post(
80
- self._get_endpoint_by_type(token_type), content=qpu_token.model_dump_json()
61
+ self._get_endpoint_by_type(token_type),
62
+ content=qpu_token.model_dump_json(),
63
+ **kwargs,
81
64
  )
82
65
  response.raise_for_status()
83
66
  qpu_token_data = response.json()
67
+ qpu_token_data["token_type"] = token_type
84
68
  return QpuTokenOut.model_validate(qpu_token_data)
85
69
 
86
70
  def get_all(
@@ -88,44 +72,45 @@ class QpuTokenRepo(IQpuTokenRepo):
88
72
  filter_provider: Optional[str] = None,
89
73
  name: Optional[str] = None,
90
74
  token_type: Optional[QpuTokenTypeEnum] = None,
75
+ limit: Optional[int] = None,
76
+ offset: Optional[int] = None,
77
+ **kwargs,
91
78
  ) -> Dict[QpuTokenTypeEnum, List[QpuTokenOut]]:
92
- """
93
- Retrieve list of user QPU tokens.
94
-
95
- Parameters
96
- ----------
97
- filter_provider: Optional[str]
98
- The provider for which qpu tokens should be retrieved
99
- name: Optional[str]
100
- Name of the QPU token that should be retrieved
101
- token_type: Optional[QpuTokenTypeEnum]
102
- If you want to retrieve only user or organization QPU tokens
103
- otherwise all QPU tokens will be retrieved
104
- token_type: QpuTokenTypeEnum
105
- There are two types of QPU tokens: PERSONAL and ORGANIZATION.
106
- The default value is PERSONAL.
107
- All users of an organization can use organization QPU tokens.
108
- User QPU tokens can only be used by the user who created them.
109
-
110
- Returns
111
- -------
112
- Dict[QpuTokenTypeEnum, List[QpuTokenOut]]
113
- List of QpuTokenOut instances.
114
- """
115
79
  params = {}
116
80
  if filter_provider:
117
81
  params["filter_provider"] = filter_provider
118
82
 
119
83
  if name:
120
84
  params["name"] = name
121
-
122
- response = self._client.get(self._get_endpoint_by_type(), params=params)
123
- response.raise_for_status()
85
+ if limit is not None:
86
+ params["limit"] = str(limit)
87
+ if offset is not None:
88
+ params["offset"] = str(offset)
124
89
 
125
90
  to_return: Dict[QpuTokenTypeEnum, List[QpuTokenOut]] = {}
126
- for key, value in response.json().items():
127
- to_return[QpuTokenTypeEnum(key)] = [
128
- QpuTokenOut.model_validate(item) for item in value
91
+ if token_type is None or token_type == QpuTokenTypeEnum.PERSONAL:
92
+ response = self._client.get(
93
+ self._get_endpoint_by_type(QpuTokenTypeEnum.PERSONAL),
94
+ params=params,
95
+ **kwargs,
96
+ )
97
+ response.raise_for_status()
98
+ personal_qpu_tokens = response.json()
99
+ to_return[QpuTokenTypeEnum.PERSONAL] = [
100
+ QpuTokenOut(**qpu_token, token_type=QpuTokenTypeEnum.PERSONAL)
101
+ for qpu_token in personal_qpu_tokens
102
+ ]
103
+ if token_type is None or token_type == QpuTokenTypeEnum.GROUP:
104
+ response = self._client.get(
105
+ self._get_endpoint_by_type(QpuTokenTypeEnum.GROUP),
106
+ params=params,
107
+ **kwargs,
108
+ )
109
+ response.raise_for_status()
110
+ shared_qpu_tokens = response.json()
111
+ to_return[QpuTokenTypeEnum.GROUP] = [
112
+ QpuTokenOut(**qpu_token, token_type=QpuTokenTypeEnum.GROUP)
113
+ for qpu_token in shared_qpu_tokens
129
114
  ]
130
115
 
131
116
  return to_return
@@ -134,93 +119,32 @@ class QpuTokenRepo(IQpuTokenRepo):
134
119
  self,
135
120
  name: str,
136
121
  token_type: QpuTokenTypeEnum = QpuTokenTypeEnum.PERSONAL,
122
+ **kwargs,
137
123
  ) -> QpuTokenOut:
138
- """
139
- Retrieve user QPU token by id
140
-
141
- Parameters
142
- ----------
143
- name: str
144
- Name of the QPU token that should be retrieved
145
- token_type: QpuTokenTypeEnum
146
- There are two types of QPU tokens: PERSONAL and ORGANIZATION.
147
- The default value is PERSONAL.
148
- All users of an organization can use organization QPU tokens.
149
- User QPU tokens can only be used by the user who created them.
150
-
151
- Returns
152
- -------
153
- QpuTokenOut
154
- QpuTokenOut instance.
155
- """
156
-
157
- qpu_token: QpuTokenOut = self._get_by_name(name, token_type)
124
+ qpu_token: QpuTokenOut = self._get_by_name(name, token_type, **kwargs)
158
125
 
159
126
  return qpu_token
160
127
 
161
128
  def rename(
162
- self,
163
- name: str,
164
- new_name: str,
165
- token_type: QpuTokenTypeEnum = QpuTokenTypeEnum.PERSONAL,
129
+ self, name: str, new_name: str, token_type: QpuTokenTypeEnum, **kwargs
166
130
  ) -> QpuTokenOut:
167
- """
168
- Update user QPU token by id
169
-
170
- Parameters
171
- ----------
172
- name: str
173
- Name of the QPU token that should be updated
174
- new_name: str
175
- The new name
176
- token_type: QpuTokenTypeEnum
177
- There are two types of QPU tokens: PERSONAL and ORGANIZATION.
178
- The default value is PERSONAL.
179
- All users of an organization can use organization QPU tokens.
180
- User QPU tokens can only be used by the user who created them.
181
-
182
- Returns
183
- -------
184
- QpuTokenOut
185
- QpuTokenOut instance.
186
- """
187
131
  qpu_token_update_data = {"name": new_name}
188
132
 
189
133
  token: QpuTokenOut = self.get(name, token_type)
190
134
 
191
- response = self._client.put(
192
- f"{self._get_endpoint_by_type(token_type)}/{token.id}",
135
+ response = self._client.patch(
136
+ f"{self._get_endpoint_by_type(token_type)}/{token.name}",
193
137
  content=json.dumps(qpu_token_update_data),
138
+ **kwargs,
194
139
  )
195
140
  response.raise_for_status()
196
141
 
197
142
  qpu_token_data = response.json()
143
+ qpu_token_data["token_type"] = token_type
198
144
  return QpuTokenOut.model_validate(qpu_token_data)
199
145
 
200
- def delete(
201
- self,
202
- name: str,
203
- token_type: QpuTokenTypeEnum = QpuTokenTypeEnum.PERSONAL,
204
- ) -> None:
205
- """
206
- Delete organization QPU token by name
207
-
208
- Parameters
209
- ----------
210
- name: str
211
- Name of the QPU token that should be deleted
212
- token_type: QpuTokenTypeEnum
213
- There are two types of QPU tokens: PERSONAL and ORGANIZATION.
214
- The default value is PERSONAL.
215
- All users of an organization can use organization QPU tokens.
216
- User QPU tokens can only be used by the user who created them.
217
-
218
- Returns
219
- -------
220
- """
221
- token: QpuTokenOut = self.get(name, token_type)
222
-
146
+ def delete(self, name: str, token_type: QpuTokenTypeEnum, **kwargs) -> None:
223
147
  response = self._client.delete(
224
- f"{self._get_endpoint_by_type(token_type)}/{token.id}"
148
+ f"{self._get_endpoint_by_type(token_type)}/{name}", **kwargs
225
149
  )
226
150
  response.raise_for_status()