Skip to content

Refactoring and enhancing user-facing Backend and Configs docs - #7404

Merged
eriknw merged 32 commits into
networkx:mainfrom
Schefflera-Arboricola:maint_styling_fixes
Jun 24, 2024
Merged

eriknw merged 32 commits into
networkx:mainfrom
Schefflera-Arboricola:maint_styling_fixes

Conversation

@Schefflera-Arboricola

@Schefflera-Arboricola Schefflera-Arboricola commented Apr 10, 2024 •

Copy link
Copy Markdown
Member

@Schefflera-Arboricola
Schefflera-Arboricola marked this pull request as ready for review April 10, 2024 18:25

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

I like the brief descriptions of the backends and all the wording checks.
The reorg is harder for me to visualize by looking at the diff. So I have to view the full source and/or the html docs. They seem good too.

See more minor comments below.

Comment thread doc/reference/backends.rst Resolved
Comment thread doc/reference/backends.rst Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/configs.py Resolved
Comment thread networkx/utils/configs.py Resolved
@Schefflera-Arboricola
Schefflera-Arboricola marked this pull request as draft April 15, 2024 12:08
@Schefflera-Arboricola
Schefflera-Arboricola marked this pull request as ready for review April 17, 2024 18:48
@dschult dschult added the Dispatching Related to dispatching and backend support label Apr 25, 2024

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready to be merged. I don't see any specific questions yet to be resolved, and we can update the docs further in another PR.
Thanks @Schefflera-Arboricola !

@eriknw eriknw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these changes! This reads better. I left a few comments, and many of them remark on possible future enhancements.

Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Outdated
Comment on lines +113 to +114
that is similar to ``can_run``, but answers whether the backend *should* be run
(converting if necessary). Like ``can_run``, it receives the original arguments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you moved these lines from elsewhere, but I'm not sure this sentence is fully accurate or clear. should_run is only run when doing conversions. Hence, should_convert_and_run would be a more accurate name. @rlratzel and I have argued about this a couple times, b/c we sometimes get confused.

Perhaps an enhancement to should_run could be to add e.g. requires_conversion=True keyword to make this more clear and more useful.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not quite accurate, can we clean up the language here?

Comment on lines +120 to +124
4. ``on_start_tests`` (Optional):
A special ``on_start_tests(items)`` function may be defined by the backend.
It will be called with the list of NetworkX tests discovered. Each item
is a test object that can be marked as xfail if the backend does not support
the test using ``item.add_marker(pytest.mark.xfail(reason=...))``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a future enhancement, I think it would be nice to have a place that demonstrates how to use this effectively. For example, both cugraph and graphblas backends define something like this for convenience. Perhaps a more complete example could be in the backend cookie-cutter that we'd like to make from the j4f or nx-loopback backends, and then this document could link there.

Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved

This decorator function dispatches to
a different backend implementation based on the input graph types, and it also
manages all the ``backend_kwargs``. Usage can be any of the following decorator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the first place we mention backend_kwargs? How should we talk about backend functions allowing additional keyword arguments? For that matter, do we talk about what get_info is able to return including "additional_docs"?

Also, should we mention backend="my_backend" to choose a bakcend when calling a dispatchable function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is previously mentioned on the "Backends and Config" docs page but this is the first time mentioned on the dispatchable decorator docs page. On the "Backends and Config" docs page, I've made its explanation more detailed. Please look at it and LMK if something doesn't seem right there because I just tried to explain it by looking at the code in __call__ of the dispatchable class, so I might be missing some context there. pls LMK if that looks fine.

I've also added the details of the get_info function as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backend_kwargs: here

get_info: here

Comment thread networkx/utils/backends.py Resolved
Comment thread networkx/utils/backends.py Resolved
Comment thread doc/reference/backends.rst Resolved
@Schefflera-Arboricola
Schefflera-Arboricola marked this pull request as draft June 3, 2024 07:02
Comment thread networkx/utils/backends.py Outdated
Comment on lines +54 to +62

And you can disable all the loggers by running this::

logging.disable(logging.CRITICAL)

And then re-enable it by running::

logging.disable(logging.NOTSET)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referred this for documenting the disabling of logging and this was working for me on my local machine. Please LMK if this is the right/standard way.
@rlratzel

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to also demonstrate how to disable logging for specific modules, since some applications may want logging elsewhere. To disable the logging calls in the dispatcher, this can be done:

   logging.getLogger("networkx.utils.backends").setLevel(logging.CRITICAL)

Then of course to re-enable debug logging:

   logging.getLogger("networkx.utils.backends").setLevel(logging.DEBUG)

