Skip to content

Commit

Permalink
Change shared data directory interface in multiverse documentation (#…
Browse files Browse the repository at this point in the history
…2609)

This PR:
1. Removes `IBMServerlessClient`.
2. Updates client methods to catalog methods for shared data directory
usage.
  • Loading branch information
azamat-bakytzhan authored Jan 30, 2025
1 parent 3c938a7 commit 1e902f0
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions docs/guides/multiverse-computing-singularity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"To solve a generic classification problem:\n",
"1. Preprocess the dataset, and split it into training and testing sets. Optionally, you can further split the training set into training and validation sets. This can be achieved using [scikit-learn](https://scikit-learn.org/1.5/modules/generated/sklearn.model_selection.train_test_split.html).\n",
"2. If the training set is imbalanced, you can resample it to balance the classes using [imbalanced-learn](https://imbalanced-learn.org/stable/introduction.html#problem-statement-regarding-imbalanced-data-sets).\n",
"3. Upload the training, validation, and test sets separately to the function's storage using the client's `file_upload` method, passing it the relevant path each time.\n",
"3. Upload the training, validation, and test sets separately to the function's storage using the catalog's `file_upload` method, passing it the relevant path each time.\n",
"4. Initialize the quantum classifier by using the function's `create` action, which accepts hyperparameters such as the number and types of learners, the regularization (lambda value), and optimization options including the number of layers, the type of classical optimizer, the quantum backend, and so on.\n",
"5. Train the quantum classifier on the training set using the function's `fit` action, passing it the labeled training set, and the validation set if applicable.\n",
"6. Make predictions on the previously unseen test set using the function's `predict` action."
Expand Down Expand Up @@ -127,7 +127,7 @@
"source": [
"### 1. List\n",
"\n",
"The `list` action retrieves all stored classifiers in `*.pkl.tar` format from the shared data directory. You can also access the contents of this directory by using the `client.files()` method. In general, the list action searches for files with the `*.pkl.tar` extension in the shared data directory and returns them in a list format."
"The `list` action retrieves all stored classifiers in `*.pkl.tar` format from the shared data directory. You can also access the contents of this directory by using the `catalog.files()` method. In general, the list action searches for files with the `*.pkl.tar` extension in the shared data directory and returns them in a list format."
]
},
{
Expand Down Expand Up @@ -586,14 +586,12 @@
"metadata": {},
"outputs": [],
"source": [
"from qiskit_serverless import IBMServerlessClient\n",
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
"# authentication\n",
"# If you have not previously saved your credentials, follow instructions at\n",
"# https://docs.quantum.ibm.com/guides/functions\n",
"# to authenticate with your API token.\n",
"client = IBMServerlessClient()\n",
"catalog = QiskitFunctionsCatalog()\n",
"\n",
"# load function\n",
Expand Down Expand Up @@ -760,13 +758,13 @@
"make_tarfile(\"y_test.npy\", \"y_test.npy.tar\")\n",
"\n",
"# upload the datasets to the shared data directory\n",
"client.file_upload(\"X_train.npy.tar\")\n",
"client.file_upload(\"y_train.npy.tar\")\n",
"client.file_upload(\"X_test.npy.tar\")\n",
"client.file_upload(\"y_test.npy.tar\")\n",
"catalog.file_upload(\"X_train.npy.tar\", singularity)\n",
"catalog.file_upload(\"y_train.npy.tar\", singularity)\n",
"catalog.file_upload(\"X_test.npy.tar\", singularity)\n",
"catalog.file_upload(\"y_test.npy.tar\", singularity)\n",
"\n",
"# view/enlist the uploaded files in the shared data directory\n",
"print(client.files())"
"print(catalog.files(singularity))"
]
},
{
Expand Down Expand Up @@ -832,7 +830,7 @@
"job = singularity.run(action=\"list\")\n",
"\n",
"# you can also find your classifiers in the shared data directory with a *.pkl.tar extension\n",
"print(client.files())"
"print(catalog.files(singularity))"
]
},
{
Expand Down Expand Up @@ -937,7 +935,7 @@
")\n",
"\n",
"# or you can delete from the shared data directory\n",
"# client.file_delete(\"classifier_name.pkl.tar\")\n",
"# catalog.file_delete(\"classifier_name.pkl.tar\", singularity)\n",
"\n",
"print(job.result())"
]
Expand Down Expand Up @@ -970,10 +968,10 @@
"os.remove(\"y_test.npy.tar\")\n",
"\n",
"# delete the tar files from the shared data\n",
"client.file_delete(\"X_train.npy.tar\")\n",
"client.file_delete(\"y_train.npy.tar\")\n",
"client.file_delete(\"X_test.npy.tar\")\n",
"client.file_delete(\"y_test.npy.tar\")"
"catalog.file_delete(\"X_train.npy.tar\", singularity)\n",
"catalog.file_delete(\"y_train.npy.tar\", singularity)\n",
"catalog.file_delete(\"X_test.npy.tar\", singularity)\n",
"catalog.file_delete(\"y_test.npy.tar\", singularity)"
]
},
{
Expand Down

0 comments on commit 1e902f0

Please sign in to comment.