Python bindings to `nads`, a C++ number-of-almost-d-simplices computer
Project description
What is this?
The packacke pynads binds nads, a C++ implementation that computes the number of almosts-d-simplices.
almost-d-simplices
In a nutshell:
Assume you have directed unweighted graph G=(V,E). Then a d-clique are d vertices, where each vertex is directly connected (in one direction or another) to all others. A d-simplex is then a (d+1)-clique without any loops.
An almost-d-simplex is then a collection of vertices and edges which miss exactly one edge in order to form a d-simplex.
It is formally described as a triplet (s,s',e), where s,s' are two different (d-1)-simplices which share a common (d-2)-simplex, together with an edge e that indicates the missing edge necessary to form a d-simplex.
An example: Three vertices V={0,1,2} have the edges E={(0,1),(0,2)}. Then this is not enough to form a 2-simplex: Either an edge e=(1,2) or e=(2,1) is missing. Thus, with s=[0,1] and s'=[0,2] we have the two almost-2-simplices (s,s',e) and (s,s',e').
Furthermore: Any d-simplex gives rise to (d^2+d)/2 almost-d-simplices. That is exactly the number of edges in a d-simplex.
Some people (e.g. me) find the number of almost-d-simplices in a big graph interesting.
Performance
This package allows one to calculate this numbers on sparse graphs in a highly efficient manner, thanks to the substantially optimised underlying C++ implementation.
As an example: The connectome of the "The Neocortical Microcircuit Collaboration Portal" https://bbp.epfl.ch/nmc-portal/welcome consists of ~30k vertices and 8M edges, connected in a nonrandom manner. pynads computes the number of almost-di-simplices for all dimensions in less than three minutes on a desktop CPU.
This is notably faster than my previous native-python implementation, which would have computed for a month at least.
TODO: Write paper/doku in LaTex.
Installation
pip install pynads should be enough.
Usage
With g being a (directed) graph without self-loops, run:
from pynads import nads
res = nads(g)
This results in a list of Integers res: Each entry res[i] corresponds to the number of almost-(i+2)-simplices found
in the graph g.
Compiling C++ code with -march=native for higher performance:
Advanced users my generate their own nads_bind.$PYTHON_VERSION.so which is probably faster on their own CPU, compared
to the generice x86-64 package delivered with pynads for each of use. On my setup this results in ~15% faster code.
To do this, get pybind11 (via github/pip) and run the following line of code
g++ -march=native -O3 -Wall -Werror --shared -std=c++14 -fPIC `python3 -m pybind11 --includes` nads_bindings.cpp -o nads_bind`python3-config --extension-suffix
in the folder nads/. Then move the shared lib in the same folder where pynads.py resides.
ToDo:
-[ ] Automate build process for architecture optimized library as described above.
-[ ] Write a paper about the algorithm and link it in the documentation
-[ ] Write a few tests or something
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pynads-0.1.4.tar.gz.
File metadata
- Download URL: pynads-0.1.4.tar.gz
- Upload date:
- Size: 124.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
987031ef2dc0532e3a233e19bd72a3985574ca730deca14c0e17136cf33f07f8
|
|
| MD5 |
fd7d97f0ebb5c3471ede11021fc65e78
|
|
| BLAKE2b-256 |
a3e365e84da38a6c4e432efe72de03efc534979c434be65bbb999ad5cec02c20
|
File details
Details for the file pynads-0.1.4-py3-none-any.whl.
File metadata
- Download URL: pynads-0.1.4-py3-none-any.whl
- Upload date:
- Size: 123.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac1f74cf21d589f446316d19d79e79d407fbbf051dadb3875f5fe4fdd27b3e46
|
|
| MD5 |
0c5bf149a2b983ebd27b48f7c3c45a15
|
|
| BLAKE2b-256 |
23fece3d00bf3fd27bdc1b413d85abb2c3cabce278dac44c898e71f6fafc9b5a
|