Skip to content

Instantly share code, notes, and snippets.

@gerritjandebruin
Last active October 28, 2021 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerritjandebruin/6e6d15589a463de72c71b3b642bd6bbd to your computer and use it in GitHub Desktop.
Save gerritjandebruin/6e6d15589a463de72c71b3b642bd6bbd to your computer and use it in GitHub Desktop.
Teexgraph.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2-final"
},
"orig_nbformat": 2,
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"colab": {
"name": "Teexgraph.ipynb",
"provenance": [],
"include_colab_link": true
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/gerritjandebruin/6e6d15589a463de72c71b3b642bd6bbd/teexgraph.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "F5B363RXC2K8",
"colab_type": "code",
"colab": {}
},
"source": [
"import networkx as nx"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "BPyh6lP0C2LA",
"colab_type": "code",
"colab": {},
"outputId": "d991ace6-fd51-4fee-ab9c-d808c8af39c4"
},
"source": [
"# Install teexgraph\n",
"!git clone https://github.com/franktakes/teexgraph.git\n",
"!git reset --hard 0c4ebef4ee938aa842bf40d1aec8a66d95fd8a82\n",
"!(cd teexgraph/ && make listener)\n",
"!printf '%s\\n' 'load_undirected network.edges' 'dist_distri' > \"input.txt\""
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"Cloning into 'teexgraph'...\n",
"remote: Enumerating objects: 219, done.\u001b[K\n",
"remote: Total 219 (delta 0), reused 0 (delta 0), pack-reused 219\u001b[K\n",
"Receiving objects: 100% (219/219), 68.11 KiB | 0 bytes/s, done.\n",
"Resolving deltas: 100% (136/136), done.\n",
"g++ -Iinclude -pedantic -Wall -march=native -fopenmp -Drunlistener=1 -o src/listener.o -c src/listener.cpp\n",
"g++ -Iinclude -pedantic -Wall -march=native -fopenmp -Drunlistener=1 -o src/Graph.o -c src/Graph.cpp\n",
"g++ -Iinclude -pedantic -Wall -march=native -fopenmp -Drunlistener=1 -o src/examples.o -c src/examples.cpp\n",
"g++ -Iinclude -pedantic -Wall -march=native -fopenmp -Drunlistener=1 -o src/Timer.o -c src/Timer.cpp\n",
"g++ -Iinclude -pedantic -Wall -march=native -fopenmp -Drunlistener=1 -o src/CenGraph.o -c src/CenGraph.cpp\n",
"g++ -Iinclude -pedantic -Wall -march=native -fopenmp -Drunlistener=1 -o src/BDGraph.o -c src/BDGraph.cpp\n",
"g++ -Iinclude -pedantic -Wall -march=native -fopenmp -Drunlistener=1 -o src/main.o -c src/main.cpp\n",
"g++ -Iinclude -pedantic -Wall -march=native -fopenmp -Drunlistener=1 -o teexgraph src/listener.o src/Graph.o src/examples.o src/Timer.o src/CenGraph.o src/BDGraph.o src/main.o\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "n5zMnSF7C2LC",
"colab_type": "code",
"colab": {},
"outputId": "476c4de1-43f1-4b5a-c50e-1b131c5cd0eb"
},
"source": [
"g = nx.read_gpickle('network_ships.gpickle')\n",
"nx.write_edgelist(g, 'network.edges', data=False)\n",
"g.number_of_nodes()"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"8535"
]
},
"metadata": {
"tags": []
},
"execution_count": 7
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "IMnBj9U2C2LF",
"colab_type": "code",
"colab": {},
"outputId": "18f675e8-9fb0-4908-ef95-6e6a1e098801"
},
"source": [
"%%time\n",
"! ./teexgraph/teexgraph < input.txt > output.txt"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"*** Welcome to teexGraph ***\n",
"- Use standard input (cin) to give commands\n",
"- Read standard output (cout) to catch the result\n",
"- Observe standard log (clog) and (cerr) for status and error messages\n",
"- Graphs up to MAXN = 10000000 nodes are accepted\n",
"Input a command: Loading an undirected graph. Enter filename: \n",
"Loading graph from network.edges ...\n",
" - 10000000 edges loaded so far...\n",
"- 11226940 edges added (m = 11226940) in total\n",
"- 0 edges skipped\n",
"- 0 self-edges added\n",
"\n",
"Sorting edge list...\n",
"Sorting done.\n",
"Loading done.\n",
"\n",
"Making graph undirected (m = 11226940)...\n",
"Sorting edge list...\n",
"Sorting done.\n",
"Undirected-making done (m = 22453880).\n",
"Loading file succeeded.\n",
"WCC computed.\n",
"\n",
"> Computing distance distribution (based on a 100% sample of 8535 nodes) with 32 CPUs...\n",
" 0% 0%0% 0% 0% 0 0% 0% 0%0% 0% 0% 0% 0% 0% 0% 0%% 0%0% 0% 0%0% 0% 0% 0%0% 00%0%% 0% 0% 0% 5% 10% 15% 20% 25% 30% 35% 40% 45% 50% 55% 60% 65% 70% 75% 80% 85% 90% 95% Done.\n",
"Weighted total: 1.23512e+08, count: 7.28462e+07, average: 1.69552\n",
"Min-index: 0, max-index: 4, min-value: 2756, max-value: 50095736\n",
"> \n",
"End of program.\n",
"CPU times: user 3.37 s, sys: 616 ms, total: 3.98 s\n",
"Wall time: 3min 54s\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "3DjyorqhC2LI",
"colab_type": "code",
"colab": {},
"outputId": "a1f28f09-57df-48b1-c860-b5300eca26f7"
},
"source": [
"import pandas as pd \n",
"pd.read_csv('output.txt', '\\t', names=['distance', 'counts'])"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" distance counts\n",
"0 0 8535\n",
"1 1 22453880\n",
"2 2 50095736\n",
"3 3 285318\n",
"4 4 2756"
],
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>distance</th>\n",
" <th>counts</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>8535</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1</td>\n",
" <td>22453880</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2</td>\n",
" <td>50095736</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>3</td>\n",
" <td>285318</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>4</td>\n",
" <td>2756</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
]
},
"metadata": {
"tags": []
},
"execution_count": 13
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "o05tzeq8C2LL",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment