{ "cells": [ { "cell_type": "markdown", "id": "violent-customs", "metadata": {}, "source": [ "# Computing Boolean networks dynamics with minibn\n", "\n", "The module `minibn` implements update modes for computing dynamics of `minibn.BooleanNetwork` objects. It is returned as [networkx.DiGraph](https://networkx.org/documentation/stable/reference/classes/digraph.html) object." ] }, { "cell_type": "code", "execution_count": 1, "id": "focal-joseph", "metadata": {}, "outputs": [], "source": [ "from colomoto import minibn" ] }, { "cell_type": "markdown", "id": "falling-story", "metadata": {}, "source": [ "Let us first define a simple Boolean network." ] }, { "cell_type": "code", "execution_count": 2, "id": "ruled-river", "metadata": {}, "outputs": [], "source": [ "bn = minibn.BooleanNetwork({\n", " \"a\": \"c\",\n", " \"b\": \"!a\",\n", " \"c\": \"!b\"\n", "})" ] }, { "cell_type": "markdown", "id": "tropical-wealth", "metadata": {}, "source": [ "By default the `.dynamics` method computes the dynamics according to the (fully) asynchronous update mode." ] }, { "cell_type": "code", "execution_count": 3, "id": "understanding-female", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# computing graph layout...\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "000\n", "\n", "000\n", "\n", "\n", "\n", "010\n", "\n", "010\n", "\n", "\n", "\n", "000->010\n", "\n", "\n", "\n", "\n", "\n", "001\n", "\n", "001\n", "\n", "\n", "\n", "000->001\n", "\n", "\n", "\n", "\n", "\n", "101\n", "\n", "101\n", "\n", "\n", "\n", "001->101\n", "\n", "\n", "\n", "\n", "\n", "011\n", "\n", "011\n", "\n", "\n", "\n", "001->011\n", "\n", "\n", "\n", "\n", "\n", "100\n", "\n", "100\n", "\n", "\n", "\n", "100->000\n", "\n", "\n", "\n", "\n", "\n", "100->101\n", "\n", "\n", "\n", "\n", "\n", "110\n", "\n", "110\n", "\n", "\n", "\n", "110->010\n", "\n", "\n", "\n", "\n", "\n", "110->100\n", "\n", "\n", "\n", "\n", "\n", "011->010\n", "\n", "\n", "\n", "\n", "\n", "111\n", "\n", "111\n", "\n", "\n", "\n", "011->111\n", "\n", "\n", "\n", "\n", "\n", "111->101\n", "\n", "\n", "\n", "\n", "\n", "111->110\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "adyn = bn.dynamics()\n", "adyn" ] }, { "cell_type": "markdown", "id": "straight-russia", "metadata": {}, "source": [ "The `networkx` module implements a wide range of graph algorithms, such as computing strongly connected components:" ] }, { "cell_type": "code", "execution_count": 4, "id": "greek-accounting", "metadata": {}, "outputs": [], "source": [ "import networkx as nx" ] }, { "cell_type": "code", "execution_count": 5, "id": "wicked-johns", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'010'}, {'101'}, {'000', '001', '011', '100', '110', '111'}]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(nx.strongly_connected_components(adyn))" ] }, { "cell_type": "markdown", "id": "corporate-eagle", "metadata": {}, "source": [ "The update mode can be specified as first argument. It can be either `\"asynchronous\"` (or equivalently `\"fully-asynchronous\"`), `\"general\"`, or `\"synchronous\"`. Custom update modes can also be implemented by inheriting from the `minibn.UpdateModeDynamics`." ] }, { "cell_type": "code", "execution_count": 6, "id": "rational-kinase", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# computing graph layout...\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "000\n", "\n", "000\n", "\n", "\n", "\n", "011\n", "\n", "011\n", "\n", "\n", "\n", "000->011\n", "\n", "\n", "\n", "\n", "\n", "110\n", "\n", "110\n", "\n", "\n", "\n", "011->110\n", "\n", "\n", "\n", "\n", "\n", "100\n", "\n", "100\n", "\n", "\n", "\n", "001\n", "\n", "001\n", "\n", "\n", "\n", "100->001\n", "\n", "\n", "\n", "\n", "\n", "111\n", "\n", "111\n", "\n", "\n", "\n", "001->111\n", "\n", "\n", "\n", "\n", "\n", "110->000\n", "\n", "\n", "\n", "\n", "\n", "010\n", "\n", "010\n", "\n", "\n", "\n", "111->100\n", "\n", "\n", "\n", "\n", "\n", "101\n", "\n", "101\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bn.dynamics(\"synchronous\")" ] }, { "cell_type": "markdown", "id": "independent-possibility", "metadata": {}, "source": [ "Finally, one can also compute the dynamics only reachable from a specified initial state, specified with the `init` keyword:" ] }, { "cell_type": "code", "execution_count": 7, "id": "russian-battle", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# computing graph layout...\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "111\n", "\n", "111\n", "\n", "\n", "\n", "100\n", "\n", "100\n", "\n", "\n", "\n", "111->100\n", "\n", "\n", "\n", "\n", "\n", "001\n", "\n", "001\n", "\n", "\n", "\n", "100->001\n", "\n", "\n", "\n", "\n", "\n", "001->111\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bn.dynamics(\"synchronous\", init={\"a\": 1, \"b\": 1, \"c\": 1})" ] }, { "cell_type": "code", "execution_count": null, "id": "curious-thanksgiving", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.7" } }, "nbformat": 4, "nbformat_minor": 5 }