From dc0954825885602b5b33942028c21926b308a8d9 Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 13:34:18 -0700 Subject: [PATCH 01/11] update readme with code minimally --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bfe95f25..aa01bba3 100644 --- a/README.md +++ b/README.md @@ -27,20 +27,55 @@ - ![tnns_network_with_layers](https://user-images.githubusercontent.com/8267869/234084036-f7d6585e-b7c2-4156-a825-cfa5b9658d71.png) `TopoModelX` (TMX) is a Python module for topological deep learning. It offers simple and efficient tools to implement topological neural networks for science and engineering. -TMX's development follows the topological deep learning (TDL) blue print laid out in: -- [Hajij et al. 2023. Topological Deep Learning: Going Beyond Graph Data](https://arxiv.org/abs/2206.00606). +_**Note:** TMX is still under development._ + +## Quick Tour for New Users -TMX can reproduce and extend the topological neural networks (TNNs) surveyed in: -- [Papillon et al. 2023. Architectures of Topological Deep Learning: A Survey on Topological Neural Networks](https://arxiv.org/abs/2304.10031). +In this quick tour, we highlight the ease of creating and training a TNN model with only a few lines of code. -See [our graphical literature review](https://github.com/pyt-team/TopoModelX/blob/main/topomodelx.jpeg) with message-passing equations available at [https://github.com/awesome-tnns/awesome-tnns](https://github.com/awesome-tnns/awesome-tnns). +#Train your own TNN model -_**Note:** TMX is still under development._ +Below is a minimal example of using TopoModelX to load a simplicial complex dataset, define a simplicial attention network (SAN), and perform a forward pass: + + +```bash +import numpy as np +import torch +from topomodelx.datasets.graph import karate_club +from topomodelx.nn.simplicial.san import SAN +from topomodelx.utils.sparse import from_sparse + +# Step 1: Load the Karate Club dataset +dataset = karate_club(complex_type="simplicial") + +# Step 2: Prepare Laplacians and node/edge features +laplacian_down = from_sparse(dataset.down_laplacian_matrix(rank=1)) +laplacian_up = from_sparse(dataset.up_laplacian_matrix(rank=1)) +incidence_0_1 = from_sparse(dataset.incidence_matrix(rank=1)) + +x_0 = torch.tensor(np.stack(list(dataset.get_simplex_attributes("node_feat").values()))) +x_1 = torch.tensor(np.stack(list(dataset.get_simplex_attributes("edge_feat").values()))) +x = x_1 + torch.sparse.mm(incidence_0_1.T, x_0) + +# Step 3: Define the network +class Network(torch.nn.Module): + def __init__(self, in_channels, hidden_channels, out_channels): + super().__init__() + self.base_model = SAN(in_channels, hidden_channels, n_layers=2) + self.linear = torch.nn.Linear(hidden_channels, out_channels) + + def forward(self, x, laplacian_up, laplacian_down): + x = self.base_model(x, laplacian_up, laplacian_down) + return torch.sigmoid(self.linear(x)) + +# Step 4: Initialize the network and perform a forward pass +model = Network(in_channels=x.shape[-1], hidden_channels=16, out_channels=2) +y_hat_edge = model(x, laplacian_up=laplacian_up, laplacian_down=laplacian_down) + ``` ## 🦾 Contributing to TMX @@ -101,6 +136,11 @@ Then: To learn more about the topological deep learning blueprint: - Mustafa Hajij, Ghada Zamzmi, Theodore Papamarkou, Nina Miolane, Aldo Guzmán-Sáenz, Karthikeyan Natesan Ramamurthy, Tolga Birdal, Tamal K. Dey, Soham Mukherjee, Shreyas N. Samaga, Neal Livesay, Robin Walters, Paul Rosen, Michael T. Schaub. [Topological Deep Learning: Going Beyond Graph Data](https://arxiv.org/abs/2206.00606). + +- TMX can reproduce and extend the topological neural networks (TNNs) surveyed in: + +Papillon et al. 2023. Architectures of Topological Deep Learning: A Survey on Topological Neural Networks. + ``` @misc{hajij2023topological, title={Topological Deep Learning: Going Beyond Graph Data}, From 057cc576257d20f7295c32a48fe7695a91bde0bf Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 13:42:50 -0700 Subject: [PATCH 02/11] trying to fix lint in tutorials --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 25583d00..22da7ef8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,7 +93,7 @@ select = [ "PERF", # performance rules "RUF", # miscellaneous rules ] -ignore = ["E501"] # line too long +ignore = ["E501", "SIM115"] # line too long [tool.ruff.lint.pydocstyle] convention = "numpy" From a28b9d8e5371be116f3608c12185d2e86bca72ce Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 13:47:48 -0700 Subject: [PATCH 03/11] updating numpy --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 22da7ef8..cb5019cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ classifiers = [ requires-python = ">= 3.10" dependencies=[ "tqdm", - "numpy", + "numpy<2", "scipy", "requests", "scikit-learn", From 5a3887578da262bb7122cae47e1187005ff9302b Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 13:54:08 -0700 Subject: [PATCH 04/11] adding more detaisl to project --- pyproject.toml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cb5019cd..21ccff2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,10 @@ dynamic = ["version"] authors = [ {name = "PyT-Team Authors", email = "mustafahajij@gmail.com"} ] + +maintainers = [ + {name = "Mustafa Hajij", email = "mustafahajij@gmail.com"} +] readme = "README.md" description = "Topological Deep Learning" license = {file = "LICENSE.txt"} @@ -67,8 +71,10 @@ dev = ["TopoModelX[test, lint]"] all = ["TopoModelX[dev, doc]"] [project.urls] -homepage="https://github.com/pyt-team/TopoModelX" -repository="https://github.com/pyt-team/TopoModelX" +homepage = "https://github.com/pyt-team/TopoModelX" +repository = "https://github.com/pyt-team/TopoModelX" +documentation = "https://pyt-team.github.io/TopoModelX" +issues = "https://github.com/pyt-team/TopoModelX/issues" [tool.ruff] target-version = "py310" From be5bbd88e1040f87595f2a63b81508dc5427f926 Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 14:01:58 -0700 Subject: [PATCH 05/11] adding the book to the readme file --- README.md | 3 ++- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa01bba3..82966ed1 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,8 @@ Then: To learn more about the topological deep learning blueprint: -- Mustafa Hajij, Ghada Zamzmi, Theodore Papamarkou, Nina Miolane, Aldo Guzmán-Sáenz, Karthikeyan Natesan Ramamurthy, Tolga Birdal, Tamal K. Dey, Soham Mukherjee, Shreyas N. Samaga, Neal Livesay, Robin Walters, Paul Rosen, Michael T. Schaub. [Topological Deep Learning: Going Beyond Graph Data](https://arxiv.org/abs/2206.00606). +- Mustafa Hajij, Ghada Zamzmi, Theodore Papamarkou, Nina Miolane, Aldo Guzmán-Sáenz, Karthikeyan Natesan Ramamurthy, Tolga Birdal, Tamal K. Dey, Soham Mukherjee, Shreyas N. Samaga, Neal Livesay, Robin Walters, Paul Rosen, Michael T. Schaub. + [Topological Deep Learning: Going Beyond Graph Data](https://arxiv.org/abs/2206.00606) (arXiv) • [Topological Deep Learning: A Book](https://tdlbook.org/) - TMX can reproduce and extend the topological neural networks (TNNs) surveyed in: diff --git a/pyproject.toml b/pyproject.toml index 21ccff2d..4a32b2c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ authors = [ ] maintainers = [ - {name = "Mustafa Hajij", email = "mustafahajij@gmail.com"} + {name = "Mustafa Hajij", email = "mustafahajij@gmail.com", Florian Frantzen} ] readme = "README.md" description = "Topological Deep Learning" From b6ed3079811a57bdbe6d0aa0b82535c02dc4cdde Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 14:09:15 -0700 Subject: [PATCH 06/11] fixing refs --- README.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 82966ed1..739552af 100644 --- a/README.md +++ b/README.md @@ -133,12 +133,16 @@ Then: ## 🔍 References ## -To learn more about the topological deep learning blueprint: +- TMX is a part of TopoX, a suite of Python packages for machine learning on topological domains. If you find TMX useful please consider citing our software paper: -- Mustafa Hajij, Ghada Zamzmi, Theodore Papamarkou, Nina Miolane, Aldo Guzmán-Sáenz, Karthikeyan Natesan Ramamurthy, Tolga Birdal, Tamal K. Dey, Soham Mukherjee, Shreyas N. Samaga, Neal Livesay, Robin Walters, Paul Rosen, Michael T. Schaub. +Hajij et al. 2023. TopoX: a suite of Python packages for machine learning on topological domains + +- To learn more about the blueprint topological deep learning that topomodelx follows : + +Mustafa Hajij, Ghada Zamzmi, Theodore Papamarkou, Nina Miolane, Aldo Guzmán-Sáenz, Karthikeyan Natesan Ramamurthy, Tolga Birdal, Tamal K. Dey, Soham Mukherjee, Shreyas N. Samaga, Neal Livesay, Robin Walters, Paul Rosen, Michael T. Schaub. [Topological Deep Learning: Going Beyond Graph Data](https://arxiv.org/abs/2206.00606) (arXiv) • [Topological Deep Learning: A Book](https://tdlbook.org/) -- TMX can reproduce and extend the topological neural networks (TNNs) surveyed in: +- TMX topological neural networks are surveyed in: Papillon et al. 2023. Architectures of Topological Deep Learning: A Survey on Topological Neural Networks. @@ -151,6 +155,21 @@ Papillon et al. 2023. Architectures of Topological Deep Learning: A Survey on To archivePrefix={arXiv}, primaryClass={cs.LG} } + +@article{hajij2024topox, + title={TopoX: a suite of Python packages for machine learning on topological domains}, + author={PYT-Team}, + journal={arXiv preprint arXiv:2402.02441}, + year={2024} +} + +@article{papillon2023architectures, + title={Architectures of Topological Deep Learning: A Survey of Message-Passing Topological Neural Networks}, + author={Papillon, Mathilde and Sanborn, Sophia and Hajij, Mustafa and Miolane, Nina}, + journal={arXiv preprint arXiv:2304.10031}, + year={2023} +} + ``` ## Funding From b5624ae6ae9d5e37912240213b2902f409853d8b Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 14:11:08 -0700 Subject: [PATCH 07/11] minor fix --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 739552af..33ea6e18 100644 --- a/README.md +++ b/README.md @@ -133,18 +133,18 @@ Then: ## 🔍 References ## -- TMX is a part of TopoX, a suite of Python packages for machine learning on topological domains. If you find TMX useful please consider citing our software paper: +TMX is a part of TopoX, a suite of Python packages for machine learning on topological domains. If you find TMX useful please consider citing our software paper: -Hajij et al. 2023. TopoX: a suite of Python packages for machine learning on topological domains +- Hajij et al. 2023. TopoX: a suite of Python packages for machine learning on topological domains -- To learn more about the blueprint topological deep learning that topomodelx follows : +To learn more about the blueprint topological deep learning that topomodelx follows : -Mustafa Hajij, Ghada Zamzmi, Theodore Papamarkou, Nina Miolane, Aldo Guzmán-Sáenz, Karthikeyan Natesan Ramamurthy, Tolga Birdal, Tamal K. Dey, Soham Mukherjee, Shreyas N. Samaga, Neal Livesay, Robin Walters, Paul Rosen, Michael T. Schaub. +- Mustafa Hajij, Ghada Zamzmi, Theodore Papamarkou, Nina Miolane, Aldo Guzmán-Sáenz, Karthikeyan Natesan Ramamurthy, Tolga Birdal, Tamal K. Dey, Soham Mukherjee, Shreyas N. Samaga, Neal Livesay, Robin Walters, Paul Rosen, Michael T. Schaub. [Topological Deep Learning: Going Beyond Graph Data](https://arxiv.org/abs/2206.00606) (arXiv) • [Topological Deep Learning: A Book](https://tdlbook.org/) -- TMX topological neural networks are surveyed in: +TMX topological neural networks are surveyed in: -Papillon et al. 2023. Architectures of Topological Deep Learning: A Survey on Topological Neural Networks. +- Papillon et al. 2023. Architectures of Topological Deep Learning: A Survey on Topological Neural Networks. ``` @misc{hajij2023topological, From d078fde19ff8128115bbda1b5bc8c4e047e0f55b Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 14:20:38 -0700 Subject: [PATCH 08/11] fixin gpyproject --- pyproject.toml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4a32b2c5..cb5019cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,10 +8,6 @@ dynamic = ["version"] authors = [ {name = "PyT-Team Authors", email = "mustafahajij@gmail.com"} ] - -maintainers = [ - {name = "Mustafa Hajij", email = "mustafahajij@gmail.com", Florian Frantzen} -] readme = "README.md" description = "Topological Deep Learning" license = {file = "LICENSE.txt"} @@ -71,10 +67,8 @@ dev = ["TopoModelX[test, lint]"] all = ["TopoModelX[dev, doc]"] [project.urls] -homepage = "https://github.com/pyt-team/TopoModelX" -repository = "https://github.com/pyt-team/TopoModelX" -documentation = "https://pyt-team.github.io/TopoModelX" -issues = "https://github.com/pyt-team/TopoModelX/issues" +homepage="https://github.com/pyt-team/TopoModelX" +repository="https://github.com/pyt-team/TopoModelX" [tool.ruff] target-version = "py310" From 487812b2c87a95a7f496ee1366a50387b517514e Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 14:23:32 -0700 Subject: [PATCH 09/11] minor changes --- pyproject.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cb5019cd..6da54f15 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,8 +67,10 @@ dev = ["TopoModelX[test, lint]"] all = ["TopoModelX[dev, doc]"] [project.urls] -homepage="https://github.com/pyt-team/TopoModelX" -repository="https://github.com/pyt-team/TopoModelX" +homepage = "https://github.com/pyt-team/TopoModelX" +repository = "https://github.com/pyt-team/TopoModelX" +documentation = "https://pyt-team.github.io/TopoModelX" +issues = "https://github.com/pyt-team/TopoModelX/issues" [tool.ruff] target-version = "py310" From bec8957559c8631b3af4fb07cbaea4ef927f0cd9 Mon Sep 17 00:00:00 2001 From: "your.user.name" Date: Sun, 20 Oct 2024 15:29:31 -0700 Subject: [PATCH 10/11] adding pip lines --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 33ea6e18..288f9049 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,28 @@ model = Network(in_channels=x.shape[-1], hidden_channels=16, out_channels=2) y_hat_edge = model(x, laplacian_up=laplacian_up, laplacian_down=laplacian_down) ``` +## 🤖 Installing TopoModelX + +`TopoModelX` is available on PyPI and can be installed using `pip`. + + +### Install with pip + +To install `TopoModelX` and its dependencies, run the following command: + +```bash +pip install topomodelx +``` +Then install torch, torch-scatter, torch-sparse with or without CUDA depending on your needs. + + ```bash + pip install torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/${CUDA} + pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+${CUDA}.html + pip install torch-cluster -f https://data.pyg.org/whl/torch-2.0.0+${CUDA}.html + ``` +where `${CUDA}` should be replaced by either `cpu`, `cu102`, `cu113`, or `cu115` depending on your PyTorch installation (`torch.version.cuda`). + + ## 🦾 Contributing to TMX To develop tmx on your machine, here are some tips. From 9e784bd05825b7504349a1bbf76d597894a1af02 Mon Sep 17 00:00:00 2001 From: Florian Frantzen Date: Mon, 21 Oct 2024 10:21:12 +0200 Subject: [PATCH 11/11] Changes from code review --- README.md | 24 ++++++++++-------------- pyproject.toml | 9 ++++----- test/tutorials/test_cell.py | 28 ++++++++++++++-------------- test/tutorials/test_combinatorial.py | 28 ++++++++++++++-------------- test/tutorials/test_hypergraph.py | 28 ++++++++++++++-------------- test/tutorials/test_simplicial.py | 28 ++++++++++++++-------------- 6 files changed, 70 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 288f9049..4e959c44 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,13 @@ Below is a minimal example of using TopoModelX to load a simplicial complex data ```bash import numpy as np +import toponetx as tnx import torch -from topomodelx.datasets.graph import karate_club from topomodelx.nn.simplicial.san import SAN from topomodelx.utils.sparse import from_sparse # Step 1: Load the Karate Club dataset -dataset = karate_club(complex_type="simplicial") +dataset = tnx.karate_club(complex_type="simplicial") # Step 2: Prepare Laplacians and node/edge features laplacian_down = from_sparse(dataset.down_laplacian_matrix(rank=1)) @@ -79,23 +79,19 @@ y_hat_edge = model(x, laplacian_up=laplacian_up, laplacian_down=laplacian_down) ## 🤖 Installing TopoModelX -`TopoModelX` is available on PyPI and can be installed using `pip`. - - -### Install with pip - -To install `TopoModelX` and its dependencies, run the following command: +`TopoModelX` is available on PyPI and can be installed using `pip`. +Run the following command: ```bash pip install topomodelx ``` -Then install torch, torch-scatter, torch-sparse with or without CUDA depending on your needs. - ```bash - pip install torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/${CUDA} - pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+${CUDA}.html - pip install torch-cluster -f https://data.pyg.org/whl/torch-2.0.0+${CUDA}.html - ``` +Then install torch, torch-scatter, torch-sparse with or without CUDA depending on your needs. +```bash +pip install torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/${CUDA} +pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.0.1+${CUDA}.html +pip install torch-cluster -f https://data.pyg.org/whl/torch-2.0.0+${CUDA}.html +``` where `${CUDA}` should be replaced by either `cpu`, `cu102`, `cu113`, or `cu115` depending on your PyTorch installation (`torch.version.cuda`). diff --git a/pyproject.toml b/pyproject.toml index 6da54f15..ed006944 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,10 +67,9 @@ dev = ["TopoModelX[test, lint]"] all = ["TopoModelX[dev, doc]"] [project.urls] -homepage = "https://github.com/pyt-team/TopoModelX" -repository = "https://github.com/pyt-team/TopoModelX" -documentation = "https://pyt-team.github.io/TopoModelX" -issues = "https://github.com/pyt-team/TopoModelX/issues" +documentation = "https://pyt-team.github.io/TopoModelX" +source = "https://github.com/pyt-team/TopoModelX" +issues = "https://github.com/pyt-team/TopoModelX/issues" [tool.ruff] target-version = "py310" @@ -95,7 +94,7 @@ select = [ "PERF", # performance rules "RUF", # miscellaneous rules ] -ignore = ["E501", "SIM115"] # line too long +ignore = ["E501"] # line too long [tool.ruff.lint.pydocstyle] convention = "numpy" diff --git a/test/tutorials/test_cell.py b/test/tutorials/test_cell.py index 1eebde07..0bea2f4b 100644 --- a/test/tutorials/test_cell.py +++ b/test/tutorials/test_cell.py @@ -9,20 +9,20 @@ def _exec_tutorial(path): """Execute a tutorial notebook.""" - file_name = tempfile.NamedTemporaryFile(suffix=".ipynb").name - args = [ - "jupyter", - "nbconvert", - "--to", - "notebook", - "--execute", - "--ExecutePreprocessor.timeout=1000", - "--ExecutePreprocessor.kernel_name=python3", - "--output", - file_name, - path, - ] - subprocess.check_call(args) + with tempfile.NamedTemporaryFile(suffix=".ipynb") as tmp_file: + args = [ + "jupyter", + "nbconvert", + "--to", + "notebook", + "--execute", + "--ExecutePreprocessor.timeout=1000", + "--ExecutePreprocessor.kernel_name=python3", + "--output", + tmp_file.name, + path, + ] + subprocess.check_call(args) paths = sorted(glob.glob("tutorials/cell/*.ipynb")) diff --git a/test/tutorials/test_combinatorial.py b/test/tutorials/test_combinatorial.py index 3190da47..d89ee074 100644 --- a/test/tutorials/test_combinatorial.py +++ b/test/tutorials/test_combinatorial.py @@ -9,20 +9,20 @@ def _exec_tutorial(path): """Execute a tutorial notebook.""" - file_name = tempfile.NamedTemporaryFile(suffix=".ipynb").name - args = [ - "jupyter", - "nbconvert", - "--to", - "notebook", - "--execute", - "--ExecutePreprocessor.timeout=1000", - "--ExecutePreprocessor.kernel_name=python3", - "--output", - file_name, - path, - ] - subprocess.check_call(args) + with tempfile.NamedTemporaryFile(suffix=".ipynb") as tmp_file: + args = [ + "jupyter", + "nbconvert", + "--to", + "notebook", + "--execute", + "--ExecutePreprocessor.timeout=1000", + "--ExecutePreprocessor.kernel_name=python3", + "--output", + tmp_file.name, + path, + ] + subprocess.check_call(args) paths = sorted(glob.glob("tutorials/combinatorial/*.ipynb")) diff --git a/test/tutorials/test_hypergraph.py b/test/tutorials/test_hypergraph.py index ecce2b48..e544d6b5 100644 --- a/test/tutorials/test_hypergraph.py +++ b/test/tutorials/test_hypergraph.py @@ -9,20 +9,20 @@ def _exec_tutorial(path): """Execute a tutorial notebook.""" - file_name = tempfile.NamedTemporaryFile(suffix=".ipynb").name - args = [ - "jupyter", - "nbconvert", - "--to", - "notebook", - "--execute", - "--ExecutePreprocessor.timeout=1500", - "--ExecutePreprocessor.kernel_name=python3", - "--output", - file_name, - path, - ] - subprocess.check_call(args) + with tempfile.NamedTemporaryFile(suffix=".ipynb") as tmp_file: + args = [ + "jupyter", + "nbconvert", + "--to", + "notebook", + "--execute", + "--ExecutePreprocessor.timeout=1500", + "--ExecutePreprocessor.kernel_name=python3", + "--output", + tmp_file.name, + path, + ] + subprocess.check_call(args) paths = sorted(glob.glob("tutorials/hypergraph/*.ipynb")) diff --git a/test/tutorials/test_simplicial.py b/test/tutorials/test_simplicial.py index 5fd05ed8..8bb2aba6 100644 --- a/test/tutorials/test_simplicial.py +++ b/test/tutorials/test_simplicial.py @@ -9,20 +9,20 @@ def _exec_tutorial(path): """Execute a tutorial notebook.""" - file_name = tempfile.NamedTemporaryFile(suffix=".ipynb").name - args = [ - "jupyter", - "nbconvert", - "--to", - "notebook", - "--execute", - "--ExecutePreprocessor.timeout=1000", - "--ExecutePreprocessor.kernel_name=python3", - "--output", - file_name, - path, - ] - subprocess.check_call(args) + with tempfile.NamedTemporaryFile(suffix=".ipynb") as tmp_file: + args = [ + "jupyter", + "nbconvert", + "--to", + "notebook", + "--execute", + "--ExecutePreprocessor.timeout=1000", + "--ExecutePreprocessor.kernel_name=python3", + "--output", + tmp_file.name, + path, + ] + subprocess.check_call(args) paths = sorted(glob.glob("tutorials/simplicial/*.ipynb"))