Skip to content

Commit

Permalink
Fix docstring format errors found by ruff (#9708)
Browse files Browse the repository at this point in the history
* Remove blank lines before class docstring, ruff D211

* Capitalize first word of docstrings, ruff D403

* Remove empty docstrings, ruff 419

* Remove blank line before function docstring, ruff D201

* Add colon to docstring section names, ruff D416

* Move closing triple quote in docstring to newline, ruff D208

The ruff rule D208 is actually "Docstring is over-indented". In fact they are
not overindented. But the error is somehow triggered because there is
no newline fore the closing triple quote. Adding this newline silences the
error.

* Use canonical capitalizatio of section names in docstrings, ruff D405

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
jlapeyre and mergify[bot] authored Mar 2, 2023
1 parent dc1737c commit 38b27d7
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 24 deletions.
1 change: 0 additions & 1 deletion qiskit/algorithms/time_evolvers/pvqd/pvqd.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def get_loss(
dt: float,
current_parameters: np.ndarray,
) -> tuple[Callable[[np.ndarray], float], Callable[[np.ndarray], np.ndarray]] | None:

"""Get a function to evaluate the infidelity between Trotter step and ansatz.
Args:
Expand Down
3 changes: 2 additions & 1 deletion qiskit/circuit/controlledgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def definition(self, excited_def: "QuantumCircuit"):
"""Set controlled gate definition with closed controls.
Args:
excited_def: The circuit with all closed controls."""
excited_def: The circuit with all closed controls.
"""
self._definition = excited_def

@property
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2947,7 +2947,7 @@ def id(self, qubit: QubitSpecifier) -> InstructionSet: # pylint: disable=invali
Returns:
A handle to the instructions created.
See also:
See Also:
QuantumCircuit.i: the same function.
"""
return self.i(qubit)
Expand Down
1 change: 0 additions & 1 deletion qiskit/opflow/gradients/qfi_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


class QFIBase(DerivativeBase):

r"""Base class for Quantum Fisher Information (QFI).
Compute the Quantum Fisher Information (QFI) given a pure, parameterized quantum state.
Expand Down
1 change: 0 additions & 1 deletion qiskit/quantum_info/operators/symplectic/base_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ def evolve(self, other, qargs=None, frame="h"):
return self.copy()._append_circuit(other.inverse(), qargs=qargs)

def _evolve_clifford(self, other, qargs=None, frame="h"):

"""Heisenberg picture evolution of a Pauli by a Clifford."""

if frame == "s":
Expand Down
2 changes: 1 addition & 1 deletion qiskit/quantum_info/synthesis/qsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def decomp_2q(mat):


def _demultiplex(um0, um1, opt_a1=False, opt_a2=False, *, _depth=0):
"""decomposes a generic multiplexer.
"""Decompose a generic multiplexer.
────□────
┌──┴──┐
Expand Down
3 changes: 0 additions & 3 deletions qiskit/tools/events/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,16 @@ def __init__(self, output_handler=None):

def _init_subscriber(self):
def _initialize_progress_bar(num_tasks):
""" """
self.start(num_tasks)

self.subscribe("terra.parallel.start", _initialize_progress_bar)

def _update_progress_bar(progress):
""" """
self.update(progress)

self.subscribe("terra.parallel.done", _update_progress_bar)

def _finish_progress_bar():
""" """
self.unsubscribe("terra.parallel.start", _initialize_progress_bar)
self.unsubscribe("terra.parallel.done", _update_progress_bar)
self.unsubscribe("terra.parallel.finish", _finish_progress_bar)
Expand Down
4 changes: 2 additions & 2 deletions qiskit/tools/events/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def subscribe(self, event, callback):
"""Subscribes to an event, so when it's emitted all the callbacks subscribed,
will be executed. We are not allowing double registration.
Args
Args:
event (string): The event to subscribed in the form of:
"terra.<component>.<method>.<action>"
callback (callable): The callback that will be executed when an event is
Expand All @@ -83,7 +83,7 @@ def subscribe(self, event, callback):
def dispatch(self, event, *args, **kwargs):
"""Emits an event if there are any subscribers.
Args
Args:
event (String): The event to be emitted
args: Arguments linked with the event
kwargs: Named arguments linked with the event
Expand Down
4 changes: 2 additions & 2 deletions qiskit/tools/jupyter/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _initialize_progress_bar(num_tasks):
"""When an event of compilation starts, this function will be called, and
will initialize the progress bar.
Args
Args:
num_tasks: Number of compilation tasks the progress bar will track
"""
self.start(num_tasks)
Expand All @@ -80,7 +80,7 @@ def _update_progress_bar(progress):
"""When an event of compilation completes, this function will be called, and
will update the progress bar indication.
Args
Args:
progress: Number of tasks completed
"""
self.update(progress)
Expand Down
4 changes: 2 additions & 2 deletions qiskit/utils/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _get_backend_provider(backend):


def has_ibmq():
"""Check if IBMQ is installed"""
"""Check if IBMQ is installed."""
if not _PROVIDER_CHECK.checked_ibmq:
try:
from qiskit.providers.ibmq import IBMQFactory
Expand All @@ -67,7 +67,7 @@ def has_ibmq():


def has_aer():
"""check if Aer is installed"""
"""Check if Aer is installed."""
if not _PROVIDER_CHECK.checked_aer:
try:
from qiskit.providers.aer import AerProvider
Expand Down
5 changes: 2 additions & 3 deletions qiskit/utils/run_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def find_regs_by_name(
def _combine_result_objects(results: List[Result]) -> Result:
"""Temporary helper function.
TODO:
This function would be removed after Terra supports job with infinite circuits.
TODO: This function would be removed after Terra supports job with infinite circuits.
"""
if len(results) == 1:
return results[0]
Expand Down Expand Up @@ -379,7 +378,7 @@ def _run_circuits_on_backend(
noise_config: Dict,
run_config: Dict,
) -> Job:
"""run on backend"""
"""Run on backend."""
run_kwargs = {}
if is_aer_provider(backend) or is_basicaer_provider(backend):
for key, value in backend_options.items():
Expand Down
1 change: 0 additions & 1 deletion qiskit/visualization/circuit/circuit_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ def _matplotlib_circuit_drawer(
cregbundle=None,
wire_order=None,
):

"""Draw a quantum circuit based on matplotlib.
If `%matplotlib inline` is invoked in a Jupyter notebook, it visualizes a circuit inline.
We recommend `%config InlineBackend.figure_format = 'svg'` for the inline visualization.
Expand Down
1 change: 0 additions & 1 deletion test/python/circuit/test_commutation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@


class TestCommutationChecker(QiskitTestCase):

"""Test CommutationChecker class."""

def test_simple_gates(self):
Expand Down
6 changes: 4 additions & 2 deletions test/python/dagcircuit/test_dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ def assert_cregs_equal(self, cregs, excluding=None):
Args:
cregs (Iterable(ClassicalRegister)): the classical registers to expect
excluding (Set(ClassicalRegister)): classical registers to remove from
``cregs`` before the comparison."""
``cregs`` before the comparison.
"""
if excluding is None:
excluding = set()
self.assertEqual(
Expand All @@ -301,7 +302,8 @@ def assert_clbits_equal(self, clbits, excluding=None):
Args:
clbits (Iterable(Clbit)): the classical bits to expect
excluding (Set(ClassicalRegister)): classical bits to remove from
``clbits`` before the comparison."""
``clbits`` before the comparison.
"""
if excluding is None:
excluding = set()
self.assertEqual(self.dag.clbits, [b for b in clbits if b not in excluding])
Expand Down
1 change: 0 additions & 1 deletion test/python/transpiler/test_commutative_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@


class TestCommutativeCancellation(QiskitTestCase):

"""Test the CommutativeCancellation pass."""

def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@


class TestCommutativeInverseCancellation(QiskitTestCase):

"""Test the CommutativeInverseCancellation pass."""

# The first suite of tests is adapted from CommutativeCancellation,
Expand Down

0 comments on commit 38b27d7

Please sign in to comment.