Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass out nodes in a specific order #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
with:
target: x86_64
args: --release --out dist --sdist
maturin-version: "v0.13.0"
maturin-version: "v0.14.13"
- name: Install built wheel - x86_64
run: |
pip install dist/${{ env.PACKAGE_NAME }}-*.whl --force-reinstall
Expand All @@ -44,7 +44,7 @@ jobs:
uses: messense/maturin-action@v1
with:
args: --release --universal2 --out dist
maturin-version: "v0.13.0"
maturin-version: "v0.14.13"
- name: Install built wheel - universal2
run: |
pip install dist/${{ env.PACKAGE_NAME }}-*universal2.whl --force-reinstall
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
with:
target: ${{ matrix.target }}
args: --release --out dist
maturin-version: "v0.13.0"
maturin-version: "v0.14.13"
- name: Install built wheel
shell: bash
run: |
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
target: ${{ matrix.target }}
manylinux: auto
args: --release --out dist
maturin-version: "v0.13.0"
maturin-version: "v0.14.13"
- name: Install built wheel
if: matrix.target == 'x86_64'
run: |
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
target: ${{ matrix.target }}
manylinux: auto
args: --release --out dist
maturin-version: "v0.13.0"
maturin-version: "v0.14.13"
- uses: uraimo/[email protected]
if: matrix.target != 'ppc64'
name: Install built wheel
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
target: ${{ matrix.target }}
manylinux: musllinux_1_2
args: --release --out dist
maturin-version: "v0.13.0"
maturin-version: "v0.14.13"
- name: Install built wheel
if: matrix.target == 'x86_64-unknown-linux-musl'
uses: addnab/docker-run-action@v3
Expand Down Expand Up @@ -216,7 +216,7 @@ jobs:
target: ${{ matrix.platform.target }}
manylinux: musllinux_1_2
args: --release --out dist
maturin-version: "v0.13.0"
maturin-version: "v0.14.13"
- uses: uraimo/run-on-arch-action@master
name: Install built wheel
with:
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:
- name: Build wheels
uses: messense/maturin-action@v1
with:
maturin-version: "v0.13.0"
maturin-version: "v0.14.13"
target: ${{ matrix.target }}
manylinux: auto
args: --release --out dist -i pypy${{ matrix.python-version }}
Expand Down
16 changes: 5 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
files: ^python/.*|^tests/.*|^src/.*
repos:
- repo: https://github.com/ambv/black
rev: 22.3.0
rev: 23.1.0
hooks:
- id: black
- repo: local
Expand All @@ -18,22 +18,16 @@ repos:
language: system
types: [rust]
pass_filenames: false
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
args: ["--max-line-length=88"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.950
rev: v1.0.0
hooks:
- id: mypy
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
rev: 5.10.1
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.247'
hooks:
- id: isort
name: isort (python)
- id: ruff
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[package]
name = "graphlib2"
version = "0.4.7"
name = "_graphlib2"
version = "0.4.8"
edition = "2021"
description = "Rust port of the Python stdlib graphlib modules"
readme = "README.md"
license-file = "LICENSE.txt"

Expand All @@ -15,6 +14,4 @@ version = "^0.17.2"
features = ["extension-module", "abi3-py37"]

[package.metadata.maturin]
python-source = "python"
description-content-type = "text/markdown; charset=UTF-8; variant=GFM"
name = "graphlib2._graphlib2"
17 changes: 14 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@ documentation = "https://github.com/adriangb/graphlib2/README.md"
repository = "https://github.com/adriangb/graphlib2"

[build-system]
requires = ["maturin>=0.13.0<14"]
requires = ["maturin>=0.14.0,<0.15.0"]
build-backend = "maturin"

[tool.maturin]
sdist-include = ["Cargo.lock"]
strip = true
python-source = "python"
profile = "release"

[tool.isort]
profile = "black"

[tool.ruff]
extend-select = [
"RUF100", # dissallow unused # noqa comments
"I001", # isort
]
ignore = [
"E501", # leave line lengths up to black
"E402", # leave imports up to isort
"E731", # assigning lambdas is convenient
]
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pytest==6.2.5
maturin>=0.13.0<14
maturin>=0.14.0,<0.15.0
pre-commit==2.16.0
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ impl PreparedState {
fn get_ready<'py>(&mut self, py: Python<'py>) -> &'py PyTuple {
let id2node = &self.dag.id2node;
self.n_passed_out += self.ready_nodes.len();
// Pass out nodes ordered by most to least
self.ready_nodes
.sort_unstable_by_key(|node| -(self.dag.parents[*node].len() as i64));
PyTuple::new(
py,
self.ready_nodes
Expand Down
19 changes: 19 additions & 0 deletions test_graphlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,24 @@ def run(ts: graphlib.TopologicalSorter[int]) -> None:
assert not ts.is_active()


def test_ready_ordered_by_number_of_upstream() -> None:
"""Ready nodes should be passed out such that if
they are processed in order and done() is called on nodes individually
we optimize unblocking more tasks so that we can saturate the
threads / tasks / etc. that we have.
"""
graphs = [
{0: [], 1: [], 2: [1], 3: [1]},
{ 1: [], 0: [], 2: [1], 3: [1]},
]
for graph in graphs:
ts: graphlib.TopologicalSorter[int] = graphlib.TopologicalSorter()
for node in graph:
ts.add(node, *graph[node])
ts.prepare()
assert list(ts.get_ready()) == [1, 0]



if __name__ == "__main__":
pytest.main([__file__,])