From 1b6975dce66aa513ea3dfe5b53d79560164d1243 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Mon, 5 Dec 2022 19:57:14 +0000 Subject: [PATCH 1/7] Fix bug when using structures with works --- src/lightning_app/structures/dict.py | 2 +- src/lightning_app/structures/list.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lightning_app/structures/dict.py b/src/lightning_app/structures/dict.py index aaf8a3c8298d0..7bf102e19f180 100644 --- a/src/lightning_app/structures/dict.py +++ b/src/lightning_app/structures/dict.py @@ -64,10 +64,10 @@ def __setitem__(self, k, v): if isinstance(k, str) and "." in k: raise Exception(f"The provided name {k} contains . which is forbidden.") + _set_child_name(self, v, k) if self._backend: if isinstance(v, LightningFlow): LightningFlow._attach_backend(v, self._backend) - _set_child_name(self, v, k) elif isinstance(v, LightningWork): self._backend._wrap_run_method(_LightningAppRef().get_current(), v) v._name = f"{self.name}.{k}" diff --git a/src/lightning_app/structures/list.py b/src/lightning_app/structures/list.py index f2ff9b4ff2ddf..7d5b3bc119fce 100644 --- a/src/lightning_app/structures/list.py +++ b/src/lightning_app/structures/list.py @@ -61,14 +61,14 @@ def __init__(self, *items: T): def append(self, v): from lightning_app import LightningFlow, LightningWork + _set_child_name(self, v, str(self._last_index)) if self._backend: if isinstance(v, LightningFlow): LightningFlow._attach_backend(v, self._backend) - _set_child_name(self, v, str(self._last_index)) elif isinstance(v, LightningWork): self._backend._wrap_run_method(_LightningAppRef().get_current(), v) - v._name = f"{self.name}.{self._last_index}" - self._last_index += 1 + v._name = f"{self.name}.{self._last_index}" + self._last_index += 1 super().append(v) @property From 8d6655039e684e99ffa4b4e6801e4c2fc66b340f Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Mon, 5 Dec 2022 20:05:45 +0000 Subject: [PATCH 2/7] Fix --- src/lightning_app/structures/list.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lightning_app/structures/list.py b/src/lightning_app/structures/list.py index 7d5b3bc119fce..aa5e29dc55d89 100644 --- a/src/lightning_app/structures/list.py +++ b/src/lightning_app/structures/list.py @@ -55,8 +55,6 @@ def __init__(self, *items: T): self._backend: Optional[Backend] = None for item in items: self.append(item) - _set_child_name(self, item, str(self._last_index)) - self._last_index += 1 def append(self, v): from lightning_app import LightningFlow, LightningWork From 15419324044b1ecf6741e1691edda2be33869aed Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Tue, 6 Dec 2022 12:56:33 +0000 Subject: [PATCH 3/7] Add test --- tests/tests_app/structures/test_structures.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/tests_app/structures/test_structures.py b/tests/tests_app/structures/test_structures.py index 05905c3421bec..2bc7b071337a0 100644 --- a/tests/tests_app/structures/test_structures.py +++ b/tests/tests_app/structures/test_structures.py @@ -497,3 +497,25 @@ def test_structures_with_payload(): app = LightningApp(FlowPayload(), log_level="debug") MultiProcessRuntime(app, start_server=False).dispatch() os.remove("payload") + + +def test_structures_have_name_on_init(): + """Test that the children in structures have the correct name assigned upon initialization.""" + + class ChildWork(LightningWork): + def run(self): + pass + + class Collection(EmptyFlow): + def __init__(self): + super().__init__() + self.list_structure = List() + self.list_structure.append(ChildWork()) + + self.dict_structure = Dict() + self.dict_structure["dict_child"] = ChildWork() + + flow = Collection() + LightningApp(flow) # wrap in app to init all component names + assert flow.list_structure[0].name == "root.list_structure.0" + assert flow.dict_structure["dict_child"].name == "root.dict_structure.dict_child" From dc91a960323aa00968090e3cb8db4e5c5e9f71d0 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Tue, 6 Dec 2022 14:24:01 +0000 Subject: [PATCH 4/7] Update CHANGELOG.md --- src/lightning_app/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index b3ab015ce44bc..cbc118123ba65 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -50,6 +50,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed Sigterm Handler causing thread lock which caused KeyboardInterrupt to hang ([#15881](https://github.com/Lightning-AI/lightning/pull/15881)) +- Fixed a bug where using `L.app.structures` would cause multiple apps to be opened and fail with an error in the cloud ([#15911](https://github.com/Lightning-AI/lightning/pull/15911)) + ## [1.8.3] - 2022-11-22 From 62bffe5b458c7e5249c87b6de899d519dee41842 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Wed, 7 Dec 2022 23:30:41 +0000 Subject: [PATCH 5/7] Fixes --- src/lightning_app/structures/list.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lightning_app/structures/list.py b/src/lightning_app/structures/list.py index aa5e29dc55d89..9f110c69b1388 100644 --- a/src/lightning_app/structures/list.py +++ b/src/lightning_app/structures/list.py @@ -1,7 +1,5 @@ import typing as t -from pyparsing import Optional - from lightning_app.utilities.app_helpers import _LightningAppRef, _set_child_name T = t.TypeVar("T") @@ -52,7 +50,7 @@ def __init__(self, *items: T): self._name: t.Optional[str] = "" self._last_index = 0 - self._backend: Optional[Backend] = None + self._backend: t.Optional[Backend] = None for item in items: self.append(item) From 52c3e1499d475a3ef88fffc1a948e432925ffec4 Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Wed, 7 Dec 2022 23:41:29 +0000 Subject: [PATCH 6/7] Fix --- requirements/app/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/app/base.txt b/requirements/app/base.txt index f9a31242e75bd..37e91689bb54d 100644 --- a/requirements/app/base.txt +++ b/requirements/app/base.txt @@ -7,7 +7,7 @@ fsspec>=2022.5.0, <=2022.7.1 croniter>=1.3.0, <1.4.0 # strict; TODO: for now until we find something more robust. traitlets>=5.3.0, <=5.4.0 arrow>=1.2.0, <1.2.4 -lightning-utilities>=0.3.*, !=0.4.0, <0.5.0 +lightning-utilities>=0.3.0, !=0.4.0, <0.5.0 beautifulsoup4>=4.8.0, <4.11.2 inquirer>=2.10.0 psutil<5.9.4 From 5d871b24d5f45cc60dc8e04cf64e6e8dc91d7c0c Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Wed, 7 Dec 2022 23:52:14 +0000 Subject: [PATCH 7/7] Fix --- requirements/lite/base.txt | 2 +- requirements/lite/examples.txt | 2 +- requirements/pytorch/base.txt | 2 +- requirements/pytorch/examples.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements/lite/base.txt b/requirements/lite/base.txt index 45fd511d315e5..dc7fd6ea578da 100644 --- a/requirements/lite/base.txt +++ b/requirements/lite/base.txt @@ -2,7 +2,7 @@ # in case you want to preserve/enforce restrictions on the latest compatible version, add "strict" as an in-line comment numpy>=1.17.2, <1.23.1 -torch>=1.10.*, <=1.13.0 +torch>=1.10.0, <=1.13.0 fsspec[http]>2021.06.0, <2022.6.0 packaging>=17.0, <=21.3 typing-extensions>=4.0.0, <=4.4.0 diff --git a/requirements/lite/examples.txt b/requirements/lite/examples.txt index ebf32e2c2c48d..43bb03e07cc80 100644 --- a/requirements/lite/examples.txt +++ b/requirements/lite/examples.txt @@ -1,4 +1,4 @@ # NOTE: the upper bound for the package version is only set for CI stability, and it is dropped while installing this package # in case you want to preserve/enforce restrictions on the latest compatible version, add "strict" as an in-line comment -torchvision>=0.10.*, <=0.13.0 +torchvision>=0.10.0, <=0.13.0 diff --git a/requirements/pytorch/base.txt b/requirements/pytorch/base.txt index 483460f88ff11..31163ecb602b7 100644 --- a/requirements/pytorch/base.txt +++ b/requirements/pytorch/base.txt @@ -2,7 +2,7 @@ # in case you want to preserve/enforce restrictions on the latest compatible version, add "strict" as an in-line comment numpy>=1.17.2, <1.23.1 -torch>=1.10.*, <=1.13.0 +torch>=1.10.0, <=1.13.0 tqdm>=4.57.0, <4.65.0 PyYAML>=5.4, <=6.0 fsspec[http]>2021.06.0, <2022.8.0 diff --git a/requirements/pytorch/examples.txt b/requirements/pytorch/examples.txt index c749c83faedb9..7e02a2f4bea99 100644 --- a/requirements/pytorch/examples.txt +++ b/requirements/pytorch/examples.txt @@ -1,6 +1,6 @@ # NOTE: the upper bound for the package version is only set for CI stability, and it is dropped while installing this package # in case you want to preserve/enforce restrictions on the latest compatible version, add "strict" as an in-line comment -torchvision>=0.11.*, <=0.14.0 +torchvision>=0.11.1, <=0.14.0 gym[classic_control]>=0.17.0, <0.26.3 ipython[all] <8.6.1