Skip to content

Commit a70a195

Browse files
mergify[bot]1ucian0jakelishman
authored
Some doc formatting and link, mostly on quantumcircuit.py file (#9771) (#9804)
* some doc formating and link, mostly on quantumcircuit.py file * Update qiskit/circuit/quantumcircuit.py Co-authored-by: Julien Gacon <[email protected]> * ident * more typos * more typos * another iteration * Bit and Register * notes on Register and Bit * Update qiskit/circuit/bit.py Co-authored-by: Eric Arellano <[email protected]> * Update qiskit/circuit/register.py Co-authored-by: Eric Arellano <[email protected]> --------- Co-authored-by: Julien Gacon <[email protected]> Co-authored-by: Eric Arellano <[email protected]> Co-authored-by: Jake Lishman <[email protected]> (cherry picked from commit b4bc559) Co-authored-by: Luciano Bello <[email protected]> Co-authored-by: Jake Lishman <[email protected]>
1 parent b8e2777 commit a70a195

File tree

8 files changed

+63
-48
lines changed

8 files changed

+63
-48
lines changed

qiskit/algorithms/optimizers/qnspsa.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def get_fidelity(
277277
F(\theta, \phi) = \big|\langle 0 | U^\dagger(\theta) U(\phi) |0\rangle \big|^2.
278278
279279
The output of this function can be used as input for the ``fidelity`` to the
280-
:class:~`qiskit.algorithms.optimizers.QNSPSA` optimizer.
280+
:class:`~.QNSPSA` optimizer.
281281
282282
Args:
283283
circuit: The circuit preparing the parameterized ansatz.

qiskit/circuit/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@
263263
AncillaRegister
264264
AncillaQubit
265265
CircuitInstruction
266+
Register
267+
Bit
266268
267269
Gates and Instructions
268270
----------------------
@@ -328,6 +330,8 @@
328330
from .parameterexpression import ParameterExpression
329331
from .quantumcircuitdata import CircuitInstruction
330332
from .equivalence import EquivalenceLibrary
333+
from .bit import Bit
334+
from .register import Register
331335
from . import library
332336
from .commutation_checker import CommutationChecker
333337

qiskit/circuit/bit.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919

2020

2121
class Bit:
22-
"""Implement a generic bit."""
22+
"""Implement a generic bit.
23+
24+
.. note::
25+
This class should not be instantiated directly. This is just a superclass
26+
for :class:`~.Clbit` and :class:`~.Qubit`.
27+
28+
"""
2329

2430
__slots__ = {"_register", "_index", "_hash", "_repr"}
2531

qiskit/circuit/controlflow/for_loop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ForLoopContext:
142142
from qiskit import QuantumCircuit
143143
qc = QuantumCircuit(2, 1)
144144
145-
with qc.for_loop(None, range(5)) as i:
145+
with qc.for_loop(range(5)) as i:
146146
qc.rx(i * math.pi/4, 0)
147147
qc.cx(0, 1)
148148
qc.measure(0, 0)

qiskit/circuit/instruction.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,11 @@ def copy(self, name=None):
417417
Copy of the instruction.
418418
419419
Args:
420-
name (str): name to be given to the copied circuit,
421-
if None then the name stays the same.
420+
name (str): name to be given to the copied circuit, if ``None`` then the name stays the same.
422421
423422
Returns:
424-
qiskit.circuit.Instruction: a copy of the current instruction, with the name
425-
updated if it was provided
423+
qiskit.circuit.Instruction: a copy of the current instruction, with the name updated if it
424+
was provided
426425
"""
427426
cpy = self.__deepcopy__()
428427

qiskit/circuit/instructionset.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ class InstructionSet:
9595
def __init__(self, circuit_cregs=None, *, resource_requester: Optional[Callable] = None):
9696
"""New collection of instructions.
9797
98-
The context (qargs and cargs that each instruction is attached to) is also stored separately
99-
for each instruction.
98+
The context (``qargs`` and ``cargs`` that each instruction is attached to) is also stored
99+
separately for each instruction.
100100
101101
Args:
102-
circuit_cregs (list[ClassicalRegister]): Optional. List of cregs of the
102+
circuit_cregs (list[ClassicalRegister]): Optional. List of ``cregs`` of the
103103
circuit to which the instruction is added. Default: `None`.
104104
105-
.. deprecated:: qiskit-terra 0.19
105+
.. deprecated:: 0.19
106106
The classical registers are insufficient to access all classical resources in a
107107
circuit, as there may be loose classical bits as well. It can also cause
108108
integer indices to be resolved incorrectly if any registers overlap. Instead,

qiskit/circuit/quantumcircuit.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ class QuantumCircuit:
130130
A circuit is a list of instructions bound to some registers.
131131
132132
Args:
133-
regs (list(:class:`Register`) or list(``int``) or list(list(:class:`Bit`))): The
133+
regs (list(:class:`~.Register`) or list(``int``) or list(list(:class:`~.Bit`))): The
134134
registers to be included in the circuit.
135135
136-
* If a list of :class:`Register` objects, represents the :class:`QuantumRegister`
137-
and/or :class:`ClassicalRegister` objects to include in the circuit.
136+
* If a list of :class:`~.Register` objects, represents the :class:`.QuantumRegister`
137+
and/or :class:`.ClassicalRegister` objects to include in the circuit.
138138
139139
For example:
140140
@@ -151,8 +151,8 @@ class QuantumCircuit:
151151
* ``QuantumCircuit(4) # A QuantumCircuit with 4 qubits``
152152
* ``QuantumCircuit(4, 3) # A QuantumCircuit with 4 qubits and 3 classical bits``
153153
154-
* If a list of python lists containing :class:`Bit` objects, a collection of
155-
:class:`Bit` s to be added to the circuit.
154+
* If a list of python lists containing :class:`.Bit` objects, a collection of
155+
:class:`.Bit` s to be added to the circuit.
156156
157157
158158
name (str): the name of the quantum circuit. If not set, an
@@ -1217,8 +1217,7 @@ def append(
12171217
were actually added to the circuit.
12181218
12191219
Raises:
1220-
CircuitError: if the operation passed is not an instance of
1221-
:class:`~.circuit..Instruction`.
1220+
CircuitError: if the operation passed is not an instance of :class:`~.circuit.Instruction` .
12221221
"""
12231222
if isinstance(instruction, CircuitInstruction):
12241223
operation = instruction.operation
@@ -1855,10 +1854,10 @@ def draw(
18551854
Default is True, except for when ``output`` is set to ``"text"``.
18561855
wire_order (list): Optional. A list of integers used to reorder the display
18571856
of the bits. The list must have an entry for every bit with the bits
1858-
in the range 0 to (num_qubits + num_clbits).
1857+
in the range 0 to (``num_qubits`` + ``num_clbits``).
18591858
18601859
Returns:
1861-
:class:`TextDrawing` or :class:`matplotlib.figure` or :class:`PIL.Image` or
1860+
:class:`.TextDrawing` or :class:`matplotlib.figure` or :class:`PIL.Image` or
18621861
:class:`str`:
18631862
18641863
* `TextDrawing` (output='text')
@@ -2860,8 +2859,8 @@ def _rebind_definition(
28602859
self._rebind_definition(inner.operation, parameter, value)
28612860

28622861
def barrier(self, *qargs: QubitSpecifier, label=None) -> InstructionSet:
2863-
"""Apply :class:`~qiskit.circuit.Barrier`. If qargs is empty, applies to all qubits in the
2864-
circuit.
2862+
"""Apply :class:`~.library.Barrier`. If ``qargs`` is empty, applies to all qubits
2863+
in the circuit.
28652864
28662865
Args:
28672866
qargs (QubitSpecifier): Specification for one or more qubit arguments.
@@ -2897,14 +2896,15 @@ def delay(
28972896
qarg: Optional[QubitSpecifier] = None,
28982897
unit: str = "dt",
28992898
) -> InstructionSet:
2900-
"""Apply :class:`~qiskit.circuit.Delay`. If qarg is None, applies to all qubits.
2899+
"""Apply :class:`~.circuit.Delay`. If qarg is ``None``, applies to all qubits.
29012900
When applying to multiple qubits, delays with the same duration will be created.
29022901
29032902
Args:
29042903
duration (int or float or ParameterExpression): duration of the delay.
29052904
qarg (Object): qubit argument to apply this delay.
2906-
unit (str): unit of the duration. Supported units: 's', 'ms', 'us', 'ns', 'ps', 'dt'.
2907-
Default is ``dt``, i.e. integer time unit depending on the target backend.
2905+
unit (str): unit of the duration. Supported units: ``'s'``, ``'ms'``, ``'us'``,
2906+
``'ns'``, ``'ps'``, and ``'dt'``. Default is ``'dt'``, i.e. integer time unit
2907+
depending on the target backend.
29082908
29092909
Returns:
29102910
qiskit.circuit.InstructionSet: handle to the added instructions.
@@ -3010,7 +3010,7 @@ def id(self, qubit: QubitSpecifier) -> InstructionSet: # pylint: disable=invali
30103010
return self.i(qubit)
30113011

30123012
def ms(self, theta: ParameterValueType, qubits: Sequence[QubitSpecifier]) -> InstructionSet:
3013-
"""Apply :class:`~qiskit.circuit.library.generalized_gates.gms.MSGate`.
3013+
"""Apply :class:`~qiskit.circuit.library.MSGate`.
30143014
30153015
For the full matrix form of this gate, see the underlying gate documentation.
30163016
@@ -3131,9 +3131,9 @@ def rv(
31313131
rotation in radians.
31323132
31333133
Args:
3134-
vx: x-compenent of the rotation axis.
3135-
vy: y-compenent of the rotation axis.
3136-
vz: z-compenent of the rotation axis.
3134+
vx: x-component of the rotation axis.
3135+
vy: y-component of the rotation axis.
3136+
vz: z-component of the rotation axis.
31373137
qubit: The qubit(s) to apply the gate to.
31383138
31393139
Returns:
@@ -3564,8 +3564,8 @@ def cswap(
35643564
target_qubit2: The qubit(s) targeted by the gate.
35653565
label: The string label of the gate in the circuit.
35663566
ctrl_state:
3567-
The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling
3568-
on the '1' state.
3567+
The control state in decimal, or as a bitstring (e.g. ``'1'``). Defaults to controlling
3568+
on the ``'1'`` state.
35693569
35703570
Returns:
35713571
A handle to the instructions created.
@@ -3906,10 +3906,10 @@ def mcx(
39063906
The multi-cX gate can be implemented using different techniques, which use different numbers
39073907
of ancilla qubits and have varying circuit depth. These modes are:
39083908
3909-
- 'noancilla': Requires 0 ancilla qubits.
3910-
- 'recursion': Requires 1 ancilla qubit if more than 4 controls are used, otherwise 0.
3911-
- 'v-chain': Requires 2 less ancillas than the number of control qubits.
3912-
- 'v-chain-dirty': Same as for the clean ancillas (but the circuit will be longer).
3909+
- ``'noancilla'``: Requires 0 ancilla qubits.
3910+
- ``'recursion'``: Requires 1 ancilla qubit if more than 4 controls are used, otherwise 0.
3911+
- ``'v-chain'``: Requires 2 less ancillas than the number of control qubits.
3912+
- ``'v-chain-dirty'``: Same as for the clean ancillas (but the circuit will be longer).
39133913
39143914
For the full matrix form of this gate, see the underlying gate documentation.
39153915
@@ -3984,10 +3984,10 @@ def mct(
39843984
The multi-cX gate can be implemented using different techniques, which use different numbers
39853985
of ancilla qubits and have varying circuit depth. These modes are:
39863986
3987-
- 'noancilla': Requires 0 ancilla qubits.
3988-
- 'recursion': Requires 1 ancilla qubit if more than 4 controls are used, otherwise 0.
3989-
- 'v-chain': Requires 2 less ancillas than the number of control qubits.
3990-
- 'v-chain-dirty': Same as for the clean ancillas (but the circuit will be longer).
3987+
- ``'noancilla'``: Requires 0 ancilla qubits.
3988+
- ``'recursion'``: Requires 1 ancilla qubit if more than 4 controls are used, otherwise 0.
3989+
- ``'v-chain'``: Requires 2 less ancillas than the number of control qubits.
3990+
- ``'v-chain-dirty'``: Same as for the clean ancillas (but the circuit will be longer).
39913991
39923992
For the full matrix form of this gate, see the underlying gate documentation.
39933993
@@ -4362,10 +4362,10 @@ def for_loop(
43624362
43634363
There are two forms for calling this function. If called with all its arguments (with the
43644364
possible exception of ``label``), it will create a
4365-
:obj:`~qiskit.circuit.controlflow.ForLoopOp` with the given ``body``. If ``body`` (and
4365+
:class:`~qiskit.circuit.ForLoopOp` with the given ``body``. If ``body`` (and
43664366
``qubits`` and ``clbits``) are *not* passed, then this acts as a context manager, which,
43674367
when entered, provides a loop variable (unless one is given, in which case it will be
4368-
reused) and will automatically build a :obj:`~qiskit.circuit.controlflow.ForLoopOp` when the
4368+
reused) and will automatically build a :class:`~qiskit.circuit.ForLoopOp` when the
43694369
scope finishes. In this form, you do not need to keep track of the qubits or clbits you are
43704370
using, because the scope will handle it for you.
43714371
@@ -4460,7 +4460,7 @@ def if_test(
44604460
44614461
There are two forms for calling this function. If called with all its arguments (with the
44624462
possible exception of ``label``), it will create a
4463-
:obj:`~qiskit.circuit.controlflow.IfElseOp` with the given ``true_body``, and there will be
4463+
:obj:`~qiskit.circuit.IfElseOp` with the given ``true_body``, and there will be
44644464
no branch for the ``false`` condition (see also the :meth:`.if_else` method). However, if
44654465
``true_body`` (and ``qubits`` and ``clbits``) are *not* passed, then this acts as a context
44664466
manager, which can be used to build ``if`` statements. The return value of the ``with``
@@ -4547,7 +4547,7 @@ def if_else(
45474547
clbits: Sequence[ClbitSpecifier],
45484548
label: Optional[str] = None,
45494549
) -> InstructionSet:
4550-
"""Apply :class:`~qiskit.circuit.controlflow.IfElseOp`.
4550+
"""Apply :class:`~qiskit.circuit.IfElseOp`.
45514551
45524552
.. note::
45534553
@@ -4592,7 +4592,7 @@ def if_else(
45924592
return self.append(IfElseOp(condition, true_body, false_body, label), qubits, clbits)
45934593

45944594
def break_loop(self) -> InstructionSet:
4595-
"""Apply :class:`~qiskit.circuit.controlflow.BreakLoopOp`.
4595+
"""Apply :class:`~qiskit.circuit.BreakLoopOp`.
45964596
45974597
.. warning::
45984598
@@ -4622,7 +4622,7 @@ def break_loop(self) -> InstructionSet:
46224622
return self.append(BreakLoopOp(self.num_qubits, self.num_clbits), self.qubits, self.clbits)
46234623

46244624
def continue_loop(self) -> InstructionSet:
4625-
"""Apply :class:`~qiskit.circuit.controlflow.ContinueLoopOp`.
4625+
"""Apply :class:`~qiskit.circuit.ContinueLoopOp`.
46264626
46274627
.. warning::
46284628
@@ -4632,8 +4632,8 @@ def continue_loop(self) -> InstructionSet:
46324632
determined. This would quickly lead to invalid circuits, and so if you are trying to
46334633
construct a reusable loop body (without the context managers), you must also use the
46344634
non-context-manager form of :meth:`.if_test` and :meth:`.if_else`. Take care that the
4635-
:obj:`.ContinueLoopOp` instruction must span all the resources of its containing loop,
4636-
not just the immediate scope.
4635+
:class:`~qiskit.circuit.ContinueLoopOp` instruction must span all the resources of its
4636+
containing loop, not just the immediate scope.
46374637
46384638
Returns:
46394639
A handle to the instruction created.

qiskit/circuit/register.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ def __get__(self, obj, objtype=None):
3838

3939

4040
class Register:
41-
"""Implement a generic register."""
41+
"""Implement a generic register.
42+
43+
.. note::
44+
This class should not be instantiated directly. This is just a superclass
45+
for :class:`~.ClassicalRegister` and :class:`~.QuantumRegister`.
46+
47+
"""
4248

4349
__slots__ = ["_name", "_size", "_bits", "_bit_indices", "_hash", "_repr"]
4450

0 commit comments

Comments
 (0)