Skip to content

Commit

Permalink
style: check commented out code
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniBodor committed Jan 16, 2024
1 parent 0158a7a commit 3a891f1
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 40 deletions.
8 changes: 0 additions & 8 deletions deeprank2/neuralnets/gnn/foutnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ def reset_parameters(self):

def forward(self, x, edge_index):
num_node = len(x)

# alpha = x * Wc
alpha = torch.mm(x, self.wc)

# beta = x * Wn
beta = torch.mm(x, self.wn)

# gamma_i = 1/Ni Sum_j x_j * Wn
Expand All @@ -62,7 +58,6 @@ def forward(self, x, edge_index):
index = edge_index[:, edge_index[0, :] == n][1, :]
gamma[n, :] = torch.mean(beta[index, :], dim=0)

# alpha = alpha + gamma
alpha = alpha + gamma

# add the bias
Expand Down Expand Up @@ -95,7 +90,6 @@ def __init__(
def forward(self, data):
act = nn.Tanhshrink()
act = F.relu
# act = nn.LeakyReLU(0.25)

# first conv block
data.x = act(self.conv1(data.x, data.edge_index))
Expand All @@ -111,7 +105,5 @@ def forward(self, data):
x = scatter_mean(x, batch, dim=0)
x = act(self.fc1(x))
x = self.fc2(x)
# x = F.dropout(x, training=self.training)

return x # noqa:RET504 (unnecessary-assign)
# return F.relu(x)
3 changes: 0 additions & 3 deletions deeprank2/neuralnets/gnn/sgat.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def __init__(
def forward(self, data):
act = nn.Tanhshrink()
act = F.relu
# act = nn.LeakyReLU(0.25)

# first conv block
data.x = act(self.conv1(data.x, data.edge_index, data.edge_attr))
Expand All @@ -116,7 +115,5 @@ def forward(self, data):
x = scatter_mean(x, batch, dim=0)
x = act(self.fc1(x))
x = self.fc2(x)
# x = F.dropout(x, training=self.training)

return x # noqa:RET504 (unnecessary-assign)
# return F.relu(x)
4 changes: 0 additions & 4 deletions deeprank2/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,6 @@ def _format_output(self, pred, target=None):
target = torch.tensor([self.classes_to_index[x] if isinstance(x, str) else self.classes_to_index[int(x)] for x in target])
if isinstance(self.lossfunction, nn.BCELoss | nn.BCEWithLogitsLoss):
# # pred must be in (0,1) range and target must be float with same shape as pred
# pred = F.softmax(pred)
# target = torch.tensor(
# [[0,1] if x == [1] else [1,0] for x in target]
# ).float()
raise ValueError(
"BCELoss and BCEWithLogitsLoss are currently not supported.\n\t"
"For further details see: https://github.com/DeepRank/deeprank2/issues/318"
Expand Down
1 change: 0 additions & 1 deletion deeprank2/utils/community_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def community_detection_per_batch(

else:
raise ValueError(f"Clustering method {method} not supported")
# return
device = edge_index.device
return torch.tensor(cluster).to(device)

Expand Down
4 changes: 2 additions & 2 deletions tests/features/test_secondary_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def test_secondary_structure_residue():
(267, "A", " ", SecondarySctructure.COIL),
(46, "A", "S", SecondarySctructure.COIL),
(104, "A", "T", SecondarySctructure.COIL),
# (None, '', 'P', SecondarySctructure.COIL), # not found in test file
# (None, '', 'P', SecondarySctructure.COIL), # not found in test file # noqa: ERA001 (commented-out code)
(194, "A", "B", SecondarySctructure.STRAND),
(385, "B", "E", SecondarySctructure.STRAND),
(235, "A", "G", SecondarySctructure.HELIX),
(263, "A", "H", SecondarySctructure.HELIX),
# (0, '', 'I', SecondarySctructure.HELIX), # not found in test file
# (0, '', 'I', SecondarySctructure.HELIX), # not found in test file # noqa: ERA001 (commented-out code)
]

for res in residues:
Expand Down
4 changes: 2 additions & 2 deletions tests/perf/ppi_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
sizes=[1.0, 1.0, 1.0],
)
grid_map_method = MapMethod.GAUSSIAN # None if you don't want grids
# grid_settings = None
# grid_map_method = None
# grid_settings = None # noqa: ERA001 (commented out code)
# grid_map_method = None # noqa: ERA001 (commented out code)
feature_modules = [components, contact, exposure, irc, secondary_structure, surfacearea]
cpu_count = 1
####################################################
Expand Down
4 changes: 2 additions & 2 deletions tests/perf/srv_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
sizes=[1.0, 1.0, 1.0],
)
grid_map_method = MapMethod.GAUSSIAN # None if you don't want grids
# grid_settings = None
# grid_map_method = None
# grid_settings = None # noqa: ERA001 (commented out code)
# grid_map_method = None # noqa: ERA001 (commented out code)
feature_modules = [components, contact, exposure, irc, surfacearea, secondary_structure]
cpu_count = 1
####################################################
Expand Down
28 changes: 15 additions & 13 deletions tests/test_set_lossfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,21 @@ def test_classif_weighted(self):
assert isinstance(trainer_pretrained.lossfunction, lossfunction)
assert trainer_pretrained.class_weights

# def test_classif_invalid_weighted(self):
# dataset = GraphDataset(hdf5_path,
# target=targets.BINARY)
# trainer = Trainer(
# neuralnet = NaiveNetwork,
# dataset_train = dataset,
# class_weights = True
# )
# # use a loss function that does not allow for weighted loss, e.g. MultiLabelMarginLoss
# lossfunction = nn.MultiLabelMarginLoss

# with pytest.raises(ValueError):
# base_test(self.save_path, trainer, lossfunction)
def test_classif_invalid_weighted(self):
dataset = GraphDataset(
hdf5_path,
target=targets.BINARY,
)
trainer = Trainer(
neuralnet=NaiveNetwork,
dataset_train=dataset,
class_weights=True,
)
# use a loss function that does not allow for weighted loss, e.g. MultiLabelMarginLoss
lossfunction = nn.MultiLabelMarginLoss

with pytest.raises(ValueError):
base_test(self.save_path, trainer, lossfunction)

def test_classif_invalid_lossfunction(self):
dataset = GraphDataset(
Expand Down
8 changes: 3 additions & 5 deletions tests/utils/test_earlystopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ def base_earlystopper(patience=10, delta=0, maxgap=None):
def test_patience():
patience = 3
final_ep = base_earlystopper(patience=patience)
# should terminate at epoch 7
assert final_ep == 7


def test_patience_with_delta():
patience = 3
delta = 1
final_ep = base_earlystopper(patience=patience, delta=delta)
# should terminate at epoch 5
assert final_ep == 5


def test_maxgap():
maxgap = 1
final_ep = base_earlystopper(maxgap=maxgap)
# should terminate at epoch 9
assert final_ep == 9


# test_patience() # should terminate at epoch 7
# test_patience_with_delta() # should terminate at epoch 5
# test_maxgap() # should terminate at epoch 9

0 comments on commit 3a891f1

Please sign in to comment.