Last active
August 14, 2024 09:12
-
-
Save eriknw/e1e9c9ceea3aa09855c8d1bc69d5d8bf to your computer and use it in GitHub Desktop.
Fallback to NetworkX examples for https://github.com/networkx/networkx/pull/7585
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "edcc97a6-fab5-4f73-8c6a-fba3c6e1786f", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import contextlib\n", | |
"import logging\n", | |
"import sys\n", | |
"import warnings\n", | |
"\n", | |
"import networkx as nx\n", | |
"import graphblas_algorithms as ga\n", | |
"import nx_pandas_graph as nxpdg\n", | |
"import nx_pandas_graph.classes\n", | |
"\n", | |
"# Sometimes it's nice to enable this to see caching log messages\n", | |
"nx.config.cache_converted_graphs = False\n", | |
"\n", | |
"nxl = logging.getLogger(\"networkx\")\n", | |
"nxl.addHandler(logging.StreamHandler())\n", | |
"nxl.setLevel(logging.DEBUG)\n", | |
"\n", | |
"warnings.filterwarnings('ignore', 'Using cached graph', UserWarning, \"networkx.utils.backends\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "18e15012-bef7-4a93-8efb-83df1057fae8", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"@contextlib.contextmanager\n", | |
"def raises(exc):\n", | |
" try:\n", | |
" yield\n", | |
" except exc as exc2:\n", | |
" print(flush=True)\n", | |
" print(f\"{type(exc2).__name__}:\", *exc2.args, file=sys.stderr)\n", | |
" else:\n", | |
" raise RuntimeError(f\"Did not raise {exc}!\")\n", | |
"\n", | |
"G = nx.complete_graph(3)\n", | |
"Ggb = ga.classes.Graph.from_networkx(G)\n", | |
"Gpd = nxpdg.classes.Graph(G)\n", | |
"MG = nx.complete_graph(3, create_using=nx.MultiGraph)\n", | |
"MGgb = ga.classes.MultiGraph.from_networkx(MG)\n", | |
"MGpd = nxpdg.classes.MultiGraph(MG)\n", | |
"Gbad = type(\"Gbad\", (), {\"__networkx_backend__\": \"bad\"})() # An object for a backend that is not installed?!" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "a51647d4-6fa8-4066-a379-deb2fcb2008e", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Converting input graphs from 'graphblas' backend to 'networkx' backend for call to `pagerank'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"{0: 0.3333333333333333, 1: 0.3333333333333333, 2: 0.3333333333333333}" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs backend graph\n", | |
"# Config: run with networkx via `backend=`\n", | |
"# Result: convert and run with networkx\n", | |
"\n", | |
"nx.pagerank(Ggb, backend=\"networkx\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "e5b7ff1d-1bd0-4ffa-bea6-73769c018219", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from multiple backends, {'graphblas', 'pandas_graph'}, that have no priority set in `nx.config.backend_priority` or `nx.config.backend_fallback`, so automatic conversions to these backends will not be attempted.\n", | |
"Converting input graphs from {'graphblas', 'pandas_graph'} backends to 'networkx' backend for call to `compose'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.graph.Graph at 0x7f2105f7d7f0>" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: graphs from multiple backends\n", | |
"# Config: auto-networkx\n", | |
"# Result: convert and run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"networkx\"]\n", | |
"nx.algorithms.binary.compose(Gpd, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"id": "671cbb21-2972-4340-98a3-fb715ff2e0fa", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'graphblas', 'pandas_graph'} backends, and will try to use backends in the following order: ['graphblas', 'networkx', 'pandas_graph']\n", | |
"Unable to convert from {'graphblas', 'pandas_graph'} backends to 'graphblas' backend\n", | |
"Trying next backend: 'networkx'\n", | |
"Converting input graphs from {'graphblas', 'pandas_graph'} backends to 'networkx' backend for call to `compose'\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Graph with 3 nodes and 3 edges\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: graphs from multiple backends\n", | |
"# Config: auto-networkx then auto-backend\n", | |
"# Result: convert and run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"networkx\", \"graphblas\"]\n", | |
"print(nx.algorithms.binary.compose(Gpd, Ggb))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "69398b1b-0102-4ec1-8736-fd0bba300c7b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from multiple backends, {'graphblas', 'pandas_graph'}, that have no priority set in `nx.config.backend_priority` or `nx.config.backend_fallback`, so automatic conversions to these backends will not be attempted.\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"TypeError: Unable to convert inputs from {'graphblas', 'pandas_graph'} backends and run `compose'. NetworkX is configured to automatically convert to [] backends. To remedy this, you may enable automatic conversion to {'graphblas', 'pandas_graph'} backends by adding them to `nx.config.backend_priority` or `nx.config.backend_fallback`, or you may specify a backend to use with the `backend=` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: multiple backends\n", | |
"# Config: no auto, no fallback\n", | |
"# Result: TypeError; suggest how to use backend_priority\n", | |
"\n", | |
"nx.config.backend_priority.compose = []\n", | |
"nx.config.backend_fallback.compose = []\n", | |
"with raises(TypeError):\n", | |
" nx.algorithms.binary.compose(Gpd, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"id": "bbe28a7f-511a-4c6c-b592-10ca4e356956", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Unable to convert from {'pandas_graph'} backends to 'graphblas' backend\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"TypeError: `pagerank' is unable to convert graph from backend 'pandas_graph' to 'graphblas' backend, which was specified with the `backend='graphblas'` keyword argument. No other backends will be attempted, because the backend was specified with the `backend='graphblas'` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph\n", | |
"# Config: run with different backend via `backend=`\n", | |
"# Result: TypeError, because backend-to-backend conversions is not yet supported\n", | |
"\n", | |
"with raises(TypeError):\n", | |
" nx.pagerank(Gpd, backend=\"graphblas\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "39beb7e6-0c07-42eb-8d2a-ea358656564a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `pagerank' has inputs from {'bad'} backends, and will try to use backends in the following order: ['bad', 'networkx']\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"ImportError: 'bad' backend is not installed\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: unknown backend graph\n", | |
"# Config: N/A\n", | |
"# Result: ImportError; nudge user to check their environment\n", | |
"\n", | |
"with raises(ImportError):\n", | |
" nx.pagerank(Gbad)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"id": "7fd73c79-ae83-4b22-8659-88328d33465c", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'graphblas', 'networkx'} backends, and will try to use backends in the following order: ['networkx', 'graphblas']\n", | |
"Converting input graphs from 'graphblas' backend to 'networkx' backend for call to `compose'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.graph.Graph at 0x7f21053976b0>" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: auto-networkx\n", | |
"# Result: convert and run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"networkx\"]\n", | |
"nx.algorithms.binary.compose(G, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"id": "f9798ffd-5dcb-4aaf-b445-87a47734b321", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from multiple backends, {'graphblas', 'networkx'}, that have no priority set in `nx.config.backend_priority` or `nx.config.backend_fallback`, so automatic conversions to these backends will not be attempted.\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"TypeError: Unable to convert inputs from {'graphblas', 'networkx'} backends and run `compose'. NetworkX is configured to automatically convert to [] backends. To remedy this, you may enable automatic conversion to {'graphblas', 'networkx'} backends by adding them to `nx.config.backend_priority` or `nx.config.backend_fallback`, or you may specify a backend to use with the `backend=` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: no auto\n", | |
"# Result: TypeError; suggest how to use backend_priority\n", | |
"\n", | |
"nx.config.backend_priority.compose = []\n", | |
"with raises(TypeError):\n", | |
" nx.algorithms.binary.compose(G, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"id": "30a86f94-a965-40d7-8a4c-179946a0e936", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'graphblas', 'networkx'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Converting input graphs from 'networkx' backend to 'graphblas' backend for call to `compose'\n", | |
"Using backend 'graphblas' for call to `compose' with arguments: (G=<graphblas_algorithms.classes.graph.Graph object at 0x7f21053c0a40>, H=<graphblas_algorithms.classes.graph.Graph object at 0x7f21197e67b0>)\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<graphblas_algorithms.classes.graph.Graph at 0x7f211a92de80>" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: auto-backend\n", | |
"# Result: convert and run with backend\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"graphblas\"]\n", | |
"nx.algorithms.binary.compose(G, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"id": "e7edbfd5-0333-4db8-b58c-5112e4c5464a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'graphblas', 'networkx'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Converting input graphs from 'networkx' backend to 'graphblas' backend for call to `compose'\n", | |
"Using backend 'graphblas' for call to `compose' with arguments: (G=<graphblas_algorithms.classes.graph.Graph object at 0x7f2106a39100>, H=<graphblas_algorithms.classes.graph.Graph object at 0x7f21197e67b0>)\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<graphblas_algorithms.classes.graph.Graph at 0x7f21053c0890>" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# (Same as above, but configured to fall back to networkx after backends)\n", | |
"\n", | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: auto-backend then auto-networkx\n", | |
"# Result: convert and run with backend\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"graphblas\", \"networkx\"]\n", | |
"nx.algorithms.binary.compose(G, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"id": "67444a08-8408-47bf-a835-600380166819", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'graphblas', 'networkx'} backends, and will try to use backends in the following order: ['networkx', 'graphblas']\n", | |
"Converting input graphs from 'graphblas' backend to 'networkx' backend for call to `compose'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.graph.Graph at 0x7f21053c0e90>" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: auto-networkx then auto-backend\n", | |
"# Result: convert and run with networkx!\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"networkx\", \"graphblas\"]\n", | |
"nx.algorithms.binary.compose(G, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"id": "9b82600b-e22b-441d-aa7f-e5df5895313e", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `pagerank' has inputs from {'graphblas'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Using backend 'graphblas' for call to `pagerank' with arguments: (G=<graphblas_algorithms.classes.graph.Graph object at 0x7f21197e67b0>, alpha=0.85, personalization=None, max_iter=100, tol=1e-06, nstart=None, weight='weight', dangling=None)\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<graphblas_algorithms.classes.nodemap.NodeMap at 0x7f21059a0e60>" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph\n", | |
"# Config: N/A\n", | |
"# Result: run with backend\n", | |
"\n", | |
"nx.pagerank(Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"id": "38835d84-d553-44eb-b6e6-829cb6e175bf", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Converting input graphs from 'networkx' backend to 'graphblas' backend for call to `compose'\n", | |
"Using backend 'graphblas' for call to `compose' with arguments: (G=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f21053c09e0>, H=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f210595c3e0>)\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: 'graphblas' backend raised NotImplementedError when calling `compose'. No other backends will be attempted, because the backend was specified with the `backend='graphblas'` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: run with backend via `backend=`; no auto\n", | |
"# Action: backend raises NotImplementedError\n", | |
"# Result: NotImplementedError; suggest how to use backend_priority\n", | |
"\n", | |
"nx.config.backend_priority.compose = []\n", | |
"nx.config.backend_fallback.compose = []\n", | |
"with raises(NotImplementedError):\n", | |
" nx.algorithms.binary.compose(MG, MGgb, backend=\"graphblas\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"id": "4e4a7827-3698-4d0d-82d5-ba9c4c8893d6", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Converting input graphs from 'networkx' backend to 'graphblas' backend for call to `compose'\n", | |
"Using backend 'graphblas' for call to `compose' with arguments: (G=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f210537b5c0>, H=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f210595c3e0>)\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: 'graphblas' backend raised NotImplementedError when calling `compose'. No other backends will be attempted, because the backend was specified with the `backend='graphblas'` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: run with backend via `backend=`; auto-networkx\n", | |
"# Action: backend raises NotImplementedError\n", | |
"# Result: NotImplementedError\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"networkx\"]\n", | |
"with raises(NotImplementedError):\n", | |
" nx.algorithms.binary.compose(MG, MGgb, backend=\"graphblas\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"id": "8787321b-10f8-451d-9f0f-cf1151eef6a6", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'graphblas', 'networkx'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Converting input graphs from 'networkx' backend to 'graphblas' backend for call to `compose'\n", | |
"Using backend 'graphblas' for call to `compose' with arguments: (G=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f21053c35f0>, H=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f210595c3e0>)\n", | |
"Backend 'graphblas' raised NotImplementedError when calling `compose'\n", | |
"Trying next backend: 'networkx'\n", | |
"Converting input graphs from 'graphblas' backend to 'networkx' backend for call to `compose'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.multigraph.MultiGraph at 0x7f216acf94c0>" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: auto-backend\n", | |
"# Action: backend raises NotImplementedError\n", | |
"# Result: NotImplementedError; suggest how to use backend_priority\n", | |
"# or Result: run with other input backend\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"graphblas\"]\n", | |
"nx.config.backend_fallback.compose = []\n", | |
"#with raises(NotImplementedError):\n", | |
"nx.algorithms.binary.compose(MG, MGgb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"id": "c706e7db-6360-46ca-9565-4463ef525575", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'graphblas', 'networkx'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Converting input graphs from 'networkx' backend to 'graphblas' backend for call to `compose'\n", | |
"Using backend 'graphblas' for call to `compose' with arguments: (G=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f216a3edee0>, H=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f210595c3e0>)\n", | |
"Backend 'graphblas' raised NotImplementedError when calling `compose'\n", | |
"Trying next backend: 'networkx'\n", | |
"Converting input graphs from 'graphblas' backend to 'networkx' backend for call to `compose'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.multigraph.MultiGraph at 0x7f21053c3320>" | |
] | |
}, | |
"execution_count": 18, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: auto-backend then auto-networkx\n", | |
"# Action: backend raises NotImplementedError\n", | |
"# Result: convert and run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"graphblas\", \"networkx\"]\n", | |
"nx.algorithms.binary.compose(MG, MGgb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"id": "ff9fe803-bb73-4473-b468-97e3ce0b5f33", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'graphblas', 'networkx'} backends, and will try to use backends in the following order: ['networkx', 'graphblas']\n", | |
"Converting input graphs from 'graphblas' backend to 'networkx' backend for call to `compose'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.multigraph.MultiGraph at 0x7f21053e08f0>" | |
] | |
}, | |
"execution_count": 19, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# (similar to above, but different backend priorities)\n", | |
"\n", | |
"# Inputs: backend graph and networkx graph\n", | |
"# Config: auto-networkx then auto-backend\n", | |
"# Result: convert and run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"networkx\", \"graphblas\"]\n", | |
"nx.algorithms.binary.compose(MG, MGgb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"id": "ed6955ff-a313-4599-bc81-a20ac75a8ff9", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Backend 'graphblas' does not implement `betweenness_centrality'\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: `betweenness_centrality' is not implemented by 'graphblas' backend. No other backends will be attempted, because the backend was specified with the `backend='graphblas'` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph\n", | |
"# Config: run with backend via `backend=`\n", | |
"# Context: can_run=False\n", | |
"# Result: NotImplementedError\n", | |
"\n", | |
"with raises(NotImplementedError):\n", | |
" nx.betweenness_centrality(Ggb, backend=\"graphblas\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"id": "3fc6bc62-1e83-4259-939f-fb0902da9d77", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Backend 'graphblas' does not implement `betweenness_centrality'\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: `betweenness_centrality' is not implemented by ['graphblas'] backends. To remedy this, you may enable automatic conversion to more backends (including 'networkx') by adding them to `nx.config.backend_priority` or `nx.config.backend_fallback`, or you may specify a backend to use with the `backend=` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph\n", | |
"# Config: no auto, no fallback\n", | |
"# Context: can_run=False\n", | |
"# Result: NotImplementedError\n", | |
"\n", | |
"nx.config.backend_priority.algos = []\n", | |
"nx.config.backend_fallback.algos = []\n", | |
"with raises(NotImplementedError):\n", | |
" nx.betweenness_centrality(Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 22, | |
"id": "0b7bf874-70b9-4cc9-8003-2faccd83147c", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Backend 'graphblas' does not implement `contracted_nodes'\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: Backend 'None' does not implement `contracted_nodes'. This call will mutate an input, so automatic conversions between backends (if configured) will not be attempted, because this may change behavior. You may specify a backend to use by passing e.g. `backend='networkx'` keyword, but this may also change behavior by not mutating inputs.\n" | |
] | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph\n", | |
"# Config: auto-networkx\n", | |
"# Context: can_run=False, call will mutate graph\n", | |
"# Result: RuntimeError\n", | |
"\n", | |
"nx.config.backend_priority.contracted_nodes = [\"networkx\"]\n", | |
"with raises(RuntimeError):\n", | |
" nx.contracted_nodes(Ggb, 0, 1, copy=False)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"id": "9b2121f6-1908-451e-92ee-1a01e26681de", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `contracted_nodes' has inputs from {'graphblas'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Backend 'graphblas' does not implement `contracted_nodes'\n", | |
"Trying next backend: 'networkx'\n", | |
"Converting input graphs from 'graphblas' backend to 'networkx' backend for call to `contracted_nodes'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.graph.Graph at 0x7f2119e1ca70>" | |
] | |
}, | |
"execution_count": 23, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: backend graph\n", | |
"# Config: fallback-networkx\n", | |
"# Context: can_run=False\n", | |
"# Result: convert and run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.contracted_nodes = []\n", | |
"nx.config.backend_fallback.contracted_nodes = [\"networkx\"]\n", | |
"nx.contracted_nodes(Ggb, 0, 1, copy=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 24, | |
"id": "24c772b0-9a93-4c6d-a20a-0a4a38dc9970", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{0: 0.3333333333333333, 1: 0.3333333333333333, 2: 0.3333333333333333}" | |
] | |
}, | |
"execution_count": 24, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: networkx graph\n", | |
"# Config: run with networkx via `backend=`\n", | |
"# Result: run with networkx\n", | |
"\n", | |
"nx.pagerank(G, backend=\"networkx\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"id": "981fce9d-e917-406d-bdaf-27d9d6b64458", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Converting input graphs from 'networkx' backend to 'graphblas' backend for call to `pagerank'\n", | |
"Using backend 'graphblas' for call to `pagerank' with arguments: (G=<graphblas_algorithms.classes.graph.Graph object at 0x7f2105e90e30>, alpha=0.85, personalization=None, max_iter=100, tol=1e-06, nstart=None, weight='weight', dangling=None)\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<graphblas_algorithms.classes.nodemap.NodeMap at 0x7f216a32df10>" | |
] | |
}, | |
"execution_count": 25, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: networkx graph\n", | |
"# Config: run with backend via `backend=`\n", | |
"# Result: run with backend\n", | |
"\n", | |
"nx.pagerank(G, backend=\"graphblas\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"id": "f9b39559-5a97-4db0-82bb-a2d117b6a69a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `betweenness_centrality' has inputs from {'networkx'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Backend 'graphblas' does not implement `betweenness_centrality'\n", | |
"Trying next backend: 'networkx'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"{0: 0.0, 1: 0.0, 2: 0.0}" | |
] | |
}, | |
"execution_count": 26, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: networkx graph\n", | |
"# Config: auto-backend then auto-networkx\n", | |
"# Context: can_run=False\n", | |
"# Result: run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.algos = [\"graphblas\"]\n", | |
"nx.config.backend_fallback.algos = [\"networkx\"]\n", | |
"nx.betweenness_centrality(G)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"id": "be573fb9-97a3-4b66-b544-e39fed148e14", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `betweenness_centrality' has inputs from {'networkx'} backends, and will try to use backends in the following order: ['networkx', 'graphblas']\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"{0: 0.0, 1: 0.0, 2: 0.0}" | |
] | |
}, | |
"execution_count": 27, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: networkx graph\n", | |
"# Config: auto-networkx then auto-backend\n", | |
"# Result: run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.algos = [\"networkx\", \"graphblas\"]\n", | |
"nx.betweenness_centrality(G)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 28, | |
"id": "7aea3dc2-180d-4fc6-bede-51fda372118d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `pagerank' has inputs from {'networkx'} backends, and will try to use backends in the following order: ['networkx', 'graphblas']\n", | |
"Call to `to_scipy_sparse_array' has inputs from {'networkx'} backends, and will try to use backends in the following order: ['networkx', 'graphblas']\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"{0: 0.3333333333333333, 1: 0.3333333333333333, 2: 0.3333333333333333}" | |
] | |
}, | |
"execution_count": 28, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: networkx graph\n", | |
"# Config: auto-backend then auto-networkx\n", | |
"# Result: run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.algos = [\"graphblas\", \"networkx\"]\n", | |
"nx.pagerank(G)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"id": "751a312e-5aff-43c7-b4fc-26f83ea9b962", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'networkx'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Converting input graphs from 'networkx' backend to 'graphblas' backend for call to `compose'\n", | |
"Using backend 'graphblas' for call to `compose' with arguments: (G=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f21059f6d20>, H=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f21053e2990>)\n", | |
"Backend 'graphblas' raised NotImplementedError when calling `compose'\n", | |
"Trying next backend: 'networkx'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.multigraph.MultiGraph at 0x7f21059d7ef0>" | |
] | |
}, | |
"execution_count": 29, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: networkx graph\n", | |
"# Config: auto-backend\n", | |
"# Action: backend raises NotImplementedError\n", | |
"# Result: run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.compose = [\"graphblas\"]\n", | |
"nx.config.backend_fallback.compose = []\n", | |
"nx.algorithms.binary.compose(MG, MG)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "120f3c5c-2fe2-4084-8f90-868aa2844fc3", | |
"metadata": {}, | |
"source": [ | |
"### More..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"id": "7d329c8e-6ff4-45b4-92b5-d95deda17d77", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"`contracted_nodes' will mutate an input graph. This prevents automatic conversion to, and use of, backends listed in `nx.config.backend_priority` and `nx.config.backend_fallback`. Using backend specified by the `backend='networkx'` keyword argument. This may change behavior by not mutating inputs.\n", | |
"Converting input graphs from 'graphblas' backend to 'networkx' backend for call to `contracted_nodes'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.graph.Graph at 0x7f21053e3170>" | |
] | |
}, | |
"execution_count": 30, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Log if graph should mutate, but can't\n", | |
"nx.contracted_nodes(Ggb, 0, 1, copy=False, backend=\"networkx\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 31, | |
"id": "34fed408-7881-4b08-891c-583d0f2f28b1", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.graph.Graph at 0x7f21053e3380>" | |
] | |
}, | |
"execution_count": 31, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Don't log if should mutate, and will\n", | |
"nx.contracted_nodes(G.copy(), 0, 1, copy=False, backend=\"networkx\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 32, | |
"id": "4ab4138d-f20b-472b-aa8c-526181d71625", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.graph.Graph at 0x7f21053e07d0>" | |
] | |
}, | |
"execution_count": 32, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Don't log if should mutate, and will\n", | |
"nx.config.backend_priority.contracted_nodes = []\n", | |
"nx.contracted_nodes(G.copy(), 0, 1, copy=False)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 33, | |
"id": "ead309e7-f5c1-4120-9363-af48868998ea", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Using backend 'graphblas' for call to `compose' with arguments: (G=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f210595c3e0>, H=<graphblas_algorithms.classes.graph.MultiGraph object at 0x7f210595c3e0>)\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: 'graphblas' backend raised NotImplementedError when calling `compose'. No other backends will be attempted, because the backend was specified with the `backend='graphblas'` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"with raises(NotImplementedError):\n", | |
" nx.algorithms.binary.compose(MGgb, MGgb, backend=\"graphblas\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 34, | |
"id": "7d5c8412-3422-4160-8284-74315ee43c76", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Backend 'graphblas' does not implement `closeness_centrality'\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: `closeness_centrality' is not implemented by 'graphblas' backend. No other backends will be attempted, because the backend was specified with the `backend='graphblas'` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"with raises(NotImplementedError):\n", | |
" nx.closeness_centrality(G, backend=\"graphblas\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 35, | |
"id": "9ccafecb-91ad-42e7-9673-4d447892c4d6", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Unable to convert from {'networkx', 'pandas_graph'} backends to 'graphblas' backend\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"TypeError: `compose' is unable to convert graph from backends {'networkx', 'pandas_graph'} to 'graphblas' backend, which was specified with the `backend='graphblas'` keyword argument. No other backends will be attempted, because the backend was specified with the `backend='graphblas'` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"with raises(TypeError):\n", | |
" nx.compose(G, Gpd, backend=\"graphblas\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 36, | |
"id": "f355aea9-7dd2-416c-94a1-e56139d8df9b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"TypeError: object of type 'object' has no len()\n" | |
] | |
} | |
], | |
"source": [ | |
"nx.config.backend_priority.pagerank = []\n", | |
"with raises(TypeError):\n", | |
" nx.pagerank(object())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 37, | |
"id": "947d59f3-bb31-4d48-b5dc-40c589ecdb16", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.graph.Graph at 0x7f2105397710>" | |
] | |
}, | |
"execution_count": 37, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"nx.config.backend_priority.contracted_nodes = [\"graphblas\"]\n", | |
"nx.contracted_nodes(G.copy(), 0, 1, copy=False)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 38, | |
"id": "e1fc98a6-441c-4538-97d5-e6e09549cbaa", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `pagerank' has inputs from {'networkx'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Converting input graphs from 'networkx' backend to 'graphblas' backend for call to `pagerank'\n", | |
"Using backend 'graphblas' for call to `pagerank' with arguments: (G=<graphblas_algorithms.classes.graph.Graph object at 0x7f21053c3d70>, alpha=0.85, personalization=None, max_iter=100, tol=1e-06, nstart=None, weight='weight', dangling=None)\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<graphblas_algorithms.classes.nodemap.NodeMap at 0x7f21053e2db0>" | |
] | |
}, | |
"execution_count": 38, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: networkx graph\n", | |
"# Config: auto-backend then fallback-networkx\n", | |
"# Result: run with backend\n", | |
"\n", | |
"nx.config.backend_priority.pagerank = [\"graphblas\"]\n", | |
"nx.config.backend_fallback.pagerank = [\"networkx\"]\n", | |
"nx.pagerank(G)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 39, | |
"id": "098dd96d-be9d-4a2e-a5f9-1a01843a9799", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Backend 'graphblas' does not implement `compose_all'\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: `compose_all' is not implemented by ['graphblas'] backends. To remedy this, you may enable automatic conversion to more backends (including 'networkx') by adding them to `nx.config.backend_priority` or `nx.config.backend_fallback`, or you may specify a backend to use with the `backend=` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"nx.config.backend_priority.compose_all = [\"graphblas\", \"graphblas\"]\n", | |
"nx.config.backend_fallback.compose_all = []\n", | |
"with raises(NotImplementedError):\n", | |
" nx.compose_all([Ggb, Ggb])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 40, | |
"id": "76160473-bb9b-4df1-a507-86f709f14613", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from multiple backends, {'graphblas', 'pandas_graph'}, that have no priority set in `nx.config.backend_priority` or `nx.config.backend_fallback`, so automatic conversions to these backends will not be attempted.\n", | |
"Converting input graphs from {'graphblas', 'pandas_graph'} backends to 'networkx' backend for call to `compose'\n", | |
"Call to `compose_all' has inputs from {'networkx'} backends, and will try to use backends in the following order: ['graphblas', 'networkx']\n", | |
"Backend 'graphblas' does not implement `compose_all'\n", | |
"Trying next backend: 'networkx'\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<networkx.classes.graph.Graph at 0x7f216a32d3d0>" | |
] | |
}, | |
"execution_count": 40, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Inputs: graphs from multiple backends\n", | |
"# Config: fallback-networkx\n", | |
"# Result: convert and run with networkx\n", | |
"\n", | |
"nx.config.backend_priority.compose = []\n", | |
"nx.config.backend_fallback.compose = [\"networkx\"]\n", | |
"nx.algorithms.binary.compose(Gpd, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 41, | |
"id": "b8f5e332-de9b-4f11-9f50-eee36772b950", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from multiple backends, {'graphblas', 'networkx'}, that have no priority set in `nx.config.backend_priority` or `nx.config.backend_fallback`, so automatic conversions to these backends will not be attempted.\n", | |
"Unable to convert from {'graphblas', 'networkx'} backends to 'pandas' backend\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"TypeError: Unable to convert inputs from {'graphblas', 'networkx'} backends and run `compose'. NetworkX is configured to automatically convert to ['pandas'] backends. To remedy this, you may enable automatic conversion to {'graphblas', 'networkx'} backends by adding them to `nx.config.backend_priority` or `nx.config.backend_fallback`, or you may specify a backend to use with the `backend=` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"nx.config.backend_priority.compose = []\n", | |
"nx.config.backend_fallback.compose = [\"pandas\"]\n", | |
"with raises(TypeError):\n", | |
" nx.algorithms.binary.compose(G, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 42, | |
"id": "fdd06178-eb5a-46d1-ae39-9cc94d605b3f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Call to `compose' has inputs from {'graphblas', 'pandas_graph'} backends, and will try to use backends in the following order: ['pandas_graph', 'graphblas']\n", | |
"Unable to convert from {'graphblas', 'pandas_graph'} backends to 'pandas_graph' backend\n", | |
"Trying next backend: 'graphblas'\n", | |
"Unable to convert from {'graphblas', 'pandas_graph'} backends to 'graphblas' backend\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: `compose' is not implemented by ['pandas_graph', 'graphblas'] backends. To remedy this, you may enable automatic conversion to more backends (including 'networkx') by adding them to `nx.config.backend_priority` or `nx.config.backend_fallback`, or you may specify a backend to use with the `backend=` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"nx.config.backend_priority.compose = []\n", | |
"nx.config.backend_fallback.compose = [\"graphblas\"]\n", | |
"with raises(NotImplementedError):\n", | |
" nx.algorithms.binary.compose(Gpd, Ggb)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 43, | |
"id": "b5b87105-eb1a-433e-ae48-354533758afc", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"TypeError: `random_geometric_graph' is not configured to run with any backend! Perhaps consider adding backends (such as 'networkx') to `nx.config.backend_fallback`. You may also specify a backend to use with the `backend=` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"nx.config.backend_priority.random_geometric_graph = []\n", | |
"nx.config.backend_fallback.random_geometric_graph = []\n", | |
"with raises(TypeError):\n", | |
" nx.random_geometric_graph(10, 2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 44, | |
"id": "304a7558-bce2-4977-b97f-666012419493", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Backend 'graphblas' does not implement `random_geometric_graph'\n" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"NotImplementedError: `random_geometric_graph' is not implemented by ['graphblas'] backends. To remedy this, you may enable automatic conversion to more backends (including 'networkx') by adding them to `nx.config.backend_priority` or `nx.config.backend_fallback`, or you may specify a backend to use with the `backend=` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"nx.config.backend_priority.random_geometric_graph = []\n", | |
"nx.config.backend_fallback.random_geometric_graph = [\"graphblas\"]\n", | |
"with raises(NotImplementedError):\n", | |
" nx.random_geometric_graph(10, 2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 45, | |
"id": "66a9bf04-269f-429a-99b3-f42977b592e1", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"TypeError: `pagerank' is not configured to run with any backend! Perhaps consider adding backends (such as 'networkx') to `nx.config.backend_fallback`. You may also specify a backend to use with the `backend=` keyword argument.\n" | |
] | |
} | |
], | |
"source": [ | |
"nx.config.backend_priority.pagerank = []\n", | |
"nx.config.backend_fallback.pagerank = []\n", | |
"with raises(TypeError):\n", | |
" nx.pagerank(object())" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"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.12.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment