Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions to securely manage token #2322

Merged
merged 68 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
cab2eea
test twisty
abbycross Nov 14, 2024
f92740f
add info on env variable
abbycross Nov 14, 2024
8cf4f0f
add to functions intro page
abbycross Nov 14, 2024
880a541
squeaky
abbycross Nov 14, 2024
8e7b1bd
add separate section
abbycross Nov 15, 2024
929a1a0
tweak
abbycross Nov 15, 2024
6004777
restore IBM Cloud note
abbycross Nov 15, 2024
ca16e69
Update setup-channel.mdx
abbycross Nov 15, 2024
08377eb
Update docs/guides/setup-channel.mdx
abbycross Nov 18, 2024
5747749
Add tabs w/Runtime option
abbycross Nov 18, 2024
eb1b3a1
Apply suggestions from code review
abbycross Nov 18, 2024
602289c
Update docs/guides/functions.ipynb
abbycross Nov 18, 2024
6f5ed59
Update setup-channel.mdx
abbycross Nov 19, 2024
04285f9
rework page
abbycross Nov 19, 2024
05ec983
rmv ref to removed section
abbycross Nov 20, 2024
2973262
tweaks
abbycross Nov 20, 2024
a150476
rmv extra comments
abbycross Nov 20, 2024
d1f89a0
clarify default
abbycross Nov 20, 2024
215ab29
updates to the Platform section of the page
abbycross Nov 20, 2024
2b88216
redundant
abbycross Nov 21, 2024
ff129c2
bold
abbycross Nov 21, 2024
8b20e08
instructions for untrusted machine
abbycross Nov 21, 2024
d2451be
input from Vignesh
abbycross Nov 22, 2024
4aa4333
tweaks to iqp section
abbycross Nov 22, 2024
185939a
no need to italicize twice in a row
abbycross Nov 22, 2024
8e334db
first pass at REST API section
abbycross Nov 22, 2024
8d26470
test out subsection for REST API
abbycross Nov 22, 2024
c800067
Update docs/guides/setup-channel.mdx
abbycross Nov 26, 2024
b8df8c2
Update docs/guides/setup-channel.mdx
abbycross Nov 26, 2024
1f3d40d
move adm higher, rmv "or random", use original lang
abbycross Nov 26, 2024
0e18cd3
rmv "in plain text"
abbycross Nov 26, 2024
2bb59bf
add save_account() API link
abbycross Nov 26, 2024
f20da5a
copy paste code from account pg
abbycross Nov 26, 2024
b311aa2
fix indent
abbycross Nov 26, 2024
84de35b
rmv overwrite=True
abbycross Nov 26, 2024
e7acc27
separate into 2 blocks
abbycross Nov 26, 2024
8aeac62
tweaks
abbycross Nov 26, 2024
acc2bbd
updating wording on Functions pg
abbycross Nov 26, 2024
54a6c47
tox
abbycross Nov 26, 2024
7925905
Merge branch 'main' into ajc/update-install-instructions
abbycross Nov 26, 2024
c84195d
start fresh w serverless-manage-resources
abbycross Nov 26, 2024
d201682
rmv placeholder API text
abbycross Nov 26, 2024
9f34a79
comment in qunasys code
abbycross Nov 26, 2024
d3d602e
Update serverless-manage-resources.ipynb
abbycross Nov 26, 2024
1e59e09
add comments, remove placeholder text for api code
abbycross Nov 26, 2024
8374f06
add catalog back in
abbycross Nov 26, 2024
97b4f1d
more fix
abbycross Nov 26, 2024
5f31633
underscore
abbycross Nov 26, 2024
beb9434
tox
abbycross Nov 26, 2024
cb6b6fc
Apply suggestions from code review
abbycross Nov 27, 2024
b003b40
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
e0a952d
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
dbf79a9
Merge branch 'main' into ajc/update-install-instructions
abbycross Nov 27, 2024
6f5da2e
format a la iqp section
abbycross Nov 27, 2024
0be84fc
bring warning higher up in section
abbycross Nov 27, 2024
89ad0c0
break up line for readability
abbycross Nov 27, 2024
8c89b3e
Python to `python`
abbycross Nov 27, 2024
ee626fe
update untrusted language
abbycross Nov 27, 2024
57dbf4f
clarify refresh token language
abbycross Nov 27, 2024
a055c25
expire rather than rotate
abbycross Nov 27, 2024
c5a9851
what to do if you accidentally share token
abbycross Nov 27, 2024
dc974c2
tox
abbycross Nov 27, 2024
fe3ad1f
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
9eec6b9
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
cb4f46f
Update docs/guides/setup-channel.mdx
abbycross Nov 27, 2024
58a0205
pythonic
abbycross Nov 27, 2024
065dd39
Merge branch 'ajc/update-install-instructions' of https://github.com/…
abbycross Nov 27, 2024
9a14488
fix up token name
abbycross Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/guides/algorithmiq-tem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
"\n",
"tem_function_name = \"algorithmiq/tem\"\n",
"\n",
"catalog = QiskitFunctionsCatalog(token=\"<YOUR_IQP_API_TOKEN>\")\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/functions to authenticate with your API token.\n",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
"catalog = QiskitFunctionsCatalog()\n",
"\n",
"# Load your function\n",
"tem = catalog.load(tem_function_name)"
Expand Down
68 changes: 55 additions & 13 deletions docs/guides/functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,52 +49,94 @@
"\n",
"### Install Qiskit Functions Catalog client\n",
"\n",
"To start using Qiskit Functions, install the IBM Qiskit Functions Catalog client:\n",
"1. To start using Qiskit Functions, install the IBM Qiskit Functions Catalog client:\n",
"\n",
"`pip install qiskit-ibm-catalog`\n",
" ```\n",
" pip install qiskit-ibm-catalog\n",
" ```\n",
"1. Retrieve your API token from the [IBM Quantum account page](https://quantum.ibm.com/account), and activate your Python virtual environment. See the [installation instructions](/guides/install-qiskit#local) if you do not already have a virtual environment set up.\n",
"\n",
"Once installed, authenticate using your [IBM Quantum Platform API token](http://quantum.ibm.com/) as follows:"
" <span id=\"save-account\"></span>**If you are working in a trusted Python environment (such as on a personal laptop or workstation),** use the `save_account()` method to save your credentials locally. ([Skip to the next step](#functions-untrusted) if you are not using a trusted environment, such as a shared or public computer, to authenticate to IBM Quantum Platform.)\n",
"\n",
" To use `save_account()`, run Python in your shell to open a REPL (read-eval-print loop), then enter the following:"
abbycross marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "be135691-adee-4a1c-98bf-e76deb12319f",
"execution_count": null,
"id": "24dc565f-bb5d-4164-ba44-fc04c2fcaafd",
"metadata": {},
"outputs": [],
"source": [
"token = \"<your-token>\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "32919d16-4b5e-439a-8cda-33687a3d96b4",
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
"catalog = QiskitFunctionsCatalog(token=\"<YOUR_IQP_API_TOKEN>\")"
"QiskitFunctionsCatalog.save_account(token=token)"
]
},
{
"cell_type": "markdown",
"id": "42843fcd-1779-4a74-8d6a-7d00c22e374e",
"id": "e458aad5-fa7c-4ba1-8e9e-be770d89a04a",
"metadata": {},
"source": [
"Optionally, you can use the `save_account()` method to save your credentials for easy access later on, before initializing the service. This saves your credentials in the same place as `QiskitRuntimeService.save_account()`, so you can skip this step if you had previously used `QiskitRuntimeService` to save your account. *Note that account credentials are saved in plain text, so only do so if you are using a trusted device.*"
"Close out of the REPL with `exit()`. From now on, whenever you need to authenticate to the service, you can load your credentials with `QiskitFunctionsCatalog()`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "54fc48c8-3a65-478c-9bc3-ec6eb4db425a",
"id": "e872c222-aee9-40eb-8778-9a8e5434a11c",
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"# Load saved credentials\n",
"catalog = QiskitFunctionsCatalog()"
]
},
{
"cell_type": "markdown",
"id": "80441467-1d9a-4107-8570-22afa6e369f7",
"metadata": {},
"source": [
"3. <span id=\"functions-untrusted\"></span>**Avoid executing code on an external cloud Python environment to minimize security risks.** If you must use an untrusted environment (on, for example, a public computer), change your API token after each use by rotating it on the [IBM Quantum Platform dashboard](https://quantum.ibm.com/) (click the refresh button in the API token field). To initialize the service in this situation, expand the following section to view code you can use:\n",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
"\n",
" <details>\n",
" <summary>Initialize the service in an untrusted environment</summary>\n",
"\n",
" ```python\n",
" from qiskit-ibm-catalog import QiskitFunctionsCatalog\n",
"\n",
"# This can be skipped if you previously did QiskitRuntimeService.save_account()\n",
"QiskitFunctionsCatalog.save_account(token=\"<YOUR_IQP_API_TOKEN>\")"
" # Refresh your API token on the dashboard after using the code as follows:\n",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
" catalog = QiskitFunctionsCatalog(token=\"<MY_IBM_QUANTUM_TOKEN>\")\n",
" ```\n",
" </details>"
]
},
{
"cell_type": "markdown",
"id": "6f2d0a37-1c6d-4cad-a9ce-c4d05c7aaaf1",
"metadata": {},
"source": [
" <Admonition type=\"caution\">\n",
" When sharing code with others, ensure that your API token is not embedded directly within the Python script. Instead, share the script without the token and provide instructions for securely setting it up.\n",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
" </Admonition>"
]
},
{
"cell_type": "markdown",
"id": "5154cbea-ccfa-42ea-a9ef-c31699c3b2c0",
"metadata": {},
"source": [
"Once you have authenticated, you can list the functions from the Qiskit Functions Catalog that you have access to:"
"4. Once you have authenticated, you can list the functions from the Qiskit Functions Catalog that you have access to:"
]
},
{
Expand Down
11 changes: 5 additions & 6 deletions docs/guides/hello-world.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "9a901271",
"metadata": {},
"outputs": [
Expand All @@ -242,8 +242,7 @@
"source": [
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"# If you did not previously save your credentials, use the following line instead:\n",
"# service = QiskitRuntimeService(channel=\"ibm_quantum\", token=\"<MY_IBM_QUANTUM_TOKEN>\")\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/setup-channel#iqp to authenticate with your API token.\n",
"service = QiskitRuntimeService()\n",
"\n",
"backend = service.least_busy(simulator=False, operational=True)\n",
Expand Down Expand Up @@ -557,16 +556,16 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "428f05e7",
"metadata": {},
"outputs": [],
"source": [
"from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"# If you did not previously save your credentials, use the following line instead:\n",
"# service = QiskitRuntimeService(channel=\"ibm_quantum\", token=\"<MY_IBM_QUANTUM_TOKEN>\")\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/setup-channel#iqp to authenticate with your API token.\n",
abbycross marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"service = QiskitRuntimeService()\n",
"\n",
"backend = service.least_busy(\n",
Expand Down
31 changes: 16 additions & 15 deletions docs/guides/multiverse-computing-singularity.ipynb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "613c4d93",
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# This cell is hidden from users\n",
"# It stops the linter complaining about undefined variables\n",
"# ruff: noqa: F821"
"cell_type": "code",
"execution_count": null,
"id": "613c4d93",
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# This cell is hidden from users\n",
"# It stops the linter complaining about undefined variables\n",
"# ruff: noqa: F821"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -590,8 +590,9 @@
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
"# authentication\n",
"client = IBMServerlessClient(token=\"<YOUR_IQP_API_TOKEN>\")\n",
"catalog = QiskitFunctionsCatalog(token=\"<YOUR_IQP_API_TOKEN>\")\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/functions to authenticate with your API token.\n",
"client = IBMServerlessClient()\n",
"catalog = QiskitFunctionsCatalog()\n",
"\n",
"# load function\n",
"singularity = catalog.load(\"multiverse/singularity\")"
Expand Down
5 changes: 2 additions & 3 deletions docs/guides/q-ctrl-optimization-solver.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,13 @@
"source": [
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
"# Credentials\n",
"token = \"<YOUR_IQP_API_TOKEN>\"\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/functions to authenticate with your API token.\n",
"hub = \"<YOUR_IQP_HUB>\"\n",
"group = \"<YOUR_IQP_GROUP>\"\n",
"project = \"<YOUR_IQP_PROJECT>\"\n",
"\n",
"# Authentication\n",
"catalog = QiskitFunctionsCatalog(token=token)\n",
"catalog = QiskitFunctionsCatalog()\n",
"\n",
"# Access Function\n",
"solver = catalog.load(\"q-ctrl/optimization-solver\")"
Expand Down
5 changes: 2 additions & 3 deletions docs/guides/q-ctrl-performance-management.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@
"source": [
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
"# Credentials\n",
"token = \"<YOUR_IQP_API_TOKEN>\"\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/functions to authenticate with your API token.\n",
"hub = \"<YOUR_IQP_HUB>\"\n",
"group = \"<YOUR_IQP_GROUP>\"\n",
"project = \"<YOUR_IQP_PROJECT>\"\n",
"\n",
"# Authentication\n",
"catalog = QiskitFunctionsCatalog(token=token)\n",
"catalog = QiskitFunctionsCatalog()\n",
"\n",
"# Access Function\n",
"perf_mgmt = catalog.load(\"q-ctrl/performance-management\")"
Expand Down
3 changes: 2 additions & 1 deletion docs/guides/qedma-qesem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"\n",
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
"catalog = QiskitFunctionsCatalog(token=\"<YOUR_IQP_API_TOKEN>\")\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/functions to authenticate with your API token.\n",
"catalog = QiskitFunctionsCatalog()\n",
"\n",
"qesem_function = catalog.load(\"qedma/qesem\")"
]
Expand Down
1 change: 1 addition & 0 deletions docs/guides/qunasys-quri-chemistry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"source": [
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/functions to authenticate with your API token.\n",
"catalog = QiskitFunctionsCatalog()\n",
"\n",
"function = catalog.load(\"qunasys/quri-chemistry\")"
Expand Down
3 changes: 2 additions & 1 deletion docs/guides/serverless-first-program.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "7077ba00-1571-4f99-8c53-b1a9ac280987",
"metadata": {},
"outputs": [
Expand All @@ -192,6 +192,7 @@
"\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/setup-channel#iqp to authenticate with your API token.\n",
"service = QiskitRuntimeService(channel=\"ibm_quantum\")\n",
"backend = service.backend(backend_name)"
]
Expand Down
11 changes: 6 additions & 5 deletions docs/guides/serverless-manage-resources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "475d82f0-15cc-4db3-b3b0-54b07822b2a0",
"metadata": {},
"outputs": [
Expand All @@ -95,6 +95,7 @@
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_serverless import distribute_task\n",
"\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/setup-channel#iqp to authenticate with your API token.\n",
"service = QiskitRuntimeService()\n",
"\n",
"@distribute_task(target={\"cpu\": 1})\n",
Expand Down Expand Up @@ -213,9 +214,9 @@
"execution_count": 6,
"id": "df28a92c-3585-49f0-a2ea-828a34638684",
"metadata": {
"tags": [
"remove-cell"
]
"tags": [
"remove-cell"
]
},
"outputs": [
{
Expand Down Expand Up @@ -493,7 +494,7 @@
"\n",
"<Admonition type=\"info\" title=\"Recommendations\">\n",
"\n",
"- See a full example that [ports existing code to Qiskit Serverless ](./serverless-port-code).\n",
"- See a full example that [ports existing code to Qiskit Serverless](./serverless-port-code).\n",
"- Read a paper in which researchers used Qiskit Serverless and quantum-centric supercomputing to [explore quantum chemistry](https://arxiv.org/abs/2405.05068v1).\n",
"\n",
"</Admonition>"
Expand Down
13 changes: 7 additions & 6 deletions docs/guides/serverless-port-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ from qiskit.circuit.random import random_circuit
qc_random = [(random_circuit(20, 20, measure=True)) for _ in range(30)]
optimization_level = 3

# Get backend
service = QiskitRuntimeService(channel="ibm_quantum", token=API_TOKEN)
# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/setup-channel#iqp to authenticate with your API token.
service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.get_backend(backend_name)

pass_manager = generate_preset_pass_manager(
Expand Down Expand Up @@ -72,6 +72,7 @@ def transpile_parallel(circuit, pass_manager):

try:
# Get backend
# Follow instructions at https://docs.quantum.ibm.com/guides/setup-channel#iqp to authenticate with your API token.
service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.get_backend(backend_name)

Expand Down Expand Up @@ -101,13 +102,13 @@ except Exception as e:

## Upload to Qiskit Serverless

Follow the instructions on the [Introduction to Qiskit Functions](/guides/functions) page to authenticate with your API token.

```python
from qiskit_ibm_catalog import QiskitServerless, QiskitFunction

# Authenticate to the remote cluster and submit the pattern for remote execution
serverless = QiskitServerless(
token=API_TOKEN
)
# Authenticate to the remote cluster and submit the pattern for remote execution.
serverless = QiskitServerless()

transpile_remote_demo = QiskitFunction(
title="transpile_remote_serverless",
Expand Down
3 changes: 2 additions & 1 deletion docs/guides/serverless-run-first-workload.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "ebefb5ac-c8a8-4350-b16f-0677f0e412e5",
"metadata": {},
"outputs": [
Expand All @@ -149,6 +149,7 @@
"source": [
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"# If you have not previously saved your credentials, follow instructions at https://docs.quantum.ibm.com/guides/setup-channel#iqp to authenticate with your API token.\n",
"service = QiskitRuntimeService()\n",
"backend = service.least_busy(operational=True, simulator=False)\n",
"print(backend.name)"
Expand Down
Loading