@planqk/planqk-service-sdk 2.3.0 → 2.5.0
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.
- package/dist/datapool.d.ts +11 -0
- package/dist/datapool.js +17 -0
- package/notebooks/python-sdk.ipynb +23 -1
- package/package.json +1 -1
- package/planqk/service/_version.py +1 -1
- package/planqk/service/datapool.py +24 -0
- package/pyproject.toml +1 -1
- package/src/datapool.ts +18 -0
- package/src/index.test.ts +29 -14
- package/uv.lock +448 -448
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare enum ReferenceType {
|
|
2
|
+
DATAPOOL = "DATAPOOL"
|
|
3
|
+
}
|
|
4
|
+
export interface DataPoolReference {
|
|
5
|
+
id: string;
|
|
6
|
+
ref: ReferenceType;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Factory function to create DataPoolReference objects with ref always set to DATAPOOL.
|
|
10
|
+
*/
|
|
11
|
+
export declare function withDataPoolReference(id: string): DataPoolReference;
|
package/dist/datapool.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReferenceType = void 0;
|
|
4
|
+
exports.withDataPoolReference = withDataPoolReference;
|
|
5
|
+
var ReferenceType;
|
|
6
|
+
(function (ReferenceType) {
|
|
7
|
+
ReferenceType["DATAPOOL"] = "DATAPOOL";
|
|
8
|
+
})(ReferenceType || (exports.ReferenceType = ReferenceType = {}));
|
|
9
|
+
/**
|
|
10
|
+
* Factory function to create DataPoolReference objects with ref always set to DATAPOOL.
|
|
11
|
+
*/
|
|
12
|
+
function withDataPoolReference(id) {
|
|
13
|
+
return {
|
|
14
|
+
id,
|
|
15
|
+
ref: ReferenceType.DATAPOOL,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -83,6 +83,28 @@
|
|
|
83
83
|
"print(f\"Service execution finished at '{ended_at}' with status '{status}'\")"
|
|
84
84
|
]
|
|
85
85
|
},
|
|
86
|
+
{
|
|
87
|
+
"cell_type": "code",
|
|
88
|
+
"execution_count": null,
|
|
89
|
+
"metadata": {},
|
|
90
|
+
"outputs": [],
|
|
91
|
+
"source": [
|
|
92
|
+
"from planqk.service.datapool import DataPoolReference\n",
|
|
93
|
+
"\n",
|
|
94
|
+
"# Prepare your input and specify which data pool to use at runtime\n",
|
|
95
|
+
"data = {\"file_to_read\": \"example.txt\"}\n",
|
|
96
|
+
"dataset = DataPoolReference(id=\"89ae42e1-9697-4742-adfb-95bf018104c3\")\n",
|
|
97
|
+
"\n",
|
|
98
|
+
"service_execution = client.run(request={\"data\": data, \"dataset\": dataset})\n",
|
|
99
|
+
"\n",
|
|
100
|
+
"# Wait for the service execution to finish (blocking)\n",
|
|
101
|
+
"service_execution.wait_for_final_state()\n",
|
|
102
|
+
"\n",
|
|
103
|
+
"status = service_execution.status\n",
|
|
104
|
+
"ended_at = service_execution.ended_at\n",
|
|
105
|
+
"print(f\"Service execution finished at '{ended_at}' with status '{status}'\")"
|
|
106
|
+
]
|
|
107
|
+
},
|
|
86
108
|
{
|
|
87
109
|
"cell_type": "code",
|
|
88
110
|
"execution_count": null,
|
|
@@ -192,7 +214,7 @@
|
|
|
192
214
|
"name": "python",
|
|
193
215
|
"nbconvert_exporter": "python",
|
|
194
216
|
"pygments_lexer": "ipython3",
|
|
195
|
-
"version": "3.11.
|
|
217
|
+
"version": "3.11.9"
|
|
196
218
|
}
|
|
197
219
|
},
|
|
198
220
|
"nbformat": 4,
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.
|
|
1
|
+
__version__ = "2.5.0"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
from enum import Enum
|
|
3
|
+
|
|
4
|
+
import pydantic
|
|
5
|
+
|
|
6
|
+
from .sdk.core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ReferenceType(str, Enum):
|
|
10
|
+
DATAPOOL = "DATAPOOL"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DataPoolReference(UniversalBaseModel):
|
|
14
|
+
id: str
|
|
15
|
+
ref: ReferenceType = ReferenceType.DATAPOOL
|
|
16
|
+
|
|
17
|
+
if IS_PYDANTIC_V2:
|
|
18
|
+
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow",
|
|
19
|
+
frozen=True) # type: ignore # Pydantic v2
|
|
20
|
+
else:
|
|
21
|
+
class Config:
|
|
22
|
+
frozen = True
|
|
23
|
+
smart_union = True
|
|
24
|
+
extra = pydantic.Extra.allow
|
package/pyproject.toml
CHANGED
package/src/datapool.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export enum ReferenceType {
|
|
2
|
+
DATAPOOL = "DATAPOOL"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface DataPoolReference {
|
|
6
|
+
id: string
|
|
7
|
+
ref: ReferenceType
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Factory function to create DataPoolReference objects with ref always set to DATAPOOL.
|
|
12
|
+
*/
|
|
13
|
+
export function withDataPoolReference(id: string): DataPoolReference {
|
|
14
|
+
return {
|
|
15
|
+
id,
|
|
16
|
+
ref: ReferenceType.DATAPOOL,
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/index.test.ts
CHANGED
|
@@ -2,29 +2,25 @@ import process from 'node:process'
|
|
|
2
2
|
import {test} from 'vitest'
|
|
3
3
|
import 'dotenv/config'
|
|
4
4
|
import {PlanqkServiceClient} from "./client";
|
|
5
|
+
import {withDataPoolReference} from "./datapool";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const consumerSecret = process.env.CONSUMER_SECRET
|
|
7
|
+
const tokenEndpoint = process.env.TOKEN_ENDPOINT
|
|
8
|
+
const serviceEndpoint = process.env.SERVICE_ENDPOINT
|
|
9
|
+
const consumerKey = process.env.CONSUMER_KEY
|
|
10
|
+
const consumerSecret = process.env.CONSUMER_SECRET
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
console.log(`Token endpoint: ${tokenEndpoint}`)
|
|
13
|
+
console.log(`Service endpoint: ${serviceEndpoint}`)
|
|
14
|
+
console.log(`Consumer key: ${consumerKey}`)
|
|
15
|
+
console.log(`Consumer secret: ${consumerSecret}`)
|
|
16
16
|
|
|
17
|
+
test.skip('integration test: coin toss', {timeout: 5 * 60 * 1000}, async () => {
|
|
17
18
|
const client = new PlanqkServiceClient(serviceEndpoint!, consumerKey, consumerSecret, tokenEndpoint);
|
|
18
19
|
|
|
19
20
|
let serviceExecutions = await client.api().getServiceExecutions()
|
|
20
21
|
console.log(serviceExecutions)
|
|
21
22
|
|
|
22
23
|
const data = {n_coin_tosses: 2}
|
|
23
|
-
// const dataRef = {
|
|
24
|
-
// dataPoolId: "87cb778e-ac43-11ec-b909-0242ac120002",
|
|
25
|
-
// dataSourceDescriptorId: "87cb778e-ac43-11ec-b909-0242ac120002",
|
|
26
|
-
// fileId: "87cb778e-ac43-11ec-b909-0242ac120002"
|
|
27
|
-
// }
|
|
28
24
|
const params = {shots: 100}
|
|
29
25
|
|
|
30
26
|
let serviceExecution = await client.api().startExecution({data, params}, {timeoutInSeconds: 60})
|
|
@@ -54,3 +50,22 @@ test.skip('integration test', {timeout: 5 * 60 * 1000}, async () => {
|
|
|
54
50
|
serviceExecutions = await client.api().getServiceExecutions()
|
|
55
51
|
console.log(serviceExecutions)
|
|
56
52
|
})
|
|
53
|
+
|
|
54
|
+
test.skip('integration test: using data pools', {timeout: 5 * 60 * 1000}, async () => {
|
|
55
|
+
const client = new PlanqkServiceClient(serviceEndpoint!, consumerKey, consumerSecret, tokenEndpoint);
|
|
56
|
+
|
|
57
|
+
const data = {file_to_read: "example.txt"}
|
|
58
|
+
const dataset = withDataPoolReference("89ae42e1-9697-4742-adfb-95bf018104c3")
|
|
59
|
+
|
|
60
|
+
let serviceExecution = await client.api().startExecution({data, dataset}, {timeoutInSeconds: 60})
|
|
61
|
+
console.log(serviceExecution)
|
|
62
|
+
|
|
63
|
+
const finalStates = ["SUCCEEDED", "CANCELLED", "FAILED"]
|
|
64
|
+
while (!finalStates.includes(serviceExecution.status!)) {
|
|
65
|
+
serviceExecution = await client.api().getStatus(serviceExecution.id!)
|
|
66
|
+
}
|
|
67
|
+
console.log(serviceExecution)
|
|
68
|
+
|
|
69
|
+
const logs = await client.api().getLogs(serviceExecution.id!)
|
|
70
|
+
console.log(logs)
|
|
71
|
+
})
|