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.file_download function and pass a file name and the Qiskit Function to start downloading the file. Or you can list all available files to you by calling QiskitServerless.files.
Files are exchanged through the following directories, which are mounted inside your function:
Directory |
Scope |
Available to |
Purpose |
|---|---|---|---|
|
function |
user and provider functions |
Files uploaded with |
|
job |
user and provider functions |
Per-job data: arguments, public logs and results. Managed by the platform, not listed by |
|
function |
provider functions only |
Provider-only files, hidden from users. Only the providers of the specific functions can see files under that path. |
|
job |
provider functions only |
Per-job private provider logs. Managed by the platform. |
Limitations:
only the top level of
/function_user_datais listed,/function_user_data/other_folderwill not be visible.the wrapper script injected by the platform at submit time is not listed by
.files().Qiskit Functions created by you and Qiskit Functions created by others don’t share directories.
⚠ The Ray runner has been replaced by the Fleets runner. The
/dataand/function_datadirectories used by the Ray runner are no longer available; use/function_user_dataand/function_provider_datainstead.⚠ 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.
[2]:
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"),
# If you are using the kubernetes approach the URL must be http://localhost
)
serverless
[2]:
<gateway-client>
Let’s create a Qiskit Function to write tar file into the /function_user_data folder
[3]:
function = QiskitFunction(
title="file-producer", entrypoint="produce_files.py", working_dir="./source_files/"
)
serverless.upload(function)
[3]:
QiskitFunction(file-producer)
[4]:
my_function = serverless.get("file-producer")
my_function
[4]:
QiskitFunction(file-producer)
[5]:
job = my_function.run()
job
[5]:
<Job | 4868d039-3342-4f3e-b843-c0d15ad52fe6>
[6]:
job.result()
[6]:
{'Message': 'my_file.txt archived into my_file.tar'}
Now we can look at files available using files method
[8]:
available_files = serverless.files(my_function)
available_files
[8]:
['my_file.tar']
And download them if needed using download method
[10]:
serverless.file_download(available_files[0], my_function)
100%|██████████| 200/200 [00:00<00:00, 309kiB/s]
[10]:
'downloaded_8d3f92ba_my_file.tar'