Skip to content

Commit 0b20aea

Browse files
doc: more properly say that Runners don't subclass Runner (#286)
1 parent 674366f commit 0b20aea

12 files changed

Lines changed: 130 additions & 62 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. important::
2+
3+
The class |name| has all the methods of the :any:`Runner` class but, for
4+
boring technical reasons, is not a subclass of :any:`Runner`. If ``thing`` is
5+
an instance of |name|, then you can use ``thing`` as if it were an instance
6+
of :any:`Runner` but ``isinstance(thing, Runner)`` will return ``False``.

src/action.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ In this documentation we refer to:
7878
* ``Side`` -- the side of the action (if it is a left or a right action).
7979
8080
.. seealso::
81+
:any:`LeftAction`, :any:`RightAction`, and :any:`Runner`.
8182
82-
* :any:`LeftAction`
83-
* :any:`RightAction`
84-
* :any:`Runner`
83+
.. |name| replace:: :any:`Action`
84+
85+
.. include:: ../../_static/runner_non_inherit.rst
8586
8687
.. doctest::
8788

src/cong.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ individual algorithms, such as :any:`Kambites`,
5252
5353
.. seealso:: :any:`Runner`, :any:`congruence_kind`, and :any:`tril`.
5454
55+
.. |name| replace:: :any:`Congruence`
56+
57+
.. include:: ../../_static/runner_non_inherit.rst
58+
5559
.. doctest::
5660
5761
>>> from libsemigroups_pybind11 import (Presentation, presentation, Congruence,

src/froidure-pin.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ full enumeration is triggered by calls to this function.
401401
pyclass_name.c_str(),
402402
// To change the top-level signature of a class, :sig=...: should be
403403
// specified here in the class docstring. This is most likely the
404-
// desired behaiour if a constructor is not overloaded.
404+
// desired behaviour if a constructor is not overloaded.
405405
// If the constructor is overloaded and the signature of an
406406
// individual overload is to be changed, :sig=...: should be
407407
// specified in the docstring of that py::init function.
@@ -427,6 +427,10 @@ the left and right Cayley graphs :any:`FroidurePin.left_cayley_graph` and
427427
terminating presentation :any:`froidure_pin.rules` for the semigroup is known.
428428
429429
.. seealso:: :any:`Runner`.
430+
431+
.. |name| replace:: :any:`FroidurePin`
432+
433+
.. include:: ../../_static/runner_non_inherit.rst
430434
)pbdoc");
431435

432436
bind_froidure_pin_core(m, thing);

src/kambites.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ computing normal forms. Note that a :any:`Kambites` instance represents a
5454
congruence on the free monoid or semigroup containing the rules of a
5555
presentation used to construct the instance, and the
5656
:any:`Kambites.generating_pairs`. As such generating pairs or rules are
57-
interchangeable in the context of :any:`Kambites` objects.)pbdoc");
57+
interchangeable in the context of :any:`Kambites` objects.
58+
59+
.. seealso:: :any:`Runner`.
60+
61+
.. |name| replace:: :any:`Kambites`
62+
63+
.. include:: ../../_static/runner_non_inherit.rst
64+
)pbdoc");
5865

5966
////////////////////////////////////////////////////////////////////////
6067
// Things from cong-common.hpp . . .

src/knuth-bendix.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,30 @@ semigroup.
5454
:any:`KnuthBendix` inherits from :any:`Runner` and has the
5555
nested class :any:`KnuthBendix.options`.
5656
57-
.. doctest::
57+
.. seealso:: :any:`Runner`.
5858
59-
>>> from libsemigroups_pybind11 import (KnuthBendix, Presentation,
60-
... presentation, congruence_kind)
61-
>>> p = Presentation("abc")
62-
>>> presentation.add_rule(p, "aaaa", "a")
63-
>>> presentation.add_rule(p, "bbbb", "b")
64-
>>> presentation.add_rule(p, "cccc", "c")
65-
>>> presentation.add_rule(p, "abab", "aaa")
66-
>>> presentation.add_rule(p, "bcbc", "bbb")
67-
>>> kb = KnuthBendix(congruence_kind.twosided, p)
68-
>>> not kb.confluent()
69-
True
70-
>>> kb.run()
71-
>>> kb.number_of_active_rules()
72-
31
73-
>>> kb.confluent()
74-
True
59+
.. |name| replace:: :any:`KnuthBendix`
60+
61+
.. include:: ../../_static/runner_non_inherit.rst
62+
63+
.. doctest::
64+
65+
>>> from libsemigroups_pybind11 import (KnuthBendix, Presentation,
66+
... presentation, congruence_kind)
67+
>>> p = Presentation("abc")
68+
>>> presentation.add_rule(p, "aaaa", "a")
69+
>>> presentation.add_rule(p, "bbbb", "b")
70+
>>> presentation.add_rule(p, "cccc", "c")
71+
>>> presentation.add_rule(p, "abab", "aaa")
72+
>>> presentation.add_rule(p, "bcbc", "bbb")
73+
>>> kb = KnuthBendix(congruence_kind.twosided, p)
74+
>>> not kb.confluent()
75+
True
76+
>>> kb.run()
77+
>>> kb.number_of_active_rules()
78+
31
79+
>>> kb.confluent()
80+
True
7581
)pbdoc");
7682

