Skip to content

Commit 73c359b

Browse files
mtreinishgadial
authored andcommitted
Enable missing argument in docstring lint (Qiskit#15721)
* Enable missing argument in docstring lint In the recently merged Qiskit#15603 we migrated from pylint to use ruff. During the development of that PR the rule group "D" for rules derived from pydocstyle was investigated but the full rule group was overly pedantic and even with disabling the most egregious rules also changed the docs for the worse (at least by autofixing many rules) so that sphinx would not succesfully build after applying the fixes. So during Qiskit#15603 the changes for this rule group were reverted. However, one of the useful rules from that group D417 which checks that all arguments are documented. This rule found real issues in the documentation and it is worthwhile to enable it. This commit enables the rule in our ruff checks and fixes the issues associated with. During this process ruff flagged one place in the `__call__` method docstring for the `TwoQubitControlledUDecomposer` class has not documented several arguments on the method. However, these arguments are unused currently. It is apparently trying to match the `__call__` signature of the other two qubit decomposers but is not using most of the arguments. Most could be conceivably supported by `TwoQubitControlledUDecomposer` and it's not clear why they were added. But, for this PR I didn't want to look into adding the support as it was out of scope. For the time being this PR suppresses the ruff rule and adds a TODO comment to start using the unused arguments. * Update filename docstring * Revise wording on state visualization filename arg
1 parent 55ff6e8 commit 73c359b

36 files changed

Lines changed: 102 additions & 28 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ select = [
347347
"INP",
348348
# flake8-print
349349
"T20",
350+
# Missing arguments in docstring
351+
"D417",
350352
]
351353
ignore = [
352354
"E402", # module-import-not-at-top-of-file false positives with module docs

qiskit/circuit/controlflow/box.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def __init__(
154154
duration: the final duration of the box.
155155
unit: the unit of ``duration``.
156156
label: an optional label for the box.
157+
annotations: any :class:`.Annotation`\\ s to apply to the box. In cases where order
158+
is important, annotations are to be interpreted in the same order they appear in
159+
the iterable.
157160
"""
158161
self._circuit = circuit
159162
self._duration = duration

qiskit/circuit/controlflow/switch_case.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(
7070
cases: an ordered iterable of the corresponding value of the ``target`` and the circuit
7171
block that should be executed if this is matched. There is no fall-through between
7272
blocks, and the order matters.
73+
label: An optional label for identifying the instruction.
7374
"""
7475

7576
from qiskit.circuit import QuantumCircuit

qiskit/circuit/duration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def convert_durations_to_dt(qc: QuantumCircuit, dt_in_sec: float, inplace=True):
4747
4848
Returns a new circuit if `inplace=False`.
4949
50-
Parameters:
50+
Args:
5151
qc (QuantumCircuit): Duration of dt in seconds used for conversion.
5252
dt_in_sec (float): Duration of dt in seconds used for conversion.
5353
inplace (bool): All durations are converted inplace or return new circuit.

qiskit/circuit/library/arithmetic/adders/adder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def __init__(self, num_state_qubits: int, label: str | None = None) -> None:
100100
Args:
101101
num_state_qubits: The number of qubits in each of the registers.
102102
name: The name of the circuit.
103+
label: An optional label for identifying the instruction.
103104
"""
104105
if num_state_qubits < 1:
105106
raise ValueError("Need at least 1 state qubit.")
@@ -155,6 +156,7 @@ def __init__(self, num_state_qubits: int, label: str | None = None) -> None:
155156
Args:
156157
num_state_qubits: The number of qubits in each of the registers.
157158
name: The name of the circuit.
159+
label: An optional label for identifying the instruction.
158160
"""
159161
if num_state_qubits < 1:
160162
raise ValueError("Need at least 1 state qubit.")
@@ -211,6 +213,7 @@ def __init__(self, num_state_qubits: int, label: str | None = None) -> None:
211213
Args:
212214
num_state_qubits: The number of qubits in each of the registers.
213215
name: The name of the circuit.
216+
label: An optional label for identifying the instruction.
214217
"""
215218
if num_state_qubits < 1:
216219
raise ValueError("Need at least 1 state qubit.")

qiskit/circuit/library/arithmetic/linear_pauli_rotations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def slope(self, slope: float) -> None:
9393
"""Set the multiplicative factor of the rotation angles.
9494
9595
Args:
96-
The slope of the rotation angles.
96+
slope: The slope of the rotation angles.
9797
"""
9898
if self._slope is None or slope != self._slope:
9999
self._invalidate()

qiskit/circuit/library/arithmetic/multipliers/multiplier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def __init__(
151151
num_result_qubits: The number of result qubits to limit the output to.
152152
Default value is ``2 * num_state_qubits`` to represent any possible
153153
result from the multiplication of the two inputs.
154-
name: The name of the circuit.
154+
label: The optional string label to apply to the instruction.
155155
Raises:
156156
ValueError: If ``num_state_qubits`` is smaller than 1.
157157
ValueError: If ``num_result_qubits`` is smaller than ``num_state_qubits``.

qiskit/circuit/library/arithmetic/polynomial_pauli_rotations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def coeffs(self, coeffs: list[float]) -> None:
206206
``coeffs[i]`` is the coefficient of the i-th power of x.
207207
208208
Args:
209-
The coefficients of the polynomial.
209+
coeffs: The coefficients of the polynomial.
210210
"""
211211
self._invalidate()
212212
self._coeffs = coeffs

qiskit/circuit/library/n_local/n_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def num_qubits(self, num_qubits: int) -> None:
446446
"""Set the number of qubits for the n-local circuit.
447447
448448
Args:
449-
The new number of qubits.
449+
num_qubits: The new number of qubits.
450450
"""
451451
if self._num_qubits != num_qubits:
452452
# invalidate the circuit
@@ -666,7 +666,7 @@ def ordered_parameters(self, parameters: ParameterVector | list[Parameter]) -> N
666666
"""Set the parameters used in the underlying circuit.
667667
668668
Args:
669-
The parameters to be used in the underlying circuit.
669+
parameters: The parameters to be used in the underlying circuit.
670670
671671
Raises:
672672
ValueError: If the length of ordered parameters does not match the number of

qiskit/circuit/library/standard_gates/x.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,15 +1243,18 @@ def __init__(
12431243
):
12441244
"""
12451245
Args:
1246+
num_ctrl_qubits: Number of controls to add. Defaults to ``1``.
12461247
dirty_ancillas: when set to ``True``, the method applies an optimized multicontrolled-X gate
12471248
up to a relative phase using dirty ancillary qubits with the properties of lemmas 7 and 8
12481249
from arXiv:1501.06911, with at most 8*k - 6 CNOT gates.
12491250
For k within the range {1, ..., ceil(n/2)}. And for n representing the total number of
12501251
qubits.
1252+
label: Optional gate label. Defaults to ``None``.
1253+
ctrl_state: The control state of the gate, specified either as an integer or a bitstring
1254+
(e.g. ``"110"``). If ``None``, defaults to the all-ones state ``2**num_ctrl_qubits - 1``
12511255
relative_phase: when set to ``True``, the method applies the optimized multicontrolled-X gate
12521256
up to a relative phase, in a way that, by lemma 7 of arXiv:1501.06911, the relative
12531257
phases of the ``action part`` cancel out with the phases of the ``reset part``.
1254-
12551258
action_only: when set to ``True``, the method applies only the action part of lemma 8
12561259
from arXiv:1501.06911.
12571260

0 commit comments

Comments
 (0)