Skip to content

Commit

Permalink
added ruff linting; added github actions configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
awa59kst120df committed Oct 7, 2024
1 parent 2f7a0e1 commit 8d1aed4
Show file tree
Hide file tree
Showing 39 changed files with 701 additions and 410 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/run_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run Unit Test

on: [push]

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install uv
uv pip install -e .
- name: Lint with Ruff
run: |
pip install ruff
ruff check .
- name: Run tests
run: |
python -m unittest discover -s tests -p '*_test.py'
16 changes: 15 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,18 @@ Additional changes:
-------------------

HOTFIX: The ``Megan.regression_reference`` running mean is now a ``nn.Parameter`` and therefore also included
when saving/loading the model from persistent files.
when saving/loading the model from persistent files.

0.18.2 - 08.08.2024
-------------------

HOTFIX: Removed batchnorm layers in the projection MLPs as this was causing significantly different results when
running the model in eval mode versus in

- modified the GraphAttentionLayerV2 to now use a "look ahead" aggregation of the neighbor nodes as well in the
message update. significantly improves the explanations for the BA2Motifs dataset.

0.18.3 - 01.10.2024
-------------------

- modified the augementations that are used for the contrastive learning now.
2 changes: 1 addition & 1 deletion graph_attention_student/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.18.1
0.18.2
11 changes: 0 additions & 11 deletions graph_attention_student/assets/models/aqsoldb/process.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import os
import pathlib
import typing as t

import click
import numpy as np
import numpy.linalg as la
import matplotlib as mpl
import matplotlib.pyplot as plt
import rdkit
import rdkit.Chem.AllChem
from rdkit import Chem
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

import visual_graph_datasets.typing as tc
# processing
from visual_graph_datasets.processing.base import *
from visual_graph_datasets.processing.colors import *
Expand Down
2 changes: 0 additions & 2 deletions graph_attention_student/cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import os
import sys
import click

from pycomex.experiment import run_experiment
from pycomex.cli import ExperimentCLI

from graph_attention_student.util import get_version
from graph_attention_student.util import DATASETS_FOLDER
from graph_attention_student.util import EXAMPLES_FOLDER
from graph_attention_student.util import EXPERIMENTS_PATH

Expand Down
20 changes: 7 additions & 13 deletions graph_attention_student/data.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
import os
import sys
import csv
import time
import json
import random
import orjson
import logging
import tempfile
import typing as t
from copy import copy
from typing import List, Tuple, Optional, Dict, Callable
from collections import defaultdict

import cairosvg
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
import tensorflow as tf
import visual_graph_datasets.typing as tv
from rdkit import Chem
from rdkit.Chem.Draw.rdMolDraw2D import MolDraw2DSVG
from rdkit.Chem import rdDepictor
rdDepictor.SetPreferCoordGen(True)

import graph_attention_student.typing as tc
from graph_attention_student.util import NULL_LOGGER
from graph_attention_student.util import graph_dict_to_list_values
from graph_attention_student.util import update_nested_dict
from graph_attention_student.visualization import draw_extended_colors_graph
from graph_attention_student.visualization import draw_edge_black
from graph_attention_student.visualization import draw_node_color_scatter

rdDepictor.SetPreferCoordGen(True)


class NumericJsonEncoder(json.JSONEncoder):

