diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a6d5d5a4..b7606452 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,20 @@ repos: - repo: local hooks: + - id: isort + name: isort + entry: isort . --settings-file pyproject.toml + language: system + pass_filenames: false - id: black name: black entry: black . language: system pass_filenames: false + - id: autoflake + name: autoflake + entry: autoflake + language: system + types: [ python ] + args: [ --in-place, --remove-all-unused-imports, --remove-duplicate-keys ] + files: ^bindsnet/|test/ \ No newline at end of file diff --git a/bindsnet/__init__.py b/bindsnet/__init__.py index 630f3129..df7ac702 100644 --- a/bindsnet/__init__.py +++ b/bindsnet/__init__.py @@ -1,18 +1,35 @@ from pathlib import Path -from . import ( - utils, - network, - models, +from bindsnet import ( analysis, - preprocessing, + conversion, datasets, encoding, - pipeline, - learning, - evaluation, environment, - conversion, + evaluation, + learning, + models, + network, + pipeline, + preprocessing, + utils, ) ROOT_DIR = Path(__file__).parents[0].parents[0] + + +__all__ = [ + "utils", + "network", + "models", + "analysis", + "preprocessing", + "datasets", + "encoding", + "pipeline", + "learning", + "evaluation", + "environment", + "conversion", + "ROOT_DIR", +] diff --git a/bindsnet/analysis/__init__.py b/bindsnet/analysis/__init__.py index d923d175..d5b93c66 100644 --- a/bindsnet/analysis/__init__.py +++ b/bindsnet/analysis/__init__.py @@ -1 +1,3 @@ -from . import plotting, visualization, pipeline_analysis +from bindsnet.analysis import pipeline_analysis, plotting, visualization + +__all__ = ["plotting", "visualization", "pipeline_analysis"] diff --git a/bindsnet/analysis/dotTrace_plotter.py b/bindsnet/analysis/dotTrace_plotter.py index d9e552b1..f1fdbc90 100644 --- a/bindsnet/analysis/dotTrace_plotter.py +++ b/bindsnet/analysis/dotTrace_plotter.py @@ -1,8 +1,8 @@ -import numpy as np import glob import sys import matplotlib.pyplot as plt +import numpy as np # Define grid dimensions globally ROWS = 28 diff --git a/bindsnet/analysis/pipeline_analysis.py b/bindsnet/analysis/pipeline_analysis.py index 5ebe4971..46230fd9 100644 --- a/bindsnet/analysis/pipeline_analysis.py +++ b/bindsnet/analysis/pipeline_analysis.py @@ -8,8 +8,8 @@ from tensorboardX import SummaryWriter from torchvision.utils import make_grid -from .plotting import plot_spikes, plot_voltages, plot_conv2d_weights from ..utils import reshape_conv2d_weights +from .plotting import plot_conv2d_weights, plot_spikes, plot_voltages class PipelineAnalyzer(ABC): @@ -25,7 +25,6 @@ def finalize_step(self) -> None: """ Flush the output from the current step. """ - pass @abstractmethod def plot_obs(self, obs: torch.Tensor, tag: str = "obs", step: int = None) -> None: @@ -38,7 +37,6 @@ def plot_obs(self, obs: torch.Tensor, tag: str = "obs", step: int = None) -> Non :param tag: A unique tag to associate the data with. :param step: The step of the pipeline. """ - pass @abstractmethod def plot_reward( @@ -57,7 +55,6 @@ def plot_reward( :param tag: A unique tag to associate the data with. :param step: The step of the pipeline. """ - pass @abstractmethod def plot_spikes( @@ -75,7 +72,6 @@ def plot_spikes( :param tag: A unique tag to associate the data with. :param step: The step of the pipeline. """ - pass @abstractmethod def plot_voltages( @@ -96,7 +92,6 @@ def plot_voltages( :param tag: A unique tag to associate the data with. :param step: The step of the pipeline. """ - pass @abstractmethod def plot_conv2d_weights( @@ -110,7 +105,6 @@ def plot_conv2d_weights( :param tag: A unique tag to associate the data with. :param step: The step of the pipeline. """ - pass class MatplotlibAnalyzer(PipelineAnalyzer): @@ -313,7 +307,6 @@ def finalize_step(self) -> None: """ No-op for ``TensorboardAnalyzer``. """ - pass def plot_obs(self, obs: torch.Tensor, tag: str = "obs", step: int = None) -> None: # language=rst diff --git a/bindsnet/analysis/plotting.py b/bindsnet/analysis/plotting.py index 64e00a5e..d7871274 100644 --- a/bindsnet/analysis/plotting.py +++ b/bindsnet/analysis/plotting.py @@ -1,15 +1,15 @@ -import torch -import numpy as np -import matplotlib.pyplot as plt +from typing import Dict, List, Optional, Sized, Tuple, Union +import matplotlib.pyplot as plt +import numpy as np +import torch from matplotlib.axes import Axes -from matplotlib.image import AxesImage -from torch.nn.modules.utils import _pair from matplotlib.collections import PathCollection +from matplotlib.image import AxesImage from mpl_toolkits.axes_grid1 import make_axes_locatable -from typing import Tuple, List, Optional, Sized, Dict, Union +from torch.nn.modules.utils import _pair -from ..utils import reshape_locally_connected_weights, reshape_conv2d_weights +from bindsnet.utils import reshape_conv2d_weights, reshape_locally_connected_weights plt.ion() diff --git a/bindsnet/analysis/visualization.py b/bindsnet/analysis/visualization.py index 0b151663..0d49315f 100644 --- a/bindsnet/analysis/visualization.py +++ b/bindsnet/analysis/visualization.py @@ -1,9 +1,9 @@ -import torch -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.animation as animation +from typing import List, Optional, Tuple -from typing import List, Tuple, Optional +import matplotlib.animation as animation +import matplotlib.pyplot as plt +import numpy as np +import torch def plot_weights_movie(ws: np.ndarray, sample_every: int = 1) -> None: diff --git a/bindsnet/conversion/__init__.py b/bindsnet/conversion/__init__.py index 05950aa3..4cdd7886 100644 --- a/bindsnet/conversion/__init__.py +++ b/bindsnet/conversion/__init__.py @@ -1,10 +1,21 @@ -from .conversion import ( - Permute, +from bindsnet.conversion.conversion import ( + ConstantPad2dConnection, FeatureExtractor, - SubtractiveResetIFNodes, PassThroughNodes, + Permute, PermuteConnection, - ConstantPad2dConnection, - data_based_normalization, + SubtractiveResetIFNodes, ann_to_snn, + data_based_normalization, ) + +__all__ = [ + "Permute", + "FeatureExtractor", + "SubtractiveResetIFNodes", + "PassThroughNodes", + "PermuteConnection", + "ConstantPad2dConnection", + "data_based_normalization", + "ann_to_snn", +] diff --git a/bindsnet/conversion/conversion.py b/bindsnet/conversion/conversion.py index 32349f9d..96037192 100644 --- a/bindsnet/conversion/conversion.py +++ b/bindsnet/conversion/conversion.py @@ -1,19 +1,16 @@ -import torch +from copy import deepcopy +from typing import Dict, Optional, Sequence, Union + import numpy as np +import torch import torch.nn as nn -import torch.nn.functional as F - from torch.nn.modules.utils import _pair -from copy import deepcopy -from typing import Union, Sequence, Optional, Tuple, Dict, Iterable - import bindsnet.network.nodes as nodes import bindsnet.network.topology as topology - +from bindsnet.conversion.nodes import PassThroughNodes, SubtractiveResetIFNodes +from bindsnet.conversion.topology import ConstantPad2dConnection, PermuteConnection from bindsnet.network import Network -from .nodes import SubtractiveResetIFNodes, PassThroughNodes -from .topology import PermuteConnection, ConstantPad2dConnection class Permute(nn.Module): diff --git a/bindsnet/conversion/nodes.py b/bindsnet/conversion/nodes.py index 27b1d1c8..2f8422d2 100644 --- a/bindsnet/conversion/nodes.py +++ b/bindsnet/conversion/nodes.py @@ -1,4 +1,4 @@ -from typing import Optional, Iterable, Union +from typing import Iterable, Optional, Union import torch diff --git a/bindsnet/conversion/topology.py b/bindsnet/conversion/topology.py index 1ab5ab49..d7f33361 100644 --- a/bindsnet/conversion/topology.py +++ b/bindsnet/conversion/topology.py @@ -1,4 +1,4 @@ -from typing import Optional, Iterable, Union, Tuple +from typing import Iterable, Optional, Tuple, Union import torch import torch.nn.functional as F diff --git a/bindsnet/datasets/__init__.py b/bindsnet/datasets/__init__.py index 16088ca5..e37f2daf 100644 --- a/bindsnet/datasets/__init__.py +++ b/bindsnet/datasets/__init__.py @@ -1,11 +1,9 @@ -from .torchvision_wrapper import create_torchvision_dataset_wrapper -from .spoken_mnist import SpokenMNIST -from .davis import Davis -from .alov300 import ALOV300 - -from .collate import time_aware_collate -from .dataloader import DataLoader - +from bindsnet.datasets.alov300 import ALOV300 +from bindsnet.datasets.collate import time_aware_collate +from bindsnet.datasets.dataloader import DataLoader +from bindsnet.datasets.davis import Davis +from bindsnet.datasets.spoken_mnist import SpokenMNIST +from bindsnet.datasets.torchvision_wrapper import create_torchvision_dataset_wrapper CIFAR10 = create_torchvision_dataset_wrapper("CIFAR10") CIFAR100 = create_torchvision_dataset_wrapper("CIFAR100") @@ -31,3 +29,44 @@ SVHN = create_torchvision_dataset_wrapper("SVHN") VOCDetection = create_torchvision_dataset_wrapper("VOCDetection") VOCSegmentation = create_torchvision_dataset_wrapper("VOCSegmentation") + + +__all__ = [ + "torchvision_wrapper", + "create_torchvision_dataset_wrapper", + "spoken_mnist", + "SpokenMNIST", + "davis", + "Davis", + "preprocess", + "alov300", + "ALOV300", + "collate", + "time_aware_collate", + "dataloader", + "DataLoader", + "CIFAR10", + "CIFAR100", + "Cityscapes", + "CocoCaptions", + "CocoDetection", + "DatasetFolder", + "EMNIST", + "FakeData", + "FashionMNIST", + "Flickr30k", + "Flickr8k", + "ImageFolder", + "KMNIST", + "LSUN", + "LSUNClass", + "MNIST", + "Omniglot", + "PhotoTour", + "SBU", + "SEMEION", + "STL10", + "SVHN", + "VOCDetection", + "VOCSegmentation", +] diff --git a/bindsnet/datasets/alov300.py b/bindsnet/datasets/alov300.py index 0039899f..a0fe495b 100644 --- a/bindsnet/datasets/alov300.py +++ b/bindsnet/datasets/alov300.py @@ -1,24 +1,20 @@ import os import sys import time -import zipfile import warnings -from glob import glob +import zipfile from urllib.request import urlretrieve -from typing import Optional, Tuple, List, Iterable import cv2 -import torch import numpy as np -from PIL import Image from torch.utils.data import Dataset from bindsnet.datasets.preprocess import ( - cropPadImage, BoundingBox, - crop_sample, Rescale, bgr2rgb, + crop_sample, + cropPadImage, ) warnings.filterwarnings("ignore") diff --git a/bindsnet/datasets/collate.py b/bindsnet/datasets/collate.py index acd42bf8..df8272bd 100644 --- a/bindsnet/datasets/collate.py +++ b/bindsnet/datasets/collate.py @@ -7,10 +7,10 @@ Modifications exist to have [time, batch, n_0, ... n_k] instead of batch in dimension 0. """ -import torch -from torch._six import string_classes import collections +import torch +from torch._six import string_classes from torch.utils.data._utils import collate as pytorch_collate diff --git a/bindsnet/datasets/dataloader.py b/bindsnet/datasets/dataloader.py index 640d8f68..d1d36ddb 100644 --- a/bindsnet/datasets/dataloader.py +++ b/bindsnet/datasets/dataloader.py @@ -1,6 +1,6 @@ import torch -from .collate import time_aware_collate +from bindsnet.datasets.collate import time_aware_collate class DataLoader(torch.utils.data.DataLoader): diff --git a/bindsnet/datasets/davis.py b/bindsnet/datasets/davis.py index 588c7c46..c494d894 100644 --- a/bindsnet/datasets/davis.py +++ b/bindsnet/datasets/davis.py @@ -1,14 +1,14 @@ import os +import shutil import sys import time -import shutil import zipfile -from glob import glob from collections import defaultdict +from glob import glob from urllib.request import urlretrieve -import torch import numpy as np +import torch from PIL import Image from tqdm import tqdm diff --git a/bindsnet/datasets/preprocess.py b/bindsnet/datasets/preprocess.py index 4c130498..d0249eb3 100644 --- a/bindsnet/datasets/preprocess.py +++ b/bindsnet/datasets/preprocess.py @@ -1,10 +1,9 @@ import math import random -import warnings import cv2 -import torch import numpy as np +import torch from torchvision import transforms diff --git a/bindsnet/datasets/spoken_mnist.py b/bindsnet/datasets/spoken_mnist.py index e299fe6b..7a86fee6 100644 --- a/bindsnet/datasets/spoken_mnist.py +++ b/bindsnet/datasets/spoken_mnist.py @@ -1,15 +1,12 @@ -from typing import Optional, Tuple, List, Iterable import os -import torch -import numpy as np import shutil import zipfile - - +from typing import Iterable, List, Tuple from urllib.request import urlretrieve -from scipy.io import wavfile -import warnings +import numpy as np +import torch +from scipy.io import wavfile class SpokenMNIST(torch.utils.data.Dataset): diff --git a/bindsnet/datasets/torchvision_wrapper.py b/bindsnet/datasets/torchvision_wrapper.py index d86fb77f..b3540c72 100644 --- a/bindsnet/datasets/torchvision_wrapper.py +++ b/bindsnet/datasets/torchvision_wrapper.py @@ -1,9 +1,9 @@ -from typing import Optional, Dict +from typing import Dict, Optional import torch import torchvision -from ..encoding import Encoder, NullEncoder +from bindsnet.encoding import Encoder, NullEncoder def create_torchvision_dataset_wrapper(ds_type): diff --git a/bindsnet/encoding/__init__.py b/bindsnet/encoding/__init__.py index 1be014f3..602af6b0 100644 --- a/bindsnet/encoding/__init__.py +++ b/bindsnet/encoding/__init__.py @@ -1,11 +1,37 @@ -from .encodings import single, repeat, bernoulli, poisson, rank_order -from .loaders import bernoulli_loader, poisson_loader, rank_order_loader +from bindsnet.encoding.encodings import bernoulli, poisson, rank_order, repeat, single +from bindsnet.encoding.loaders import ( + bernoulli_loader, + poisson_loader, + rank_order_loader, +) + from .encoders import ( + BernoulliEncoder, Encoder, NullEncoder, - SingleEncoder, - RepeatEncoder, - BernoulliEncoder, PoissonEncoder, RankOrderEncoder, + RepeatEncoder, + SingleEncoder, ) + +__all__ = [ + "encodings", + "single", + "repeat", + "bernoulli", + "poisson", + "rank_order", + "loaders", + "bernoulli_loader", + "poisson_loader", + "rank_order_loader", + "encoders", + "Encoder", + "NullEncoder", + "SingleEncoder", + "RepeatEncoder", + "BernoulliEncoder", + "PoissonEncoder", + "RankOrderEncoder", +] diff --git a/bindsnet/encoding/encoders.py b/bindsnet/encoding/encoders.py index 111e939f..c6a91e1e 100644 --- a/bindsnet/encoding/encoders.py +++ b/bindsnet/encoding/encoders.py @@ -1,4 +1,4 @@ -from . import encodings +from bindsnet.encoding import encodings class Encoder: diff --git a/bindsnet/encoding/loaders.py b/bindsnet/encoding/loaders.py index 16dfbd40..3ba7f881 100644 --- a/bindsnet/encoding/loaders.py +++ b/bindsnet/encoding/loaders.py @@ -1,8 +1,8 @@ -from typing import Optional, Union, Iterable, Iterator +from typing import Iterable, Iterator, Optional, Union import torch -from .encodings import bernoulli, poisson, rank_order +from bindsnet.encoding.encodings import bernoulli, poisson, rank_order def bernoulli_loader( diff --git a/bindsnet/environment/__init__.py b/bindsnet/environment/__init__.py index 5167910f..67965489 100644 --- a/bindsnet/environment/__init__.py +++ b/bindsnet/environment/__init__.py @@ -1 +1,3 @@ -from .environment import Environment, GymEnvironment +from bindsnet.environment.environment import Environment, GymEnvironment + +__all__ = ["Environment", "GymEnvironment"] diff --git a/bindsnet/environment/cue_reward.py b/bindsnet/environment/cue_reward.py index 857b91db..113e6f55 100644 --- a/bindsnet/environment/cue_reward.py +++ b/bindsnet/environment/cue_reward.py @@ -1,10 +1,9 @@ -import numpy as np import random from time import time +import numpy as np import torch - # Number of cues to be used in the experiment. NUM_CUES = 4 diff --git a/bindsnet/environment/dot_simulator.py b/bindsnet/environment/dot_simulator.py index e33cf160..e2148748 100644 --- a/bindsnet/environment/dot_simulator.py +++ b/bindsnet/environment/dot_simulator.py @@ -1,13 +1,12 @@ -import numpy as np import os -import pandas as pd import random from time import time +import matplotlib.pyplot as plt +import numpy as np +import pandas as pd import torch from gym import spaces -import matplotlib.pyplot as plt - # Mappings for changing direction if reflected. # Cannot cross a row boundary moving right or left. diff --git a/bindsnet/environment/environment.py b/bindsnet/environment/environment.py index fba9d769..ba48b8b2 100644 --- a/bindsnet/environment/environment.py +++ b/bindsnet/environment/environment.py @@ -1,12 +1,12 @@ from abc import ABC, abstractmethod -from typing import Tuple, Dict, Any +from typing import Any, Dict, Tuple import gym import numpy as np import torch -from ..datasets.preprocess import subsample, gray_scale, binary_image, crop -from ..encoding import Encoder, NullEncoder +from bindsnet.datasets.preprocess import binary_image, crop, gray_scale, subsample +from bindsnet.encoding import Encoder, NullEncoder class Environment(ABC): @@ -23,7 +23,6 @@ def step(self, a: int) -> Tuple[Any, ...]: :param a: Integer action to take in environment. """ - pass @abstractmethod def reset(self) -> None: @@ -31,7 +30,6 @@ def reset(self) -> None: """ Abstract method header for ``reset()``. """ - pass @abstractmethod def render(self) -> None: @@ -39,7 +37,6 @@ def render(self) -> None: """ Abstract method header for ``render()``. """ - pass @abstractmethod def close(self) -> None: @@ -47,7 +44,6 @@ def close(self) -> None: """ Abstract method header for ``close()``. """ - pass @abstractmethod def preprocess(self) -> None: @@ -55,7 +51,6 @@ def preprocess(self) -> None: """ Abstract method header for ``preprocess()``. """ - pass class GymEnvironment(Environment): diff --git a/bindsnet/evaluation/__init__.py b/bindsnet/evaluation/__init__.py index 95f35dda..e70ed097 100644 --- a/bindsnet/evaluation/__init__.py +++ b/bindsnet/evaluation/__init__.py @@ -1,9 +1,19 @@ -from .evaluation import ( +from bindsnet.evaluation.evaluation import ( + all_activity, assign_labels, logreg_fit, logreg_predict, - all_activity, - proportion_weighting, ngram, + proportion_weighting, update_ngram_scores, ) + +__all__ = [ + "assign_labels", + "logreg_fit", + "logreg_predict", + "all_activity", + "proportion_weighting", + "ngram", + "update_ngram_scores", +] diff --git a/bindsnet/evaluation/evaluation.py b/bindsnet/evaluation/evaluation.py index 9d47f35f..5271d762 100644 --- a/bindsnet/evaluation/evaluation.py +++ b/bindsnet/evaluation/evaluation.py @@ -1,5 +1,5 @@ from itertools import product -from typing import Optional, Tuple, Dict +from typing import Dict, Optional, Tuple import torch from sklearn.linear_model import LogisticRegression diff --git a/bindsnet/learning/__init__.py b/bindsnet/learning/__init__.py index 2a37c9ec..5a733783 100644 --- a/bindsnet/learning/__init__.py +++ b/bindsnet/learning/__init__.py @@ -1,10 +1,21 @@ -from .learning import ( +from bindsnet.learning.learning import ( + MSTDP, + MSTDPET, + Hebbian, LearningRule, NoOp, PostPre, - WeightDependentPostPre, - Hebbian, - MSTDP, - MSTDPET, Rmax, + WeightDependentPostPre, ) + +__all__ = [ + "LearningRule", + "NoOp", + "PostPre", + "WeightDependentPostPre", + "Hebbian", + "MSTDP", + "MSTDPET", + "Rmax", +] diff --git a/bindsnet/learning/learning.py b/bindsnet/learning/learning.py index 1cde512c..d57f8cec 100644 --- a/bindsnet/learning/learning.py +++ b/bindsnet/learning/learning.py @@ -1,9 +1,11 @@ -from abc import ABC -from typing import Union, Optional, Sequence import warnings +from abc import ABC +from typing import Optional, Sequence, Union -import torch import numpy as np +import torch + +from bindsnet.utils import im2col_indices from ..network.nodes import SRM0Nodes from ..network.topology import ( @@ -12,7 +14,6 @@ Conv2dConnection, LocalConnection, ) -from ..utils import im2col_indices class LearningRule(ABC): diff --git a/bindsnet/learning/reward.py b/bindsnet/learning/reward.py index c70f91e4..fde135d0 100644 --- a/bindsnet/learning/reward.py +++ b/bindsnet/learning/reward.py @@ -15,7 +15,6 @@ def compute(self, **kwargs) -> None: """ Computes/modifies reward. """ - pass @abstractmethod def update(self, **kwargs) -> None: @@ -24,7 +23,6 @@ def update(self, **kwargs) -> None: Updates internal variables needed to modify reward. Usually called once per episode. """ - pass class MovingAvgRPE(AbstractReward): diff --git a/bindsnet/models/__init__.py b/bindsnet/models/__init__.py index 8d0e295e..b57121bc 100644 --- a/bindsnet/models/__init__.py +++ b/bindsnet/models/__init__.py @@ -1,7 +1,15 @@ -from .models import ( - TwoLayerNetwork, +from bindsnet.models.models import ( DiehlAndCook2015, DiehlAndCook2015v2, IncreasingInhibitionNetwork, LocallyConnectedNetwork, + TwoLayerNetwork, ) + +__all__ = [ + "TwoLayerNetwork", + "DiehlAndCook2015v2", + "DiehlAndCook2015", + "IncreasingInhibitionNetwork", + "LocallyConnectedNetwork", +] diff --git a/bindsnet/models/models.py b/bindsnet/models/models.py index a0639ee4..50f27872 100644 --- a/bindsnet/models/models.py +++ b/bindsnet/models/models.py @@ -1,16 +1,14 @@ -from typing import Optional, Union, Tuple, List, Sequence, Iterable +from typing import Iterable, List, Optional, Sequence, Tuple, Union import numpy as np import torch from scipy.spatial.distance import euclidean from torch.nn.modules.utils import _pair -import torch.nn as nn -from torchvision import models -from ..learning import PostPre -from ..network import Network -from ..network.nodes import Input, LIFNodes, DiehlAndCookNodes, AdaptiveLIFNodes -from ..network.topology import Connection, LocalConnection +from bindsnet.learning import PostPre +from bindsnet.network import Network +from bindsnet.network.nodes import DiehlAndCookNodes, Input, LIFNodes +from bindsnet.network.topology import Connection, LocalConnection class TwoLayerNetwork(Network): diff --git a/bindsnet/network/__init__.py b/bindsnet/network/__init__.py index 942f1f4c..0a30587c 100644 --- a/bindsnet/network/__init__.py +++ b/bindsnet/network/__init__.py @@ -1,2 +1,4 @@ -from .network import Network, load -from . import nodes, topology, monitors +from bindsnet.network import monitors, nodes, topology +from bindsnet.network.network import Network, load + +__all__ = ["Network", "load", "nodes", "topology", "monitors"] diff --git a/bindsnet/network/monitors.py b/bindsnet/network/monitors.py index ca5fd529..3aab2cc5 100644 --- a/bindsnet/network/monitors.py +++ b/bindsnet/network/monitors.py @@ -1,14 +1,12 @@ import os -import torch -import numpy as np - from abc import ABC -from typing import Union, Optional, Iterable, Dict +from typing import TYPE_CHECKING, Dict, Iterable, Optional, Union -from .nodes import Nodes -from .topology import AbstractConnection +import numpy as np +import torch -from typing import TYPE_CHECKING +from bindsnet.network.nodes import Nodes +from bindsnet.network.topology import AbstractConnection if TYPE_CHECKING: from .network import Network diff --git a/bindsnet/network/network.py b/bindsnet/network/network.py index 0bf02a08..fce2e374 100644 --- a/bindsnet/network/network.py +++ b/bindsnet/network/network.py @@ -1,12 +1,12 @@ import tempfile -from typing import Dict, Optional, Type, Iterable +from typing import Dict, Iterable, Optional, Type import torch -from .monitors import AbstractMonitor -from .nodes import Nodes, CSRMNodes -from .topology import AbstractConnection -from ..learning.reward import AbstractReward +from bindsnet.learning.reward import AbstractReward +from bindsnet.network.monitors import AbstractMonitor +from bindsnet.network.nodes import CSRMNodes, Nodes +from bindsnet.network.topology import AbstractConnection def load(file_name: str, map_location: str = "cpu", learning: bool = None) -> "Network": diff --git a/bindsnet/network/topology.py b/bindsnet/network/topology.py index d65f82d6..3b166f18 100644 --- a/bindsnet/network/topology.py +++ b/bindsnet/network/topology.py @@ -1,13 +1,13 @@ from abc import ABC, abstractmethod -from typing import Union, Tuple, Optional, Sequence +from typing import Optional, Sequence, Tuple, Union import numpy as np import torch -from torch.nn import Module, Parameter import torch.nn.functional as F +from torch.nn import Module, Parameter from torch.nn.modules.utils import _pair -from .nodes import Nodes, CSRMNodes +from bindsnet.network.nodes import CSRMNodes, Nodes class AbstractConnection(ABC, Module): @@ -93,7 +93,6 @@ def compute(self, s: torch.Tensor) -> None: :param s: Incoming spikes. """ - pass @abstractmethod def update(self, **kwargs) -> None: @@ -121,7 +120,6 @@ def reset_state_variables(self) -> None: """ Contains resetting logic for the connection. """ - pass class Connection(AbstractConnection): @@ -487,7 +485,6 @@ def normalize(self) -> None: """ No weights -> no normalization. """ - pass def reset_state_variables(self) -> None: # language=rst @@ -848,7 +845,6 @@ def update(self, **kwargs) -> None: """ Compute connection's update rule. """ - pass def normalize(self) -> None: # language=rst @@ -856,7 +852,6 @@ def normalize(self) -> None: Normalize weights along the first axis according to total weight per target neuron. """ - pass def reset_state_variables(self) -> None: # language=rst diff --git a/bindsnet/pipeline/__init__.py b/bindsnet/pipeline/__init__.py index 1c44c2e4..bdf860b4 100644 --- a/bindsnet/pipeline/__init__.py +++ b/bindsnet/pipeline/__init__.py @@ -1,4 +1,15 @@ -from .environment_pipeline import EnvironmentPipeline -from .base_pipeline import BasePipeline -from .dataloader_pipeline import DataLoaderPipeline, TorchVisionDatasetPipeline -from . import action +from bindsnet.pipeline import action +from bindsnet.pipeline.base_pipeline import BasePipeline +from bindsnet.pipeline.dataloader_pipeline import ( + DataLoaderPipeline, + TorchVisionDatasetPipeline, +) +from bindsnet.pipeline.environment_pipeline import EnvironmentPipeline + +__all__ = [ + "EnvironmentPipeline", + "BasePipeline", + "DataLoaderPipeline", + "TorchVisionDatasetPipeline", + "action", +] diff --git a/bindsnet/pipeline/action.py b/bindsnet/pipeline/action.py index fbe97d73..55f468d1 100644 --- a/bindsnet/pipeline/action.py +++ b/bindsnet/pipeline/action.py @@ -1,7 +1,6 @@ import torch -import numpy as np -from . import EnvironmentPipeline +from bindsnet.pipeline.environment_pipeline import EnvironmentPipeline def select_multinomial(pipeline: EnvironmentPipeline, **kwargs) -> int: diff --git a/bindsnet/pipeline/base_pipeline.py b/bindsnet/pipeline/base_pipeline.py index 6790a504..0d8b1c35 100644 --- a/bindsnet/pipeline/base_pipeline.py +++ b/bindsnet/pipeline/base_pipeline.py @@ -1,12 +1,12 @@ +import collections import time -from typing import Tuple, Dict, Any +from typing import Any, Dict, Tuple import torch from torch._six import string_classes -import collections -from ..network import Network -from ..network.monitors import Monitor +from bindsnet.network import Network +from bindsnet.network.monitors import Monitor def recursive_to(item, device): diff --git a/bindsnet/pipeline/dataloader_pipeline.py b/bindsnet/pipeline/dataloader_pipeline.py index 995285fc..fbe2fa24 100644 --- a/bindsnet/pipeline/dataloader_pipeline.py +++ b/bindsnet/pipeline/dataloader_pipeline.py @@ -1,13 +1,13 @@ -from typing import Optional, Dict +from typing import Dict, Optional import torch from torch.utils.data import Dataset from tqdm import tqdm -from ..network import Network -from .base_pipeline import BasePipeline -from ..analysis.pipeline_analysis import PipelineAnalyzer -from ..datasets import DataLoader +from bindsnet.analysis.pipeline_analysis import PipelineAnalyzer +from bindsnet.datasets import DataLoader +from bindsnet.network import Network +from bindsnet.pipeline.base_pipeline import BasePipeline class DataLoaderPipeline(BasePipeline): diff --git a/bindsnet/pipeline/environment_pipeline.py b/bindsnet/pipeline/environment_pipeline.py index b1f50b2b..119e22bd 100644 --- a/bindsnet/pipeline/environment_pipeline.py +++ b/bindsnet/pipeline/environment_pipeline.py @@ -1,16 +1,15 @@ import itertools -from typing import Callable, Optional, Tuple, Dict +from typing import Callable, Dict, Optional, Tuple import torch - from tqdm import tqdm -from .base_pipeline import BasePipeline -from ..analysis.pipeline_analysis import MatplotlibAnalyzer -from ..environment import Environment -from ..network import Network -from ..network.nodes import AbstractInput -from ..network.monitors import Monitor +from bindsnet.analysis.pipeline_analysis import MatplotlibAnalyzer +from bindsnet.environment import Environment +from bindsnet.network import Network +from bindsnet.network.monitors import Monitor +from bindsnet.network.nodes import AbstractInput +from bindsnet.pipeline.base_pipeline import BasePipeline class EnvironmentPipeline(BasePipeline): diff --git a/bindsnet/preprocessing/__init__.py b/bindsnet/preprocessing/__init__.py index 035665ad..fe9947f0 100644 --- a/bindsnet/preprocessing/__init__.py +++ b/bindsnet/preprocessing/__init__.py @@ -1 +1,3 @@ from .preprocessing import AbstractPreprocessor + +__all__ = ["AbstractPreprocessor"] diff --git a/bindsnet/preprocessing/preprocessing.py b/bindsnet/preprocessing/preprocessing.py index 1676586f..050df8b4 100644 --- a/bindsnet/preprocessing/preprocessing.py +++ b/bindsnet/preprocessing/preprocessing.py @@ -1,9 +1,9 @@ import hashlib import os import pickle -import torch +from abc import ABC, abstractmethod -from abc import abstractmethod, ABC +import torch class AbstractPreprocessor(ABC): @@ -50,7 +50,6 @@ def _process(self, filename: str, cache: dict): :param cache: Dictionary for caching 'data' needs to be updated for caching to work. """ - pass def __gen_hash(self, filename: str) -> str: # language=rst diff --git a/bindsnet/utils.py b/bindsnet/utils.py index 274cb8e6..05863662 100644 --- a/bindsnet/utils.py +++ b/bindsnet/utils.py @@ -1,11 +1,10 @@ import math -import torch -import numpy as np +from typing import Tuple, Union -from torch import Tensor +import numpy as np +import torch import torch.nn.functional as F -from numpy import ndarray -from typing import Tuple, Union +from torch import Tensor from torch.nn.modules.utils import _pair diff --git a/examples/benchmark/annarchy.py b/examples/benchmark/annarchy.py index 7ec517a9..c58763da 100755 --- a/examples/benchmark/annarchy.py +++ b/examples/benchmark/annarchy.py @@ -1,13 +1,13 @@ from __future__ import print_function -import os import argparse +import os +from time import time as t + import ANNarchy import numpy as np import pandas as pd -from time import time as t - plots_path = os.path.join("..", "..", "figures") benchmark_path = os.path.join("..", "..", "benchmark") if not os.path.isdir(benchmark_path): diff --git a/examples/benchmark/benchmark.py b/examples/benchmark/benchmark.py index 6260befc..75f9bf92 100755 --- a/examples/benchmark/benchmark.py +++ b/examples/benchmark/benchmark.py @@ -1,24 +1,22 @@ +import argparse import os +from time import time as t + +import brian2genn +import matplotlib.pyplot as plt import nengo -import torch -import argparse import numpy as np import pandas as pd -import matplotlib.pyplot as plt - +import torch from brian2 import * -from nest import * -from time import time as t from experiments import ROOT_DIR +from experiments.benchmark import plot_benchmark +from nest import * -import brian2genn - +from bindsnet.encoding import poisson from bindsnet.network import Network -from bindsnet.network.topology import Connection from bindsnet.network.nodes import Input, LIFNodes -from bindsnet.encoding import poisson - -from experiments.benchmark import plot_benchmark +from bindsnet.network.topology import Connection plots_path = os.path.join(ROOT_DIR, "figures") benchmark_path = os.path.join(ROOT_DIR, "benchmark") diff --git a/examples/benchmark/gpu_annarchy.py b/examples/benchmark/gpu_annarchy.py index 2847fca7..b65988a6 100755 --- a/examples/benchmark/gpu_annarchy.py +++ b/examples/benchmark/gpu_annarchy.py @@ -1,13 +1,13 @@ from __future__ import print_function -import os import argparse +import os +from time import time as t + import ANNarchy import numpy as np import pandas as pd -from time import time as t - plots_path = os.path.join("..", "..", "figures") benchmark_path = os.path.join("..", "..", "benchmark") if not os.path.isdir(benchmark_path): diff --git a/examples/benchmark/plot_benchmark.py b/examples/benchmark/plot_benchmark.py index e71b1788..6975c645 100755 --- a/examples/benchmark/plot_benchmark.py +++ b/examples/benchmark/plot_benchmark.py @@ -1,8 +1,8 @@ -import os import argparse -import pandas as pd -import matplotlib.pyplot as plt +import os +import matplotlib.pyplot as plt +import pandas as pd from experiments import ROOT_DIR benchmark_path = os.path.join(ROOT_DIR, "benchmark") diff --git a/examples/breakout/breakout.py b/examples/breakout/breakout.py index 3fd8c353..7366faf8 100644 --- a/examples/breakout/breakout.py +++ b/examples/breakout/breakout.py @@ -1,9 +1,9 @@ -from bindsnet.network import Network -from bindsnet.pipeline import EnvironmentPipeline from bindsnet.encoding import bernoulli -from bindsnet.network.topology import Connection from bindsnet.environment import GymEnvironment +from bindsnet.network import Network from bindsnet.network.nodes import Input, IzhikevichNodes +from bindsnet.network.topology import Connection +from bindsnet.pipeline import EnvironmentPipeline from bindsnet.pipeline.action import select_softmax # Build network. diff --git a/examples/breakout/breakout_stdp.py b/examples/breakout/breakout_stdp.py index f41224d5..90fc7ca5 100644 --- a/examples/breakout/breakout_stdp.py +++ b/examples/breakout/breakout_stdp.py @@ -1,10 +1,10 @@ -from bindsnet.network import Network -from bindsnet.pipeline import EnvironmentPipeline -from bindsnet.learning import MSTDP from bindsnet.encoding import bernoulli -from bindsnet.network.topology import Connection from bindsnet.environment import GymEnvironment +from bindsnet.learning import MSTDP +from bindsnet.network import Network from bindsnet.network.nodes import Input, LIFNodes +from bindsnet.network.topology import Connection +from bindsnet.pipeline import EnvironmentPipeline from bindsnet.pipeline.action import select_softmax # Build network. diff --git a/examples/breakout/play_breakout_from_ANN.py b/examples/breakout/play_breakout_from_ANN.py index 00aa10ea..5b6be3e7 100644 --- a/examples/breakout/play_breakout_from_ANN.py +++ b/examples/breakout/play_breakout_from_ANN.py @@ -1,21 +1,26 @@ import argparse -from tqdm import tqdm +from typing import Iterable, Optional, Union + +import torch import torch.nn as nn import torch.nn.functional as F -import torch - +from tqdm import tqdm -from bindsnet.network import Network -from bindsnet.pipeline import EnvironmentPipeline from bindsnet.encoding import bernoulli, poisson -from bindsnet.network.topology import Connection from bindsnet.environment import GymEnvironment -from bindsnet.network.nodes import Input, LIFNodes, IzhikevichNodes, IFNodes +from bindsnet.network import Network +from bindsnet.network.nodes import ( + AbstractInput, + IFNodes, + Input, + IzhikevichNodes, + LIFNodes, + Nodes, +) +from bindsnet.network.topology import Connection +from bindsnet.pipeline import EnvironmentPipeline from bindsnet.pipeline.action import * -from bindsnet.network.nodes import Nodes, AbstractInput -from typing import Iterable, Optional, Union - parser = argparse.ArgumentParser(prefix_chars="@") parser.add_argument("@@seed", type=int, default=42) parser.add_argument("@@dt", type=float, default=1.0) diff --git a/examples/breakout/random_baseline.py b/examples/breakout/random_baseline.py index ff845036..acae530b 100644 --- a/examples/breakout/random_baseline.py +++ b/examples/breakout/random_baseline.py @@ -1,5 +1,6 @@ -import os import argparse +import os + import numpy as np from bindsnet.environment import GymEnvironment diff --git a/examples/breakout/random_network_baseline.py b/examples/breakout/random_network_baseline.py index 790e72f8..ad53fc50 100644 --- a/examples/breakout/random_network_baseline.py +++ b/examples/breakout/random_network_baseline.py @@ -1,14 +1,15 @@ -import torch import argparse -from bindsnet.network import Network -from bindsnet.learning import Hebbian -from bindsnet.pipeline import EnvironmentPipeline +import torch + from bindsnet.encoding import bernoulli -from bindsnet.network.monitors import Monitor from bindsnet.environment import GymEnvironment -from bindsnet.network.topology import Connection +from bindsnet.learning import Hebbian +from bindsnet.network import Network +from bindsnet.network.monitors import Monitor from bindsnet.network.nodes import Input, LIFNodes +from bindsnet.network.topology import Connection +from bindsnet.pipeline import EnvironmentPipeline from bindsnet.pipeline.action import select_multinomial parser = argparse.ArgumentParser() diff --git a/examples/dotTracing/dot_tracing.py b/examples/dotTracing/dot_tracing.py index 6447cdb8..6e1387ac 100644 --- a/examples/dotTracing/dot_tracing.py +++ b/examples/dotTracing/dot_tracing.py @@ -1,29 +1,25 @@ -from bindsnet.network import Network +import argparse +import time -# from bindsnet.pipeline import EnvironmentPipeline -# from bindsnet.learning import MSTDP -from bindsnet.learning import MSTDPET -from bindsnet.learning import PostPre +import numpy as np +import torch + +from bindsnet.analysis.plotting import plot_spikes # plot_performance # from bindsnet.encoding import bernoulli from bindsnet.encoding import poisson -from bindsnet.network.topology import Connection from bindsnet.environment.dot_simulator import DotSimulator -from bindsnet.network.nodes import Input, LIFNodes + +# from bindsnet.pipeline import EnvironmentPipeline +# from bindsnet.learning import MSTDP +from bindsnet.learning import MSTDPET, PostPre +from bindsnet.network import Network # from bindsnet.pipeline.action import select_softmax # from bindsnet.network.nodes import AbstractInput from bindsnet.network.monitors import Monitor -from bindsnet.analysis.plotting import ( - plot_spikes, - # plot_performance -) - -import argparse -import numpy as np -import time -import torch - +from bindsnet.network.nodes import Input, LIFNodes +from bindsnet.network.topology import Connection # Handle arguments for dot tracing params. parser = argparse.ArgumentParser() diff --git a/examples/mnist/SOM_LM-SNNs.py b/examples/mnist/SOM_LM-SNNs.py index 69b1be77..ecaef577 100644 --- a/examples/mnist/SOM_LM-SNNs.py +++ b/examples/mnist/SOM_LM-SNNs.py @@ -1,28 +1,27 @@ -import os -import torch import argparse -import numpy as np -import matplotlib.pyplot as plt +import os +from time import time as t +import matplotlib.pyplot as plt +import numpy as np +import torch from torchvision import transforms from tqdm import tqdm -from time import time as t - -from bindsnet.datasets import MNIST -from bindsnet.encoding import PoissonEncoder, poisson -from bindsnet.models import IncreasingInhibitionNetwork -from bindsnet.network.monitors import Monitor -from bindsnet.utils import get_square_weights, get_square_assignments -from bindsnet.evaluation import all_activity, proportion_weighting, assign_labels from bindsnet.analysis.plotting import ( - plot_input, - plot_spikes, - plot_weights, plot_assignments, + plot_input, plot_performance, + plot_spikes, plot_voltages, + plot_weights, ) +from bindsnet.datasets import MNIST +from bindsnet.encoding import PoissonEncoder, poisson +from bindsnet.evaluation import all_activity, assign_labels, proportion_weighting +from bindsnet.models import IncreasingInhibitionNetwork +from bindsnet.network.monitors import Monitor +from bindsnet.utils import get_square_assignments, get_square_weights parser = argparse.ArgumentParser() parser.add_argument("--seed", type=int, default=0) diff --git a/examples/mnist/batch_eth_mnist.py b/examples/mnist/batch_eth_mnist.py index 0508cd93..7db36d2b 100644 --- a/examples/mnist/batch_eth_mnist.py +++ b/examples/mnist/batch_eth_mnist.py @@ -1,29 +1,28 @@ -import os -import torch import argparse -import numpy as np -import matplotlib.pyplot as plt +import os +from time import time as t +import matplotlib.pyplot as plt +import numpy as np +import torch from torchvision import transforms from tqdm import tqdm -from time import time as t - from bindsnet import ROOT_DIR -from bindsnet.datasets import MNIST, DataLoader -from bindsnet.encoding import PoissonEncoder -from bindsnet.evaluation import all_activity, proportion_weighting, assign_labels -from bindsnet.models import DiehlAndCook2015 -from bindsnet.network.monitors import Monitor -from bindsnet.utils import get_square_weights, get_square_assignments from bindsnet.analysis.plotting import ( + plot_assignments, plot_input, - plot_spikes, - plot_weights, plot_performance, - plot_assignments, + plot_spikes, plot_voltages, + plot_weights, ) +from bindsnet.datasets import MNIST, DataLoader +from bindsnet.encoding import PoissonEncoder +from bindsnet.evaluation import all_activity, assign_labels, proportion_weighting +from bindsnet.models import DiehlAndCook2015 +from bindsnet.network.monitors import Monitor +from bindsnet.utils import get_square_assignments, get_square_weights parser = argparse.ArgumentParser() parser.add_argument("--seed", type=int, default=0) diff --git a/examples/mnist/conv_mnist.py b/examples/mnist/conv_mnist.py index 88225300..99d75cd5 100644 --- a/examples/mnist/conv_mnist.py +++ b/examples/mnist/conv_mnist.py @@ -1,25 +1,25 @@ -import os -import torch import argparse +import os +from time import time as t + import matplotlib.pyplot as plt +import torch from torchvision import transforms - -from time import time as t from tqdm import tqdm -from bindsnet.datasets import MNIST -from bindsnet.encoding import PoissonEncoder -from bindsnet.network import Network -from bindsnet.learning import PostPre -from bindsnet.network.monitors import Monitor -from bindsnet.network.nodes import DiehlAndCookNodes, Input -from bindsnet.network.topology import Conv2dConnection, Connection from bindsnet.analysis.plotting import ( + plot_conv2d_weights, plot_input, plot_spikes, - plot_conv2d_weights, plot_voltages, ) +from bindsnet.datasets import MNIST +from bindsnet.encoding import PoissonEncoder +from bindsnet.learning import PostPre +from bindsnet.network import Network +from bindsnet.network.monitors import Monitor +from bindsnet.network.nodes import DiehlAndCookNodes, Input +from bindsnet.network.topology import Connection, Conv2dConnection print() diff --git a/examples/mnist/eth_mnist.py b/examples/mnist/eth_mnist.py index c96aa90a..5dfd1bbe 100644 --- a/examples/mnist/eth_mnist.py +++ b/examples/mnist/eth_mnist.py @@ -1,29 +1,27 @@ -import os -import torch import argparse -import numpy as np -import matplotlib.pyplot as plt +import os +from time import time as t +import matplotlib.pyplot as plt +import numpy as np +import torch from torchvision import transforms from tqdm import tqdm -from time import time as t - -from bindsnet.datasets import MNIST -from bindsnet.encoding import PoissonEncoder -from bindsnet.models import DiehlAndCook2015 -from bindsnet.network.monitors import Monitor -from bindsnet.utils import get_square_weights, get_square_assignments -from bindsnet.evaluation import all_activity, proportion_weighting, assign_labels from bindsnet.analysis.plotting import ( - plot_input, - plot_spikes, - plot_weights, plot_assignments, + plot_input, plot_performance, + plot_spikes, plot_voltages, + plot_weights, ) - +from bindsnet.datasets import MNIST +from bindsnet.encoding import PoissonEncoder +from bindsnet.evaluation import all_activity, assign_labels, proportion_weighting +from bindsnet.models import DiehlAndCook2015 +from bindsnet.network.monitors import Monitor +from bindsnet.utils import get_square_assignments, get_square_weights parser = argparse.ArgumentParser() parser.add_argument("--seed", type=int, default=0) diff --git a/examples/mnist/reservoir.py b/examples/mnist/reservoir.py index 1370c0dd..69acdc83 100644 --- a/examples/mnist/reservoir.py +++ b/examples/mnist/reservoir.py @@ -1,10 +1,10 @@ +import argparse import os + +import matplotlib.pyplot as plt import numpy as np import torch import torch.nn as nn -import argparse -import matplotlib.pyplot as plt - from torchvision import transforms from tqdm import tqdm @@ -17,15 +17,13 @@ from bindsnet.datasets import MNIST from bindsnet.encoding import PoissonEncoder from bindsnet.network import Network -from bindsnet.network.nodes import Input # Build a simple two-layer, input-output network. from bindsnet.network.monitors import Monitor -from bindsnet.network.nodes import LIFNodes +from bindsnet.network.nodes import Input, LIFNodes from bindsnet.network.topology import Connection from bindsnet.utils import get_square_weights - parser = argparse.ArgumentParser() parser.add_argument("--seed", type=int, default=0) parser.add_argument("--n_neurons", type=int, default=500) diff --git a/examples/mnist/supervised_mnist.py b/examples/mnist/supervised_mnist.py index 91cdee23..13a1745b 100644 --- a/examples/mnist/supervised_mnist.py +++ b/examples/mnist/supervised_mnist.py @@ -1,27 +1,26 @@ -import os -import torch -import numpy as np import argparse -import matplotlib.pyplot as plt +import os +import matplotlib.pyplot as plt +import numpy as np +import torch from torchvision import transforms from tqdm import tqdm - -from bindsnet.datasets import MNIST -from bindsnet.encoding import PoissonEncoder -from bindsnet.models import DiehlAndCook2015 -from bindsnet.network.monitors import Monitor -from bindsnet.utils import get_square_assignments, get_square_weights -from bindsnet.evaluation import all_activity, proportion_weighting, assign_labels from bindsnet.analysis.plotting import ( - plot_input, plot_assignments, + plot_input, plot_performance, - plot_weights, plot_spikes, plot_voltages, + plot_weights, ) +from bindsnet.datasets import MNIST +from bindsnet.encoding import PoissonEncoder +from bindsnet.evaluation import all_activity, assign_labels, proportion_weighting +from bindsnet.models import DiehlAndCook2015 +from bindsnet.network.monitors import Monitor +from bindsnet.utils import get_square_assignments, get_square_weights parser = argparse.ArgumentParser() parser.add_argument("--seed", type=int, default=0) diff --git a/examples/tensorboard/tensorboard.py b/examples/tensorboard/tensorboard.py index 39a5319a..127b1e52 100644 --- a/examples/tensorboard/tensorboard.py +++ b/examples/tensorboard/tensorboard.py @@ -1,20 +1,18 @@ -import os import argparse +import os +from time import time as t import torch from torchvision import transforms - -from time import time as t from tqdm import tqdm import bindsnet.datasets -from bindsnet.encoding import PoissonEncoder, NullEncoder - -from bindsnet.network import Network +from bindsnet.analysis.pipeline_analysis import MatplotlibAnalyzer, TensorboardAnalyzer +from bindsnet.encoding import NullEncoder, PoissonEncoder from bindsnet.learning import PostPre -from bindsnet.network.nodes import LIFNodes, Input -from bindsnet.network.topology import Conv2dConnection, Connection -from bindsnet.analysis.pipeline_analysis import TensorboardAnalyzer, MatplotlibAnalyzer +from bindsnet.network import Network +from bindsnet.network.nodes import Input, LIFNodes +from bindsnet.network.topology import Connection, Conv2dConnection parser = argparse.ArgumentParser() parser.add_argument( diff --git a/poetry.lock b/poetry.lock index 9cd86669..8f040812 100644 --- a/poetry.lock +++ b/poetry.lock @@ -536,6 +536,20 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "isort" +version = "5.9.3" +description = "A Python utility / library to sort Python imports." +category = "dev" +optional = false +python-versions = ">=3.6.1,<4.0" + +[package.extras] +pipfile_deprecated_finder = ["pipreqs", "requirementslib"] +requirements_deprecated_finder = ["pipreqs", "pip-api"] +colors = ["colorama (>=0.4.3,<0.5.0)"] +plugins = ["setuptools"] + [[package]] name = "jedi" version = "0.18.0" @@ -1756,6 +1770,7 @@ alabaster = [ {file = "alabaster-0.7.12-py2.py3-none-any.whl", hash = "sha256:446438bdcca0e05bd45ea2de1668c1d9b032e1a9154c2c259092d77031ddd359"}, {file = "alabaster-0.7.12.tar.gz", hash = "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02"}, ] + anyio = [ {file = "anyio-3.3.1-py3-none-any.whl", hash = "sha256:d7c604dd491eca70e19c78664d685d5e4337612d574419d503e76f5d7d1590bd"}, {file = "anyio-3.3.1.tar.gz", hash = "sha256:85913b4e2fec030e8c72a8f9f98092eeb9e25847a6e00d567751b77e34f856fe"}, @@ -2049,6 +2064,10 @@ ipython-genutils = [ {file = "ipython_genutils-0.2.0-py2.py3-none-any.whl", hash = "sha256:72dd37233799e619666c9f639a9da83c34013a73e8bbc79a7a6348d93c61fab8"}, {file = "ipython_genutils-0.2.0.tar.gz", hash = "sha256:eb2e116e75ecef9d4d228fdc66af54269afa26ab4463042e33785b887c628ba8"}, ] +isort = [ + {file = "isort-5.9.3-py3-none-any.whl", hash = "sha256:e17d6e2b81095c9db0a03a8025a957f334d6ea30b26f9ec70805411e5c7c81f2"}, + {file = "isort-5.9.3.tar.gz", hash = "sha256:9c2ea1e62d871267b78307fe511c0838ba0da28698c5732d54e2790bf3ba9899"}, +] jedi = [ {file = "jedi-0.18.0-py2.py3-none-any.whl", hash = "sha256:18456d83f65f400ab0c2d3319e48520420ef43b23a086fdc05dff34132f0fb93"}, {file = "jedi-0.18.0.tar.gz", hash = "sha256:92550a404bad8afed881a137ec9a461fed49eca661414be45059329614ed0707"}, diff --git a/pyproject.toml b/pyproject.toml index 11efd884..45802666 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,8 +32,10 @@ pytest = "^6.2.4" pre-commit = "^2.14.0" notebook = "^6.4.3" jupyterlab = "^3.1.9" +isort = "^5.9.3" black = "^21.7b0" autoflake = "^1.4" + Sphinx = "3.4.3" sphinx-rtd-theme = "0.5.1" imagecodecs = "^2021.8.26" @@ -42,6 +44,10 @@ imagecodecs = "^2021.8.26" requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" +[tool.isort] +profile = "black" +line_length = 88 +src_paths = ["bindsnet", "test"] [tool.black] target-version = ['py37'] diff --git a/test/analysis/test_analyzers.py b/test/analysis/test_analyzers.py index ef0a6057..618ca061 100644 --- a/test/analysis/test_analyzers.py +++ b/test/analysis/test_analyzers.py @@ -1,9 +1,9 @@ -import torch - -from bindsnet.analysis.pipeline_analysis import TensorboardAnalyzer, MatplotlibAnalyzer +import os import matplotlib.pyplot as plt -import os +import torch + +from bindsnet.analysis.pipeline_analysis import MatplotlibAnalyzer, TensorboardAnalyzer class TestAnalyzer: diff --git a/test/encoding/test_encoding.py b/test/encoding/test_encoding.py index 4484fd39..f56ee8ce 100644 --- a/test/encoding/test_encoding.py +++ b/test/encoding/test_encoding.py @@ -1,7 +1,7 @@ -from bindsnet.encoding import * - import torch +from bindsnet.encoding import * + class TestEncodings: """ diff --git a/test/import/test_import.py b/test/import/test_import.py index 0a57d73d..e69de29b 100644 --- a/test/import/test_import.py +++ b/test/import/test_import.py @@ -1,25 +0,0 @@ -import bindsnet - -import bindsnet.analysis -import bindsnet.conversion -import bindsnet.datasets -import bindsnet.encoding -import bindsnet.environment -import bindsnet.learning -import bindsnet.models -import bindsnet.network -import bindsnet.pipeline -import bindsnet.preprocessing - -import bindsnet.utils - -from bindsnet.analysis import * -from bindsnet.conversion import * -from bindsnet.datasets import * -from bindsnet.encoding import * -from bindsnet.environment import * -from bindsnet.learning import * -from bindsnet.models import * -from bindsnet.network import * -from bindsnet.pipeline import * -from bindsnet.preprocessing import * diff --git a/test/models/test_models.py b/test/models/test_models.py index 55aca651..04ec584f 100644 --- a/test/models/test_models.py +++ b/test/models/test_models.py @@ -1,6 +1,6 @@ +from bindsnet.models import DiehlAndCook2015, TwoLayerNetwork +from bindsnet.network.nodes import DiehlAndCookNodes, Input, LIFNodes from bindsnet.network.topology import Connection -from bindsnet.models import TwoLayerNetwork, DiehlAndCook2015 -from bindsnet.network.nodes import Input, LIFNodes, DiehlAndCookNodes class TestTwoLayerNetwork: diff --git a/test/network/test_connections.py b/test/network/test_connections.py index 3d201435..fdbc2db8 100644 --- a/test/network/test_connections.py +++ b/test/network/test_connections.py @@ -1,19 +1,17 @@ import torch -from bindsnet.network import Network -from bindsnet.network.nodes import Input, LIFNodes, SRM0Nodes - -from bindsnet.network.topology import * - from bindsnet.learning import ( - Hebbian, - PostPre, - WeightDependentPostPre, MSTDP, MSTDPET, - Rmax, + Hebbian, NoOp, + PostPre, + Rmax, + WeightDependentPostPre, ) +from bindsnet.network import Network +from bindsnet.network.nodes import Input, LIFNodes, SRM0Nodes +from bindsnet.network.topology import * class TestConnection: diff --git a/test/network/test_learning.py b/test/network/test_learning.py index 47f96d0f..926b921a 100644 --- a/test/network/test_learning.py +++ b/test/network/test_learning.py @@ -1,16 +1,16 @@ import torch -from bindsnet.network import Network -from bindsnet.network.nodes import Input, LIFNodes, CSRMNodes, SRM0Nodes -from bindsnet.network.topology import Connection, Conv2dConnection from bindsnet.learning import ( - Hebbian, - PostPre, - WeightDependentPostPre, MSTDP, MSTDPET, + Hebbian, + PostPre, Rmax, + WeightDependentPostPre, ) +from bindsnet.network import Network +from bindsnet.network.nodes import CSRMNodes, Input, LIFNodes, SRM0Nodes +from bindsnet.network.topology import Connection, Conv2dConnection class TestLearningRules: diff --git a/test/network/test_monitors.py b/test/network/test_monitors.py index 031ca108..a2d194b5 100644 --- a/test/network/test_monitors.py +++ b/test/network/test_monitors.py @@ -2,7 +2,7 @@ from bindsnet.network import Network from bindsnet.network.monitors import Monitor, NetworkMonitor -from bindsnet.network.nodes import Input, IFNodes +from bindsnet.network.nodes import IFNodes, Input from bindsnet.network.topology import Connection diff --git a/test/network/test_network.py b/test/network/test_network.py index 5f957f49..c661a39c 100644 --- a/test/network/test_network.py +++ b/test/network/test_network.py @@ -1,9 +1,9 @@ import os +from bindsnet.network import Network, load from bindsnet.network.monitors import Monitor -from bindsnet.network.topology import Connection from bindsnet.network.nodes import Input, LIFNodes -from bindsnet.network import Network, load +from bindsnet.network.topology import Connection class TestNetwork: diff --git a/test/network/test_nodes.py b/test/network/test_nodes.py index cd54b737..da5e319b 100644 --- a/test/network/test_nodes.py +++ b/test/network/test_nodes.py @@ -2,12 +2,12 @@ from bindsnet.network import Network from bindsnet.network.nodes import ( - Nodes, - Input, - McCullochPitts, + AdaptiveLIFNodes, IFNodes, + Input, LIFNodes, - AdaptiveLIFNodes, + McCullochPitts, + Nodes, SRM0Nodes, ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..367d7d65 --- /dev/null +++ b/tox.ini @@ -0,0 +1,4 @@ +[flake8] +max-line-length = 88 +extend-ignore = E203, E501 +exclude = .eggs,.git,.hg,.mypy_cache,.pytest_cache,.tox,.venv,build,dist