Repository navigation
Add config option to disable warning when using cached value - #7497
Conversation
The warning was updated to show how to use the config setting.
|
When the first caching warning shows up, the user no longer knows about caching (caching is "on" by default now -- they used to have to be turned on so the user knew they were doing that). So the current message does not start well for its new placement. Can we change the first sentence to something like: |
|
And now that I said that, I'm not sure that this PR makes caching turned on by default. Is caching turned on by default? |
#7498 enables the cache by default. I can merge the two PRs to consider them simultaneously. I'll see about updating the first sentence and will resolve the merge conflict. |
What's wrong with starting with Your suggested intro doesn't make sense here--we are not actually doing the conversion. Do you want to add a warning message when values are added to the cache? This is something that should be more clear via introspection and/or logging. There are a few other key points in the warning message that we can consider reorganizing if you'd like:
|
|
I think I just don't have it straight in my head when this message gets shown. If caching the graph conversions is turned on by default, then I think it is shown the first time a user calls a function that checks the cache (the first time they call a function that could cache a converted graph). That means a user reads about backends somewhere, installs cugraph or another backend and tries it. They get the warning. But they don't know anything about caching yet. As far as they know, they just turned on the backend. And now they are getting a warning about caching being done. When caching is not turned on by default, then the user has to install the backend, play around a bit, find out about caching and turn it on, and that's when they get the warning message. So they know that caching is a thing when they get the message. I was just thinking that if the user hasn't heard about caching before, we should introduce it slightly at the start of the warning. |
| warning_message = ( | ||
| f"Using cached graph for {backend_name!r} backend in " | ||
| "Note: conversions to backend graphs are saved to cache " | ||
| "(`G.__networkx_cache__` on the original graph) by default." |
There was a problem hiding this comment.
I know this isn't the first time we've documented __networkx_cache__ but do we want to advertise our "private" members? Would it be better to just add a well-named property for formally inspecting things like the state of the cache now and document that? That would give us the freedom to possibly change things related to caching later without breaking docs/users.
OTOH, keeping it a dunder makes it obvious to a user that it's not related to "their graph" (IOW, it's NX bookkeeping and not user data), so I could go either way. I think I'm leaning toward making it a property though.
There was a problem hiding this comment.
I don't understand this suggestion, or maybe I just don't agree with it. Dunders aren't private. x.foo is public, x._foo is an implementation detail, x.__foo is private (and mangled), and x.__foo__ is a dunder. Dunder methods are different. They are good for protocols, even if the protocol is simply "here there be caching". I think it is helpful to indicate that the cache exists on the object, which is why I advertise it.
I think introducing e.g. G.cache is out of scope for this PR. Similarly, helper functions for working with the cache is another thing I think we've discussed (not today, but other days) could make sense, and when we have them we can update this message.
In other words, I don't think this feedback is actionable for this PR, but is something we can be aware of and discuss (and perhaps track) elsewhere.
| cache_converted_graphs=bool(os.environ.get("NETWORKX_CACHE_CONVERTED_GRAPHS", "")), | ||
| warnings={ | ||
| x.strip() | ||
| for x in os.environ.get("NETWORKX_WARNINGS", "cache").split(",") |
There was a problem hiding this comment.
Is this a new env var? I didn't notice it documented anywhere. Am I interpreting it right that you add a comma-separated list of "things" to ignore warnings for? If so, it seems like the name should be something more like NETWORK_WARNINGS_TO_DISCARD or something like that but better.
There was a problem hiding this comment.
Looks like I misinterpreted this and NETWORKX_WARNINGS is a list of things/categories for which warnings should be shown. I'm assuming this is then used to override configuration settings that have certain warnings disabled?
Either way, can you also update the docstring for NetworkXConfig to include this new env var to the list of existing env vars here?
There was a problem hiding this comment.
Yes, the set is positive, not negative. Do you think we should change it to be negative?
The docstring is already updated. Do you mean to update docs somewhere else?
There was a problem hiding this comment.
What about something like NETWORKX_WARNINGS_TO_IGNORE and/or nx.config.warnings_to_ignore? Is this more convenient to use? Would we also want to keep the current nx.config.warnings and to keep warnings and warnings_to_ignore consistent such that warnings ^ warnings_to_ignore == set() and warnings | warnings_to_ignore == all_warnings? When using environment variables, I do think choosing which ones to ignore is more convenient, but from Python I prefer nx.config.warnings.
Alternatively, is there a good name for a boolean config to enable/disable the specific warning about caching (i.e., to not use a more generic nx.config.warning approach)?
|
I changed the config to |
Co-authored-by: Dan Schult <[email protected]>
…x#7574) Fix installation instructions for default extras
The warning was updated to show how to use the config setting:
Here is a way to ignore this warning using
warningsmodule:There are a lot of options for how to spell and codify this behavior. I'm not sure what would be best, so this PR is an initial proposal. It can also generalize for other warnings if desired.
CC @rlratzel