Expand Down Expand Up @@ -96,7 +91,6 @@ def process_index_data_map(index_data_map: t.Dict[int, dict],
:returns: A tuple of two lists.
"""
dataset_length = len(index_data_map)
dataset_indices = []
dataset = [None for _ in range(max(index_data_map.keys()) + 1)]
for index, data in index_data_map.items():
Expand Down Expand Up @@ -270,7 +264,7 @@ def load_eye_tracking_dataset_dict(dataset_path: str,
:param sanitize_dict:
:return:
"""
logger.info(f'determining the file names...')
logger.info('determining the file names...')
files = os.listdir(dataset_path)
names = set()
for file_name in files:
Expand Down Expand Up @@ -431,7 +425,7 @@ def graphs_locally_similar(primary_graph: dict,
primary_adjacency_mask[i][primary_index] = primary_ingoing
break

except StopIteration as e:
except StopIteration:
pass

# If we have not found a similar node at the end of the iteration, then there is none within the
Expand Down Expand Up @@ -825,9 +819,9 @@ def insert_edge(self, i: int, j: int) -> None:
else:
edges = [[i, j], [j, i]]

for k, l in edges:
self.edge_indices[self.current_edge_index] = [k, l]
self.edge_attributes[self.current_edge_index] = self.create_single_edge_attributes(k, l)
for k, h in edges:
self.edge_indices[self.current_edge_index] = [k, h]
self.edge_attributes[self.current_edge_index] = self.create_single_edge_attributes(k, h)
self.current_edge_index += 1

def grow_nodes(self):
Expand Down
10 changes: 10 additions & 0 deletions graph_attention_student/examples/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
===========
📌 Examples
===========

This folder defines a series of example scripts that demonstrate how to use various functionalities of the
``graph_attention_student`` package and the ``Megan`` graph neural network model.

The examples are split into the following files:

- ``00_quickstart.py``: A quickstart guide
11 changes: 0 additions & 11 deletions graph_attention_student/examples/assets/aqsoldb_process.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import os
import pathlib
import typing as t

import click
import numpy as np
import numpy.linalg as la
import matplotlib as mpl
import matplotlib.pyplot as plt
import rdkit
import rdkit.Chem.AllChem
from rdkit import Chem
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

import visual_graph_datasets.typing as tc
# processing
from visual_graph_datasets.processing.base import *
from visual_graph_datasets.processing.colors import *
Expand Down
3 changes: 0 additions & 3 deletions graph_attention_student/experiments/plot_explanations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import typing as t

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from pycomex.functional.experiment import Experiment
from pycomex.utils import file_namespace, folder_path
from visual_graph_datasets.config import Config
Expand All @@ -15,7 +13,6 @@
from visual_graph_datasets.data import VisualGraphDatasetWriter
from visual_graph_datasets.processing.base import ProcessingBase
from visual_graph_datasets.visualization.importances import create_importances_pdf
from visual_graph_datasets.visualization.importances import create_combined_importances_pdf
from visual_graph_datasets.visualization.importances import plot_node_importances_background
from visual_graph_datasets.visualization.importances import plot_edge_importances_background

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import os
import pathlib
import typing as t

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.colors as mcolors
from graph_attention_student.visualization import truncate_colormap
Expand All @@ -13,7 +11,6 @@

from graph_attention_student.torch.megan import Megan
from graph_attention_student.utils import fidelity_from_deviation
from graph_attention_student.visualization import truncate_colormap

# == DATASET PARAMETERS ==
# This section contains the parameters which determine the dataset and how to handle said dataset.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import os
import json
import pathlib
import textwrap
import typing as t

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
from pycomex.functional.experiment import Experiment
from pycomex.utils import file_namespace, folder_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import os
import json
import pathlib
import textwrap
import typing as t

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
from pycomex.functional.experiment import Experiment
from pycomex.utils import file_namespace, folder_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
import json
import pathlib
import textwrap
import typing as t

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
from pycomex.functional.experiment import Experiment
from pycomex.utils import file_namespace, folder_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import os
import json
import pathlib
import textwrap
import typing as t

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
from pycomex.functional.experiment import Experiment
from pycomex.utils import file_namespace, folder_path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""
import os
import pathlib
import typing as t

from pycomex.util import Skippable
from pycomex.experiment import SubExperiment
Expand Down
7 changes: 2 additions & 5 deletions graph_attention_student/experiments/vgd_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@

import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import torch.nn as nn
import pytorch_lightning as pl
from matplotlib.backends.backend_pdf import PdfPages
from sklearn.metrics import r2_score
Expand All @@ -42,7 +40,6 @@
from visual_graph_datasets.web import ensure_dataset
from visual_graph_datasets.data import VisualGraphDatasetReader
from visual_graph_datasets.visualization.base import draw_image
from torch_geometric.data import Data
from torch_geometric.loader import DataLoader
from lightning.pytorch.loggers import CSVLogger

Expand Down Expand Up @@ -618,8 +615,8 @@ def testing(e: Experiment):
dataset_path = e.VISUAL_GRAPH_DATASET

else:
e.log(f'dataset is not a local folder')
e.log(f'attempting to fetch dataset from remote file share...')
e.log('dataset is not a local folder')
e.log('attempting to fetch dataset from remote file share...')
config = Config()
config.load()
dataset_path = ensure_dataset(e.VISUAL_GRAPH_DATASET, config)
Expand Down
Loading

0 comments on commit 8d1aed4

Please sign in to comment.