{ "cells": [ { "cell_type": "raw", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ ".. _user_guide_graph:" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "# Graphs and Graph Routines" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The library only provides a few tools for graphs, related to algorithms for bandwith reduction, such as the calculation of pseudo peripheral nodes and rooted level structures." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `Graph` class is a subclass of the `Graph` class from `networkx`, with a few additions." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from sigmaepsilon.math.graph import Graph\n", "import networkx as nx\n", "\n", "grid = nx.grid_2d_graph(5, 5) # 5x5 grid\n", "G = Graph(grid)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One of these additions is that it is possible to get the adjacency matrix of a graph directly, by calling the `adjacency_matrix` method of an instance. The method returns a Numba-jittable instance of the `csr_matrix` class from `sigmaepsilon.math.linalg`, hence making the graph instance itself sort of Numba-jittable as well." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G.adjacency_matrix()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `Graph` class in `sigmaepsilon.math.graph` is also equipped with methods for the calculation of pseudo peripheral nodes and rooted level structures." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([24, 0], dtype=int64)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G.pseudo_peripheral_nodes()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "DictType[int64,array(int64, 1d, C)]({0: [0], 1: [1 5], 2: [ 2 6 10], 3: [ 3 7 11 15], 4: [ 4 8 12 16 20], 5: [ 9 13 17 21], 6: [14 18 22], 7: [19 23], 8: [24]})" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G.rooted_level_structure()" ] } ], "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.10.11" }, "vscode": { "interpreter": { "hash": "4e251a336b180e3c877fd4b81be72acfad98293ac2abcf90f00390a06765d313" } }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }