{"id":41713188,"url":"https://github.com/kentwait/nxsim","last_synced_at":"2026-01-24T21:49:48.120Z","repository":{"id":34319364,"uuid":"38237404","full_name":"kentwait/nxsim","owner":"kentwait","description":"nxsim is a Python package for simulating agents in a network","archived":false,"fork":false,"pushed_at":"2016-01-19T09:17:15.000Z","size":216,"stargazers_count":38,"open_issues_count":3,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-28T17:49:07.699Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kentwait.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-29T08:48:26.000Z","updated_at":"2025-09-22T16:22:44.000Z","dependencies_parsed_at":"2022-09-26T16:20:49.602Z","dependency_job_id":null,"html_url":"https://github.com/kentwait/nxsim","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kentwait/nxsim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentwait%2Fnxsim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentwait%2Fnxsim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentwait%2Fnxsim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentwait%2Fnxsim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kentwait","download_url":"https://codeload.github.com/kentwait/nxsim/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentwait%2Fnxsim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28737622,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T21:19:41.845Z","status":"ssl_error","status_checked_at":"2026-01-24T21:13:38.675Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-24T21:49:48.034Z","updated_at":"2026-01-24T21:49:48.112Z","avatar_url":"https://github.com/kentwait.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [nxsim](https://github.com/kentwait/nxsim)\n\nNxsim is a Python package for simulating agents connected by any type of network using\nSimPy and Networkx in Python 3.4.\n\n## Install\n\n    pip3 install nxsim  # from PyPI\n    pip3 install git+git://github.com/kentwait/nxsim.git  # from GitHub\n\n## Quickstart\nNxsim provides a framework for doing forward-time simulations of events occurring in a network. It uses Networkx to\ncreate a network and SimPy 3 to create agents over each node in the network.\n\nTo create a simulation, nxsim requires a graph generated by Networkx and an \"agent\" class to populate each node of the\nnetwork.\n\nFirst, create a graph using Networkx.\n\n    import networkx as nx\n\n    number_of_nodes = 10\n    G = nx.complete_graph(number_of_nodes)\n\nThen, subclass *BaseNetworkAgent* to create your own agent based on your needs.\n\n    from nxsim import BaseNetworkAgent\n\n    # Just like subclassing a process in SimPy\n    class MyAgent(BaseNetworkAgent):\n        def __init__(self, environment=None, agent_id=0, state=()):  # Make sure to have these three keyword arguments\n            super().__init__(environment=environment, agent_id=agent_id, state=state)\n            # Add your own attributes here\n\n        def run(self):\n            # Add your behaviors here\n\nNotice that \"agents\" in nxsim use the same concepts as \"processes\" in SimPy 3 except that their interactions can be\nlimited by the graph in the simulation environment. For more information about SimPy, they have a great introduction\nposted on their [website](https://simpy.readthedocs.org/en/latest/simpy_intro/index.html).\n\nHere is a graph-based example:\n\n    import random\n    from nxsim import BaseNetworkAgent\n\n    class ZombieOutbreak(BaseNetworkAgent):\n        def __init__(self, environment=None, agent_id=0, state=()):\n            super().__init__(environment=environment, agent_id=agent_id, state=state)\n            self.bite_prob = 0.05\n\n        def run(self):\n            while True:\n                if self.state['id'] == 1:\n                    self.zombify()\n                    yield self.env.timeout(1)\n                else:\n                    yield self.env.event()\n\n        def zombify(self):\n            normal_neighbors = self.get_neighboring_agents(state_id=0)\n            for neighbor in normal_neighbors:\n                if random.random() \u003c self.bite_prob:\n                    neighbor.state['id'] = 1  # zombie\n                    print(self.env.now, self.id, neighbor.id, sep='\\t')\n                    break\n\nYou can now set-up your simulation by creating a *NetworkSimulation* instance.\n\n    from nxsim import NetworkSimulation\n\n    # Initialize agent states. Let's assume everyone is normal.\n    # Add keys as as necessary, but \"id\" must always refer to that state category\n    init_states = [{'id': 0, } for _ in range(number_of_nodes)]\n\n    # Seed a zombie\n    init_states[5] = {'id': 1}\n    sim = NetworkSimulation(topology=G, states=init_states, agent_type=ZombieOutbreak,\n                            max_time=30, dir_path='sim_01', num_trials=1, logging_interval=1.0)\n\nAnd finally, start it up.\n\n    sim.run_simulation()\n\nRunning the simulation saves pickled dictionaries into the *dir_path* folder, in this case to \"sim_01\".\nNow, let's retrieve the history and states of the trial\n\n    trial = BaseLoggingAgent.open_trial_state_history(dir_path='sim_01', trial_id=0)\n\nAnd plot the number of zombies per time interval using matplotlib:\n\n    from matplotlib import pyplot as plt\n    zombie_census = [sum([1 for node_id, state in g.items() if state['id'] == 1]) for t,g in trial.items()]\n    plt.plot(zombie_census)\n\nAnd that's it!\n\n## Note\nThis package is still under development. If you encounter a bug, please file an issue at [https://github.com/kentwait/nxsim/issues](https://github.com/kentwait/nxsim/issues) to get it resolved.\n\n## Acknowledgment\nThanks to Joé Schaul for bringing [ComplexNetworkSim](https://github.com/jschaul/ComplexNetworkSim) to the world.\nThis project is a SimPy 3- and Python 3.4-compatible fork of ComplexNetworkSim.\n\n## Links\n- [nxsim - Github](https://github.com/kentwait/nxsim)\n- [nxsim - PyPI](https://pypi.python.org/pypi/nxsim)\n- [SimPy v3.0 Documentation](https://simpy.readthedocs.org/en/latest/contents.html)\n- [Networkx v1.9 Documentation](http://networkx.github.io/documentation/networkx-1.9.1)\n- [matplotlib v1.4.3 Documentation](http://matplotlib.org/users/)\n- [ComplexNetworkSim Documentation](https://pythonhosted.org/ComplexNetworkSim)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkentwait%2Fnxsim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkentwait%2Fnxsim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkentwait%2Fnxsim/lists"}