For similar reasons, users may want to enable debug logging only for networkx and nothing else. To do that, they can use:

    nxl = logging.getLogger("networkx")
    nxl.addHandler(logging.StreamHandler())
    nxl.setLevel(logging.DEBUG)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to sound like we are re-documenting how to do logging. Logging needs to be simple and useful to be included.

Can we point to a good link that explains logging in a clear way? Could that let us remove docs here rather than repeating (and continually updating) what is developed and controlled eslewhere?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that's a good point. I think backend users and devs might appreciate a short note about how logging can be used to help tune/debug workflows though, so maybe something like this?

Add the following code to enable debug log messages:

    import logging
    logging.basicConfig(level=logging.DEBUG)

See https://docs.python.org/3/library/logging.html for detailed usage
and https://docs.python.org/3/howto/logging-cookbook.html for additional examples.

If that's too much, maybe just this (or some version of this)?

NetworkX has debug logging which can be enabled to assist backend users and developers in
debugging (e.g. what backend is being used and what args are being passed) using the standard
python logging library.  See the Python docs on logging for usage and examples:

https://docs.python.org/3/library/logging.html
https://docs.python.org/3/howto/logging-cookbook.html

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your first example is certainly not too much: how to turn it on and a pointer to where to learn more.
And I like the second example's first sentence as an overview. Is this too much?

NetworkX has debug logging which can be enabled to assist backend users and developers in
debugging (e.g. what backend is being used and what args are being passed) using the standard
python logging library. Add the following code to enable debug log messages:

    import logging
    logging.basicConfig(level=logging.DEBUG)

See https://docs.python.org/3/library/logging.html for detailed usage
and https://docs.python.org/3/howto/logging-cookbook.html for additional examples.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only added the first link because the second link is very clearly available on the first link's page in a box with the heading "Important". And I also added the code for disabling the logging because that seemed like an important functionality and I thought it would be nice if someone doesn't have to go to an external link to find how it is done.

@Schefflera-Arboricola
Schefflera-Arboricola marked this pull request as ready for review June 3, 2024 12:09
@dschult
dschult self-requested a review June 3, 2024 15:30

@rlratzel rlratzel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very happy to see the new docs for backend developers and testing!

Comment thread networkx/utils/backends.py Resolved
Comment thread doc/reference/backends.rst Outdated
let you execute an alternative backend implementation instead of NetworkX's
pure Python dictionaries implementation. Things will almost certainly
change and break in future releases!
.. note:: Both NetworkX backend and config systems are experimental.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new separate sections in the code for backend users and backend developers, but people reading this doc may not see that and think backends should not be used for production code. Since this doc seems to be aimed at end users, my preference would be to remove this note completely.

Comment thread doc/reference/backends.rst Resolved

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready to merge. And we can change things moving forward in other PRs. It doesn't have to be a large rewrite -- but I think this fairly large change really set us on the right track and we can tweak it as needed more easily.

Comment thread doc/reference/backends.rst Resolved
Comment thread networkx/utils/backends.py Resolved

@eriknw eriknw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! Thanks everyone who helped with this, and especially @Schefflera-Arboricola who did most of the work 👍

@Schefflera-Arboricola

Copy link
Copy Markdown
Member Author

Is there a reason you approved it but haven't merged it @eriknw? @dschult already approved it, so it has 2 approvals. Do you want it to be reviewed by more people?

@eriknw
eriknw merged commit 546eea2 into networkx:main Jun 24, 2024
@jarrodmillman jarrodmillman added this to the 3.4 milestone Jun 24, 2024
@eriknw

eriknw commented Jun 24, 2024

Copy link
Copy Markdown
Contributor

Is there a reason you approved it but haven't merged it @eriknw? @dschult already approved it, so it has 2 approvals. Do you want it to be reviewed by more people?

Thanks for the gentle nudge! The main reason is that I'm still getting used to merging in this org 😂 . @rlratzel and I were also discussing this PR last week, and I wanted to give him a chance to review one last time (he did, and he approved).

Peiffap pushed a commit to Peiffap/networkx that referenced this pull request Jun 26, 2024
…tworkx#7404)

* refactoring and enhancing docs

* Update networkx/utils/backends.py

Co-authored-by: Dan Schult <[email protected]>

* wording change__

Co-authored-by: Dan Schult <[email protected]>

* Update configs.py

* added docs for logging

* renamed LoopbackDispatcher to LoopbackBackendInterface

* updated entry_point

* updated example

* updated logging example

* updated experimental note and divided docs into users and developers

* reverting renaming

* nx to networkx

Co-authored-by: Erik Welch <[email protected]>

* Update note

Co-authored-by: Erik Welch <[email protected]>

---------

Co-authored-by: Dan Schult <[email protected]>
Co-authored-by: Erik Welch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dispatching Related to dispatching and backend support type: Documentation

Development

Successfully merging this pull request may close these issues.

5 participants