Skip to content

Commit

Permalink
Move standard gates first in Circuit Library pg (#1410)
Browse files Browse the repository at this point in the history
Closes #1409

---------

Co-authored-by: Frank Harkins <frankharkins@hotmail.co.uk>
  • Loading branch information
abbycross and frankharkins authored May 20, 2024
1 parent be977b1 commit ebdb6c9
Showing 1 changed file with 51 additions and 52 deletions.
103 changes: 51 additions & 52 deletions docs/build/circuit-library.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,57 @@
"This page lists the different circuit categories the library provides. For a full list of circuits, see the [circuit library API documentation](/api/qiskit/circuit_library)."
]
},
{
"cell_type": "markdown",
"id": "0b473350",
"metadata": {},
"source": [
"## Standard gates\n",
"\n",
"The circuit library also includes standard quantum gates. Some are more fundamental gates (such as the `UGate`), and others are multi-qubit gates that usually need building from single- and two-qubit gates. To add imported gates to your circuit, use the `append` method; the first argument is the gate, and the next argument is a list of qubits to apply the gate to.\n",
"\n",
"For example, the following code cell creates a circuit with a Hadamard gate and a multi-controlled-X gate."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a846a845-7ac5-4c92-b124-d2b90a773ba2",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg width=\"173.79pt\" height=\"218.36pt\" version=\"1.1\" viewBox=\"0 0 173.79 218.36\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs><style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style></defs><path d=\"m0 218.36h173.79v-218.36h-173.79z\" fill=\"#ffffff\"/><path d=\"m64.609 44.283h97.343\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#000000\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m64.609 90.637h97.343\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#000000\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m64.609 136.99h97.343\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#000000\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m64.609 183.35h97.343\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#000000\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m59.974 21.106h-1158.8v231.77h1158.8z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#ffffff\" stroke=\"#ffffff\" stroke-width=\"1.5\"/><path d=\"m135.99 183.35v-139.06\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#002d9c\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m74.575 59.348h30.13v-30.13h-30.13z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#fa4d56\" stroke=\"#fa4d56\" stroke-width=\"1.5\"/><path d=\"m135.99 48.803c1.1986 0 2.3482-0.4762 3.1958-1.3237 0.84753-0.84753 1.3237-1.9972 1.3237-3.1958 0-1.1986-0.4762-2.3482-1.3237-3.1958-0.84753-0.84753-1.9972-1.3237-3.1958-1.3237-1.1986 0-2.3482 0.4762-3.1958 1.3237s-1.3237 1.9972-1.3237 3.1958c0 1.1986 0.4762 2.3482 1.3237 3.1958s1.9972 1.3237 3.1958 1.3237z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#002d9c\" stroke=\"#002d9c\" stroke-width=\"1.5\"/><path d=\"m135.99 95.157c1.1986 0 2.3482-0.4762 3.1958-1.3237 0.84753-0.84753 1.3237-1.9972 1.3237-3.1958s-0.4762-2.3482-1.3237-3.1958c-0.84753-0.84753-1.9972-1.3237-3.1958-1.3237-1.1986 0-2.3482 0.4762-3.1958 1.3237-0.84753 0.84753-1.3237 1.9972-1.3237 3.1958s0.4762 2.3482 1.3237 3.1958c0.84753 0.84753 1.9972 1.3237 3.1958 1.3237z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#002d9c\" stroke=\"#002d9c\" stroke-width=\"1.5\"/><path d=\"m135.99 141.51c1.1986 0 2.3482-0.4762 3.1958-1.3237 0.84753-0.84753 1.3237-1.9972 1.3237-3.1958 0-1.1986-0.4762-2.3482-1.3237-3.1958-0.84753-0.84753-1.9972-1.3237-3.1958-1.3237-1.1986 0-2.3482 0.4762-3.1958 1.3237-0.84753 0.84753-1.3237 1.9972-1.3237 3.1958 0 1.1986 0.4762 2.3482 1.3237 3.1958s1.9972 1.3237 3.1958 1.3237z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#002d9c\" stroke=\"#002d9c\" stroke-width=\"1.5\"/><path d=\"m135.99 193.89c2.7967 0 5.4792-1.1111 7.4568-3.0887 1.9776-1.9776 3.0887-4.6601 3.0887-7.4568 0-2.7967-1.1111-5.4792-3.0887-7.4568-1.9776-1.9776-4.6601-3.0887-7.4568-3.0887-2.7967 0-5.4792 1.1111-7.4568 3.0887-1.9776 1.9776-3.0887 4.6601-3.0887 7.4568 0 2.7967 1.1111 5.4792 3.0887 7.4568 1.9776 1.9776 4.6601 3.0887 7.4568 3.0887z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#002d9c\" stroke=\"#002d9c\" stroke-width=\"2\"/><path d=\"m135.99 189.37v-12.052\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#ffffff\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m129.97 183.35h12.052\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#ffffff\" stroke-linecap=\"square\" stroke-width=\"2\"/><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(37.301 48.734) scale(.1625 -.1625)\"><defs><path id=\"DejaVuSans-Oblique-71\" transform=\"scale(.015625)\" d=\"m2669 525q-231-303-546-460-314-156-695-156-531 0-833 358-301 358-301 986 0 506 186 978t533 847q225 244 517 375t614 131q387 0 637-153t363-462l100 525h578l-934-4813h-579l360 1844zm-1778 813q0-463 193-705 194-242 560-242 544 0 928 520t384 1264q0 450-199 689-198 239-569 239-272 0-504-127-231-126-403-370-181-256-286-600-104-343-104-668z\"/><path id=\"DejaVuSans-30\" transform=\"scale(.015625)\" d=\"m2034 4250q-487 0-733-480-245-479-245-1442 0-959 245-1439 246-480 733-480 491 0 736 480 246 480 246 1439 0 963-246 1442-245 480-736 480zm0 500q785 0 1199-621 414-620 414-1801 0-1178-414-1799-414-620-1199-620-784 0-1198 620-414 621-414 1799 0 1181 414 1801 414 621 1198 621z\"/></defs><use xlink:href=\"#DejaVuSans-Oblique-71\"/><use transform=\"translate(63.477 -16.406) scale(.7)\" xlink:href=\"#DejaVuSans-30\"/></g></g><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(37.301 95.088) scale(.1625 -.1625)\"><defs><path id=\"DejaVuSans-31\" transform=\"scale(.015625)\" d=\"m794 531h1031v3560l-1122-225v575l1116 225h631v-4135h1031v-531h-2687v531z\"/></defs><use xlink:href=\"#DejaVuSans-Oblique-71\"/><use transform=\"translate(63.477 -16.406) scale(.7)\" xlink:href=\"#DejaVuSans-31\"/></g></g><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(37.301 141.44) scale(.1625 -.1625)\"><defs><path id=\"DejaVuSans-32\" transform=\"scale(.015625)\" d=\"m1228 531h2203v-531h-2962v531q359 372 979 998 621 627 780 809 303 340 423 576 121 236 121 464 0 372-261 606-261 235-680 235-297 0-627-103-329-103-704-313v638q381 153 712 231 332 78 607 78 725 0 1156-363 431-362 431-968 0-288-108-546-107-257-392-607-78-91-497-524-418-433-1181-1211z\"/></defs><use xlink:href=\"#DejaVuSans-Oblique-71\"/><use transform=\"translate(63.477 -16.406) scale(.7)\" xlink:href=\"#DejaVuSans-32\"/></g></g><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(37.301 187.8) scale(.1625 -.1625)\"><defs><path id=\"DejaVuSans-33\" transform=\"scale(.015625)\" d=\"m2597 2516q453-97 707-404 255-306 255-756 0-690-475-1069-475-378-1350-378-293 0-604 58t-642 174v609q262-153 574-231 313-78 654-78 593 0 904 234t311 681q0 413-289 645-289 233-804 233h-544v519h569q465 0 712 186t247 536q0 359-255 551-254 193-729 193-260 0-557-57-297-56-653-174v562q360 100 674 150t592 50q719 0 1137-327 419-326 419-882 0-388-222-655t-631-370z\"/></defs><use xlink:href=\"#DejaVuSans-Oblique-71\"/><use transform=\"translate(63.477 -16.406) scale(.7)\" xlink:href=\"#DejaVuSans-33\"/></g></g><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(84.752 47.87) scale(.13 -.13)\"><defs><path id=\"DejaVuSans-48\" transform=\"scale(.015625)\" d=\"m628 4666h631v-1913h2294v1913h631v-4666h-631v2222h-2294v-2222h-631v4666z\"/></defs><use xlink:href=\"#DejaVuSans-48\"/></g></g><defs><clipPath id=\"16ae6c5277f\"><rect x=\"7.2\" y=\"7.2\" width=\"159.39\" height=\"203.96\"/></clipPath></defs></svg>"
],
"text/plain": [
"<Figure size 287.496x367.889 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from qiskit import QuantumCircuit\n",
"from qiskit.circuit.library import HGate, MCXGate\n",
"mcx_gate = MCXGate(3)\n",
"hadamard_gate = HGate()\n",
"\n",
"qc = QuantumCircuit(4)\n",
"qc.append(hadamard_gate, [0])\n",
"qc.append(mcx_gate, [0,1,2,3])\n",
"qc.draw('mpl')"
]
},
{
"cell_type": "markdown",
"id": "e5066595",
"metadata": {},
"source": [
"See [Standard gates](/api/qiskit/circuit_library#standard-gates) in the circuit library API documentation."
]
},
{
"cell_type": "markdown",
"id": "f1d7c8c9-1b4d-45e1-9cd5-c5d76c2e25ab",
Expand Down Expand Up @@ -389,58 +440,6 @@
"See [Arithmetic circuits](/api/qiskit/circuit_library#arithmetic-circuits) in the circuit library API documentation."
]
},
{
"cell_type": "markdown",
"id": "ee5a64f5-1316-4217-a443-f09cb6d35c19",
"metadata": {},
"source": [
"## Standard gates\n",
"\n",
"The circuit library also includes standard quantum gates. Some are more fundamental gates (such as the `UGate`), and others are multi-qubit gates that usually need building from single- and two-qubit gates. To add imported gates to your circuit, use the `append` method; the first argument is the gate, and the next argument is a list of qubits to apply the gate to.\n",
"\n",
"For example, the following code cell creates a circuit with a Hadamard gate and a multi-controlled-X gate."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "a846a845-7ac5-4c92-b124-d2b90a773ba2",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg width=\"173.79pt\" height=\"218.36pt\" version=\"1.1\" viewBox=\"0 0 173.79 218.36\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs><style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style></defs><path d=\"m0 218.36h173.79v-218.36h-173.79z\" fill=\"#ffffff\"/><path d=\"m64.609 44.283h97.343\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#000000\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m64.609 90.637h97.343\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#000000\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m64.609 136.99h97.343\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#000000\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m64.609 183.35h97.343\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#000000\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m59.974 21.106h-1158.8v231.77h1158.8z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#ffffff\" stroke=\"#ffffff\" stroke-width=\"1.5\"/><path d=\"m135.99 183.35v-139.06\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#002d9c\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m74.575 59.348h30.13v-30.13h-30.13z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#fa4d56\" stroke=\"#fa4d56\" stroke-width=\"1.5\"/><path d=\"m135.99 48.803c1.1986 0 2.3482-0.4762 3.1958-1.3237 0.84753-0.84753 1.3237-1.9972 1.3237-3.1958 0-1.1986-0.4762-2.3482-1.3237-3.1958-0.84753-0.84753-1.9972-1.3237-3.1958-1.3237-1.1986 0-2.3482 0.4762-3.1958 1.3237s-1.3237 1.9972-1.3237 3.1958c0 1.1986 0.4762 2.3482 1.3237 3.1958s1.9972 1.3237 3.1958 1.3237z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#002d9c\" stroke=\"#002d9c\" stroke-width=\"1.5\"/><path d=\"m135.99 95.157c1.1986 0 2.3482-0.4762 3.1958-1.3237 0.84753-0.84753 1.3237-1.9972 1.3237-3.1958s-0.4762-2.3482-1.3237-3.1958c-0.84753-0.84753-1.9972-1.3237-3.1958-1.3237-1.1986 0-2.3482 0.4762-3.1958 1.3237-0.84753 0.84753-1.3237 1.9972-1.3237 3.1958s0.4762 2.3482 1.3237 3.1958c0.84753 0.84753 1.9972 1.3237 3.1958 1.3237z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#002d9c\" stroke=\"#002d9c\" stroke-width=\"1.5\"/><path d=\"m135.99 141.51c1.1986 0 2.3482-0.4762 3.1958-1.3237 0.84753-0.84753 1.3237-1.9972 1.3237-3.1958 0-1.1986-0.4762-2.3482-1.3237-3.1958-0.84753-0.84753-1.9972-1.3237-3.1958-1.3237-1.1986 0-2.3482 0.4762-3.1958 1.3237-0.84753 0.84753-1.3237 1.9972-1.3237 3.1958 0 1.1986 0.4762 2.3482 1.3237 3.1958s1.9972 1.3237 3.1958 1.3237z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#002d9c\" stroke=\"#002d9c\" stroke-width=\"1.5\"/><path d=\"m135.99 193.89c2.7967 0 5.4792-1.1111 7.4568-3.0887 1.9776-1.9776 3.0887-4.6601 3.0887-7.4568 0-2.7967-1.1111-5.4792-3.0887-7.4568-1.9776-1.9776-4.6601-3.0887-7.4568-3.0887-2.7967 0-5.4792 1.1111-7.4568 3.0887-1.9776 1.9776-3.0887 4.6601-3.0887 7.4568 0 2.7967 1.1111 5.4792 3.0887 7.4568 1.9776 1.9776 4.6601 3.0887 7.4568 3.0887z\" clip-path=\"url(#16ae6c5277f)\" fill=\"#002d9c\" stroke=\"#002d9c\" stroke-width=\"2\"/><path d=\"m135.99 189.37v-12.052\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#ffffff\" stroke-linecap=\"square\" stroke-width=\"2\"/><path d=\"m129.97 183.35h12.052\" clip-path=\"url(#16ae6c5277f)\" fill=\"none\" stroke=\"#ffffff\" stroke-linecap=\"square\" stroke-width=\"2\"/><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(37.301 48.734) scale(.1625 -.1625)\"><defs><path id=\"DejaVuSans-Oblique-71\" transform=\"scale(.015625)\" d=\"m2669 525q-231-303-546-460-314-156-695-156-531 0-833 358-301 358-301 986 0 506 186 978t533 847q225 244 517 375t614 131q387 0 637-153t363-462l100 525h578l-934-4813h-579l360 1844zm-1778 813q0-463 193-705 194-242 560-242 544 0 928 520t384 1264q0 450-199 689-198 239-569 239-272 0-504-127-231-126-403-370-181-256-286-600-104-343-104-668z\"/><path id=\"DejaVuSans-30\" transform=\"scale(.015625)\" d=\"m2034 4250q-487 0-733-480-245-479-245-1442 0-959 245-1439 246-480 733-480 491 0 736 480 246 480 246 1439 0 963-246 1442-245 480-736 480zm0 500q785 0 1199-621 414-620 414-1801 0-1178-414-1799-414-620-1199-620-784 0-1198 620-414 621-414 1799 0 1181 414 1801 414 621 1198 621z\"/></defs><use xlink:href=\"#DejaVuSans-Oblique-71\"/><use transform=\"translate(63.477 -16.406) scale(.7)\" xlink:href=\"#DejaVuSans-30\"/></g></g><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(37.301 95.088) scale(.1625 -.1625)\"><defs><path id=\"DejaVuSans-31\" transform=\"scale(.015625)\" d=\"m794 531h1031v3560l-1122-225v575l1116 225h631v-4135h1031v-531h-2687v531z\"/></defs><use xlink:href=\"#DejaVuSans-Oblique-71\"/><use transform=\"translate(63.477 -16.406) scale(.7)\" xlink:href=\"#DejaVuSans-31\"/></g></g><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(37.301 141.44) scale(.1625 -.1625)\"><defs><path id=\"DejaVuSans-32\" transform=\"scale(.015625)\" d=\"m1228 531h2203v-531h-2962v531q359 372 979 998 621 627 780 809 303 340 423 576 121 236 121 464 0 372-261 606-261 235-680 235-297 0-627-103-329-103-704-313v638q381 153 712 231 332 78 607 78 725 0 1156-363 431-362 431-968 0-288-108-546-107-257-392-607-78-91-497-524-418-433-1181-1211z\"/></defs><use xlink:href=\"#DejaVuSans-Oblique-71\"/><use transform=\"translate(63.477 -16.406) scale(.7)\" xlink:href=\"#DejaVuSans-32\"/></g></g><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(37.301 187.8) scale(.1625 -.1625)\"><defs><path id=\"DejaVuSans-33\" transform=\"scale(.015625)\" d=\"m2597 2516q453-97 707-404 255-306 255-756 0-690-475-1069-475-378-1350-378-293 0-604 58t-642 174v609q262-153 574-231 313-78 654-78 593 0 904 234t311 681q0 413-289 645-289 233-804 233h-544v519h569q465 0 712 186t247 536q0 359-255 551-254 193-729 193-260 0-557-57-297-56-653-174v562q360 100 674 150t592 50q719 0 1137-327 419-326 419-882 0-388-222-655t-631-370z\"/></defs><use xlink:href=\"#DejaVuSans-Oblique-71\"/><use transform=\"translate(63.477 -16.406) scale(.7)\" xlink:href=\"#DejaVuSans-33\"/></g></g><g clip-path=\"url(#16ae6c5277f)\"><g transform=\"translate(84.752 47.87) scale(.13 -.13)\"><defs><path id=\"DejaVuSans-48\" transform=\"scale(.015625)\" d=\"m628 4666h631v-1913h2294v1913h631v-4666h-631v2222h-2294v-2222h-631v4666z\"/></defs><use xlink:href=\"#DejaVuSans-48\"/></g></g><defs><clipPath id=\"16ae6c5277f\"><rect x=\"7.2\" y=\"7.2\" width=\"159.39\" height=\"203.96\"/></clipPath></defs></svg>"
],
"text/plain": [
"<Figure size 287.496x367.889 with 1 Axes>"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from qiskit import QuantumCircuit\n",
"from qiskit.circuit.library import HGate, MCXGate\n",
"mcx_gate = MCXGate(3)\n",
"hadamard_gate = HGate()\n",
"\n",
"qc = QuantumCircuit(4)\n",
"qc.append(hadamard_gate, [0])\n",
"qc.append(mcx_gate, [0,1,2,3])\n",
"qc.draw('mpl')"
]
},
{
"cell_type": "markdown",
"id": "d6c33a70",
"metadata": {},
"source": [
"See [Standard gates](/api/qiskit/circuit_library#standard-gates) in the circuit library API documentation."
]
},
{
"cell_type": "markdown",
"id": "9a900a84-c52f-4a03-b3e9-87c71fa93e88",
Expand Down

0 comments on commit ebdb6c9

Please sign in to comment.