Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/add-better-error-messege-edges-g…
Browse files Browse the repository at this point in the history
…etitem' into add-better-error-messege-edges-getitem
  • Loading branch information
finsberg committed Mar 6, 2024
2 parents 3fc2676 + 93f46f6 commit c956934
Show file tree
Hide file tree
Showing 215 changed files with 4,367 additions and 2,234 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ be23fa0e422b51f4526828cb19b8105c89e5dcbb
5c0b11afb4c0882a070d522ef3fa41482ba935d3
5fcf01b9a43a097c4f579486023d1279b2b88619
7297ae8a37dd3356b64d383cb0c55735a6364bcc
3c0f096f66ab352cfaf8dbe2d5fc5731cbbc4338
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ updates:
directory: "/"
schedule:
interval: "monthly"
groups:
actions:
patterns:
- "*"
labels:
- "type: Maintenance"
- package-ecosystem: "pip"
Expand Down
117 changes: 117 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
### Inspired from https://github.com/scikit-image/scikit-image/blob/main/.github/workflows/benchmarks.yml

name: Benchmark PR
on:
pull_request:
types: [labeled, synchronize]

jobs:
## This code below is to make sure a new commit on a PR with the label
## retriggers the benchmark, otherwise the label needs to be removed and
## applied again to run the benchmark.
check:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.check.outputs.result }}
steps:
- uses: actions/checkout@v4

- uses: actions/github-script@v7
name: Check for benchmark label and new commit
id: check
with:
script: |
const { owner, repo, number: pull_number } = context.issue;
// Check for label
const { data: pullRequest } = await github.rest.pulls.get({ owner, repo, pull_number });
if (!pullRequest.labels.some(({ name }) => name === 'run:benchmark')) {
return false;
}
// Check for repo name and organization name
const { data: repository } = await github.rest.repos.get({ owner, repo });
return repository.name === 'networkx' && repository.owner.login === 'networkx';
benchmark:
needs: check
if: ${{ needs.check.outputs.result == 'true' }}
# if: contains(github.event.pull_request.labels.*.name, 'run:benchmark') || ${{ github.event.label.name == 'run:benchmark' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Setup some dependencies
shell: bash -l {0}
run: |
sudo apt-get update -y && sudo apt-get install -y ccache
# Make gcc/gxx symlinks first in path
sudo /usr/sbin/update-ccache-symlinks
echo "/usr/lib/ccache" >> $GITHUB_PATH
- name: "Prepare ccache"
id: prepare-ccache
shell: bash -l {0}
run: |
echo "key=benchmark-$RUNNER_OS" >> $GITHUB_OUTPUT
echo "timestamp=$(date +%Y%m%d-%H%M%S)" >> $GITHUB_OUTPUT
ccache -p
ccache -z
- name: "Restore ccache"
uses: actions/cache@v3
with:
path: .ccache
key: ccache-${{ secrets.CACHE_VERSION }}-${{ steps.prepare-ccache.outputs.key }}-${{ steps.prepare-ccache.outputs.timestamp }}
restore-keys: |
ccache-${{ secrets.CACHE_VERSION }}-${{ steps.prepare-ccache.outputs.key }}-
- name: Install packages
run: |
pip install --upgrade pip
pip install -r requirements/default.txt
pip install .
pip list
- name: Run benchmarks
shell: bash -l {0}
id: benchmark
env:
ASV_FACTOR: 1.5
ASV_SKIP_SLOW: 1
run: |
set -x
python -m pip install asv virtualenv packaging
cd benchmarks/
# ID this runner
python -m asv machine --yes --conf asv.conf.json
echo "Baseline: ${{ github.event.pull_request.base.sha }} (${{ github.event.pull_request.base.label }})"
echo "Contender: ${GITHUB_SHA} (${{ github.event.pull_request.head.label }})"
# Run benchmarks for current commit against base
ASV_OPTIONS="--split --show-stderr --factor $ASV_FACTOR --conf asv.conf.json"
python -m asv continuous $ASV_OPTIONS ${{ github.event.pull_request.base.sha }} ${GITHUB_SHA} \
| sed "/Traceback \|failed$\|PERFORMANCE DECREASED/ s/^/::error::/" \
| tee benchmarks.log
# Report and export results for subsequent steps
if grep "Traceback \|failed\|PERFORMANCE DECREASED" benchmarks.log > /dev/null ; then
exit 1
fi
- name: "Check ccache performance"
shell: bash -l {0}
run: ccache -s
if: always()

- uses: actions/upload-artifact@v4
if: always()
with:
name: asv-benchmark-results-${{ runner.os }}
path: benchmarks.log
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: List contents of wheel
run: python -m zipfile --list dist/networkx-*.whl
- name: Upload nighlty wheel
uses: scientific-python/upload-nightly-action@5fb764c5bce1ac2297084c0f7161b1919f17c74f # 0.2.0
uses: scientific-python/upload-nightly-action@b67d7fcc0396e1128a474d1ab2b48aa94680f9fc # 0.5.0
with:
anaconda_nightly_upload_token: ${{ secrets.ANACONDA_NIGHTLY }}
artifacts_path: dist/
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
# pre-commit install

