Skip to main content

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 in a digraph, to python.

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.

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.

<<<<<<< HEAD

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.

Usage

With g being a (directed) graph without self-loops, run:

292bacd50a0689a684345889fa025014d47268f3

<<<<<<< HEAD
g++ -march=native -O3 -Wall -Werror --shared -std=c++14 -fPIC `python3 -m pybind11 --includes` src/nads_bindings.cpp -o pynads/nads_bind`python3-config --extension-suffix`

in the top folder.

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`. 
>>>>>>> 292bacd50a0689a684345889fa025014d47268f3


## 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

pynads-0.1.5.linux-x86_64.tar.gz (123.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynads-0.1.5-py3-none-any.whl (123.6 kB view details)

Uploaded Python 3

File details

Details for the file pynads-0.1.5.linux-x86_64.tar.gz.

File metadata

  • Download URL: pynads-0.1.5.linux-x86_64.tar.gz
  • Upload date:
  • Size: 123.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.2 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pynads-0.1.5.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 eeda21da46d8fb0c00df5fd75102b3dccef6df7d04cd8232138ee17a0b88da84
MD5 a201da0521546135eb0cdc8c478eff2a
BLAKE2b-256 324b4819cfef1e158cb5b71330f7e05841cd6fc2ea4af3a616096f66a10e4398

See more details on using hashes here.

File details

Details for the file pynads-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pynads-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 123.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.2 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pynads-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 792d24890c1e046b4764a24f7e866b9d0f1edcec9b15a65f612111bae534d3ae
MD5 681086c621bb1189af364ce7644bd02c
BLAKE2b-256 1f8ee4233785a2f36dc6837b6ca23f84ab915c2e8e619fc08a2baa758f4d92b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page