From 957c7c85521c883688038055a1889d7f7487117e Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 23 Aug 2022 14:57:41 +0530 Subject: [PATCH 1/5] Fix app dag example --- examples/app_dag/app.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/app_dag/app.py b/examples/app_dag/app.py index adfb2055f2c48..aa4c29509b846 100644 --- a/examples/app_dag/app.py +++ b/examples/app_dag/app.py @@ -56,7 +56,7 @@ class DAG(L.LightningFlow): """This component is a DAG.""" - def __init__(self, models_paths): + def __init__(self, models_paths: list): super().__init__() # Step 1: Create a work to get the data. self.data_collector = GetDataWork() @@ -80,12 +80,10 @@ def __init__(self, models_paths): def run(self): # Step 1 and 2: Download and process the data. self.data_collector.run() - self.data_collector.stop() # Stop the data_collector to reduce cost self.processing.run( df_data=self.data_collector.df_data, df_target=self.data_collector.df_target, ) - self.processing.stop() # Stop the processing to reduce cost # Step 3: Launch n models training in parallel. for model, work in self.dict.items(): @@ -128,7 +126,7 @@ def run(self): app = L.LightningApp( ScheduledDAG( DAG, - models=[ + models_paths=[ "svm.SVR", "linear_model.LinearRegression", "tree.DecisionTreeRegressor", From 0c1dabe42efcb7762fb7f33b324608ae10cc51c6 Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 23 Aug 2022 15:35:38 +0530 Subject: [PATCH 2/5] Fix typing --- src/lightning_app/testing/testing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lightning_app/testing/testing.py b/src/lightning_app/testing/testing.py index 884c02a0521c1..127ee75b29017 100644 --- a/src/lightning_app/testing/testing.py +++ b/src/lightning_app/testing/testing.py @@ -167,8 +167,8 @@ def run_cli(args) -> Generator: @requires("playwright") @contextmanager -def run_app_in_cloud(app_folder: str, app_name: str = "app.py", extra_args: [str] = []) -> Generator: - """This utility is used to automate testing e2e application with lightning_app.ai.""" +def run_app_in_cloud(app_folder: str, app_name: str = "app.py", extra_args: List[str] = []) -> Generator: + """This utility is used to automate testing e2e application with lightning.ai.""" # 1. Validate the provide app_folder is correct. if not os.path.exists(os.path.join(app_folder, "app.py")): raise Exception("The app folder should contain an app.py file.") From 96b96e95a1fe233243b0c81b89f48d15af441da5 Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 23 Aug 2022 15:49:53 +0530 Subject: [PATCH 3/5] Add test --- src/lightning_app/CHANGELOG.md | 3 +++ tests/tests_app_examples/test_app_dag.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/tests_app_examples/test_app_dag.py diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index de2416b4208a9..54913d9cc89ff 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -57,6 +57,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Unification of app template: moved `app.py` to root dir for `lightning init app ` template ([#13853](https://github.com/Lightning-AI/lightning/pull/13853)) +- Fixed the `examples/app_dag` example ([#14359](https://github.com/Lightning-AI/lightning/pull/14359)) + + ## [0.5.5] - 2022-08-9 ### Deprecated diff --git a/tests/tests_app_examples/test_app_dag.py b/tests/tests_app_examples/test_app_dag.py new file mode 100644 index 0000000000000..3a81162da4105 --- /dev/null +++ b/tests/tests_app_examples/test_app_dag.py @@ -0,0 +1,21 @@ +import os +from time import sleep + +import pytest +from tests_app import _PROJECT_ROOT + +from lightning_app.testing.testing import run_app_in_cloud + + +@pytest.mark.cloud +def test_app_dag_example_cloud() -> None: + with run_app_in_cloud(os.path.join(_PROJECT_ROOT, "examples/app_dag")) as (_, _, fetch_logs, _): + + launch_log, finish_log = False, False + while not launch_log and not finish_log: + for log in fetch_logs(["flow"]): + if "Launching a new DAG" in log: + launch_log = True + elif "Finished training and evaluating" in log: + finish_log = True + sleep(1) From 91d71123bdeb525251c242cbbc89771f18c16bd0 Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 23 Aug 2022 16:04:39 +0530 Subject: [PATCH 4/5] Update doc --- docs/source-app/examples/dag/dag_from_scratch.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/source-app/examples/dag/dag_from_scratch.rst b/docs/source-app/examples/dag/dag_from_scratch.rst index cde46953328bd..4af39f1af794e 100644 --- a/docs/source-app/examples/dag/dag_from_scratch.rst +++ b/docs/source-app/examples/dag/dag_from_scratch.rst @@ -39,10 +39,9 @@ First, let's define the component we need: :lines: 55-79 And its run method executes the steps described above. -Additionally, ``work.stop`` is used to reduce cost when running in the cloud. .. literalinclude:: ../../../examples/app_dag/app.py - :lines: 81-108 + :lines: 80-103 ---- @@ -51,4 +50,4 @@ Step 2: Define the scheduling ***************************** .. literalinclude:: ../../../examples/app_dag/app.py - :lines: 109-137 + :lines: 106-135 From b07eb641f67a12e84717a3b2868087d683ca02ff Mon Sep 17 00:00:00 2001 From: Kaushik B <45285388+kaushikb11@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:13:24 +0530 Subject: [PATCH 5/5] Update tests/tests_app_examples/test_app_dag.py Co-authored-by: Sherin Thomas --- tests/tests_app_examples/test_app_dag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests_app_examples/test_app_dag.py b/tests/tests_app_examples/test_app_dag.py index 3a81162da4105..6d9a865a0a000 100644 --- a/tests/tests_app_examples/test_app_dag.py +++ b/tests/tests_app_examples/test_app_dag.py @@ -12,7 +12,7 @@ def test_app_dag_example_cloud() -> None: with run_app_in_cloud(os.path.join(_PROJECT_ROOT, "examples/app_dag")) as (_, _, fetch_logs, _): launch_log, finish_log = False, False - while not launch_log and not finish_log: + while not (launch_log and finish_log): for log in fetch_logs(["flow"]): if "Launching a new DAG" in log: launch_log = True