Skip to content

Commit 2b61c92

Browse files
kaushikb11Sherin Thomas
andauthored
Fix the examples/app_dag App (#14359)
* Fix app dag example * Add test * Update doc * Update tests/tests_app_examples/test_app_dag.py Co-authored-by: Sherin Thomas <[email protected]>
1 parent cfb27bd commit 2b61c92

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

docs/source-app/examples/dag/dag_from_scratch.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ First, let's define the component we need:
3939
:lines: 55-79
4040

4141
And its run method executes the steps described above.
42-
Additionally, ``work.stop`` is used to reduce cost when running in the cloud.
4342

4443
.. literalinclude:: ../../../examples/app_dag/app.py
45-
:lines: 81-108
44+
:lines: 80-103
4645

4746
----
4847

@@ -51,4 +50,4 @@ Step 2: Define the scheduling
5150
*****************************
5251

5352
.. literalinclude:: ../../../examples/app_dag/app.py
54-
:lines: 109-137
53+
:lines: 106-135

examples/app_dag/app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class DAG(L.LightningFlow):
5656

5757
"""This component is a DAG."""
5858

59-
def __init__(self, models_paths):
59+
def __init__(self, models_paths: list):
6060
super().__init__()
6161
# Step 1: Create a work to get the data.
6262
self.data_collector = GetDataWork()
@@ -80,12 +80,10 @@ def __init__(self, models_paths):
8080
def run(self):
8181
# Step 1 and 2: Download and process the data.
8282
self.data_collector.run()
83-
self.data_collector.stop() # Stop the data_collector to reduce cost
8483
self.processing.run(
8584
df_data=self.data_collector.df_data,
8685
df_target=self.data_collector.df_target,
8786
)
88-
self.processing.stop() # Stop the processing to reduce cost
8987

9088
# Step 3: Launch n models training in parallel.
9189
for model, work in self.dict.items():
@@ -128,7 +126,7 @@ def run(self):
128126
app = L.LightningApp(
129127
ScheduledDAG(
130128
DAG,
131-
models=[
129+
models_paths=[
132130
"svm.SVR",
133131
"linear_model.LinearRegression",
134132
"tree.DecisionTreeRegressor",

src/lightning_app/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
221221
- Resolved a bug where the `install` command was not installing the latest version of an app/component by default ([#14181](https://github.com/Lightning-AI/lightning/pull/14181))
222222

223223

224+
- Fixed the `examples/app_dag` example ([#14359](https://github.com/Lightning-AI/lightning/pull/14359))
225+
226+
224227
## [0.5.5] - 2022-08-9
225228

226229
### Deprecated

src/lightning_app/testing/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _run_cli(args) -> Generator:
219219
def run_app_in_cloud(
220220
app_folder: str, app_name: str = "app.py", extra_args: List[str] = [], debug: bool = True
221221
) -> Generator:
222-
"""This utility is used to automate testing e2e application with lightning_app.ai."""
222+
"""This utility is used to automate testing e2e application with lightning.ai."""
223223
# 1. Validate the provide app_folder is correct.
224224
if not os.path.exists(os.path.join(app_folder, "app.py")):
225225
raise Exception("The app folder should contain an app.py file.")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
from time import sleep
3+
4+
import pytest
5+
from tests_app import _PROJECT_ROOT
6+
7+
from lightning_app.testing.testing import run_app_in_cloud
8+
9+
10+
@pytest.mark.cloud
11+
def test_app_dag_example_cloud() -> None:
12+
with run_app_in_cloud(os.path.join(_PROJECT_ROOT, "examples/app_dag")) as (_, _, fetch_logs, _):
13+
14+
launch_log, finish_log = False, False
15+
while not (launch_log and finish_log):
16+
for log in fetch_logs(["flow"]):
17+
if "Launching a new DAG" in log:
18+
launch_log = True
19+
elif "Finished training and evaluating" in log:
20+
finish_log = True
21+
sleep(1)

0 commit comments

Comments
 (0)