-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
231 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ services: | |
- [email protected] | ||
- SITE_HOST=http://gateway:8000 | ||
- SETTINGS_AUTH_MECHANISM=mock_token | ||
- SETTINGS_AUTH_MOCKPROVIDER_REGISTRY=test | ||
- DATABASE_HOST=postgres | ||
- DATABASE_PORT=5432 | ||
- DATABASE_NAME=serverlessdb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ services: | |
- [email protected] | ||
- SITE_HOST=http://gateway:8000 | ||
- SETTINGS_AUTH_MECHANISM=mock_token | ||
- SETTINGS_AUTH_MOCKPROVIDER_REGISTRY=test | ||
- DATABASE_HOST=postgres | ||
- DATABASE_PORT=5432 | ||
- DATABASE_NAME=serverlessdb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
from qiskit_serverless import QiskitFunction, ServerlessClient | ||
|
||
serverless = ServerlessClient( | ||
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"), | ||
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"), | ||
) | ||
|
||
help = """ | ||
title: custom-image-function | ||
description: sample function implemented in a custom image | ||
arguments: | ||
service: service created with the accunt information | ||
circuit: circuit | ||
observable: observable | ||
""" | ||
|
||
function_with_custom_image = QiskitFunction( | ||
title="custom-image-function", | ||
image="test_function:latest", | ||
provider=os.environ.get("PROVIDER_ID", "mockprovider"), | ||
description=help | ||
) | ||
serverless.upload(function_with_custom_image) | ||
|
||
my_functions = serverless.list() | ||
for function in my_functions: | ||
print("Name: " + function.title) | ||
print(function.description) | ||
print() | ||
|
||
my_function = serverless.get("custom-image-function") | ||
job = my_function.run(message="Argument for the custum function") | ||
|
||
print(job.result()) | ||
print(job.logs()) | ||
|
||
jobs = my_function.get_jobs() | ||
print(jobs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM icr.io/quantum-public/qiskit-serverless/ray-node:0.14.0-py310 | ||
|
||
# install all necessary dependencies for your custom image | ||
|
||
# copy our function implementation in `/runner.py` of the docker image | ||
USER 0 | ||
RUN mkdir /runner | ||
WORKDIR /runner | ||
COPY function/runner.py . | ||
WORKDIR / | ||
|
||
USER $RAY_UID | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from qiskit import QuantumCircuit | ||
from qiskit.primitives import StatevectorSampler as Sampler | ||
|
||
def custom_function(arguments): | ||
# all print statement will be available in job logs | ||
print("Running function...") | ||
message = arguments.get("message") | ||
print(message) | ||
|
||
# creating circuit | ||
circuit = QuantumCircuit(2) | ||
circuit.h(0) | ||
circuit.cx(0, 1) | ||
circuit.measure_all() | ||
|
||
# running Sampler primitive | ||
sampler = Sampler() | ||
quasi_dists = sampler.run([(circuit)]).result()[0].data.meas.get_counts() | ||
|
||
print("Completed running pattern.") | ||
return quasi_dists | ||
|
||
class Runner: | ||
def run(self, arguments: dict) -> dict: | ||
return custom_function(arguments) |