Repository navigation
Conversation
- _find_chordality_breaker: - clique_wanna_be = numbered.intersection(G[v]) avoids useless conversion set(G[v]); - try / except statement avoids call to _is_complete_graph; - _is_complete_graph: - removed function since its only call in the whole networkx package was in _find_chordality_breaker (checked with grep _is_complete_graph -R .); - _max_cardinality_node: - fixed typo in docstring; - number = len(wanna_connect.intersection(G[x])) avoids useless list comprehension;
|
It looks like the change to remove Can you try removing even more set creation e.g. for |
|
Using I hadn't had a look at the source code of (Side note: |
It may not improve computation time, but preventing the creation of another Collection can improve the overall memory footprint; even if it's not relevant except for very large, very dense graphs. In practice the best way to motivate performance-related enhancements1 is to add benchmarks so that others can formally and reliably reproduce timing results across various machines. Footnotes
|
|
Thanks for this! +1 on adding a benchmark
I recently learned that |
|
Duly noted, thanks. I made the change and will have a look at the benchmarks. |
rossbar
left a comment
There was a problem hiding this comment.
I've added some benchmarks in #8462 to help evaluate the performance impacts of these changes. The proposed changes increase computation time for larger graphs.
Benchmarking results
| Change | Before [c49a4359] main | After [bf1cd2c8] faster_chordality_verification | Ratio | Benchmark (Parameter) | |----------|----------------------------|-----------------------------------------------------|---------|----------------------------------------------------------------------| | + | 1.90±0.01ms | 3.35±0.02ms | 1.76 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_star(100) | | + | 612±1μs | 975±2μs | 1.59 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_star(50) | | + | 1.98±0.01ms | 2.48±0.03ms | 1.26 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_cycle_graph(100) | | + | 1.97±0.01ms | 2.47±0.01ms | 1.25 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_path(100) | | + | 621±5μs | 751±7μs | 1.21 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_path(50) | | + | 71.0±0.6μs | 85.9±0.2μs | 1.21 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_star(10) | | + | 630±3μs | 754±4μs | 1.2 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_cycle_graph(50) | | + | 32.6±0.1μs | 36.3±0.3μs | 1.11 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_star(5) | | - | 207±0.8μs | 174±2μs | 0.84 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_complete(10) | | - | 49.9±0.06μs | 40.4±0.3μs | 0.81 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_complete(5) | | - | 35.0±0.1μs | 28.0±0.2μs | 0.8 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_cycle_graph(5) | | - | 118±0.8μs | 90.9±0.3μs | 0.77 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_wheel(10) | | - | 51.4±0.2μs | 34.0±0.2μs | 0.66 | benchmark_chordal.ChordalBenchmarks.time_is_chordal_wheel(5) |SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE DECREASED.
The benchmarks can be run with asv continuous --bench ChordalBenchmarks main faster_chordality_verification
|
Given how this scales for graphs with larger cliques, I don't think this should go in as-is. At face value at least, it makes sense why the set-based approach works better than an iterative one as the number of nodes increases. However, there are at least two things I think are worth pursuing here:
Footnotes
|
|
You're right, this is disappointing. I can't think of ways to make this PR worth your time at the moment, I'll get back to it should fruitful ideas occur to me. |
No need to be disappointed - this was a very productive discussion and there are certainly a lot of opportunities to add/improve here! IMO this is an excellent example of a strong PR with a nice, clear motivation --- very helpful even if it doesn't go in as-is! I will go ahead and close this, if for no other reason than some of the changes inspired by this PR will create merge conflicts anyways. Please don't hesitate to open new PRs/issues! |
I made the following changes to
chordal.py:_find_chordality_breaker:clique_wanna_be = numbered.intersection(G[v])avoids useless conversionset(G[v]), sinceset.intersectionallows any iterable;try / exceptstatement avoids call to_is_complete_graph;_is_complete_graph:networkxpackage was in_find_chordality_breaker(checked withgrep _is_complete_graph -R .);_max_cardinality_node:number = len(wanna_connect.intersection(G[x]))avoids useless list comprehension;A few words about my choice for the
try / exceptbit (the rest is straightforward): I figured that the worst case for the algorithm would be the one where we had to repeatedly check whethersgis complete, so I decided instead to assume that it wasn't by trying to select an arbitrary missing edge from it, which if it exists can be obtained withnon_edges. If this fails, thennon_edgesraises aStopIterationerror, and then we know thatsgis complete.What happens in practice is not spectacular, but it's better than nothing (and I've only tested this on rather small graphs, because I don't have access to large ones). I tried recognising the first 20,000 chordal graphs on 11 vertices (there are too many to recognise them all), and this is the difference in running time that my benchmark yields:
(benchmark is attached, as well as the zipped dataset; if you don't trust this file, you can generate the dataset
chordal-connected-11.g6.zip
yourself using
nauty-geng -cT 11 > chordal-connected-11.g6).Note: it is possible that some of these improvements can be applied to other functions in
chordal.py. I haven't checked yet.bench_chordal.py