File download (Experimental)¶
In this tutorial we will describe a way to retrieve files produced by Qiskit Functions.
This function provides a way to download files produced by functions during execution. All you need is to call QiskitServerless.download
function and pass tar
file name to start downloading the file. Or you can list all available files to you by calling QiskitServerless.files
.
Limitations:
only
tar
andh5
files are supportedtar
orh5
file should be saved in/data
directory during your function execution to be visible by.files()
method callonly
/data
directory is supported,/data/other_folder
will not be visibleas a provider you have access to
/function-data
, it works in a similar way as the/data
folder with the distinction that users don’t have access to it. Only the providers of the specific functions can see files under that path.
⚠ This interface is experimental, therefore it is subjected to breaking changes.
⚠ This provider is set up with default credentials to a test cluster intended to run on your machine. For information on setting up infrastructure on your local machine, check out the guide on local infrastructure setup.
[ ]:
import os
from qiskit_serverless import ServerlessClient, QiskitFunction
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
# If you are using the kubernetes approach the URL must be http://localhost
)
serverless
<gateway-client>
Let’s create a Qiskit Function to write tar
file into /data
folder
[2]:
function = QiskitFunction(
title="file-producer", entrypoint="produce_files.py", working_dir="./source_files/"
)
serverless.upload(function)
[2]:
QiskitFunction(file-producer)
[3]:
job = serverless.run("file-producer")
job
[3]:
<Job | 6be3ac4d-b20e-4493-9961-a187847cff49>
[4]:
job.result()
[4]:
{'Message': 'my_file.txt archived into my_file.tar'}
Now we can look at files available using files
method
[5]:
available_files = serverless.files()
available_files
[5]:
['my_file.tar']
And download them if needed using download
method
[6]:
serverless.file_download(available_files[0])
100%|██████████| 201/201 [00:00<00:00, 331kiB/s]
[6]:
'downloaded_91ea37d9_my_file.tar'