Skip to content

Commit

Permalink
Fix deep learning bug on Windows. (#148)
Browse files Browse the repository at this point in the history
* Add CI for Windows.

* Update copyright years.

* Skip spark tests on Windows.

Spark API is designed for spark-on-k8s with Linux.

* Update version.

* Add n_jobs argument to IsolationForest.

* Set use_gpu=True by default.
  • Loading branch information
aadyotb committed Feb 15, 2023
1 parent 879e92e commit 3d025ad
Show file tree
Hide file tree
Showing 103 changed files with 171 additions and 128 deletions.
45 changes: 40 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

jobs:
tests:

runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -22,15 +21,19 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Set up Java 17
uses: actions/setup-java@v3
with:
distribution: adopt
java-version: 17

- name: Install Merlion
run: |
sudo apt-get update -y
sudo apt-get install bc openjdk-11-jre-headless -y --fix-missing
python -m pip install --upgrade pip setuptools wheel build
python -m pip install pytest coverage
python -m build
for f in dist/*.whl; do pip install $f[all]; done
pip install -e ts_datasets/
for f in dist/*.whl; do python -m pip install $f[all]; done
python -m pip install -e ts_datasets/
- name: Test with pytest
id: test
Expand Down Expand Up @@ -86,3 +89,35 @@ jobs:
BRANCH: badges
FOLDER: .github/badges
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tests_windows:

runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Set up Java 17
uses: actions/setup-java@v3
with:
distribution: microsoft
java-version: 17

- name: Install Merlion
run: |
python -m pip install --upgrade pip setuptools wheel build pytest
python -m pip install ".[all]"
python -m pip install -e ts_datasets/
- name: Test with pytest
id: test
run: pytest -v -s --ignore=tests/spark
2 changes: 1 addition & 1 deletion merlion/dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/callbacks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/callbacks/anomaly.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/callbacks/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/callbacks/forecast.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/models/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/models/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/pages/anomaly.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/pages/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
4 changes: 2 additions & 2 deletions merlion/dashboard/pages/forecast.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down Expand Up @@ -96,7 +96,7 @@ def create_control_panel() -> html.Div:
html.Br(),
html.P("Algorithm Setting"),
html.Div(id="forecasting-param-table", children=[create_param_table()]),
html.Progress(id="forecasting-progressbar", style={"width": "100%", 'color':'#1AB9FF'}),
html.Progress(id="forecasting-progressbar", style={"width": "100%", "color": "#1AB9FF"}),
html.Br(),
html.Div(
children=[
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/pages/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
4 changes: 2 additions & 2 deletions merlion/dashboard/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
#
TABLE_HEADER_COLOR = "#014486"
TABLE_DATA_COLOR = 'white'
TABLE_DATA_COLOR = "white"
2 changes: 1 addition & 1 deletion merlion/dashboard/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/utils/file_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
6 changes: 3 additions & 3 deletions merlion/dashboard/utils/layout.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand All @@ -9,8 +9,8 @@


tab_style = {
"borderBottom": "1px solid #d6d6d6",
"padding": "6px",
"borderBottom": "1px solid #d6d6d6",
"padding": "6px",
"fontWeight": "bold",
"backgroundColor": "#1B96FF",
"color": "white",
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/utils/log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/dashboard/utils/plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
4 changes: 2 additions & 2 deletions merlion/evaluate/anomaly.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down Expand Up @@ -118,7 +118,7 @@ def f_beta(self, score_type: ScoreType = ScoreType.RevisedPointAdjusted, beta=1.
prec_score_type = rec_score_type = score_type
p = self.precision(prec_score_type)
r = self.recall(rec_score_type)
return 0.0 if p == 0 or r == 0 else (1 + beta ** 2) * p * r / (beta ** 2 * p + r)
return 0.0 if p == 0 or r == 0 else (1 + beta**2) * p * r / (beta**2 * p + r)

def mean_time_to_detect(self):
t = np.mean(self.tp_detection_delays) if self.tp_detection_delays else 0
Expand Down
2 changes: 1 addition & 1 deletion merlion/evaluate/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/evaluate/forecast.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/autoencoder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/change_point/bocpd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/dagmm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/dbl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/deep_point_anomaly_detector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/forecast_based/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/forecast_based/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/forecast_based/mses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/forecast_based/prophet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
7 changes: 4 additions & 3 deletions merlion/models/anomaly/isolation_forest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down Expand Up @@ -29,7 +29,7 @@ class IsolationForestConfig(DetectorConfig):

_default_transform = TransformSequence([DifferenceTransform(), Shingle(size=2, stride=1)])

def __init__(self, max_n_samples: int = None, n_estimators: int = 100, **kwargs):
def __init__(self, max_n_samples: int = None, n_estimators: int = 100, n_jobs=-1, **kwargs):
"""
:param max_n_samples: Maximum number of samples to allow the isolation
forest to train on. Specify ``None`` to use all samples in the
Expand All @@ -38,6 +38,7 @@ def __init__(self, max_n_samples: int = None, n_estimators: int = 100, **kwargs)
"""
self.max_n_samples = 1.0 if max_n_samples is None else max_n_samples
self.n_estimators = n_estimators
self.n_jobs = n_jobs
# Isolation forest's uncalibrated scores are between 0 and 1
kwargs["max_score"] = 1.0
super().__init__(**kwargs)
Expand All @@ -54,7 +55,7 @@ class IsolationForest(DetectorBase):
def __init__(self, config: IsolationForestConfig):
super().__init__(config)
self.model = skl_IsolationForest(
max_samples=config.max_n_samples, n_estimators=config.n_estimators, random_state=0
max_samples=config.max_n_samples, n_estimators=config.n_estimators, random_state=0, n_jobs=config.n_jobs
)

@property
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/lstm_ed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/random_cut_forest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/spectral_residual.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
2 changes: 1 addition & 1 deletion merlion/models/anomaly/stat_threshold.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022 salesforce.com, inc.
# Copyright (c) 2023 salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
Expand Down
Loading

0 comments on commit 3d025ad

Please sign in to comment.