repos:
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ Development Workflow
# Test your installation
pytest --pyargs networkx

* Finally, we recommend you use a pre-commit hook, which runs black when
you type ``git commit``::
* Finally, we recommend you install pre-commit which checks
that your code matches formatting guidelines::

pre-commit install

Expand Down
51 changes: 51 additions & 0 deletions benchmarks/benchmarks/benchmark_neighbors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import networkx as nx


# NOTE: explicit set construction in benchmarks is required for meaningful
# comparisons due to change in return type from generator -> set. See gh-7244.
class NonNeighbors:
param_names = ["num_nodes"]
params = [10, 100, 1000]

def setup(self, num_nodes):
self.star_graph = nx.star_graph(num_nodes)
self.complete_graph = nx.complete_graph(num_nodes)
self.path_graph = nx.path_graph(num_nodes)

def time_star_center(self, num_nodes):
set(nx.non_neighbors(self.star_graph, 0))

def time_star_rim(self, num_nodes):
set(nx.non_neighbors(self.star_graph, 5))

def time_complete(self, num_nodes):
set(nx.non_neighbors(self.complete_graph, 0))

def time_path_first(self, num_nodes):
set(nx.non_neighbors(self.path_graph, 0))

def time_path_last(self, num_nodes):
set(nx.non_neighbors(self.path_graph, num_nodes - 1))

def time_path_center(self, num_nodes):
set(nx.non_neighbors(self.path_graph, num_nodes // 2))


# NOTE: explicit set construction in benchmarks is required for meaningful
# comparisons due to change in return type from generator -> set. See gh-7244.
class CommonNeighbors:
param_names = ["num_nodes"]
params = [10, 100, 1000]

def setup(self, num_nodes):
self.star_graph = nx.star_graph(num_nodes)
self.complete_graph = nx.complete_graph(num_nodes)

def time_star_center_rim(self, num_nodes):
set(nx.common_neighbors(self.star_graph, 0, num_nodes // 2))

def time_star_rim_rim(self, num_nodes):
set(nx.common_neighbors(self.star_graph, 4, 5))

def time_complete(self, num_nodes):
set(nx.common_neighbors(self.complete_graph, 0, num_nodes // 2))
10 changes: 7 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx_gallery.gen_gallery",
"nb2plots",
"texext",
"numpydoc",
"matplotlib.sphinxext.plot_directive",
"myst_nb",
]

# https://github.com/sphinx-gallery/sphinx-gallery
Expand Down Expand Up @@ -77,8 +77,9 @@
# The encoding of source files.
source_encoding = "utf-8"

# Do not include release announcement template
exclude_patterns = ["release/release_template.rst"]
# Items to exclude during source collection, including release announcement
# template, build outputs, and READMEs (markdown only)
exclude_patterns = ["release/release_template.rst", "build/*", "README.md"]

# General substitutions.
project = "NetworkX"
Expand Down Expand Up @@ -258,6 +259,9 @@
def setup(app):
app.add_css_file("custom.css")
app.add_js_file("copybutton.js")
# Workaround to prevent duplicate file warnings from sphinx w/ myst-nb.
# See executablebooks/MyST-NB#363
app.registry.source_suffix.pop(".ipynb")


# Monkeypatch numpydoc to show "Backends" section
Expand Down
3 changes: 3 additions & 0 deletions doc/developer/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ Version 3.5
to return a dict. See #6527
* Change ``shortest_path`` in ``algorithms/shortest_path/generic.py``
to return a iterator. See #6527
* Remove ``total_spanning_tree_weight`` from ``linalg/laplacianmatrix.py``
* Remove ``create`` keyword argument from ``nonisomorphic_trees`` in
``generators/nonisomorphic_trees``.
8 changes: 8 additions & 0 deletions doc/reference/algorithms/assortativity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Assortativity
.. autosummary::
:toctree: generated/

.. _networkx.algorithms.assortativity.correlation:

Assortativity
-------------
.. autosummary::
Expand All @@ -16,13 +18,16 @@ Assortativity
numeric_assortativity_coefficient
degree_pearson_correlation_coefficient

.. _networkx.algorithms.assortativity.neighbor_degree:

Average neighbor degree
-----------------------
.. autosummary::
:toctree: generated/

average_neighbor_degree

.. _networkx.algorithms.assortativity.connectivity:

Average degree connectivity
---------------------------
Expand All @@ -31,6 +36,7 @@ Average degree connectivity

average_degree_connectivity

.. _networkx.algorithms.assortativity.mixing:

Mixing
------
Expand All @@ -43,6 +49,8 @@ Mixing
degree_mixing_dict
mixing_dict

.. _networkx.algorithms.assortativity.pairs:

Pairs
-----
.. autosummary::
Expand Down

0 comments on commit c956934

Please sign in to comment.