Skip to content

Commit b921693

Browse files
authored
Add job tags page (#3947)
A followup to #3942 : in discussion with the original requestors, we decided the save/retrieve jobs topic is too different from the add job tags topic, and so we separate them in this PR. cc: @drew-distefano @francabrera @kt474
1 parent e4ee88c commit b921693

File tree

7 files changed

+206
-137
lines changed

7 files changed

+206
-137
lines changed

docs/guides/_toc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,11 @@
571571
"url": "/docs/guides/job-limits"
572572
},
573573
{
574-
"title": "Tag, retrieve, and save results",
574+
"title": "Organize and search by job tags",
575+
"url": "/docs/guides/add-job-tags"
576+
},
577+
{
578+
"title": "Retrieve and save job results",
575579
"url": "/docs/guides/save-jobs"
576580
}
577581
]

docs/guides/add-job-tags.ipynb

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "ef283f37-0ad4-48c7-bb92-8a09baaae6e5",
6+
"metadata": {},
7+
"source": [
8+
"# Organize and search by job tags"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "f4471d6b-dc12-486c-95de-22ac12e367d2",
14+
"metadata": {
15+
"tags": [
16+
"version-info"
17+
]
18+
},
19+
"source": [
20+
"<details>\n",
21+
"<summary><b>Package versions</b></summary>\n",
22+
"\n",
23+
"The code on this page was developed using the following requirements.\n",
24+
"We recommend using these versions or newer.\n",
25+
"\n",
26+
"```\n",
27+
"qiskit-ibm-runtime~=0.40.1\n",
28+
"```\n",
29+
"</details>"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"id": "ec8277ad-1811-4318-8282-84d6d282bb17",
35+
"metadata": {},
36+
"source": [
37+
"This guide focuses on how to add and update job tags, as well as how to search by job tags, so that you can better organize, track, and understand your experiments."
38+
]
39+
},
40+
{
41+
"cell_type": "markdown",
42+
"id": "59e38320-db15-4566-b262-40d4fcf19b82",
43+
"metadata": {},
44+
"source": [
45+
"## Assign tags\n",
46+
"\n",
47+
"You can assign one or more tags to your jobs when you run them so that you can filter by a tag later. You might want to use job tags to label particular error mitigation settings, circuit parameters, and so forth."
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": 19,
53+
"id": "74a7a1ea-f2ae-4b8c-9499-af52840c2e74",
54+
"metadata": {},
55+
"outputs": [
56+
{
57+
"name": "stdout",
58+
"output_type": "stream",
59+
"text": [
60+
"['experiment-2025', 'sampler-example']\n"
61+
]
62+
}
63+
],
64+
"source": [
65+
"from qiskit_ibm_runtime import QiskitRuntimeService, Sampler\n",
66+
"from qiskit import QuantumCircuit\n",
67+
"from qiskit.transpiler import generate_preset_pass_manager\n",
68+
"\n",
69+
"service = QiskitRuntimeService()\n",
70+
"backend = service.least_busy(simulator=False, operational=True)\n",
71+
"\n",
72+
"qc = QuantumCircuit(2)\n",
73+
"qc.h(0)\n",
74+
"qc.cx(0, 1)\n",
75+
"qc.measure_all()\n",
76+
"\n",
77+
"sampler = Sampler(backend)\n",
78+
"\n",
79+
"pm = generate_preset_pass_manager(backend=backend, optimization_level=1)\n",
80+
"isa_circuit = pm.run(qc)\n",
81+
"\n",
82+
"# Assign tags before executing\n",
83+
"sampler.options.environment.job_tags = [\"experiment-2025\", \"sampler-example\"]\n",
84+
"\n",
85+
"# Submit\n",
86+
"job = sampler.run([isa_circuit])\n",
87+
"\n",
88+
"print(service.job(job.job_id()).tags)"
89+
]
90+
},
91+
{
92+
"cell_type": "markdown",
93+
"id": "2b29f9da-3fca-4ffc-b4b2-6f0d130b5b23",
94+
"metadata": {},
95+
"source": [
96+
"## Add and update tags\n",
97+
"\n",
98+
"You can add tags after you submit a job with the `update_tags()` method. This method overwrites current tags, so if you have already assigned tags to a job and you want to add additional tags, be sure to re-assign the original tags."
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": 20,
104+
"id": "205ceaf7-f79d-4452-b4b0-9688e39a4564",
105+
"metadata": {},
106+
"outputs": [
107+
{
108+
"name": "stdout",
109+
"output_type": "stream",
110+
"text": [
111+
"['sampler-example', 'experiment-2025', '127-qubit']\n"
112+
]
113+
}
114+
],
115+
"source": [
116+
"# Add a new tag while keeping the previously assigned tags\n",
117+
"job.update_tags([\"experiment-2025\", \"sampler-example\", \"127-qubit\"])\n",
118+
"\n",
119+
"# Confirm updated tags\n",
120+
"print(job.tags)"
121+
]
122+
},
123+
{
124+
"cell_type": "markdown",
125+
"id": "9e2e8c4a-5fbb-4a15-ab75-ddb61e35b65e",
126+
"metadata": {},
127+
"source": [
128+
"## Retrieve jobs by tag\n",
129+
"\n",
130+
"Display a list of jobs with certain tags as follows:"
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": 21,
136+
"id": "b6db503e-46ef-406e-9420-ef73446df564",
137+
"metadata": {},
138+
"outputs": [
139+
{
140+
"data": {
141+
"text/plain": [
142+
"[<RuntimeJobV2('d38l3pkgenls73cf263g', 'sampler')>,\n",
143+
" <RuntimeJobV2('d36s55gitjus73f5li10', 'sampler')>,\n",
144+
" <RuntimeJobV2('d36s4mkda4cs73a8994g', 'sampler')>,\n",
145+
" <RuntimeJobV2('d36rs9o0sqis73982e4g', 'sampler')>,\n",
146+
" <RuntimeJobV2('d36rptsgenls73cda9n0', 'sampler')>,\n",
147+
" <RuntimeJobV2('d36rohkgenls73cda87g', 'sampler')>,\n",
148+
" <RuntimeJobV2('d36rnr0itjus73f5l4m0', 'sampler')>,\n",
149+
" <RuntimeJobV2('d36rnp0itjus73f5l4j0', 'sampler')>,\n",
150+
" <RuntimeJobV2('d35f3joitjus73f49ds0', 'sampler')>,\n",
151+
" <RuntimeJobV2('d35bsn80sqis7396img0', 'sampler')>]"
152+
]
153+
},
154+
"execution_count": 21,
155+
"metadata": {},
156+
"output_type": "execute_result"
157+
}
158+
],
159+
"source": [
160+
"# List jobs with a specific tag or set of tags\n",
161+
"\n",
162+
"service.jobs(job_tags=[\"experiment-2025\", \"sampler-example\"])"
163+
]
164+
}
165+
],
166+
"metadata": {
167+
"description": "Assign job tags, add and update tags, and search by tag to better organize your experiments.",
168+
"kernelspec": {
169+
"display_name": "Python 3",
170+
"language": "python",
171+
"name": "python3"
172+
},
173+
"language_info": {
174+
"codemirror_mode": {
175+
"name": "ipython",
176+
"version": 3
177+
},
178+
"file_extension": ".py",
179+
"mimetype": "text/x-python",
180+
"name": "python",
181+
"nbconvert_exporter": "python",
182+
"pygments_lexer": "ipython3",
183+
"version": "3"
184+
},
185+
"title": "Organize and search by job tags"
186+
},
187+
"nbformat": 4,
188+
"nbformat_minor": 4
189+
}

docs/guides/execute-on-hardware.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ expectation values of observables corresponding to physical quantities or cost f
5454
* [Minimize job run time](./minimize-time)
5555
* [Maximum execution time](./max-execution-time)
5656
* [Job limits](./job-limits)
57+
* [Organize and search by job tags](/docs/guides/add-job-tags)
5758

5859
### QPU and platform information
5960

docs/guides/post-process-results.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ properties of the problem, such as total spin, parity, or particle conservation
1515
unphysical observables.
1616

1717
## Guides for post-processing results
18-
* [Tag, retrieve, and save results](/docs/guides/save-jobs)
18+
* [Retrieve and save job results](/docs/guides/save-jobs)
1919
* [Visualize results](/docs/guides/visualize-results)
2020
* [Sample-based quantum diagonalization (SQD) overview](/docs/guides/qiskit-addons-sqd)
2121
* [Getting started with SQD](/docs/guides/qiskit-addons-sqd-get-started)

0 commit comments

Comments
 (0)