diff --git a/docs/getting_started/experimental/file_download.ipynb b/docs/getting_started/experimental/file_download.ipynb index e1adec3a0..2fa8edf3e 100644 --- a/docs/getting_started/experimental/file_download.ipynb +++ b/docs/getting_started/experimental/file_download.ipynb @@ -9,23 +9,21 @@ "\n", "In this tutorial we will describe a way to retrieve files produced by Qiskit Functions.\n", "\n", - "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`.\n", + "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`.\n", "\n", "Limitations:\n", "\n", - "- only `tar` and `h5` files are supported\n", - "- `tar` or `h5` file should be saved in `/data` directory during your function execution to be visible by `.files()` method call\n", - "- only `/data` directory is supported, `/data/other_folder` will not be visible\n", + "- files should be saved in `/data` directory during your function execution to be visible by `.files()` method call.\n", + "- only `/data` directory is supported, `/data/other_folder` will not be visible.\n", "- as 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.\n", - "\n", - "> ⚠ This interface is experimental, therefore it is subjected to breaking changes.\n", + "- Qiskit Functions created by you and Qiskit Functions created by others don't share directories.\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": null, + "execution_count": 2, "id": "93717e14-d06e-4e11-bd5b-6cdc3f1b1abd", "metadata": {}, "outputs": [ @@ -35,7 +33,7 @@ "" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -46,7 +44,7 @@ "\n", "serverless = ServerlessClient(\n", " token=os.environ.get(\"GATEWAY_TOKEN\", \"awesome_token\"),\n", - " host=os.environ.get(\"GATEWAY_HOST\", \"http://localhost:8000\"),\n", + " host=os.environ.get(\"GATEWAY_HOST\", \"http://localhost\"),\n", " # If you are using the kubernetes approach the URL must be http://localhost\n", ")\n", "serverless" @@ -62,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "id": "8d93f33b-f7f1-475d-b46e-1106cbe45cae", "metadata": {}, "outputs": [ @@ -72,7 +70,7 @@ "QiskitFunction(file-producer)" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -87,29 +85,51 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, + "id": "3577cc07", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "QiskitFunction(file-producer)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_function = serverless.get(\"file-producer\")\n", + "my_function" + ] + }, + { + "cell_type": "code", + "execution_count": 5, "id": "3fef0868-7574-4fbf-b8de-4a7889bdf5ec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 3, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "job = serverless.run(\"file-producer\")\n", + "job = my_function.run()\n", "job" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "id": "ecd0bb68-4d3c-450e-b363-a58fd91880b3", "metadata": {}, "outputs": [ @@ -119,7 +139,7 @@ "{'Message': 'my_file.txt archived into my_file.tar'}" ] }, - "execution_count": 4, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -138,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 8, "id": "08205fd4-b3d6-44d1-a33c-fb3918c26b12", "metadata": {}, "outputs": [ @@ -148,13 +168,13 @@ "['my_file.tar']" ] }, - "execution_count": 5, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "available_files = serverless.files()\n", + "available_files = serverless.files(my_function)\n", "available_files" ] }, @@ -168,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 10, "id": "39ca652d-77d7-49d2-97e9-42b60963a671", "metadata": {}, "outputs": [ @@ -176,22 +196,22 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|██████████| 201/201 [00:00<00:00, 331kiB/s]\n" + "100%|██████████| 200/200 [00:00<00:00, 309kiB/s]\n" ] }, { "data": { "text/plain": [ - "'downloaded_91ea37d9_my_file.tar'" + "'downloaded_8d3f92ba_my_file.tar'" ] }, - "execution_count": 6, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "serverless.file_download(available_files[0])" + "serverless.file_download(available_files[0], my_function)" ] } ], diff --git a/docs/getting_started/experimental/manage_data_directory.ipynb b/docs/getting_started/experimental/manage_data_directory.ipynb index 233854217..1a1925249 100644 --- a/docs/getting_started/experimental/manage_data_directory.ipynb +++ b/docs/getting_started/experimental/manage_data_directory.ipynb @@ -7,26 +7,23 @@ "source": [ "# Shared data directory (Experimental)\n", "\n", - "In this tutorial we will describe a shared directory `data`. Qiskit Functions can produce and consume files in the `data` directory. The files in the `data` directory are shared among Qiskit Functions.\n", + "In this tutorial we will describe a shared directory `data`. Qiskit Functions can produce and consume files in the `data` directory.\n", "\n", - "`QiskitServerless` has `file_download`, `file_upload`, `file_delete` and `files` functions that provide file upload, file download, file delete and list files function.\n", + "`QiskitServerless` has `file_download`, `file_upload`, `file_delete` and `files` functions that provide file upload, file download, file delete and list files.\n", "\n", "Limitations:\n", "\n", - "- only `tar` and `h5` files are supported\n", - "- `tar` or `h5` file should be saved in `/data` director during your function execution to be visible by `.files()` method call\n", - "- only `/data` directory is supported, `/data/other_folder` will not be visible\n", - "- the working directory of these functions are `/data`\n", + "- files should be saved in `/data` directory during your function execution to be visible by `.files()` method call.\n", + "- only `/data` directory is supported, `/data/other_folder` will not be visible.\n", "- as 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.\n", - "\n", - "> ⚠ This interface is experimental, therefore it is subjected to breaking changes.\n", + "- Qiskit Functions created by you and Qiskit Functions created by others don't share directories.\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, + "execution_count": 2, "id": "429d8e73-aa75-47ca-9dcd-ed3b33a2cdf8", "metadata": {}, "outputs": [ @@ -36,7 +33,7 @@ "" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -53,6 +50,53 @@ "serverless" ] }, + { + "cell_type": "code", + "execution_count": 3, + "id": "87622133", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "QiskitFunction(file-producer)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "producer_function = QiskitFunction(\n", + " title=\"file-producer\", entrypoint=\"produce_files.py\", working_dir=\"./source_files/\"\n", + ")\n", + "\n", + "serverless.upload(producer_function)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "c26a3422", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "QiskitFunction(file-producer)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "producer_function = serverless.get(\"file-producer\")\n", + "producer_function" + ] + }, { "cell_type": "markdown", "id": "bc286ee3-2b3b-47ca-a60e-b4db8a57ee06", @@ -63,7 +107,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "id": "4f35187e-952e-4f2b-8871-1c971e28a739", "metadata": {}, "outputs": [], @@ -78,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "id": "71d0cd3f-95fd-42ed-ab77-c363433e4172", "metadata": {}, "outputs": [ @@ -88,13 +132,13 @@ "'{\"message\":\"/usr/src/app/media/mockuser/uploaded_file.tar\"}'" ] }, - "execution_count": 3, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "serverless.file_upload(filename)" + "serverless.file_upload(filename, producer_function)" ] }, { @@ -107,28 +151,44 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 7, "id": "d0009872-7da2-45c9-8bd6-d42be9da67a9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'Message': 'my_file.txt archived into my_file.tar'}" + "" ] }, - "execution_count": 4, + "execution_count": 7, "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)\n", "job = serverless.run(\"file-producer\")\n", + "job" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "e2e46a7f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Message': 'my_file.txt archived into my_file.tar'}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ "job.result()" ] }, @@ -142,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 9, "id": "81ca879c-352f-41ae-a97a-5eb08b4b2c19", "metadata": {}, "outputs": [ @@ -152,13 +212,13 @@ "['uploaded_file.tar', 'my_file.tar']" ] }, - "execution_count": 5, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "serverless.files()" + "serverless.files(producer_function)" ] }, { @@ -171,28 +231,90 @@ }, { "cell_type": "code", - "execution_count": 6, - "id": "06c345d7-b7dd-49b4-8c67-e8158acdcf33", + "execution_count": 10, + "id": "0741ca7e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'Message': \"b'Hello!'\"}" + "QiskitFunction(file-consumer)" ] }, - "execution_count": 6, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "function = QiskitFunction(\n", + "consumer_function = QiskitFunction(\n", " title=\"file-consumer\", entrypoint=\"consume_files.py\", working_dir=\"./source_files/\"\n", ")\n", - "\n", - "serverless.upload(function)\n", - "job = serverless.run(\"file-consumer\")\n", + "serverless.upload(consumer_function)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "05286e6d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "QiskitFunction(file-consumer)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "consumer_function = serverless.get(\"file-consumer\")\n", + "consumer_function" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "06c345d7-b7dd-49b4-8c67-e8158acdcf33", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "job = consumer_function.run()\n", + "job" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "0fff1967", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Message': \"b'Hello!'\"}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ "job.result()" ] }, @@ -206,7 +328,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 14, "id": "da35c2cd-8b26-4d36-83f3-02fda396d56d", "metadata": {}, "outputs": [ @@ -216,13 +338,13 @@ "['uploaded_file.tar', 'my_file.tar']" ] }, - "execution_count": 7, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "serverless.files()" + "serverless.files(consumer_function)" ] }, { @@ -235,7 +357,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 15, "id": "c826ed42-9ca6-44f4-83c3-20b2f28c09fc", "metadata": {}, "outputs": [ @@ -245,18 +367,18 @@ "'Requested file was deleted.'" ] }, - "execution_count": 8, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "serverless.file_delete(\"uploaded_file.tar\")" + "serverless.file_delete(filename, consumer_function)" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 16, "id": "cd6a3009-80bf-4c70-a731-63c5d58bfa6a", "metadata": {}, "outputs": [ @@ -266,13 +388,13 @@ "['my_file.tar']" ] }, - "execution_count": 9, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "serverless.files()" + "serverless.files(consumer_function)" ] } ],