Repository navigation
Conversation
This is like doing `backend=...` when calling a dispatchable function.
|
I'm in favor of this idea since it makes it easy for a user to essentially say "I want strict and exclusive use of this one backend, and an error if that can't be done" without changing each algo call to specify that using However, I'm having a bit of trouble envisioning myself explaining the difference between the config options |
Suggestions? I can't think of anything better. @jim22k any ideas? |
We can just have one |
Schefflera-Arboricola
left a comment
There was a problem hiding this comment.
I have been thinking about these context managers and how we could potentially combine the context manager introduced in PR #7363 with this one. This combination could simplify the usage of nx.config in a more cohesive manner.
So, something like this:
with nx.config(backend=backend_name, *backend_args, **backend_kwargs):
# nx codeThis approach leverages the flexibility introduced in PR #7363 and could make setting configurations more intuitive, I think, especially when dealing with different backends. Your thoughts on this would be greatly appreciated. Thank you :)
|
Interesting and fun idea @Schefflera-Arboricola! So, this can be a generalization to add keyword arguments to dispatchable calls such that adding a specific with nx.config(backend=backend_name):
...
with nx.config(backend="parallel", get_chunks=chunks):
...
with nx.config(parallel_kwargs={"get_chunks": chunks}, cugraph_kwargs={"dtype": "float32"}):
...The latter example requires #7297. This is pretty nice. I don't think baking in with nx.config(G):
cc = nx.connected_components()
pr = nx.pagerank()The main pro of baking in Another pro is that this may in some ways avoid the confusion that @rlratzel raised by having both Another con (for the purists!) may be that this usage mixes configuration items with keyword arguments. In practice, merging name spaces like this is often pragmatic and fine. Two more question:
For example for (1): with nx.config(chunks=7) as cfg:
assert cfg.kwargs == {"chunks": 7} # ??? or some other way? |
|
I began experimenting with this in #7528. Fortunately, with nx.config(G=G):
cc = nx.connected_components() # raises, hooray!
pr = nx.pagerank()so this really ought to be used for backend kwargs as originally suggested. I'm still torn whether to have |
|
Really sorry, I didn't mean this
I wanted to suggest with nx.config(backend=backend_name, backend_configs):
# nx codeSo, this way the backend and the backend configs will be in the same context manager. And if you want to include the suggestion above . This one:
Then backend_configs will be either a dict or list of dicts or a dict of dicts with nx.config(backend=parallel, backend_configs={"n_jobs":6}):
# nx codeOr with nx.config(backend=[cugraph, parallel], backend_configs=[{"cugraph_config_param": "xyz"},{"n_jobs"=6}]:
# nx codeOr with nx.config(backend=[cugraph, parallel], backend_configs={{"cugraph" : {"cugraph_config_param": "xyz"}, "parallel" : {"n_jobs"=6}}:
# nx codeReally sorry for the confusion. |
|
I see, thanks for clarifying @Schefflera-Arboricola. I think I understand now. Let me respond to your previous suggestion first, which we also discussed briefly in our weekly meetings:
I'm -1 on this. I think this introduces complexity. I don't like having different behaviors based on the type of something. Generally, I would prefer to have two simple things than one complicated thing. And I think If I understand your latest idea, you are discussing adding Naming things is also hard, and So, if I may, I'd like to respond to my own criticisms and compare two approaches:
with nx.config(backend="parallel", extra_kwargs={"n_jobs": 16}):
... # 1
with nx.config(backend="parallel", n_jobs=16):
... # 2and with nx.config(
backend_priority=["cugraph", "parallel"],
extra_kwargs={
"cugraph_kwargs": {"dtype": "float32"},
"parallel_kwargs": {"n_jobs": 16},
},
):
... # 1
with nx.config(
backend_priority=["cugraph", "parallel"],
cugraph_kwargs={"dtype": "float32"},
parallel_kwargs={"n_jobs": 16},
):
... # 2I really appreciate this discussion @Schefflera-Arboricola. In general, I'm glad we've been taking a careful, incremental approach around dispatching. We all have different perspectives and sensibilities, and I think we build better things when we consider each other and explore possibilities! |
|
Continuing to experiment... #7528 now has a |
This is like doing
backend=...when calling a dispatchable function.I think this will be especially nice when combined with #7363, which will let us set it within a context:
Thanks to @seberg for this idea!
CC @rlratzel