Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion notebooks/00-preface/01-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ That's it! The `--sandbox` flag ensures a clean, isolated environment for runnin
- The `--sandbox` flag creates an isolated environment for each notebook, preventing dependency conflicts
- All required packages are automatically installed when you run the notebook

This approach eliminates the need for manual environment setup, conda environments, or Docker containers while ensuring reproducible execution of the tutorial content.
This approach eliminates the need for manual environment setup, conda environments, or Docker containers while ensuring reproducible execution of the tutorial content.
3 changes: 2 additions & 1 deletion notebooks/00-preface/01-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _(mo):

Once Marimo is launched, on the bottom, click on "on startup", "on cel change", and "on module change" to disable automatic execution. This will allow us to mimic original Jupyter behaviour, which is advantageous for a teaching setting (but toggle them back to "autorun" )


That's it! The `--sandbox` flag ensures a clean, isolated environment for running the notebooks with all necessary dependencies automatically managed.
"""
)
Expand All @@ -79,6 +79,7 @@ def _(mo):
@app.cell(hide_code=True)
def _():
import marimo as mo

return (mo,)


Expand Down
5 changes: 3 additions & 2 deletions notebooks/00-preface/03-goals.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def __(mo):
@app.cell(hide_code=True)
def __():
import marimo as mo
return mo,

return (mo,)


if __name__ == "__main__":
app.run()
app.run()
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,4 @@
"console": []
}
]
}
}
7 changes: 2 additions & 5 deletions notebooks/02-algorithms/02-paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def _(mo):
def _(____, _____, _________, ___________, _____________, _________________):
# FILL IN THE BLANKS BELOW


def path_exists(node1, node2, G):
"""
This function checks whether a path exists between two nodes (node1,
Expand Down Expand Up @@ -172,6 +171,7 @@ def path_exists(node1, node2, G):

# print('Path does not exist between nodes {0} and {1}'.format(node1, node2))
return False

return (path_exists,)


Expand All @@ -190,7 +190,6 @@ def _(G, path_exists):
from random import sample
import networkx as nx


def test_path_exists(N):
"""
N: The number of times to spot-check.
Expand All @@ -200,7 +199,6 @@ def test_path_exists(N):
assert path_exists(n1, n2, G) == bool(nx.shortest_path(G, n1, n2))
return True


# Uncomment the next line to check the tests.
# assert test_path_exists(10)
return (nx,)
Expand Down Expand Up @@ -332,12 +330,10 @@ def _(mo):
def _(plt):
from nams.solutions.paths import plot_path_with_neighbors


def plot_path_with_neighbors_answer(G, node1, node2):
# Your answer here
plt.show()


# Now execute `plot_path_with_neighbors_answer`
return (plot_path_with_neighbors,)

Expand Down Expand Up @@ -512,6 +508,7 @@ def _():
@app.cell
def _():
import marimo as mo

return (mo,)


Expand Down
17 changes: 2 additions & 15 deletions notebooks/02-algorithms/03-structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def in_triangle(G, node):
# Your answer here
pass


# COMMENT OUT THE IMPORT LINE TO TEST YOUR ANSWER
from nams.solutions.structures import in_triangle

Expand All @@ -173,13 +172,11 @@ def _(G, in_triangle):
from random import sample
import networkx as nx


def test_in_triangle():
nodes = sample(list(G.nodes()), 10)
for node in nodes:
assert in_triangle(G, 3) == bool(nx.triangles(G, 3))


test_in_triangle()
return (nx,)

Expand Down Expand Up @@ -226,7 +223,6 @@ def get_triangle_neighbors(G, n):
# Your answer here
pass


# COMMENT OUT THE IMPORT LINE TO TEST YOUR ANSWER
from nams.solutions.structures import get_triangle_neighbors

Expand All @@ -241,7 +237,6 @@ def plot_triangle_relations(G, n):
# Your answer here
pass


# COMMENT OUT THE IMPORT LINE TO TEST YOUR ANSWER
from nams.solutions.structures import plot_triangle_relations

Expand Down Expand Up @@ -309,7 +304,6 @@ def get_open_triangles_neighbors(G, n):
# Your answer here
pass


# COMMENT OUT THE IMPORT LINE TO TEST YOUR ANSWER
from nams.solutions.structures import get_open_triangles_neighbors

Expand Down Expand Up @@ -338,7 +332,6 @@ def plot_open_triangle_relations(G, n):
# Your answer here
pass


# COMMENT OUT THE IMPORT LINE TO TEST YOUR ANSWER
from nams.solutions.structures import plot_open_triangle_relations

Expand Down Expand Up @@ -442,9 +435,9 @@ def size_k_maximal_cliques(G, k):
# Your answer here
pass


# COMMENT OUT THE IMPORT LINE TO TEST YOUR ANSWER
from nams.solutions.structures import size_k_maximal_cliques

return (size_k_maximal_cliques,)


Expand All @@ -461,7 +454,6 @@ def test_size_k_maximal_cliques(G, k):
for clique in clique_generator:
assert len(clique) == k


test_size_k_maximal_cliques(G, 5)
return

Expand Down Expand Up @@ -516,16 +508,13 @@ def find_k_cliques(G, k):
# your answer here
pass


# COMMENT OUT THE IMPORT LINE TO TEST YOUR ANSWER
from nams.solutions.structures import find_k_cliques


def test_find_k_cliques(G, k):
for clique in find_k_cliques(G, k):
assert len(clique) == k


test_find_k_cliques(G, 3)
return

Expand Down Expand Up @@ -642,7 +631,6 @@ def label_connected_component_subgraphs(G):
# Your answer here
return G


# COMMENT OUT THE IMPORT LINE TO TEST YOUR ANSWER
from nams.solutions.structures import label_connected_component_subgraphs

Expand All @@ -668,12 +656,10 @@ def _(mo):
def _(G_labelled):
import matplotlib.pyplot as plt


def plot_cc_subgraph(G):
# Your answer here
pass


# COMMENT OUT THE IMPORT LINE TO TEST YOUR ANSWER
from nams.solutions.structures import plot_cc_subgraph
from nxviz import annotate
Expand Down Expand Up @@ -740,6 +726,7 @@ def _(getsource):
@app.cell
def _():
import marimo as mo

return (mo,)


Expand Down
4 changes: 3 additions & 1 deletion notebooks/03-practical/01-io.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ def _(G):

@app.cell(hide_code=True)
def _(mo):
mo.md(r"""You'll notice that the edge metadata have been added correctly: we have recorded in there the number of trips between stations.""")
mo.md(
r"""You'll notice that the edge metadata have been added correctly: we have recorded in there the number of trips between stations."""
)
return


Expand Down
25 changes: 19 additions & 6 deletions notebooks/04-advanced/02-linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ def _(mo):

@app.cell(hide_code=True)
def _(mo):
mo.md(r"""Let's start by looking at a toy bipartite graph, a "customer-product" purchase record graph, with 4 products and 3 customers. The matrix representation might be as follows:""")
mo.md(
r"""Let's start by looking at a toy bipartite graph, a "customer-product" purchase record graph, with 4 products and 3 customers. The matrix representation might be as follows:"""
)
return


Expand All @@ -489,7 +491,9 @@ def _(np):

@app.cell(hide_code=True)
def _(mo):
mo.md(r"""From this "bi-adjacency" matrix, one can compute the projection onto the customers, matrix multiplying the matrix with its transpose.""")
mo.md(
r"""From this "bi-adjacency" matrix, one can compute the projection onto the customers, matrix multiplying the matrix with its transpose."""
)
return


Expand All @@ -515,7 +519,9 @@ def _(mo):

@app.cell(hide_code=True)
def _(mo):
mo.md(r"""To get the products matrix, we make the transposed matrix the left side of the matrix multiplication.""")
mo.md(
r"""To get the products matrix, we make the transposed matrix the left side of the matrix multiplication."""
)
return


Expand All @@ -528,7 +534,9 @@ def _(cp_mat):

@app.cell(hide_code=True)
def _(mo):
mo.md(r"""You may now try to convince yourself that the diagonals are the number of times a customer purchased that product, and the off-diagonals are the connectivity matrix of the products, weighted by how similar two customers are.""")
mo.md(
r"""You may now try to convince yourself that the diagonals are the number of times a customer purchased that product, and the off-diagonals are the connectivity matrix of the products, weighted by how similar two customers are."""
)
return


Expand Down Expand Up @@ -564,7 +572,9 @@ def _():

@app.cell(hide_code=True)
def _(mo):
mo.md(r"""Remember that with bipartite graphs, it is useful to obtain nodes from one of the partitions.""")
mo.md(
r"""Remember that with bipartite graphs, it is useful to obtain nodes from one of the partitions."""
)
return


Expand Down Expand Up @@ -655,7 +665,9 @@ def _(degrees, np):

@app.cell(hide_code=True)
def _(mo):
mo.md(r"""We can verify this independently by sorting the customer nodes by degree.""")
mo.md(
r"""We can verify this independently by sorting the customer nodes by degree."""
)
return


Expand Down Expand Up @@ -834,6 +846,7 @@ def _(mo):
@app.cell(hide_code=True)
def _():
import marimo as mo

return (mo,)


Expand Down
Loading