Skip to content

Commit

Permalink
Merge pull request #125 from saleml/autoflake
Browse files Browse the repository at this point in the history
Add autoflake to pre-commit
  • Loading branch information
josephdviviano authored Aug 14, 2023
2 parents 24633d0 + 27a11ae commit 47f8d3b
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
18 changes: 16 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@ 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
- repo: https://github.com/pre-commit/pre-commit-hooks
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:
- id: isort
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
Expand Down
3 changes: 0 additions & 3 deletions src/gfn/containers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 0 additions & 5 deletions src/gfn/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/gfn/gflownet/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abc import ABC, abstractmethod
from abc import abstractmethod
from typing import Tuple

import torch
Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/gfn/gym/box.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gfn/gym/helpers/box_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/gfn/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/gfn/preprocessors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import Callable, Tuple
from typing import Callable

from torchtyping import TensorType as TT

Expand Down
1 change: 0 additions & 1 deletion src/gfn/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47f8d3b

Please sign in to comment.