Skip to content

Commit 9892065

Browse files
authored
Show how to generate built-in transpiler stage (#1546)
Fixes #1044 .
1 parent 194d0be commit 9892065

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

docs/transpile/create-a-transpiler-plugin.ipynb

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
"metadata": {},
5959
"outputs": [],
6060
"source": [
61+
"# This import is needed for python versions prior to 3.10\n",
62+
"from __future__ import annotations\n",
63+
"\n",
6164
"from qiskit.transpiler import PassManager\n",
6265
"from qiskit.transpiler.passes import VF2Layout\n",
6366
"from qiskit.transpiler.passmanager_config import PassManagerConfig\n",
@@ -163,7 +166,33 @@
163166
"id": "d62c4edb",
164167
"metadata": {},
165168
"source": [
166-
"If our example plugin were installed, then the name `my_layout` would appear in this list."
169+
"If our example plugin were installed, then the name `my_layout` would appear in this list.\n",
170+
"\n",
171+
"If you want to use a built-in transpiler stage as the starting point for your transpiler stage plugin, you can obtain the pass manager for a built-in transpiler stage using [PassManagerStagePluginManager](/api/qiskit/qiskit.transpiler.preset_passmanagers.plugin.PassManagerStagePluginManager#passmanagerstagepluginmanager). The following code cell shows how to do this to obtain the built-in optimization stage for optimization level 3."
172+
]
173+
},
174+
{
175+
"cell_type": "code",
176+
"execution_count": 3,
177+
"id": "f4d578d6",
178+
"metadata": {},
179+
"outputs": [],
180+
"source": [
181+
"from qiskit.transpiler.passmanager_config import PassManagerConfig\n",
182+
"from qiskit.transpiler.preset_passmanagers.plugin import PassManagerStagePluginManager\n",
183+
"\n",
184+
"# Initialize the plugin manager\n",
185+
"plugin_manager = PassManagerStagePluginManager()\n",
186+
"\n",
187+
"# Here we create a pass manager config to use as an example.\n",
188+
"# Instead, you should use the pass manager config that you already received as input\n",
189+
"# to the pass_manager method of your PassManagerStagePlugin.\n",
190+
"pass_manager_config = PassManagerConfig()\n",
191+
"\n",
192+
"# Obtain the desired built-in transpiler stage\n",
193+
"optimization = plugin_manager.get_passmanager_stage(\n",
194+
" \"optimization\", \"default\", pass_manager_config, optimization_level=3\n",
195+
")"
167196
]
168197
},
169198
{
@@ -188,7 +217,7 @@
188217
},
189218
{
190219
"cell_type": "code",
191-
"execution_count": 3,
220+
"execution_count": 4,
192221
"id": "6bc1011c-b15d-4210-973b-d9d530ece880",
193222
"metadata": {},
194223
"outputs": [],
@@ -324,17 +353,17 @@
324353
},
325354
{
326355
"cell_type": "code",
327-
"execution_count": 4,
356+
"execution_count": 5,
328357
"id": "31bfaf30",
329358
"metadata": {},
330359
"outputs": [
331360
{
332361
"data": {
333362
"text/plain": [
334-
"['aqc', 'default', 'sk']"
363+
"['default', 'sk', 'aqc']"
335364
]
336365
},
337-
"execution_count": 4,
366+
"execution_count": 5,
338367
"metadata": {},
339368
"output_type": "execute_result"
340369
}
@@ -397,7 +426,7 @@
397426
},
398427
{
399428
"cell_type": "code",
400-
"execution_count": 5,
429+
"execution_count": 6,
401430
"id": "3c0e59d4-85b0-4157-824b-b1f6220e83ad",
402431
"metadata": {},
403432
"outputs": [],
@@ -469,17 +498,17 @@
469498
},
470499
{
471500
"cell_type": "code",
472-
"execution_count": 6,
501+
"execution_count": 7,
473502
"id": "fbe1f265",
474503
"metadata": {},
475504
"outputs": [
476505
{
477506
"data": {
478507
"text/plain": [
479-
"['ag', 'bm', 'default', 'greedy', 'layers', 'lnn']"
508+
"['rb_default', 'ag', 'bm', 'default', 'greedy', 'layers', 'lnn']"
480509
]
481510
},
482-
"execution_count": 6,
511+
"execution_count": 7,
483512
"metadata": {},
484513
"output_type": "execute_result"
485514
}

0 commit comments

Comments
 (0)