From 27a11ae98f29788ca0f15fdb5f7b9726da298993 Mon Sep 17 00:00:00 2001 From: Salem Date: Fri, 4 Aug 2023 19:03:33 -0400 Subject: [PATCH] Add autoflake to pre-commit --- .pre-commit-config.yaml | 18 ++++++++++++++++-- src/gfn/containers/base.py | 3 --- src/gfn/env.py | 5 ----- src/gfn/gflownet/base.py | 4 +--- src/gfn/gym/box.py | 2 +- src/gfn/gym/helpers/box_utils.py | 2 +- src/gfn/modules.py | 1 - src/gfn/preprocessors.py | 2 +- src/gfn/states.py | 1 - 9 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f214eea3..75e15a9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ default_language_version: node: 15.1.0 repos: - repo: https://github.com/python/black - rev: 22.3.0 + rev: 23.7.0 hooks: - id: black language_version: python3.10 @@ -11,6 +11,20 @@ repos: rev: v2.0.0 hooks: - id: flake8 + - repo: https://github.com/pycqa/autoflake + rev: v2.2.0 + hooks: + - id: autoflake + name: autoflake + entry: autoflake + language: python + "types": [python] + require_serial: true + args: + - "--in-place" + - "--expand-star-imports" + - "--remove-duplicate-keys" + - "--remove-unused-variables" - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: @@ -18,7 +32,7 @@ repos: files: "\\.(py)$" args: [--settings-path=pyproject.toml] - repo: https://github.com/RobertCraigie/pyright-python - rev: v1.1.314 + rev: v1.1.320 hooks: - id: pyright name: pyright diff --git a/src/gfn/containers/base.py b/src/gfn/containers/base.py index 7bb8757f..21d4f9f1 100644 --- a/src/gfn/containers/base.py +++ b/src/gfn/containers/base.py @@ -16,17 +16,14 @@ class Container(ABC): @abstractmethod def __len__(self) -> int: """Returns the number of elements in the container.""" - pass @abstractmethod def __getitem__(self, index: int | Sequence[int]) -> Container: """Subsets the container.""" - pass @abstractmethod def extend(self, other: Container) -> None: "Extends the current container" - pass def sample(self, n_samples: int) -> Container: """Samples a subset of the container.""" diff --git a/src/gfn/env.py b/src/gfn/env.py index a1758899..6adc4d34 100644 --- a/src/gfn/env.py +++ b/src/gfn/env.py @@ -57,12 +57,10 @@ def __init__( @abstractmethod def make_States_class(self) -> type[States]: """Returns a class that inherits from States and implements the environment-specific methods.""" - pass @abstractmethod def make_Actions_class(self) -> type[Actions]: """Returns a class that inherits from Actions and implements the environment-specific methods.""" - pass def reset( self, @@ -96,7 +94,6 @@ def maskless_step( """Function that takes a batch of states and actions and returns a batch of next states. Does not need to check whether the actions are valid or the states are sink states. """ - pass @abstractmethod def maskless_backward_step( @@ -105,7 +102,6 @@ def maskless_backward_step( """Function that takes a batch of states and actions and returns a batch of previous states. Does not need to check whether the actions are valid or the states are sink states. """ - pass @abstractmethod def is_action_valid( @@ -115,7 +111,6 @@ def is_action_valid( backward: bool = False, ) -> bool: """Returns True if the actions are valid in the given states.""" - pass def validate_actions( self, states: States, actions: Actions, backward: bool = False diff --git a/src/gfn/gflownet/base.py b/src/gfn/gflownet/base.py index 314994d4..e1291a8f 100644 --- a/src/gfn/gflownet/base.py +++ b/src/gfn/gflownet/base.py @@ -1,4 +1,4 @@ -from abc import ABC, abstractmethod +from abc import abstractmethod from typing import Tuple import torch @@ -26,7 +26,6 @@ def sample_trajectories(self, n_samples: int) -> Trajectories: Returns: Trajectories: sampled trajectories object. """ - pass def sample_terminating_states(self, n_samples: int) -> States: """Rolls out the parametrization's policy and returns the terminating states. @@ -42,7 +41,6 @@ def sample_terminating_states(self, n_samples: int) -> States: @abstractmethod def to_training_samples(self, trajectories: Trajectories): """Converts trajectories to training samples. The type depends on the GFlowNet.""" - pass class PFBasedGFlowNet(GFlowNet): diff --git a/src/gfn/gym/box.py b/src/gfn/gym/box.py index 2600e3f3..2a1bcc01 100644 --- a/src/gfn/gym/box.py +++ b/src/gfn/gym/box.py @@ -1,5 +1,5 @@ from math import log -from typing import ClassVar, Literal, Tuple, cast +from typing import ClassVar, Literal, Tuple import torch from torchtyping import TensorType as TT diff --git a/src/gfn/gym/helpers/box_utils.py b/src/gfn/gym/helpers/box_utils.py index b34d5449..0783b701 100644 --- a/src/gfn/gym/helpers/box_utils.py +++ b/src/gfn/gym/helpers/box_utils.py @@ -1,5 +1,5 @@ """This file contains utilitary functions for the Box environment.""" -from typing import Literal, Optional, Tuple +from typing import Tuple import numpy as np import torch diff --git a/src/gfn/modules.py b/src/gfn/modules.py index 4c642e8b..55f6361f 100644 --- a/src/gfn/modules.py +++ b/src/gfn/modules.py @@ -73,7 +73,6 @@ def __repr__(self): @abstractmethod def expected_output_dim(self) -> int: """Expected output dimension of the module.""" - pass def check_output_dim( self, module_output: TT["batch_shape", "output_dim", float] diff --git a/src/gfn/preprocessors.py b/src/gfn/preprocessors.py index 856af6ab..b00020dd 100644 --- a/src/gfn/preprocessors.py +++ b/src/gfn/preprocessors.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import Callable, Tuple +from typing import Callable from torchtyping import TensorType as TT diff --git a/src/gfn/states.py b/src/gfn/states.py index b177687c..19b4de57 100644 --- a/src/gfn/states.py +++ b/src/gfn/states.py @@ -306,7 +306,6 @@ def __init__( @abstractmethod def update_masks(self) -> None: """Updates the masks, called after each action is taken.""" - pass def _check_both_forward_backward_masks_exist(self): assert self.forward_masks is not None and self.backward_masks is not None