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

Test notebooks with test-eagle #2447

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
38 changes: 38 additions & 0 deletions .github/workflows/notebook-test-extended.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This code is a Qiskit project.
#
# (C) Copyright IBM 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

name: Test notebooks that submit jobs
on:
workflow_dispatch:
jobs:
execute:
name: Execute notebooks with test-eagle
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Get relevant changed files
id: all-changed
uses: tj-actions/changed-files@af2816c65436325c50621100d67f6e853cd1b0f1
with:
files: "{docs/**/*.ipynb,scripts/nb-tester/**/*}"
separator: "\n"
write_output_files: true

- name: Setup environment
uses: ./.github/actions/set-up-notebook-testing
with:
ibm-quantum-token: ${{ secrets.IBM_QUANTUM_TEST_TOKEN }}
instance: "client-enablement/documentation/qiskit-documenta"

- name: Execute notebooks
run: python scripts/ci/extended-execute-notebooks.py
4 changes: 3 additions & 1 deletion docs/guides/algorithmiq-tem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@
"service = QiskitRuntimeService()\n",
"backend_name = service.least_busy(operational=True).name\n",
"\n",
"instance = \"<IQP_HUB/IQP_GROUP/IQP_PROJECT>\"\n",
"# Instance is a string of the form \"<IQP_HUB/IQP_GROUP/IQP_PROJECT>\".\n",
"# The following line gets the instance of the active QiskitRuntimeService account.\n",
"instance = service.active_account()[\"instance\"]\n",
"\n",
"pub = (qc, [observable])\n",
"options = {\"default_precision\": 0.02}\n",
Expand Down
72 changes: 40 additions & 32 deletions docs/guides/functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,15 @@
"\n",
" <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:"
]
},
{
"cell_type": "code",
"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",
" To use `save_account()`, run `python` in your shell to open a REPL (read-eval-print loop), then enter the following:\n",
"\n",
"QiskitFunctionsCatalog.save_account(token=token)"
]
},
{
"cell_type": "markdown",
"id": "e458aad5-fa7c-4ba1-8e9e-be770d89a04a",
"metadata": {},
"source": [
"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()`."
" ```python\n",
" from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
" QiskitFunctionsCatalog.save_account(token=\"<your-token>\")\n",
" ```\n",
"\n",
" 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()`."
]
},
{
Expand All @@ -99,6 +77,8 @@
"outputs": [],
"source": [
"# Load saved credentials\n",
"from qiskit_ibm_catalog import QiskitFunctionsCatalog\n",
"\n",
"catalog = QiskitFunctionsCatalog()"
]
},
Expand Down Expand Up @@ -190,7 +170,31 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "139ac1d5-3727-4f44-a26c-0d8a1d8a58f2",
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# This cell is hidden from users\n",
"# It gets these details programatically so we can test this notebook\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit.circuit.random import random_circuit\n",
"\n",
"service = QiskitRuntimeService()\n",
"instance = service.active_account()[\"instance\"]\n",
"backend_name = service.least_busy().name\n",
"\n",
"circuit = random_circuit(num_qubits=2, depth=2, seed=42)\n",
"observable = \"Z\" * circuit.num_qubits"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b9a7a3c-cc98-4c19-93cd-f59793515c70",
"metadata": {},
"outputs": [
Expand All @@ -203,7 +207,11 @@
}
],
"source": [
"job = ibm_cf.run(instance=..., pubs=[], backend=\"backend_name\")\n",
"job = ibm_cf.run(\n",
" pubs=[(circuit, observable)],\n",
" instance=instance, # E.g. \"ibm-q/open/main\"\n",
" backend_name=backend_name, # E.g. \"ibm_kyiv\"\n",
")\n",
"\n",
"job.job_id"
]
Expand Down
6 changes: 5 additions & 1 deletion docs/guides/ibm-circuit-function.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,11 @@
"cell_type": "code",
"execution_count": 8,
"id": "4070e592",
"metadata": {},
"metadata": {
"tags": [
"raises-exception"
]
Comment on lines +346 to +348
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice feature of most Jupyter execution tools. The exception in this cell is intentional.

},
"outputs": [
{
"name": "stdout",
Expand Down
33 changes: 25 additions & 8 deletions docs/guides/q-ctrl-optimization-solver.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@
"# If you have not previously saved your credentials, follow instructions at\n",
"# https://docs.quantum.ibm.com/guides/setup-channel#iqp\n",
"# 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()\n",
"\n",
"# Access Function\n",
Expand Down Expand Up @@ -252,7 +247,26 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"id": "cf53550c",
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# This cell is hidden from users\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"service = QiskitRuntimeService()\n",
"instance = service.active_account()[\"instance\"]\n",
"backend_name = service.least_busy().name"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16c66d64",
"metadata": {},
"outputs": [],
Expand All @@ -261,7 +275,8 @@
"maxcut_job = solver.run(\n",
" problem=problem_as_str,\n",
" problem_type=\"maxcut\",\n",
" instance=hub + \"/\" + group + \"/\" + project,\n",
" instance=instance, # E.g. \"ibm-q/open/main\"\n",
" backend_name=backend_name, # E.g. \"ibm_kyiv\"\n",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change to most notebooks: We load the backend_name and instance variables in a hidden cell, then use them in the function call with a comment giving an example of the value.

")"
]
},
Expand Down Expand Up @@ -476,7 +491,9 @@
"source": [
"# Solve the problem\n",
"mvc_job = solver.run(\n",
" problem=srepr(cost_function), instance=hub + \"/\" + group + \"/\" + project\n",
" problem=srepr(cost_function),\n",
" instance=instance,\n",
frankharkins marked this conversation as resolved.
Show resolved Hide resolved
" backend_name=backend_name, # E.g. \"ibm_kyiv\"\n",
")"
]
},
Expand Down
38 changes: 23 additions & 15 deletions docs/guides/q-ctrl-performance-management.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@
"# 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",
"hub = \"<YOUR_IQP_HUB>\"\n",
"group = \"<YOUR_IQP_GROUP>\"\n",
"project = \"<YOUR_IQP_PROJECT>\"\n",
"\n",
"# Authentication\n",
"catalog = QiskitFunctionsCatalog()\n",
"\n",
"# Access Function\n",
Expand Down Expand Up @@ -203,22 +198,38 @@
"Run the circuit and optionally define the backend and number of shots."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b892956",
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# This cell is hidden from users\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"service = QiskitRuntimeService()\n",
"instance = service.active_account()[\"instance\"]\n",
"backend_name = service.least_busy().name"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "26952e1f",
"metadata": {},
"outputs": [],
"source": [
"# Choose a backend or remove this option to default to the least busy device\n",
"backend_name = \"<CHOOSE_A_BACKEND>\"\n",
"\n",
"# Run the circuit using the sampler\n",
"qctrl_estimator_job = perf_mgmt.run(\n",
" primitive=\"estimator\",\n",
" pubs=estimator_pubs,\n",
" instance=hub + \"/\" + group + \"/\" + project,\n",
" backend_name=backend_name,\n",
" instance=instance, # E.g. \"ibm-q/open/main\"\n",
" backend_name=backend_name, # E.g. \"ibm_kyiv\", or omit to default to the least busy device\n",
")"
]
},
Expand Down Expand Up @@ -447,15 +458,12 @@
"metadata": {},
"outputs": [],
"source": [
"# Choose a backend or remove this option to default to the least busy device\n",
"backend_name = \"<CHOOSE_A_BACKEND>\"\n",
"\n",
"# Run the circuit using the sampler\n",
"qctrl_sampler_job = perf_mgmt.run(\n",
" primitive=\"sampler\",\n",
" pubs=sampler_pubs,\n",
" instance=hub + \"/\" + group + \"/\" + project,\n",
" backend_name=backend_name,\n",
" instance=instance, # E.g. \"ibm-q/open/main\"\n",
" backend_name=backend_name, # E.g. \"ibm_kyiv\", or omit to default to the least busy device\n",
")"
]
},
Expand Down
27 changes: 23 additions & 4 deletions docs/guides/qedma-qesem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@
"To get started, try this basic example of estimating the required QPU time to run the QESEM for a given `pub`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2fb4efc4",
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# This cell is hidden from users\n",
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"\n",
"service = QiskitRuntimeService()\n",
"instance = service.active_account()[\"instance\"]\n",
"backend_name = service.least_busy().name"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -138,12 +157,12 @@
")\n",
"\n",
"job = qesem_function.run(\n",
" instance=\"hub1/group1/project1\",\n",
" pubs=[(circ, [avg_magnetization, other_observable])],\n",
" options={\n",
" \"estimate_time_only\": True,\n",
" },\n",
" backend_name=\"ibm_brisbane\",\n",
" instance=instance, # E.g. \"ibm-q/open/main\"\n",
" backend_name=backend_name, # E.g. \"ibm_brisbane\"\n",
")"
]
},
Expand All @@ -163,9 +182,9 @@
"outputs": [],
"source": [
"job = qesem_function.run(\n",
" instance=\"hub1/group1/project1\",\n",
" pubs=[(circ, [avg_magnetization, other_observable])],\n",
" backend_name=\"ibm_brisbane\",\n",
" instance=instance, # E.g. \"ibm-q/open/main\"\n",
" backend_name=backend_name, # E.g. \"ibm_brisbane\"\n",
")"
]
},
Expand Down
Loading
Loading