From cad1c031891bc68b0118faaa44ba2bd2bebb9ba7 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Mon, 4 Dec 2023 17:06:21 -0500 Subject: [PATCH 01/22] Create config.yml --- .github/ISSUE_TEMPLATE/config.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/config.yml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000000..2e27c8ede63e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: + - name: Non-API docs issues + url: https://github.com/Qiskit/documentation/issues/new/choose + about: Open a documentation issue about pages that do not have /api/ in the url (e.g., docs in the Build, Run, Transpile etc. sections) \ No newline at end of file From 185ee782ac81183a1a999bca8360303541bcdf17 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Mon, 4 Dec 2023 17:11:03 -0500 Subject: [PATCH 02/22] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e50d61f73c76..29bdd4b4ccdf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -148,6 +148,8 @@ the code. It also lets the community know what you're working on, and if you need help, you can reference the issue when discussing it with other community and team members. +Please note that the repo for any docs page that does not have `/api/` in its url is [https://github.com/Qiskit/documentation](https://github.com/Qiskit/documentation) and you can open an issue [here](https://github.com/Qiskit/documentation/issues/new/choose) for any non-API docs fixes or suggestions. + If you've written some code but need help finishing it, want to get initial feedback on it prior to finishing it, or want to share it and discuss prior to finishing the implementation, you can open a *Draft* pull request and prepend From 2a8978bc5f8d5477ef9a26c0fb8be7fec430c2e1 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Tue, 5 Dec 2023 14:29:01 -0500 Subject: [PATCH 03/22] Update contributing.md --- .github/ISSUE_TEMPLATE/config.yml | 2 +- CONTRIBUTING.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 2e27c8ede63e..7af0b931c9de 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,4 +2,4 @@ blank_issues_enabled: true contact_links: - name: Non-API docs issues url: https://github.com/Qiskit/documentation/issues/new/choose - about: Open a documentation issue about pages that do not have /api/ in the url (e.g., docs in the Build, Run, Transpile etc. sections) \ No newline at end of file + about: Open an issue about documentation in the Start, Build, Transpile, Verify, Run, or Migration guides sections (non-API documentation) \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 29bdd4b4ccdf..1bebc05eca2c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -148,7 +148,8 @@ the code. It also lets the community know what you're working on, and if you need help, you can reference the issue when discussing it with other community and team members. -Please note that the repo for any docs page that does not have `/api/` in its url is [https://github.com/Qiskit/documentation](https://github.com/Qiskit/documentation) and you can open an issue [here](https://github.com/Qiskit/documentation/issues/new/choose) for any non-API docs fixes or suggestions. +* For documentation issues relating to pages in the Start, Build, Transpile, Verify, Run, and Migration guides sections, please open an issue in the [Qiskit/documentation repo](https://github.com/Qiskit/documentation/issues/new/choose) rather than the Qiskit/qiskit repo. In other words, any page that DOES NOT have `/api/` in the url should be addressed in the Qiskit/documentation repo. (Exception: the Migration guide urls contain `/api/` but are managed in the Qiskit/documentation repo.) +* For issues relating to API reference pages (any page that contains /api/ in the url), please open an issue in the repo specific to that API reference. If you've written some code but need help finishing it, want to get initial feedback on it prior to finishing it, or want to share it and discuss prior From a61f9cfe97a6860dd3b16f42a595c17bfadfc934 Mon Sep 17 00:00:00 2001 From: abbycross Date: Wed, 6 Dec 2023 11:58:47 -0500 Subject: [PATCH 04/22] Update .github/ISSUE_TEMPLATE/config.yml Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 7af0b931c9de..f94ee26f4498 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,4 +2,4 @@ blank_issues_enabled: true contact_links: - name: Non-API docs issues url: https://github.com/Qiskit/documentation/issues/new/choose - about: Open an issue about documentation in the Start, Build, Transpile, Verify, Run, or Migration guides sections (non-API documentation) \ No newline at end of file + about: Open an issue about documentation in the Start, Build, Transpile, Verify, Run, or Migration guides sections of docs.quantum.ibm.com (non-API documentation) \ No newline at end of file From 17574333fe15bb3ac481f89ad60960a3b502ad23 Mon Sep 17 00:00:00 2001 From: abbycross Date: Wed, 6 Dec 2023 11:58:53 -0500 Subject: [PATCH 05/22] Update CONTRIBUTING.md Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1bebc05eca2c..52a7179b99d0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -148,7 +148,7 @@ the code. It also lets the community know what you're working on, and if you need help, you can reference the issue when discussing it with other community and team members. -* For documentation issues relating to pages in the Start, Build, Transpile, Verify, Run, and Migration guides sections, please open an issue in the [Qiskit/documentation repo](https://github.com/Qiskit/documentation/issues/new/choose) rather than the Qiskit/qiskit repo. In other words, any page that DOES NOT have `/api/` in the url should be addressed in the Qiskit/documentation repo. (Exception: the Migration guide urls contain `/api/` but are managed in the Qiskit/documentation repo.) +* For documentation issues relating to pages in the Start, Build, Transpile, Verify, Run, and Migration guides sections of docs.quantum.ibm.com, please open an issue in the [Qiskit/documentation repo](https://github.com/Qiskit/documentation/issues/new/choose) rather than the Qiskit/qiskit repo. In other words, any page that DOES NOT have `/api/` in the url should be addressed in the Qiskit/documentation repo. (Exception: the Migration guide urls contain `/api/` but are managed in the Qiskit/documentation repo.) * For issues relating to API reference pages (any page that contains /api/ in the url), please open an issue in the repo specific to that API reference. If you've written some code but need help finishing it, want to get initial From 22899e63e2662fa1be11a8c05af0174f32ea1dc2 Mon Sep 17 00:00:00 2001 From: abbycross Date: Thu, 7 Dec 2023 10:59:11 -0500 Subject: [PATCH 06/22] code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 52a7179b99d0..39a8e20b2b04 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -148,7 +148,7 @@ the code. It also lets the community know what you're working on, and if you need help, you can reference the issue when discussing it with other community and team members. -* For documentation issues relating to pages in the Start, Build, Transpile, Verify, Run, and Migration guides sections of docs.quantum.ibm.com, please open an issue in the [Qiskit/documentation repo](https://github.com/Qiskit/documentation/issues/new/choose) rather than the Qiskit/qiskit repo. In other words, any page that DOES NOT have `/api/` in the url should be addressed in the Qiskit/documentation repo. (Exception: the Migration guide urls contain `/api/` but are managed in the Qiskit/documentation repo.) +* For documentation issues relating to pages in the Start, Build, Transpile, Verify, Run, and Migration guides sections of [docs.quantum.ibm.com](https://docs.quantum.ibm.com/), please open an issue in the [Qiskit/documentation repo](https://github.com/Qiskit/documentation/issues/new/choose) rather than the Qiskit/qiskit repo. In other words, any page that DOES NOT have `/api/` in the url should be addressed in the Qiskit/documentation repo. (Exception: the Migration guide urls contain `/api/` but are managed in the Qiskit/documentation repo.) * For issues relating to API reference pages (any page that contains /api/ in the url), please open an issue in the repo specific to that API reference. If you've written some code but need help finishing it, want to get initial From 538aebb1e8c0cf0c64e8139004eb9a284219e133 Mon Sep 17 00:00:00 2001 From: abbycross Date: Thu, 7 Dec 2023 10:59:38 -0500 Subject: [PATCH 07/22] code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 39a8e20b2b04..a82a1890cc1b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -149,7 +149,7 @@ need help, you can reference the issue when discussing it with other community and team members. * For documentation issues relating to pages in the Start, Build, Transpile, Verify, Run, and Migration guides sections of [docs.quantum.ibm.com](https://docs.quantum.ibm.com/), please open an issue in the [Qiskit/documentation repo](https://github.com/Qiskit/documentation/issues/new/choose) rather than the Qiskit/qiskit repo. In other words, any page that DOES NOT have `/api/` in the url should be addressed in the Qiskit/documentation repo. (Exception: the Migration guide urls contain `/api/` but are managed in the Qiskit/documentation repo.) -* For issues relating to API reference pages (any page that contains /api/ in the url), please open an issue in the repo specific to that API reference. +* For issues relating to API reference pages (any page that contains /api/ in the url), please open an issue in the repo specific to that API reference, for example [Qiskit/qiskit](https://github.com/Qiskit/qiskit/issues/new/choose), [Qiskit/qiskit-aer](https://github.com/Qiskit/qiskit-aer/issues/new/choose) or [Qiskit/qiskit-ibm-runtime](https://github.com/Qiskit/qiskit-ibm-runtime/issues/new/choose). If you've written some code but need help finishing it, want to get initial feedback on it prior to finishing it, or want to share it and discuss prior From 1800b91ee5ac77be9c880414f381758efb3d42c9 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Thu, 7 Dec 2023 11:02:23 -0500 Subject: [PATCH 08/22] add migration guide link, add "issues" to header --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a82a1890cc1b..969199d78cab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -135,7 +135,7 @@ dependency packages installed in your environment, which are listed in the `pyproject.toml` file under the `[build-system]` section. -## Pull requests +## Issues and pull requests We use [GitHub pull requests](https://help.github.com/articles/about-pull-requests) to accept contributions. @@ -148,8 +148,8 @@ the code. It also lets the community know what you're working on, and if you need help, you can reference the issue when discussing it with other community and team members. -* For documentation issues relating to pages in the Start, Build, Transpile, Verify, Run, and Migration guides sections of [docs.quantum.ibm.com](https://docs.quantum.ibm.com/), please open an issue in the [Qiskit/documentation repo](https://github.com/Qiskit/documentation/issues/new/choose) rather than the Qiskit/qiskit repo. In other words, any page that DOES NOT have `/api/` in the url should be addressed in the Qiskit/documentation repo. (Exception: the Migration guide urls contain `/api/` but are managed in the Qiskit/documentation repo.) -* For issues relating to API reference pages (any page that contains /api/ in the url), please open an issue in the repo specific to that API reference, for example [Qiskit/qiskit](https://github.com/Qiskit/qiskit/issues/new/choose), [Qiskit/qiskit-aer](https://github.com/Qiskit/qiskit-aer/issues/new/choose) or [Qiskit/qiskit-ibm-runtime](https://github.com/Qiskit/qiskit-ibm-runtime/issues/new/choose). +* For documentation issues relating to pages in the Start, Build, Transpile, Verify, Run, and Migration guides sections of [docs.quantum.ibm.com](https://docs.quantum.ibm.com/), please open an issue in the [Qiskit/documentation repo](https://github.com/Qiskit/documentation/issues/new/choose) rather than the Qiskit/qiskit repo. In other words, any page that DOES NOT have `/api/` in the url should be addressed in the Qiskit/documentation repo. (Exception: the [Migration guide](https://docs.quantum.ibm.com/api/migration-guides) urls contain `/api/` but are managed in the Qiskit/documentation repo.) +* For issues relating to API reference pages (any page that contains /api/ in the url), please open an issue in the repo specific to that API reference, for example [Qiskit/qiskit](https://github.com/Qiskit/qiskit/issues/new/choose), [Qiskit/qiskit-aer](https://github.com/Qiskit/qiskit-aer/issues/new/choose), or [Qiskit/qiskit-ibm-runtime](https://github.com/Qiskit/qiskit-ibm-runtime/issues/new/choose). If you've written some code but need help finishing it, want to get initial feedback on it prior to finishing it, or want to share it and discuss prior From d6bd6bf2db26dc85781d3f3f86a6df5c25e3563a Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Thu, 7 Dec 2023 12:24:56 -0500 Subject: [PATCH 09/22] add to toc at top, update anchor tag --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 969199d78cab..7b3057f4522b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ community in this goal. * [Choose an issue to work on](#Choose-an-issue-to-work-on) * [Set up Python virtual development environment](#set-up-python-virtual-development-environment) * [Installing Qiskit from source](#installing-qiskit-from-source) -* [Pull requests](#pull-requests) +* [Issues and pull requests](#issues-and-pull-requests) * [Contributor Licensing Agreement](#contributor-licensing-agreement) * [Changelog generation](#changelog-generation) * [Release notes](#release-notes) From e6d068eea86d2b254a46223059c1cf29c9b689d9 Mon Sep 17 00:00:00 2001 From: abbycross Date: Thu, 7 Dec 2023 13:59:58 -0500 Subject: [PATCH 10/22] Update CONTRIBUTING.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7b3057f4522b..84259495d8d8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -149,7 +149,7 @@ need help, you can reference the issue when discussing it with other community and team members. * For documentation issues relating to pages in the Start, Build, Transpile, Verify, Run, and Migration guides sections of [docs.quantum.ibm.com](https://docs.quantum.ibm.com/), please open an issue in the [Qiskit/documentation repo](https://github.com/Qiskit/documentation/issues/new/choose) rather than the Qiskit/qiskit repo. In other words, any page that DOES NOT have `/api/` in the url should be addressed in the Qiskit/documentation repo. (Exception: the [Migration guide](https://docs.quantum.ibm.com/api/migration-guides) urls contain `/api/` but are managed in the Qiskit/documentation repo.) -* For issues relating to API reference pages (any page that contains /api/ in the url), please open an issue in the repo specific to that API reference, for example [Qiskit/qiskit](https://github.com/Qiskit/qiskit/issues/new/choose), [Qiskit/qiskit-aer](https://github.com/Qiskit/qiskit-aer/issues/new/choose), or [Qiskit/qiskit-ibm-runtime](https://github.com/Qiskit/qiskit-ibm-runtime/issues/new/choose). +* For issues relating to API reference pages (any page that contains `/api/` in the url), please open an issue in the repo specific to that API reference, for example [Qiskit/qiskit](https://github.com/Qiskit/qiskit/issues/new/choose), [Qiskit/qiskit-aer](https://github.com/Qiskit/qiskit-aer/issues/new/choose), or [Qiskit/qiskit-ibm-runtime](https://github.com/Qiskit/qiskit-ibm-runtime/issues/new/choose). If you've written some code but need help finishing it, want to get initial feedback on it prior to finishing it, or want to share it and discuss prior From a0fe84d279b0fd0a17dd0872474cd15f624c1147 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Tue, 8 Oct 2024 17:10:38 -0400 Subject: [PATCH 11/22] Add code example to class description --- qiskit/circuit/quantumcircuit.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 0a151a8476e3..5dd0d4ea0d8e 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -124,6 +124,34 @@ class QuantumCircuit: structures that go with it, how it fits into the rest of the :mod:`qiskit` package, and the different regimes of quantum-circuit descriptions in Qiskit, see the module-level documentation of :mod:`qiskit.circuit`. + + Example: + + .. plot:: + :include-source: + :nofigs: + + from qiskit import QuantumCircuit + + # Create a new circuit with two qubits + qc = QuantumCircuit(2) + + # Add a Hadamard gate to qubit 0 + qc.h(0) + + # Perform a controlled-X gate on qubit 1, controlled by qubit 0 + qc.cx(0, 1) + + # Return a text drawing of the circuit. + qc.draw() + + .. code-block:: text + + ┌───┐ + q_0: ┤ H ├──■── + └───┘┌─┴─┐ + q_1: ─────┤ X ├ + └───┘ Circuit attributes ================== From a94a0991ab9701aaea0244318b3f680cd14fddcf Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Fri, 18 Oct 2024 12:02:49 -0400 Subject: [PATCH 12/22] add data example --- qiskit/circuit/quantumcircuit.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 5dd0d4ea0d8e..38a3e36c030c 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -214,6 +214,22 @@ class QuantumCircuit: .. autoattribute:: data + Example: + + .. plot:: + :include-source: + :nofigs: + + from qiskit import QuantumCircuit + + qc = QuantumCircuit(2, 2) + qc.measure([0], [1]) + print(qc.data) + + .. code-block:: text + + [CircuitInstruction(operation=Instruction(name='measure', num_qubits=1, num_clbits=1, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),), clbits=(Clbit(ClassicalRegister(2, 'c'), 1),))] + Alongside the :attr:`data`, the :attr:`global_phase` of a circuit can have some impact on its output, if the circuit is used to describe a :class:`.Gate` that may be controlled. This is measured in radians and is directly settable. From 9b8b3fb42648790f6baab4381f3fb4018d04d62d Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Fri, 18 Oct 2024 13:51:32 -0400 Subject: [PATCH 13/22] first attempt to add global_phase examples --- qiskit/circuit/quantumcircuit.py | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 38a3e36c030c..f54f7d9d388c 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -236,6 +236,47 @@ class QuantumCircuit: .. autoattribute:: global_phase + Example: + + .. plot:: + :include-source: + :nofigs: + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + qreg_q = QuantumRegister(2, 'q') + creg_c = ClassicalRegister(2, 'c') + circuit = QuantumCircuit(qreg_q, creg_c) + + circuit.reset(qreg_q[0]) + circuit.h(qreg_q[0]) + circuit.reset(qreg_q[1]) + circuit.cx(qreg_q[0], qreg_q[1]) + + print(circuit.global_phase) # find the global phase of the current circuit + + .. code-block:: text + + 0.0 + + .. plot:: + :include-source: + :nofigs: + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + qreg_q = QuantumRegister(2, 'q') + creg_c = ClassicalRegister(2, 'c') + circuit = QuantumCircuit(qreg_q, creg_c) + from numpy import pi + + circuit.global_phase = pi/4 # set the global phase of the circuit to pi/4 + print(circuit.global_phase) + + .. code-block:: text + + 0.7853981633974483 + The :attr:`name` of a circuit becomes the name of the :class:`~.circuit.Instruction` or :class:`.Gate` resulting from :meth:`to_instruction` and :meth:`to_gate` calls, which can be handy for visualizations. From 0f110c08762e2221a55d9b1ad7330eea9b2242bd Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Mon, 21 Oct 2024 14:53:57 -0400 Subject: [PATCH 14/22] add :context: --- qiskit/circuit/quantumcircuit.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index f54f7d9d388c..155bc8c84395 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -241,6 +241,7 @@ class QuantumCircuit: .. plot:: :include-source: :nofigs: + :context: reset from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit @@ -248,9 +249,7 @@ class QuantumCircuit: creg_c = ClassicalRegister(2, 'c') circuit = QuantumCircuit(qreg_q, creg_c) - circuit.reset(qreg_q[0]) circuit.h(qreg_q[0]) - circuit.reset(qreg_q[1]) circuit.cx(qreg_q[0], qreg_q[1]) print(circuit.global_phase) # find the global phase of the current circuit @@ -262,12 +261,8 @@ class QuantumCircuit: .. plot:: :include-source: :nofigs: + :context: - from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit - - qreg_q = QuantumRegister(2, 'q') - creg_c = ClassicalRegister(2, 'c') - circuit = QuantumCircuit(qreg_q, creg_c) from numpy import pi circuit.global_phase = pi/4 # set the global phase of the circuit to pi/4 From e0dedbfaef3afef21405d1b22a7b034b3c5937c7 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Tue, 22 Oct 2024 09:37:20 -0400 Subject: [PATCH 15/22] tox -e black --- qiskit/circuit/quantumcircuit.py | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index f93c63c078bb..406d239a1d5d 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -124,30 +124,30 @@ class QuantumCircuit: structures that go with it, how it fits into the rest of the :mod:`qiskit` package, and the different regimes of quantum-circuit descriptions in Qiskit, see the module-level documentation of :mod:`qiskit.circuit`. - + Example: - + .. plot:: :include-source: :nofigs: - + from qiskit import QuantumCircuit - + # Create a new circuit with two qubits qc = QuantumCircuit(2) - + # Add a Hadamard gate to qubit 0 qc.h(0) - + # Perform a controlled-X gate on qubit 1, controlled by qubit 0 qc.cx(0, 1) - + # Return a text drawing of the circuit. qc.draw() - + .. code-block:: text - ┌───┐ + ┌───┐ q_0: ┤ H ├──■── └───┘┌─┴─┐ q_1: ─────┤ X ├ @@ -215,11 +215,11 @@ class QuantumCircuit: .. autoattribute:: data Example: - + .. plot:: :include-source: :nofigs: - + from qiskit import QuantumCircuit qc = QuantumCircuit(2, 2) @@ -237,12 +237,12 @@ class QuantumCircuit: .. autoattribute:: global_phase Example: - + .. plot:: :include-source: :nofigs: :context: reset - + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit qreg_q = QuantumRegister(2, 'q') @@ -251,25 +251,25 @@ class QuantumCircuit: circuit.h(qreg_q[0]) circuit.cx(qreg_q[0], qreg_q[1]) - + print(circuit.global_phase) # find the global phase of the current circuit - + .. code-block:: text - + 0.0 - + .. plot:: :include-source: :nofigs: :context: - + from numpy import pi - + circuit.global_phase = pi/4 # set the global phase of the circuit to pi/4 print(circuit.global_phase) - + .. code-block:: text - + 0.7853981633974483 The :attr:`name` of a circuit becomes the name of the :class:`~.circuit.Instruction` or From b533bc53f37004d5d1c496b275b060d5dcb5ddc4 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Tue, 22 Oct 2024 10:10:52 -0400 Subject: [PATCH 16/22] shorten line --- qiskit/circuit/quantumcircuit.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 406d239a1d5d..ad93541a791c 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -228,7 +228,9 @@ class QuantumCircuit: .. code-block:: text - [CircuitInstruction(operation=Instruction(name='measure', num_qubits=1, num_clbits=1, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),), clbits=(Clbit(ClassicalRegister(2, 'c'), 1),))] + [CircuitInstruction(operation=Instruction(name='measure', num_qubits=1, + num_clbits=1, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),), + clbits=(Clbit(ClassicalRegister(2, 'c'), 1),))] Alongside the :attr:`data`, the :attr:`global_phase` of a circuit can have some impact on its output, if the circuit is used to describe a :class:`.Gate` that may be controlled. This is From 05df475df62bad64e4e3c6b2ea7592ad903b5fc9 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Wed, 23 Oct 2024 16:33:35 -0400 Subject: [PATCH 17/22] example for name attr --- qiskit/circuit/quantumcircuit.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index ad93541a791c..53fed285981d 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -280,6 +280,31 @@ class QuantumCircuit: .. autoattribute:: name + Example: + + .. plot:: + :include-source: + :nofigs: + :context: reset + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + qr = QuantumRegister(2) + cr = ClassicalRegister(2) + qc = QuantumCircuit(qr, cr) + + qc.h(qr[0]) + qc.cx(qr[0], qr[1]) + qc.measure(qr, cr) + qc.name = "my_circuit" + + print(qc.name) + + .. code-block:: text + + my_circuit + + You can attach arbitrary :attr:`metadata` to a circuit. No part of core Qiskit will inspect this or change its behavior based on metadata, but it will be faithfully passed through the transpiler, so you can tag your circuits yourself. When serializing a circuit with QPY (see From f7409b05dad696823485e5f82f1a0655081f0aae Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Wed, 23 Oct 2024 17:05:11 -0400 Subject: [PATCH 18/22] example of metadata attr --- qiskit/circuit/quantumcircuit.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 53fed285981d..89ddcd90d2ed 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -304,7 +304,6 @@ class QuantumCircuit: my_circuit - You can attach arbitrary :attr:`metadata` to a circuit. No part of core Qiskit will inspect this or change its behavior based on metadata, but it will be faithfully passed through the transpiler, so you can tag your circuits yourself. When serializing a circuit with QPY (see @@ -314,6 +313,26 @@ class QuantumCircuit: .. autoattribute:: metadata + Example: + + .. plot:: + :include-source: + :nofigs: + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + q = QuantumRegister(2) + c = ClassicalRegister(2) + qc = QuantumCircuit(q, c) + + qc.metadata = {'experiment_type': 'Bell state experiment'} + + print(qc.metadata) + + .. code-block:: text + + {'experiment_type': 'Bell state experiment'} + :class:`QuantumCircuit` exposes data attributes tracking its internal quantum and classical bits and registers. These appear as Python :class:`list`\\ s, but you should treat them as immutable; changing them will *at best* have no effect, and more likely will simply corrupt From ffc2d4e224cbdcd6942eb37219d0d0dcfc7cffaa Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Thu, 24 Oct 2024 11:31:15 -0400 Subject: [PATCH 19/22] clarify it's a dictionary, copyedit --- qiskit/circuit/quantumcircuit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 89ddcd90d2ed..f5924d4e3ba9 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -1274,7 +1274,7 @@ def __init__( self._duration = None self._unit = "dt" self.metadata = {} if metadata is None else metadata - """Arbitrary user-defined metadata for the circuit. + """Arbitrary user-defined dictionary of metadata for the circuit. Qiskit will not examine the content of this mapping, but it will pass it through the transpiler and reattach it to the output, so you can track your own metadata.""" @@ -1506,12 +1506,12 @@ def has_calibration_for(self, instruction: CircuitInstruction | tuple): @property def metadata(self) -> dict: - """The user provided metadata associated with the circuit. + """The user-provided metadata associated with the circuit. - The metadata for the circuit is a user provided ``dict`` of metadata + The metadata for the circuit is a user-provided ``dict`` of metadata for the circuit. It will not be used to influence the execution or operation of the circuit, but it is expected to be passed between - all transforms of the circuit (ie transpilation) and that providers will + all transforms of the circuit (i.e., transpilation) and that providers will associate any circuit metadata with the results it returns from execution of that circuit. """ From 31bb0d6046a4a8d4655a012c24bab670b6075392 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Thu, 24 Oct 2024 15:28:36 -0400 Subject: [PATCH 20/22] ex. for qregs cregs qubits ancilla clbits --- qiskit/circuit/quantumcircuit.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index f5924d4e3ba9..3eeabb9a04f4 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -344,6 +344,41 @@ class QuantumCircuit: .. autoattribute:: ancillas .. autoattribute:: clbits + Example: + + .. plot:: + :include-source: + :nofigs: + :context: reset + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + qr1 = QuantumRegister(2) + qr2 = QuantumRegister(1) + cr1 = ClassicalRegister(2) + cr2 = ClassicalRegister(1) + qc = QuantumCircuit(qr1, qr2, cr1, cr2) + + print("List the quantum registers:", qc.qregs) + print("List the classical registers:", qc.cregs) + print("List the qubits in this circuit:", qc.qubits) + print("List the ancilla qubits:", qc.ancillas) + print("List the classical bits in this circuit:", qc.clbits) + + .. code-block:: text + + List the quantum registers: [QuantumRegister(2, 'q0'), + QuantumRegister(1, 'q1')] + List the classical registers: [ClassicalRegister(2, 'c0'), + ClassicalRegister(1, 'c1')] + List the qubits in this circuit: [Qubit(QuantumRegister(2, + 'q0'), 0), Qubit(QuantumRegister(2, 'q0'), 1), Qubit + (QuantumRegister(1, 'q1'), 0)] + List the ancilla qubits: [] + List the classical bits in this circuit: [Clbit + (ClassicalRegister(2, 'c0'), 0), Clbit(ClassicalRegister(2, + 'c0'), 1), Clbit(ClassicalRegister(1, 'c1'), 0)] + The :ref:`compile-time parameters ` present in instructions on the circuit are available in :attr:`parameters`. This has a canonical order (mostly lexical, except in the case of :class:`.ParameterVector`), which matches the order that parameters will From d49d26b3a745ca13adcb4f99e6142d8bdd8aa4ca Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Thu, 24 Oct 2024 15:29:04 -0400 Subject: [PATCH 21/22] tox -e black fix --- qiskit/circuit/quantumcircuit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 3eeabb9a04f4..6e475c9fa768 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -367,16 +367,16 @@ class QuantumCircuit: .. code-block:: text - List the quantum registers: [QuantumRegister(2, 'q0'), + List the quantum registers: [QuantumRegister(2, 'q0'), QuantumRegister(1, 'q1')] - List the classical registers: [ClassicalRegister(2, 'c0'), + List the classical registers: [ClassicalRegister(2, 'c0'), ClassicalRegister(1, 'c1')] - List the qubits in this circuit: [Qubit(QuantumRegister(2, + List the qubits in this circuit: [Qubit(QuantumRegister(2, 'q0'), 0), Qubit(QuantumRegister(2, 'q0'), 1), Qubit (QuantumRegister(1, 'q1'), 0)] List the ancilla qubits: [] List the classical bits in this circuit: [Clbit - (ClassicalRegister(2, 'c0'), 0), Clbit(ClassicalRegister(2, + (ClassicalRegister(2, 'c0'), 0), Clbit(ClassicalRegister(2, 'c0'), 1), Clbit(ClassicalRegister(1, 'c1'), 0)] The :ref:`compile-time parameters ` present in instructions on From 6c0f207193cb32b04e214767e36759ea80058560 Mon Sep 17 00:00:00 2001 From: ABBY CROSS Date: Mon, 18 Nov 2024 15:12:19 -0500 Subject: [PATCH 22/22] relocate code examples --- qiskit/circuit/quantumcircuit.py | 305 +++++++++++++++++-------------- 1 file changed, 165 insertions(+), 140 deletions(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index b637b5e4bb3a..7dfc2a723cb2 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -216,96 +216,18 @@ class QuantumCircuit: .. autoattribute:: data - Example: - - .. plot:: - :include-source: - :nofigs: - - from qiskit import QuantumCircuit - - qc = QuantumCircuit(2, 2) - qc.measure([0], [1]) - print(qc.data) - - .. code-block:: text - - [CircuitInstruction(operation=Instruction(name='measure', num_qubits=1, - num_clbits=1, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),), - clbits=(Clbit(ClassicalRegister(2, 'c'), 1),))] - Alongside the :attr:`data`, the :attr:`global_phase` of a circuit can have some impact on its output, if the circuit is used to describe a :class:`.Gate` that may be controlled. This is measured in radians and is directly settable. .. autoattribute:: global_phase - Example: - - .. plot:: - :include-source: - :nofigs: - :context: reset - - from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit - - qreg_q = QuantumRegister(2, 'q') - creg_c = ClassicalRegister(2, 'c') - circuit = QuantumCircuit(qreg_q, creg_c) - - circuit.h(qreg_q[0]) - circuit.cx(qreg_q[0], qreg_q[1]) - - print(circuit.global_phase) # find the global phase of the current circuit - - .. code-block:: text - - 0.0 - - .. plot:: - :include-source: - :nofigs: - :context: - - from numpy import pi - - circuit.global_phase = pi/4 # set the global phase of the circuit to pi/4 - print(circuit.global_phase) - - .. code-block:: text - - 0.7853981633974483 - The :attr:`name` of a circuit becomes the name of the :class:`~.circuit.Instruction` or :class:`.Gate` resulting from :meth:`to_instruction` and :meth:`to_gate` calls, which can be handy for visualizations. .. autoattribute:: name - Example: - - .. plot:: - :include-source: - :nofigs: - :context: reset - - from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit - - qr = QuantumRegister(2) - cr = ClassicalRegister(2) - qc = QuantumCircuit(qr, cr) - - qc.h(qr[0]) - qc.cx(qr[0], qr[1]) - qc.measure(qr, cr) - qc.name = "my_circuit" - - print(qc.name) - - .. code-block:: text - - my_circuit - You can attach arbitrary :attr:`metadata` to a circuit. No part of core Qiskit will inspect this or change its behavior based on metadata, but it will be faithfully passed through the transpiler, so you can tag your circuits yourself. When serializing a circuit with QPY (see @@ -315,26 +237,6 @@ class QuantumCircuit: .. autoattribute:: metadata - Example: - - .. plot:: - :include-source: - :nofigs: - - from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit - - q = QuantumRegister(2) - c = ClassicalRegister(2) - qc = QuantumCircuit(q, c) - - qc.metadata = {'experiment_type': 'Bell state experiment'} - - print(qc.metadata) - - .. code-block:: text - - {'experiment_type': 'Bell state experiment'} - :class:`QuantumCircuit` exposes data attributes tracking its internal quantum and classical bits and registers. These appear as Python :class:`list`\\ s, but you should treat them as immutable; changing them will *at best* have no effect, and more likely will simply corrupt @@ -346,41 +248,6 @@ class QuantumCircuit: .. autoattribute:: ancillas .. autoattribute:: clbits - Example: - - .. plot:: - :include-source: - :nofigs: - :context: reset - - from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit - - qr1 = QuantumRegister(2) - qr2 = QuantumRegister(1) - cr1 = ClassicalRegister(2) - cr2 = ClassicalRegister(1) - qc = QuantumCircuit(qr1, qr2, cr1, cr2) - - print("List the quantum registers:", qc.qregs) - print("List the classical registers:", qc.cregs) - print("List the qubits in this circuit:", qc.qubits) - print("List the ancilla qubits:", qc.ancillas) - print("List the classical bits in this circuit:", qc.clbits) - - .. code-block:: text - - List the quantum registers: [QuantumRegister(2, 'q0'), - QuantumRegister(1, 'q1')] - List the classical registers: [ClassicalRegister(2, 'c0'), - ClassicalRegister(1, 'c1')] - List the qubits in this circuit: [Qubit(QuantumRegister(2, - 'q0'), 0), Qubit(QuantumRegister(2, 'q0'), 1), Qubit - (QuantumRegister(1, 'q1'), 0)] - List the ancilla qubits: [] - List the classical bits in this circuit: [Clbit - (ClassicalRegister(2, 'c0'), 0), Clbit(ClassicalRegister(2, - 'c0'), 1), Clbit(ClassicalRegister(1, 'c1'), 0)] - The :ref:`compile-time parameters ` present in instructions on the circuit are available in :attr:`parameters`. This has a canonical order (mostly lexical, except in the case of :class:`.ParameterVector`), which matches the order that parameters will @@ -1240,7 +1107,32 @@ def __init__( regs = tuple(int(reg) for reg in regs) # cast to int self._base_name = None self.name: str - """A human-readable name for the circuit.""" + """A human-readable name for the circuit. + + Example: + + .. plot:: + :include-source: + :nofigs: + :context: reset + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + qr = QuantumRegister(2) + cr = ClassicalRegister(2) + qc = QuantumCircuit(qr, cr) + + qc.h(qr[0]) + qc.cx(qr[0], qr[1]) + qc.measure(qr, cr) + qc.name = "my_circuit" + + print(qc.name) + + .. code-block:: text + + my_circuit + """ if name is None: self._base_name = self._cls_prefix() self._name_update() @@ -1314,7 +1206,28 @@ def __init__( """Arbitrary user-defined dictionary of metadata for the circuit. Qiskit will not examine the content of this mapping, but it will pass it through the - transpiler and reattach it to the output, so you can track your own metadata.""" + transpiler and reattach it to the output, so you can track your own metadata. + + Example: + + .. plot:: + :include-source: + :nofigs: + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + q = QuantumRegister(2) + c = ClassicalRegister(2) + qc = QuantumCircuit(q, c) + + qc.metadata = {'experiment_type': 'Bell state experiment'} + + print(qc.metadata) + + .. code-block:: text + + {'experiment_type': 'Bell state experiment'} + """ @property @deprecate_func(since="1.3.0", removal_timeline="in Qiskit 2.0.0", is_property=True) @@ -1446,9 +1359,27 @@ def layout(self) -> Optional[TranspileLayout]: def data(self) -> QuantumCircuitData: """The circuit data (instructions and context). - Returns: - QuantumCircuitData: a list-like object containing the :class:`.CircuitInstruction`\\ s - for each instruction. + Example: + + .. plot:: + :include-source: + :nofigs: + + from qiskit import QuantumCircuit + + qc = QuantumCircuit(2, 2) + qc.measure([0], [1]) + print(qc.data) + + .. code-block:: text + + [CircuitInstruction(operation=Instruction(name='measure', num_qubits=1, + num_clbits=1, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),), + clbits=(Clbit(ClassicalRegister(2, 'c'), 1),))] + + Returns: + QuantumCircuitData: a list-like object containing the :class:`.CircuitInstruction`\\ s + for each instruction. """ return QuantumCircuitData(self) @@ -1574,6 +1505,26 @@ def metadata(self) -> dict: all transforms of the circuit (i.e., transpilation) and that providers will associate any circuit metadata with the results it returns from execution of that circuit. + + Example: + + .. plot:: + :include-source: + :nofigs: + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + q = QuantumRegister(2) + c = ClassicalRegister(2) + qc = QuantumCircuit(q, c) + + qc.metadata = {'experiment_type': 'Bell state experiment'} + + print(qc.metadata) + + .. code-block:: text + + {'experiment_type': 'Bell state experiment'} """ return self._metadata @@ -2406,7 +2357,43 @@ def qubits(self) -> list[Qubit]: @property def clbits(self) -> list[Clbit]: """A list of :class:`Clbit`\\ s in the order that they were added. You should not mutate - this.""" + this. + + Example: + + .. plot:: + :include-source: + :nofigs: + :context: reset + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + qr1 = QuantumRegister(2) + qr2 = QuantumRegister(1) + cr1 = ClassicalRegister(2) + cr2 = ClassicalRegister(1) + qc = QuantumCircuit(qr1, qr2, cr1, cr2) + + print("List the quantum registers:", qc.qregs) + print("List the classical registers:", qc.cregs) + print("List the qubits in this circuit:", qc.qubits) + print("List the ancilla qubits:", qc.ancillas) + print("List the classical bits in this circuit:", qc.clbits) + + .. code-block:: text + + List the quantum registers: [QuantumRegister(2, 'q0'), + QuantumRegister(1, 'q1')] + List the classical registers: [ClassicalRegister(2, 'c0'), + ClassicalRegister(1, 'c1')] + List the qubits in this circuit: [Qubit(QuantumRegister(2, + 'q0'), 0), Qubit(QuantumRegister(2, 'q0'), 1), Qubit + (QuantumRegister(1, 'q1'), 0)] + List the ancilla qubits: [] + List the classical bits in this circuit: [Clbit + (ClassicalRegister(2, 'c0'), 0), Clbit(ClassicalRegister(2, + 'c0'), 1), Clbit(ClassicalRegister(1, 'c1'), 0)] + """ return self._data.clbits @property @@ -4292,7 +4279,45 @@ def from_qasm_str(qasm_str: str) -> "QuantumCircuit": @property def global_phase(self) -> ParameterValueType: - """The global phase of the current circuit scope in radians.""" + """The global phase of the current circuit scope in radians. + + Example: + + .. plot:: + :include-source: + :nofigs: + :context: reset + + from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit + + qreg_q = QuantumRegister(2, 'q') + creg_c = ClassicalRegister(2, 'c') + circuit = QuantumCircuit(qreg_q, creg_c) + + circuit.h(qreg_q[0]) + circuit.cx(qreg_q[0], qreg_q[1]) + + print(circuit.global_phase) # find the global phase of the current circuit + + .. code-block:: text + + 0.0 + + .. plot:: + :include-source: + :nofigs: + :context: + + from numpy import pi + + circuit.global_phase = pi/4 # set the global phase of the circuit to pi/4 + print(circuit.global_phase) + + .. code-block:: text + + 0.7853981633974483 + """ + if self._control_flow_scopes: return self._control_flow_scopes[-1].global_phase return self._data.global_phase