{ "cells": [ { "cell_type": "markdown", "id": "aa077791-1bcf-43f6-ab2b-e04db48b9cb1", "metadata": {}, "source": [ "# File download (Experimental)\n", "\n", "In this tutorial we will describe a way to retrieve files produced by patterns.\n", "\n", "This function provides a way to download files produced by patterns 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 file to you by calling `QiskitServerless.files`.\n", "\n", "Limitations:\n", "\n", "- only `tar` files are supported\n", "- `tar` file should be saved in `/data` directory during your pattern execution to be visible by `.files()` method call\n", "- only `/data` directory is supported, `/data/other_folder` will not be visible\n", "\n", "> ⚠ This interface is experimental, therefore it is subjected to breaking changes.\n", "\n", "> ⚠ 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](https://qiskit.github.io/qiskit-serverless/deployment/local.html)." ] }, { "cell_type": "code", "execution_count": 1, "id": "93717e14-d06e-4e11-bd5b-6cdc3f1b1abd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import os\n", "from qiskit_serverless import ServerlessClient, QiskitFunction\n", "\n", "serverless = ServerlessClient(\n", " token=os.environ.get(\"GATEWAY_TOKEN\", \"awesome_token\"),\n", " host=os.environ.get(\"GATEWAY_HOST\", \"http://localhost:8000\"),\n", ")\n", "serverless" ] }, { "cell_type": "markdown", "id": "fc30a74a-2100-40b8-a283-30bd51875b45", "metadata": {}, "source": [ "Let's create a pattern to write `tar` file into `/data` folder" ] }, { "cell_type": "code", "execution_count": 2, "id": "8d93f33b-f7f1-475d-b46e-1106cbe45cae", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'file-producer'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function = QiskitFunction(\n", " title=\"file-producer\", entrypoint=\"produce_files.py\", working_dir=\"./source_files/\"\n", ")\n", "\n", "serverless.upload(function)" ] }, { "cell_type": "code", "execution_count": 3, "id": "3fef0868-7574-4fbf-b8de-4a7889bdf5ec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "job = serverless.run(\"file-producer\")\n", "job" ] }, { "cell_type": "code", "execution_count": 4, "id": "ecd0bb68-4d3c-450e-b363-a58fd91880b3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Message': 'my_file.txt archived into my_file.tar'}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "job.result()" ] }, { "cell_type": "markdown", "id": "f0e57aa6-5573-4f07-9ac8-753cb7998091", "metadata": {}, "source": [ "Now we can look at files available using `files` method" ] }, { "cell_type": "code", "execution_count": null, "id": "08205fd4-b3d6-44d1-a33c-fb3918c26b12", "metadata": {}, "outputs": [], "source": [ "available_files = serverless.files()\n", "available_files" ] }, { "cell_type": "markdown", "id": "16c3d7a6-4cce-4ef0-a1f2-e8a6d7f2c531", "metadata": {}, "source": [ "And download them if needed using `download` method" ] }, { "cell_type": "code", "execution_count": 6, "id": "39ca652d-77d7-49d2-97e9-42b60963a671", "metadata": {}, "outputs": [], "source": [ "if len(available_files) > 0:\n", " serverless.file_download(available_files[0])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }