Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
STYLE: Trim trailing whitespaces with pre-commit (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
fepegar committed Apr 4, 2022
1 parent 760cbe0 commit 2edbdc8
Show file tree
Hide file tree
Showing 29 changed files with 193 additions and 192 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting_and_hello_world.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
pip install flake8
python -m flake8
shell: bash
if: always()
if: always()

# This script also does "conda init" for all shells. For bash, this modifies .bashrc.
# However, the default "bash" in a github workflow does not execute bashrc. Hence, all
Expand Down
45 changes: 23 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
# See https://pre-commit.com/hooks.html for more hooks
# See https://github.com/pre-commit/pre-commit-hooks/blob/master/.pre-commit-config.yaml for an example with more hooks

exclude: '^excluded_files_regex$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-ast
- id: check-merge-conflict
- id: debug-statements
- id: mixed-line-ending
args: [--fix=lf]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-ast
- id: check-merge-conflict
- id: debug-statements
- id: mixed-line-ending
args:
- --fix=lf

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports==1.7.0]
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies:
- flake8-typing-imports==1.7.0

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.7
hooks:
- id: autopep8
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.7
hooks:
- id: autopep8
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"Tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
"python.testing.pytestEnabled": true,
"files.trimTrailingWhitespace": true
}
2 changes: 1 addition & 1 deletion InnerEye/ML/SSL/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_ssl_encoder(encoder_name: str, use_7x7_first_conv_in_resnet: bool = T
"""
Creates SSL encoder.
:param encoder_name: available choices: resnet18, resnet50, resnet101 and densenet121.
:param use_7x7_first_conv_in_resnet: If True, use a 7x7 kernel (default) in the first layer of resnet.
:param use_7x7_first_conv_in_resnet: If True, use a 7x7 kernel (default) in the first layer of resnet.
If False, replace first layer by a 3x3 kernel. This is required for small CIFAR 32x32 images to not shrink them.
"""
from pl_bolts.models.self_supervised.resnets import resnet18, resnet50, resnet101
Expand Down
2 changes: 1 addition & 1 deletion InnerEye/ML/configs/classification/DummyClassification.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class DummyClassification(ScalarModelBase):
"A config file for dummy image classification model for debugging purposes"
"A config file for dummy image classification model for debugging purposes"

def __init__(self) -> None:
num_epochs = 4
Expand Down
8 changes: 4 additions & 4 deletions InnerEye/ML/configs/other/HelloContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, raw_data: List[List[float]]) -> None:
must be numeric data which can be converted into a tensor. See the static method
from_path_and_indexes for an example call.
"""
super().__init__()
super().__init__()
self.data = torch.tensor(raw_data, dtype=torch.float)

def __len__(self) -> int:
Expand Down Expand Up @@ -253,9 +253,9 @@ def create_model(self) -> LightningModule:
return HelloRegression()

# This method must be overridden by any subclass of LightningContainer. It returns a data module, which
# in turn contains 3 data loaders for training, validation, and test set.
#
# If the container is used for cross validation then this method must handle the cross validation splits.
# in turn contains 3 data loaders for training, validation, and test set.
#
# If the container is used for cross validation then this method must handle the cross validation splits.
# Because this deals with data loaders, not loaded data, we cannot check automatically that cross validation is
# handled correctly within the LightningContainer base class, i.e. if you forget to do the cross validation split
# in your subclass nothing will fail, but each child run will be identical since they will each be given the full
Expand Down
2 changes: 1 addition & 1 deletion InnerEye/ML/configs/segmentation/HelloWorld.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class HelloWorld(SegmentationModelBase):
* This model can be trained from the commandline: python InnerEye/runner.py --model=HelloWorld
* If you want to test that your AzureML workspace is working, please follow the instructions in
* If you want to test that your AzureML workspace is working, please follow the instructions in
<repo_root>/docs/hello_world_model.md.
In this example, the model is trained on 2 input image channels channel1 and channel2, and
Expand Down
2 changes: 1 addition & 1 deletion InnerEye/ML/dataset/scalar_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def _load_single_data_source(_rows: pd.DataFrame,
is_classification_dataset=self.is_classification_dataset,
num_classes=self.num_classes,
sequence_position_numeric=_sequence_position_numeric
)
)
if len(self.expected_channels) > 0:
missing_channels = self.expected_channels - set(rows[self.channel_column])
if len(missing_channels) > 0:
Expand Down
2 changes: 1 addition & 1 deletion InnerEye/ML/lightning_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def get_cross_validation_hyperdrive_config(self, run_config: ScriptRunConfig) ->
"""
Returns a configuration for AzureML Hyperdrive that varies the cross validation split index.
Because this adds a val/Loss metric it is important that when subclassing LightningContainer
your implementeation of LightningModule logs val/Loss. There is an example of this in
your implementation of LightningModule logs val/Loss. There is an example of this in
HelloRegression's validation_step method.
:param run_config: The AzureML run configuration object that training for an individual model.
:return: A hyperdrive configuration object.
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Instead, please report them to the Microsoft Security Response Center (MSRC) at

If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

Expand Down
2 changes: 1 addition & 1 deletion Tests/ML/models/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class SimpleModel(BaseSegmentationModel):
"""
A simple neural network model to test model parallelisation functions.
A simple neural network model to test model parallelisation functions.
"""

def __init__(self, input_channels: Any, channels: Any, n_classes: int, kernel_size: int):
Expand Down
8 changes: 4 additions & 4 deletions Tests/ML/models/test_scalar_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ def test_train_classification_model(class_name: str, test_output_dirs: OutputFol
f"{LoggingColumns.OptimalThreshold.value}," \
f"{LoggingColumns.SubjectCount.value},{LoggingColumns.Epoch.value}," \
f"{LoggingColumns.CrossValidationSplitIndex.value}\n" + \
"""0.6866141557693481,0.6866141557693481,0.5,0.0001,1.0,1.0,0.5,0.0,0.0,0.529514,2.0,0,-1
0.6864652633666992,0.6864652633666992,0.5,9.999712322065557e-05,1.0,1.0,0.5,0.0,0.0,0.529475,2.0,1,-1
0.6863163113594055,0.6863162517547607,0.5,9.999306876841536e-05,1.0,1.0,0.5,0.0,0.0,0.529437,2.0,2,-1
0.6861673593521118,0.6861673593521118,0.5,9.998613801725043e-05,1.0,1.0,0.5,0.0,0.0,0.529399,2.0,3,-1
"""0.6866141557693481,0.6866141557693481,0.5,0.0001,1.0,1.0,0.5,0.0,0.0,0.529514,2.0,0,-1
0.6864652633666992,0.6864652633666992,0.5,9.999712322065557e-05,1.0,1.0,0.5,0.0,0.0,0.529475,2.0,1,-1
0.6863163113594055,0.6863162517547607,0.5,9.999306876841536e-05,1.0,1.0,0.5,0.0,0.0,0.529437,2.0,2,-1
0.6861673593521118,0.6861673593521118,0.5,9.998613801725043e-05,1.0,1.0,0.5,0.0,0.0,0.529399,2.0,3,-1
"""
check_log_file(epoch_metrics_path, expected_epoch_metrics, ignore_columns=[])
# Check metrics.csv: This contains the per-subject per-epoch model outputs
Expand Down
4 changes: 2 additions & 2 deletions Tests/ML/reports/test_segmentation_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def _test_generate_segmentation_report_with_partial_ground_truth(
partial_metrics.to_csv(partial_metrics_file, index=False, float_format="%.3f", na_rep="")
result_html = generate_segmentation_notebook(result_notebook=result_file, test_metrics=partial_metrics_file)
result_html_text = result_html.read_text(encoding='utf-8')
# Look for this row in the HTML Dice table:
# <td>brainstem</td>\n <td>0.82600</td>\n <td>0.8570</td>\n <td>0.87600</td>\n <td>17.0</td>\n
# Look for this row in the HTML Dice table:
# <td>brainstem</td>\n <td>0.82600</td>\n <td>0.8570</td>\n <td>0.87600</td>\n <td>17.0</td>\n
# It shows that for the brainstem label there are only 17, not 20, patients with that label,
# because we removed the brainstem label for patients 14, 15, and 19.

Expand Down
2 changes: 1 addition & 1 deletion Tests/ML/test_data/Val_outliers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=== METRIC: Dice ===

count mean min max
Patient Structure seriesId institutionId
Patient Structure seriesId institutionId
341 rectum d41cb61517793f87f97d5d6c0cee9f91df94169c29701c10190723ff8ede419a 641eda02-90c3-45ed-b8b1-2651b6a5da6c 1.0 1.1 1.1 1.1
366 rectum f040ac05a1eeee9a064662adda21f703d7ba969b7dfc2787248b2c596ccf59a7 641eda02-90c3-45ed-b8b1-2651b6a5da6c 1.0 0.9 0.9 0.9
411 rectum 6fa04f324339c532a7c06877d1129bfacd7504d9c0bf6277a393915e73e41d66 5a6ba8fe-65bc-43ec-b1fc-682c8c37e40c 1.0 0.9 0.9 0.9
Expand Down
2 changes: 1 addition & 1 deletion Tests/ML/test_data/Val_outliers_pruned.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=== METRIC: Dice ===

count mean min max
Patient Structure
Patient Structure
341 rectum 1.0 1.1 1.1 1.1
366 rectum 1.0 0.9 0.9 0.9
411 rectum 1.0 0.9 0.9 0.9
Expand Down
2 changes: 1 addition & 1 deletion Tests/ML/test_lightning_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_get_hyperdrive_config(number_of_cross_validation_splits: int,
with pytest.raises(NotImplementedError) as not_implemented_error:
container.get_hyperdrive_config(run_config=run_config)
assert 'Parameter search is not implemented' in str(not_implemented_error.value)
# The error should be thrown by
# The error should be thrown by
# InnerEye.ML.lightning_container.LightningContainer.get_parameter_search_hyperdrive_config
# since number_of_cross_validation_splits == 0 implies a parameter search hyperdrive config and
# not a cross validation one.
Expand Down
4 changes: 2 additions & 2 deletions Tests/SSL/test_ssl_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_simclr_lr_scheduler() -> None:

@pytest.mark.gpu
def test_simclr_training_recovery(test_output_dirs: OutputFolderForTests) -> None:
""" This test checks if a SSLContainer correctly resumes training.
""" This test checks if a SSLContainer correctly resumes training.
First we run SSL using a Trainer for 20 epochs.
Second, we run a new SSL job for 15 epochs.
Third we resume the job and run it for 5 more epochs.
Expand Down Expand Up @@ -332,7 +332,7 @@ def run_simclr_dummy_container(test_output_dirs: OutputFolderForTests,

small_encoder = torch.nn.Sequential(torch.nn.Flatten(), torch.nn.Linear(3, 2))
with mock.patch("InnerEye.ML.SSL.encoders.create_ssl_encoder", return_value=small_encoder):
with mock.patch("InnerEye.ML.SSL.encoders.get_encoder_output_dim", return_value=2):
with mock.patch("InnerEye.ML.SSL.encoders.get_encoder_output_dim", return_value=2):
# Normal run
normal_lrs, normal_loss, _ = run_simclr_dummy_container(test_output_dirs, 20, last_checkpoint=None)

Expand Down
4 changes: 2 additions & 2 deletions docs/WSL.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ winget install Microsoft.WindowsTerminal
Remember to restart your machine if you were doing a fresh installation of WSL 2 before trying further steps.

Since it is possible to choose the version of WSL that a particular distribution is running, once you have WSL2
installed, ensure that your distribution is running on top of WSL2 by executing
`wsl --list --verbose`
installed, ensure that your distribution is running on top of WSL2 by executing
`wsl --list --verbose`
If all is good, the output should look like this:

```
Expand Down
Loading

0 comments on commit 2edbdc8

Please sign in to comment.