7783
// __repr__ is implemented in KnuthBendixImpl_

src/konieczny.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ function is :any:`Runner.run`, which implements Konieczny's Algorithm. If
5555
the size, partial order of :math:`\mathscr{D}`-classes, and frames for each
5656
:math:`\mathscr{D}`-class are known.
5757
58-
.. seealso:: :any:`Konieczny.DClass`)pbdoc");
58+
.. seealso:: :any:`Konieczny.DClass` and :any:`Runner`.
59+
60+
.. |name| replace:: :any:`Konieczny`
61+
62+
.. include:: ../../_static/runner_non_inherit.rst
63+
)pbdoc");
5964
thing.def("__repr__", [](Konieczny_ const& self) {
6065
return to_human_readable_repr(self);
6166
});

src/libsemigroups_pybind11/action.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ class Action(_CxxWrapper): # pylint: disable=missing-class-docstring
180180
########################################################################
181181

182182
# pylint: disable=redefined-outer-name
183-
def __init__(
184-
self: _Self, *args, generators=None, seeds=None, func=None, side=None
185-
) -> None:
183+
def __init__(self: _Self, *args, generators=None, seeds=None, func=None, side=None) -> None:
186184
"""
187185
:sig=(self: Action, generators=None, seeds=None, func=None, side=None) -> None:
188186
@@ -214,9 +212,7 @@ def __init__(
214212
if _to_cxx(self) is not None:
215213
return
216214
if len(args) != 0:
217-
raise TypeError(
218-
f"expected 0 positional arguments, but found {len(args)}"
219-
)
215+
raise TypeError(f"expected 0 positional arguments, but found {len(args)}")
220216
if not isinstance(generators, list):
221217
raise TypeError(
222218
"expected the keyword argument 'generators' to be "
@@ -279,9 +275,7 @@ def generators(self: _Self) -> Iterator[Element]:
279275

280276
_copy_cxx_mem_fns(_RightActionPPerm1PPerm1, Action)
281277

282-
for (
283-
_type
284-
) in (
278+
for _type in (
285279
Action._py_template_params_to_cxx_type.values() # pylint: disable=protected-access
286280
):
287281
_register_cxx_wrapped_type(_type, Action)
@@ -295,14 +289,14 @@ class RightAction(Action):
295289
"""
296290
Class representing a right action of a semigroup or monoid on a set.
297291
298-
This page contains the documentation for the class ``RightAction``, which
299-
just calls :any:`Action` with the keyword arguments *func* given by
292+
This page contains the documentation for the class :any:`RightAction`,
293+
which just calls :any:`Action` with the keyword arguments *func* given by
300294
:any:`ImageRightAction` and *side* given by :py:class:`side.right`.
301295
"""
302296

303297
def __init__(self: _Self, *args, generators=None, seeds=None) -> None:
304298
"""
305-
:sig=(self: Action, generators=None, seeds=None, func=None, side=None) -> None:
299+
:sig=(self: RightAction, generators=None, seeds=None) -> None:
306300
307301
Construct an :any:`Action` from generators and seeds,
308302
:any:`ImageRightAction` and :py:class:`side.right`.
@@ -318,6 +312,10 @@ def __init__(self: _Self, *args, generators=None, seeds=None) -> None:
318312
if *generators* or *seeds* has length ``0``.
319313
:raises KeyError:
320314
if the action given by the arguments is not yet implemented.
315+
316+
.. |name| replace:: :any:`RightAction`
317+
318+
.. include:: ../../_static/runner_non_inherit.rst
321319
"""
322320
super().__init__(
323321
*args,
@@ -344,7 +342,7 @@ class LeftAction(Action):
344342

345343
def __init__(self: _Self, *args, generators=None, seeds=None) -> None:
346344
"""
347-
:sig=(self: Action, generators=None, seeds=None, func=None, side=None) -> None:
345+
:sig=(self: LeftAction, generators=None, seeds=None) -> None:
348346
349347
Construct an :any:`Action` from generators and seeds,
350348
:any:`ImageLeftAction` and :py:class:`side.left`.
@@ -360,6 +358,10 @@ def __init__(self: _Self, *args, generators=None, seeds=None) -> None:
360358
if *generators* or *seeds* has length ``0``.
361359
:raises KeyError:
362360
if the action given by the arguments is not yet implemented.
361+
362+
.. |name| replace:: :any:`LeftAction`
363+
364+
.. include:: ../../_static/runner_non_inherit.rst
363365
"""
364366
super().__init__(
365367
generators=generators,

src/runner.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,26 @@ The time between the given point and now.
5656
R"pbdoc(
5757
Collection of values related to reporting.
5858
59-
This class exists to collect some values related to reporting in its derived
60-
classes. These values are:
59+
This class exists to collect some values related to reporting in its
60+
derived [#sortof]_ classes. These values are:
6161
6262
- :any:`report_prefix()`;
6363
- :any:`report_every()`;
6464
- :any:`last_report()`;
6565
- :any:`start_time()`.
66+
67+
This class has limited (no?) utility on its own, and you are unlikely to want to use it directly.
68+
69+
.. important::
70+
71+
The classes that we claim derive from :any:`Reporter` in this documentation have all the methods of the
72+
:any:`Reporter` class but, for boring technical reasons, are not formally
73+
subclasses of :any:`Reporter`. If ``thing`` is an instance of a class
74+
derived from :any:`Reporter`, then you can use ``thing`` as if it were an
75+
instance of :any:`Reporter` but ``isinstance(thing, Reporter)`` will return
76+
``False``.
77+
78+
.. [#sortof] Sort of, please see the note above.
6679
)pbdoc");
6780

6881
thing.def(py::init<>(), R"pbdoc(
@@ -239,13 +252,13 @@ run at the outmost level.
239252
py::class_<Runner, Reporter> thing(m,
240253
"Runner",
241254
R"pbdoc(
242-
Abstract class for derived classes that run an algorithm.
255+
Abstract class for derived [#sortof]_ classes that run an algorithm.
243256
244-
Many of the classes in ``libsemigroups`` implementing the algorithms, that are
245-
the reason for the existence of this library, are derived from :any:`Runner`.
246-
The :any:`Runner` class exists to collect various common tasks required by such
247-
a derived class with a possibly long running :any:`run`. These common tasks
248-
include:
257+
Many of the classes in ``libsemigroups_pybind11`` implementing the algorithms,
258+
that are the reason for the existence of this package, are derived from
259+
:any:`Runner`. The :any:`Runner` class exists to collect various common tasks
260+
required by such a derived class with a possibly long running :any:`run`. These
261+
common tasks include:
249262
250263
* running for a given amount of time (:any:`run_for`)
251264
* running until a nullary predicate is true (:any:`run_until`)
@@ -254,7 +267,19 @@ a derived class with a possibly long running :any:`run`. These common tasks
254267
out (:any:`timed_out`)? has it :any:`stopped` for any reason?
255268
* permit the function :any:`run` to be killed from another thread (:any:`kill`).
256269
270+
Because :any:`Runner` is an abstract class it is not possible to create instances of :any:`Runner` except via a derived class.
271+
257272
This class inherits from :any:`Reporter`.
273+
274+
.. important::
275+
276+
The classes derived from :any:`Runner` have all the methods of the
277+
:any:`Runner` class but, for boring technical reasons, are not formally
278+
subclasses of :any:`Runner`. If ``thing`` is an instance of a class derived
279+
from :any:`Runner`, then you can use ``thing`` as if it were an instance of
280+
:any:`Runner` but ``isinstance(thing, Runner)`` will return ``False``.
281+
282+
.. [#sortof] Sort of, please see the note above.
258283
)pbdoc");
259284

260285
py::enum_<Runner::state> state(m, "Runner.state", R"pbdoc(

src/schreier-sims.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Add a base point to the stabiliser chain.
106106
107107
:raises LibsemigroupsError: if *pt* is already a base point.
108108
109-
:raises LibsemigroupsError: if :any:`Runner.finished()` returns ``True``.
109+
:raises LibsemigroupsError: if :any:`finished()` returns ``True``.
110110
111111
:complexity: Linear in the current number of base points.)pbdoc");
112112
thing.def("add_generator",

0 commit comments

Comments
 (0)