Skip to content

Commit

Permalink
quick start added to documentation, automatic testing added..
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziaeemehr committed Aug 3, 2024
1 parent 537738c commit 837b3be
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test

on: [push]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
pip install .
- name: Run tests
run: |
python -m unittest discover
56 changes: 56 additions & 0 deletions docs/quick_start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
First import the necessary libraries:
.. literalinclude:: quick_start.py
:start-after: example-st\u0061rt
:lines: 1-4
:dedent: 0
Next, create a simple graph with self-avoiding edges (SAE) between nodes.
.. literalinclude:: quick_start.py
:start-after: example-st\u0061rt
:lines: 6-8
Now, find all self-avoiding paths from a given start node to a target node.
.. literalinclude:: quick_start.py
:start-after: example-st\u0061rt
:lines: 11-16
Finally, visualize the graph.
.. literalinclude:: quick_start.py
:start-after: example-st\u0061rt
:lines: 18
.. figure:: images/01.png
:scale: 80 %
"""

# example-start
import networkx as nx
import matplotlib.pyplot as plt
from netsci.plot import plot_graph
from netsci.analysis import find_sap

G = nx.Graph()
edges = [("A", "B"), ("A", "C"), ("B", "D"), ("B", "E"), ("C", "F"), ("E", "F")]
G.add_edges_from(edges)

# Find all self-avoiding paths from 'A' to 'F'
start_node = "A"
target_node = "F"
all_saps = list(find_sap(G, start_node, target_node))

for path in all_saps:
print("->".join(path))

plot_graph(G, seed=2, figsize=(3, 3))
import os
os.makedirs("images", exist_ok=True)
plt.savefig("images/01.png", bbox_inches="tight")

# example-end

0 comments on commit 837b3be

Please sign in to comment.