From 8c1fe5d901d13dc7418153c00c4d9b3ee79b0abc Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Wed, 22 May 2024 15:37:40 -0500 Subject: [PATCH 01/13] pushing for matt --- smartsim/jobgrouphold/__init__.py | 7 ++++++ smartsim/jobgrouphold/baseJobGroup.py | 34 +++++++++++++++++++++++++++ smartsim/jobgrouphold/jobGroup.py | 25 ++++++++++++++++++++ tests/temp_tests/job_tests.py | 7 ++++++ 4 files changed, 73 insertions(+) create mode 100644 smartsim/jobgrouphold/__init__.py create mode 100644 smartsim/jobgrouphold/baseJobGroup.py create mode 100644 smartsim/jobgrouphold/jobGroup.py create mode 100644 tests/temp_tests/job_tests.py diff --git a/smartsim/jobgrouphold/__init__.py b/smartsim/jobgrouphold/__init__.py new file mode 100644 index 0000000000..5968fe9ef1 --- /dev/null +++ b/smartsim/jobgrouphold/__init__.py @@ -0,0 +1,7 @@ +from .baseJobGroup import BaseJobGroup +from .jobGroup import JobGroup + +__all__ = [ + "JobGroup", + "BaseJobGroup", +] \ No newline at end of file diff --git a/smartsim/jobgrouphold/baseJobGroup.py b/smartsim/jobgrouphold/baseJobGroup.py new file mode 100644 index 0000000000..b142a2cac7 --- /dev/null +++ b/smartsim/jobgrouphold/baseJobGroup.py @@ -0,0 +1,34 @@ +import typing as t +from abc import abstractmethod +from copy import deepcopy +class BaseJob: pass # assume BaseJob class exists until Julias implementation +class Launchable: pass # assume BaseJob class exists until Julias implementation +class MutableSequence: pass + +class BaseJobGroup(Launchable, MutableSequence): + """Highest level ABC of a group of jobs that can be + launched + """ + def __init__(self) -> None: + super().__init__() + + @property + @abstractmethod + def jobs(self) -> t.List[BaseJob]: + return self.jobs + + def __getitem___(self, idx) -> BaseJob: + return self.jobs[idx] + + def __setitem__(self, idx, value) -> None: + self.jobs[idx] = deepcopy(value) + + def __delitem__(self, idx) -> None: + del self.jobs[idx] +# after that just need to do dunder string + def __len__(self) -> int: + return len(self.jobs) + + def __str__(self): # pragma: no-cover + string = "" + string += f"Jobs: {self.jobs}" \ No newline at end of file diff --git a/smartsim/jobgrouphold/jobGroup.py b/smartsim/jobgrouphold/jobGroup.py new file mode 100644 index 0000000000..d77202d400 --- /dev/null +++ b/smartsim/jobgrouphold/jobGroup.py @@ -0,0 +1,25 @@ +import typing as t +from copy import deepcopy +from .baseJobGroup import BaseJobGroup, BaseJob +class Job: pass # assume Job class exists until Julias implementation + +class JobGroup(BaseJobGroup): + """A job group holds references to multiple jobs that + will be executed all at the same time when resources + permit. Execution is blocked until resources are available. + """ + def __init__( + self, + jobs: t.List[BaseJob], + ) -> None: + super().__init__() + # TODO we should be doing deep copies of objects (i.e. Job objets) + self.jobs = deepcopy(jobs) + + @property + def jobs(self) -> t.List[BaseJob]: + return self.jobs + + def __str__(self): # pragma: no-cover + string = "" + string += f"Jobs: {self.jobs}" \ No newline at end of file diff --git a/tests/temp_tests/job_tests.py b/tests/temp_tests/job_tests.py new file mode 100644 index 0000000000..f16d4b9047 --- /dev/null +++ b/tests/temp_tests/job_tests.py @@ -0,0 +1,7 @@ +from smartsim.jobgrouphold.baseJobGroup import BaseJobGroup +from smartsim.jobgrouphold.jobGroup import JobGroup, BaseJob + +def test_jobs_property(): + job = BaseJob() + job_group = JobGroup([job]) + assert len(job_group) == 1 \ No newline at end of file From ad2acb4eb2053e8ff9e2a563edd4422438bad566 Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Wed, 22 May 2024 16:07:02 -0500 Subject: [PATCH 02/13] update --- smartsim/jobgrouphold/baseJobGroup.py | 5 ++++- smartsim/jobgrouphold/jobGroup.py | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/smartsim/jobgrouphold/baseJobGroup.py b/smartsim/jobgrouphold/baseJobGroup.py index b142a2cac7..bf651da7f4 100644 --- a/smartsim/jobgrouphold/baseJobGroup.py +++ b/smartsim/jobgrouphold/baseJobGroup.py @@ -25,10 +25,13 @@ def __setitem__(self, idx, value) -> None: def __delitem__(self, idx) -> None: del self.jobs[idx] -# after that just need to do dunder string + def __len__(self) -> int: return len(self.jobs) + def __insert__(self) -> int: + pass + def __str__(self): # pragma: no-cover string = "" string += f"Jobs: {self.jobs}" \ No newline at end of file diff --git a/smartsim/jobgrouphold/jobGroup.py b/smartsim/jobgrouphold/jobGroup.py index d77202d400..5357a7ef6b 100644 --- a/smartsim/jobgrouphold/jobGroup.py +++ b/smartsim/jobgrouphold/jobGroup.py @@ -13,12 +13,11 @@ def __init__( jobs: t.List[BaseJob], ) -> None: super().__init__() - # TODO we should be doing deep copies of objects (i.e. Job objets) - self.jobs = deepcopy(jobs) + self._jobs = jobs @property def jobs(self) -> t.List[BaseJob]: - return self.jobs + return self._jobs def __str__(self): # pragma: no-cover string = "" From 4eb5822bebc3dd76a05b5d71d68a885a8d4957c0 Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Wed, 22 May 2024 16:11:27 -0500 Subject: [PATCH 03/13] updating --- smartsim/jobgrouphold/baseJobGroup.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/smartsim/jobgrouphold/baseJobGroup.py b/smartsim/jobgrouphold/baseJobGroup.py index bf651da7f4..b260b0813c 100644 --- a/smartsim/jobgrouphold/baseJobGroup.py +++ b/smartsim/jobgrouphold/baseJobGroup.py @@ -15,22 +15,22 @@ def __init__(self) -> None: @property @abstractmethod def jobs(self) -> t.List[BaseJob]: - return self.jobs + pass - def __getitem___(self, idx) -> BaseJob: + def __getitem__(self, idx: int) -> BaseJob: return self.jobs[idx] - def __setitem__(self, idx, value) -> None: + def __setitem__(self, idx: int, value: BaseJob) -> None: self.jobs[idx] = deepcopy(value) - def __delitem__(self, idx) -> None: + def __delitem__(self, idx: int) -> None: del self.jobs[idx] def __len__(self) -> int: return len(self.jobs) - def __insert__(self) -> int: - pass + def __insert__(self, index: int, value: BaseJob) -> int: + self.jobs.insert(index, value) def __str__(self): # pragma: no-cover string = "" From 3399aa32080358520fa94d7e25d0c397c782580b Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Wed, 22 May 2024 17:01:45 -0500 Subject: [PATCH 04/13] tested --- smartsim/jobgrouphold/baseJobGroup.py | 16 ++++++--- tests/temp_tests/job_tests.py | 7 ---- tests/temp_tests/test_jobGroup.py | 47 +++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 12 deletions(-) delete mode 100644 tests/temp_tests/job_tests.py create mode 100644 tests/temp_tests/test_jobGroup.py diff --git a/smartsim/jobgrouphold/baseJobGroup.py b/smartsim/jobgrouphold/baseJobGroup.py index b260b0813c..704096399b 100644 --- a/smartsim/jobgrouphold/baseJobGroup.py +++ b/smartsim/jobgrouphold/baseJobGroup.py @@ -16,12 +16,21 @@ def __init__(self) -> None: @abstractmethod def jobs(self) -> t.List[BaseJob]: pass - + + def insert(self, idx: int, value: BaseJob) -> None: + if 0 <= idx <= len(self.jobs): + self.jobs.insert(idx, value) + else: + print(f"Invalid index {idx}. Cannot insert value: {value}.") + + def __iter__(self) -> t.Iterator[BaseJob]: + return iter(self.jobs) + def __getitem__(self, idx: int) -> BaseJob: return self.jobs[idx] def __setitem__(self, idx: int, value: BaseJob) -> None: - self.jobs[idx] = deepcopy(value) + self.jobs[idx] = value def __delitem__(self, idx: int) -> None: del self.jobs[idx] @@ -29,9 +38,6 @@ def __delitem__(self, idx: int) -> None: def __len__(self) -> int: return len(self.jobs) - def __insert__(self, index: int, value: BaseJob) -> int: - self.jobs.insert(index, value) - def __str__(self): # pragma: no-cover string = "" string += f"Jobs: {self.jobs}" \ No newline at end of file diff --git a/tests/temp_tests/job_tests.py b/tests/temp_tests/job_tests.py deleted file mode 100644 index f16d4b9047..0000000000 --- a/tests/temp_tests/job_tests.py +++ /dev/null @@ -1,7 +0,0 @@ -from smartsim.jobgrouphold.baseJobGroup import BaseJobGroup -from smartsim.jobgrouphold.jobGroup import JobGroup, BaseJob - -def test_jobs_property(): - job = BaseJob() - job_group = JobGroup([job]) - assert len(job_group) == 1 \ No newline at end of file diff --git a/tests/temp_tests/test_jobGroup.py b/tests/temp_tests/test_jobGroup.py new file mode 100644 index 0000000000..be2aba8679 --- /dev/null +++ b/tests/temp_tests/test_jobGroup.py @@ -0,0 +1,47 @@ +from smartsim.jobgrouphold.baseJobGroup import BaseJobGroup +from smartsim.jobgrouphold.jobGroup import JobGroup, BaseJob + +def test_create_JobGroup(): + job_1 = BaseJob() + job_group = JobGroup([job_1]) + assert len(job_group) == 1 + +def test_getitem_JobGroup(): + job_1 = BaseJob() + job_2 = BaseJob() + job_group = JobGroup([job_1,job_2]) + get_value = job_group[0] + assert get_value == job_1 + +# cannot test setitem until Job is implemented since there is no comparison bc of the deep copy +# def test_setitem_JobGroup(): +# job_1 = BaseJob() +# job_2 = BaseJob() +# job_group = JobGroup([job_1,job_2]) +# job_3 = BaseJob() +# job_group[1] = job_3 +# get_value = job_group[1] +# assert get_value == job_3 + +def test_delitem_JobGroup(): + job_1 = BaseJob() + job_2 = BaseJob() + job_group = JobGroup([job_1,job_2]) + assert len(job_group) == 2 + del(job_group[1]) + assert len(job_group) == 1 + +def test_len_JobGroup(): + job_1 = BaseJob() + job_2 = BaseJob() + job_group = JobGroup([job_1,job_2]) + assert len(job_group) == 2 + +def test_insert_JobGroup(): + job_1 = BaseJob() + job_2 = BaseJob() + job_group = JobGroup([job_1,job_2]) + job_3 = BaseJob() + job_group.insert(0, job_3) + get_value = job_group[0] + assert get_value == job_3 \ No newline at end of file From ef3b2380692303bfbedacb7e3978647202d135f7 Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Wed, 22 May 2024 17:18:12 -0500 Subject: [PATCH 05/13] docstrings --- smartsim/jobgrouphold/baseJobGroup.py | 20 ++++++++++++++++++++ smartsim/jobgrouphold/jobGroup.py | 8 +++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/smartsim/jobgrouphold/baseJobGroup.py b/smartsim/jobgrouphold/baseJobGroup.py index 704096399b..887e1f45d8 100644 --- a/smartsim/jobgrouphold/baseJobGroup.py +++ b/smartsim/jobgrouphold/baseJobGroup.py @@ -15,29 +15,49 @@ def __init__(self) -> None: @property @abstractmethod def jobs(self) -> t.List[BaseJob]: + """This property method returns a list of BaseJob objects. + It represents the collection of jobs associated with an + instance of the BaseJobGroup abstract class. + """ pass def insert(self, idx: int, value: BaseJob) -> None: + """Inserts the given value at the specified index (idx) in + the list of jobs. If the index is out of bounds, the method + prints an error message. + """ if 0 <= idx <= len(self.jobs): self.jobs.insert(idx, value) else: print(f"Invalid index {idx}. Cannot insert value: {value}.") def __iter__(self) -> t.Iterator[BaseJob]: + """Allows iteration over the jobs in the collection. + """ return iter(self.jobs) def __getitem__(self, idx: int) -> BaseJob: + """Retrieves the job at the specified index (idx). + """ return self.jobs[idx] def __setitem__(self, idx: int, value: BaseJob) -> None: + """Sets the job at the specified index (idx) to the given value. + """ self.jobs[idx] = value def __delitem__(self, idx: int) -> None: + """Deletes the job at the specified index (idx). + """ del self.jobs[idx] def __len__(self) -> int: + """Returns the total number of jobs in the collection. + """ return len(self.jobs) def __str__(self): # pragma: no-cover + """Returns a string representation of the collection of jobs. + """ string = "" string += f"Jobs: {self.jobs}" \ No newline at end of file diff --git a/smartsim/jobgrouphold/jobGroup.py b/smartsim/jobgrouphold/jobGroup.py index 5357a7ef6b..507ebe12af 100644 --- a/smartsim/jobgrouphold/jobGroup.py +++ b/smartsim/jobgrouphold/jobGroup.py @@ -17,8 +17,14 @@ def __init__( @property def jobs(self) -> t.List[BaseJob]: - return self._jobs + """This property method returns a list of BaseJob objects. + It represents the collection of jobs associated with an + instance of the BaseJobGroup abstract class. + """ + return self._jobs def __str__(self): # pragma: no-cover + """Returns a string representation of the collection of jobs. + """ string = "" string += f"Jobs: {self.jobs}" \ No newline at end of file From e8afaf6c878309b883e607b51fc05019e0d2e8c8 Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Wed, 22 May 2024 18:28:56 -0500 Subject: [PATCH 06/13] insert --- smartsim/jobgrouphold/baseJobGroup.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/smartsim/jobgrouphold/baseJobGroup.py b/smartsim/jobgrouphold/baseJobGroup.py index 887e1f45d8..11b2d1bba2 100644 --- a/smartsim/jobgrouphold/baseJobGroup.py +++ b/smartsim/jobgrouphold/baseJobGroup.py @@ -26,10 +26,7 @@ def insert(self, idx: int, value: BaseJob) -> None: the list of jobs. If the index is out of bounds, the method prints an error message. """ - if 0 <= idx <= len(self.jobs): - self.jobs.insert(idx, value) - else: - print(f"Invalid index {idx}. Cannot insert value: {value}.") + self.jobs.insert(idx, value) def __iter__(self) -> t.Iterator[BaseJob]: """Allows iteration over the jobs in the collection. From 80f24636c860433fadf2136dcc555c0d7d4b217a Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Thu, 23 May 2024 11:34:07 -0500 Subject: [PATCH 07/13] colocated job group --- smartsim/jobgrouphold/__init__.py | 3 +- smartsim/jobgrouphold/baseJobGroup.py | 2 +- smartsim/jobgrouphold/colocatedJobGroup.py | 30 ++++++++++++++ smartsim/jobgrouphold/jobGroup.py | 12 +++--- tests/temp_tests/test_colocatedJobGroup.py | 47 ++++++++++++++++++++++ tests/temp_tests/test_jobGroup.py | 13 +++--- 6 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 smartsim/jobgrouphold/colocatedJobGroup.py create mode 100644 tests/temp_tests/test_colocatedJobGroup.py diff --git a/smartsim/jobgrouphold/__init__.py b/smartsim/jobgrouphold/__init__.py index 5968fe9ef1..754f90c6e9 100644 --- a/smartsim/jobgrouphold/__init__.py +++ b/smartsim/jobgrouphold/__init__.py @@ -1,7 +1,8 @@ from .baseJobGroup import BaseJobGroup from .jobGroup import JobGroup - +from .colocatedJobGroup import ColocatedJobGroup __all__ = [ "JobGroup", "BaseJobGroup", + "ColocatedJobGroup", ] \ No newline at end of file diff --git a/smartsim/jobgrouphold/baseJobGroup.py b/smartsim/jobgrouphold/baseJobGroup.py index 11b2d1bba2..af7335626a 100644 --- a/smartsim/jobgrouphold/baseJobGroup.py +++ b/smartsim/jobgrouphold/baseJobGroup.py @@ -41,7 +41,7 @@ def __getitem__(self, idx: int) -> BaseJob: def __setitem__(self, idx: int, value: BaseJob) -> None: """Sets the job at the specified index (idx) to the given value. """ - self.jobs[idx] = value + self.jobs[idx] = deepcopy(value) def __delitem__(self, idx: int) -> None: """Deletes the job at the specified index (idx). diff --git a/smartsim/jobgrouphold/colocatedJobGroup.py b/smartsim/jobgrouphold/colocatedJobGroup.py new file mode 100644 index 0000000000..f45a160066 --- /dev/null +++ b/smartsim/jobgrouphold/colocatedJobGroup.py @@ -0,0 +1,30 @@ +import typing as t +from .baseJobGroup import BaseJobGroup, BaseJob +from copy import deepcopy + +class ColocatedJobGroup(BaseJobGroup): + """A colocated job group holds references to multiple jobs that + will be executed all at the same time when resources + permit. Execution is blocked until resources are available. + """ + def __init__( + self, + jobs: t.List[BaseJob], + ) -> None: + super().__init__() + self._jobs = deepcopy(jobs) + + @property + def jobs(self) -> t.List[BaseJob]: + """This property method returns a list of BaseJob objects. + It represents the collection of jobs associated with an + instance of the BaseJobGroup abstract class. + """ + return self._jobs + + def __str__(self): # pragma: no-cover + """Returns a string representation of the collection of + colocated job groups. + """ + string = "" + string += f"Colocated Jobs: {self.jobs}" \ No newline at end of file diff --git a/smartsim/jobgrouphold/jobGroup.py b/smartsim/jobgrouphold/jobGroup.py index 507ebe12af..009eeb47fa 100644 --- a/smartsim/jobgrouphold/jobGroup.py +++ b/smartsim/jobgrouphold/jobGroup.py @@ -1,19 +1,18 @@ import typing as t -from copy import deepcopy from .baseJobGroup import BaseJobGroup, BaseJob -class Job: pass # assume Job class exists until Julias implementation +from copy import deepcopy class JobGroup(BaseJobGroup): """A job group holds references to multiple jobs that will be executed all at the same time when resources - permit. Execution is blocked until resources are available. + permit. Execution is blocked until resources are available. """ def __init__( self, jobs: t.List[BaseJob], ) -> None: super().__init__() - self._jobs = jobs + self._jobs = deepcopy(jobs) @property def jobs(self) -> t.List[BaseJob]: @@ -24,7 +23,8 @@ def jobs(self) -> t.List[BaseJob]: return self._jobs def __str__(self): # pragma: no-cover - """Returns a string representation of the collection of jobs. + """Returns a string representation of the collection of + job groups. """ string = "" - string += f"Jobs: {self.jobs}" \ No newline at end of file + string += f"Job Groups: {self.jobs}" \ No newline at end of file diff --git a/tests/temp_tests/test_colocatedJobGroup.py b/tests/temp_tests/test_colocatedJobGroup.py new file mode 100644 index 0000000000..2e398119e9 --- /dev/null +++ b/tests/temp_tests/test_colocatedJobGroup.py @@ -0,0 +1,47 @@ +from smartsim.jobgrouphold.colocatedJobGroup import ColocatedJobGroup, BaseJob + +def test_create_ColocatedJobGroup(): + job_1 = BaseJob() + job_group = ColocatedJobGroup([job_1]) + assert len(job_group) == 1 + +# cannot test setitem until Job is implemented since there is no comparison bc of the deep copy +# def test_getitem_ColocatedJobGroup(): +# job_1 = BaseJob() +# job_2 = BaseJob() +# job_group = ColocatedJobGroup([job_1,job_2]) +# get_value = job_group[0] +# assert get_value == job_1 + +# cannot test setitem until Job is implemented since there is no comparison bc of the deep copy +# def test_setitem_JobGroup(): +# job_1 = BaseJob() +# job_2 = BaseJob() +# job_group = JobGroup([job_1,job_2]) +# job_3 = BaseJob() +# job_group[1] = job_3 +# get_value = job_group[1] +# assert get_value == job_3 + +def test_delitem_ColocatedJobGroup(): + job_1 = BaseJob() + job_2 = BaseJob() + job_group = ColocatedJobGroup([job_1,job_2]) + assert len(job_group) == 2 + del(job_group[1]) + assert len(job_group) == 1 + +def test_len_ColocatedJobGroup(): + job_1 = BaseJob() + job_2 = BaseJob() + job_group = ColocatedJobGroup([job_1,job_2]) + assert len(job_group) == 2 + +def test_insert_ColocatedJobGroup(): + job_1 = BaseJob() + job_2 = BaseJob() + job_group = ColocatedJobGroup([job_1,job_2]) + job_3 = BaseJob() + job_group.insert(0, job_3) + get_value = job_group[0] + assert get_value == job_3 \ No newline at end of file diff --git a/tests/temp_tests/test_jobGroup.py b/tests/temp_tests/test_jobGroup.py index be2aba8679..998f8b3ef2 100644 --- a/tests/temp_tests/test_jobGroup.py +++ b/tests/temp_tests/test_jobGroup.py @@ -6,12 +6,13 @@ def test_create_JobGroup(): job_group = JobGroup([job_1]) assert len(job_group) == 1 -def test_getitem_JobGroup(): - job_1 = BaseJob() - job_2 = BaseJob() - job_group = JobGroup([job_1,job_2]) - get_value = job_group[0] - assert get_value == job_1 +# cannot test setitem until Job is implemented since there is no comparison bc of the deep copy +# def test_getitem_JobGroup(): +# job_1 = BaseJob() +# job_2 = BaseJob() +# job_group = JobGroup([job_1,job_2]) +# get_value = job_group[0] +# assert get_value == job_1 # cannot test setitem until Job is implemented since there is no comparison bc of the deep copy # def test_setitem_JobGroup(): From f1982288682115d40ac1cd372ef4adff2b293672 Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Thu, 23 May 2024 15:00:02 -0500 Subject: [PATCH 08/13] pushing but will update --- tests/temp_tests/test_colocatedJobGroup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/temp_tests/test_colocatedJobGroup.py b/tests/temp_tests/test_colocatedJobGroup.py index 2e398119e9..80a50e5ca7 100644 --- a/tests/temp_tests/test_colocatedJobGroup.py +++ b/tests/temp_tests/test_colocatedJobGroup.py @@ -5,6 +5,7 @@ def test_create_ColocatedJobGroup(): job_group = ColocatedJobGroup([job_1]) assert len(job_group) == 1 +# compare job names when Job class is up, handleful of other atts, not reused elsewhere # cannot test setitem until Job is implemented since there is no comparison bc of the deep copy # def test_getitem_ColocatedJobGroup(): # job_1 = BaseJob() From afb75dfb6ef53a9109472dd838f9a177a07f76e4 Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Thu, 30 May 2024 14:22:43 -0500 Subject: [PATCH 09/13] mutable sequence import --- smartsim/jobgrouphold/baseJobGroup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smartsim/jobgrouphold/baseJobGroup.py b/smartsim/jobgrouphold/baseJobGroup.py index af7335626a..ed7a5be9af 100644 --- a/smartsim/jobgrouphold/baseJobGroup.py +++ b/smartsim/jobgrouphold/baseJobGroup.py @@ -1,9 +1,10 @@ import typing as t from abc import abstractmethod +from collections.abc import MutableSequence from copy import deepcopy + class BaseJob: pass # assume BaseJob class exists until Julias implementation class Launchable: pass # assume BaseJob class exists until Julias implementation -class MutableSequence: pass class BaseJobGroup(Launchable, MutableSequence): """Highest level ABC of a group of jobs that can be From 62da6e1950beab4b2437765ea22300f20f84e86c Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Tue, 11 Jun 2024 16:43:31 -0500 Subject: [PATCH 10/13] push --- smartsim/jobgrouphold/__init__.py | 8 -- smartsim/launchable/__init__.py | 3 + .../baseJobGroup.py | 4 +- smartsim/launchable/basejob.py | 1 - .../colocatedJobGroup.py | 3 +- .../{jobgrouphold => launchable}/jobGroup.py | 3 +- smartsim/launchable/mpmdpair.py | 5 +- tests/temp_tests/test_colocatedJobGroup.py | 43 ++++---- tests/temp_tests/test_jobGroup.py | 43 ++++---- .../test_launchable.py | 99 +++++++++---------- 10 files changed, 110 insertions(+), 102 deletions(-) delete mode 100644 smartsim/jobgrouphold/__init__.py rename smartsim/{jobgrouphold => launchable}/baseJobGroup.py (91%) rename smartsim/{jobgrouphold => launchable}/colocatedJobGroup.py (93%) rename smartsim/{jobgrouphold => launchable}/jobGroup.py (92%) rename tests/{_legacy => temp_tests}/test_launchable.py (64%) diff --git a/smartsim/jobgrouphold/__init__.py b/smartsim/jobgrouphold/__init__.py deleted file mode 100644 index 754f90c6e9..0000000000 --- a/smartsim/jobgrouphold/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from .baseJobGroup import BaseJobGroup -from .jobGroup import JobGroup -from .colocatedJobGroup import ColocatedJobGroup -__all__ = [ - "JobGroup", - "BaseJobGroup", - "ColocatedJobGroup", -] \ No newline at end of file diff --git a/smartsim/launchable/__init__.py b/smartsim/launchable/__init__.py index e04fdddd14..399084ed51 100644 --- a/smartsim/launchable/__init__.py +++ b/smartsim/launchable/__init__.py @@ -29,3 +29,6 @@ from .launchable import Launchable from .mpmdjob import MPMDJob from .mpmdpair import MPMDPair +from .baseJobGroup import BaseJobGroup +from .jobGroup import JobGroup +from .colocatedJobGroup import ColocatedJobGroup diff --git a/smartsim/jobgrouphold/baseJobGroup.py b/smartsim/launchable/baseJobGroup.py similarity index 91% rename from smartsim/jobgrouphold/baseJobGroup.py rename to smartsim/launchable/baseJobGroup.py index ed7a5be9af..3d727bd14a 100644 --- a/smartsim/jobgrouphold/baseJobGroup.py +++ b/smartsim/launchable/baseJobGroup.py @@ -3,8 +3,8 @@ from collections.abc import MutableSequence from copy import deepcopy -class BaseJob: pass # assume BaseJob class exists until Julias implementation -class Launchable: pass # assume BaseJob class exists until Julias implementation +from .basejob import BaseJob +from smartsim.launchable.launchable import Launchable class BaseJobGroup(Launchable, MutableSequence): """Highest level ABC of a group of jobs that can be diff --git a/smartsim/launchable/basejob.py b/smartsim/launchable/basejob.py index bcefd04880..7136768ce3 100644 --- a/smartsim/launchable/basejob.py +++ b/smartsim/launchable/basejob.py @@ -33,7 +33,6 @@ class BaseJob(ABC, Launchable): """The highest level abstract base class for a single job that can be launched""" - @abstractmethod def get_launch_steps(self) -> None: # TODO: -> LaunchSteps: """Return the launch steps corresponding to the internal data. diff --git a/smartsim/jobgrouphold/colocatedJobGroup.py b/smartsim/launchable/colocatedJobGroup.py similarity index 93% rename from smartsim/jobgrouphold/colocatedJobGroup.py rename to smartsim/launchable/colocatedJobGroup.py index f45a160066..800cd4cfa2 100644 --- a/smartsim/jobgrouphold/colocatedJobGroup.py +++ b/smartsim/launchable/colocatedJobGroup.py @@ -1,5 +1,6 @@ import typing as t -from .baseJobGroup import BaseJobGroup, BaseJob +from .baseJobGroup import BaseJobGroup +from .basejob import BaseJob from copy import deepcopy class ColocatedJobGroup(BaseJobGroup): diff --git a/smartsim/jobgrouphold/jobGroup.py b/smartsim/launchable/jobGroup.py similarity index 92% rename from smartsim/jobgrouphold/jobGroup.py rename to smartsim/launchable/jobGroup.py index 009eeb47fa..2ce9b2f9ca 100644 --- a/smartsim/jobgrouphold/jobGroup.py +++ b/smartsim/launchable/jobGroup.py @@ -1,5 +1,6 @@ import typing as t -from .baseJobGroup import BaseJobGroup, BaseJob +from .baseJobGroup import BaseJobGroup +from .basejob import BaseJob from copy import deepcopy class JobGroup(BaseJobGroup): diff --git a/smartsim/launchable/mpmdpair.py b/smartsim/launchable/mpmdpair.py index ec9f2ffae7..c79bcf34da 100644 --- a/smartsim/launchable/mpmdpair.py +++ b/smartsim/launchable/mpmdpair.py @@ -26,6 +26,7 @@ from smartsim.entity.entity import SmartSimEntity from smartsim.settings.base import RunSettings +import copy class MPMDPair: @@ -34,5 +35,5 @@ class MPMDPair: def __init__( self, entity: SmartSimEntity, launch_settings: RunSettings ): # TODO: rename to LaunchSettings - self.entity = entity - self.launch_settings = launch_settings + self.entity = copy.deepcopy(entity) + self.launch_settings = copy.deepcopy(launch_settings) diff --git a/tests/temp_tests/test_colocatedJobGroup.py b/tests/temp_tests/test_colocatedJobGroup.py index 80a50e5ca7..e081c8ce51 100644 --- a/tests/temp_tests/test_colocatedJobGroup.py +++ b/tests/temp_tests/test_colocatedJobGroup.py @@ -1,28 +1,35 @@ -from smartsim.jobgrouphold.colocatedJobGroup import ColocatedJobGroup, BaseJob +from smartsim.launchable.colocatedJobGroup import ColocatedJobGroup +from smartsim.launchable.basejob import BaseJob +from smartsim.launchable.job import Job +from smartsim.entity.model import Application +# TODO replace with LaunchSettings +class RunSettings: pass + +app_1 = Application("app_1", "python",RunSettings()) +app_2 = Application("app_2", "python",RunSettings()) +app_3 = Application("app_3", "python",RunSettings()) def test_create_ColocatedJobGroup(): job_1 = BaseJob() job_group = ColocatedJobGroup([job_1]) assert len(job_group) == 1 -# compare job names when Job class is up, handleful of other atts, not reused elsewhere -# cannot test setitem until Job is implemented since there is no comparison bc of the deep copy -# def test_getitem_ColocatedJobGroup(): -# job_1 = BaseJob() -# job_2 = BaseJob() -# job_group = ColocatedJobGroup([job_1,job_2]) -# get_value = job_group[0] -# assert get_value == job_1 +def test_getitem_ColocatedJobGroup(): + job_1 = Job(app_1,RunSettings()) + job_2 = Job(app_2,RunSettings()) + job_group = ColocatedJobGroup([job_1,job_2]) + get_value = job_group[0].entity.name + assert get_value == job_1.entity.name -# cannot test setitem until Job is implemented since there is no comparison bc of the deep copy -# def test_setitem_JobGroup(): -# job_1 = BaseJob() -# job_2 = BaseJob() -# job_group = JobGroup([job_1,job_2]) -# job_3 = BaseJob() -# job_group[1] = job_3 -# get_value = job_group[1] -# assert get_value == job_3 +def test_setitem_JobGroup(): + job_1 = Job(app_1,RunSettings()) + job_2 = Job(app_2,RunSettings()) + job_group = ColocatedJobGroup([job_1,job_2]) + job_3 = Job(app_3,RunSettings()) + job_group[1] = job_3 + assert len(job_group) == 2 + get_value = job_group[1].entity.name + assert get_value == job_3.entity.name def test_delitem_ColocatedJobGroup(): job_1 = BaseJob() diff --git a/tests/temp_tests/test_jobGroup.py b/tests/temp_tests/test_jobGroup.py index 998f8b3ef2..6fc3d97036 100644 --- a/tests/temp_tests/test_jobGroup.py +++ b/tests/temp_tests/test_jobGroup.py @@ -1,28 +1,35 @@ -from smartsim.jobgrouphold.baseJobGroup import BaseJobGroup -from smartsim.jobgrouphold.jobGroup import JobGroup, BaseJob +from smartsim.launchable.jobGroup import JobGroup +from smartsim.launchable.basejob import BaseJob +from smartsim.launchable.job import Job +from smartsim.entity.model import Application +# TODO replace with LaunchSettings +class RunSettings: pass +app_1 = Application("app_1", "python",RunSettings()) +app_2 = Application("app_2", "python",RunSettings()) +app_3 = Application("app_3", "python",RunSettings()) + def test_create_JobGroup(): job_1 = BaseJob() job_group = JobGroup([job_1]) assert len(job_group) == 1 -# cannot test setitem until Job is implemented since there is no comparison bc of the deep copy -# def test_getitem_JobGroup(): -# job_1 = BaseJob() -# job_2 = BaseJob() -# job_group = JobGroup([job_1,job_2]) -# get_value = job_group[0] -# assert get_value == job_1 +def test_getitem_JobGroup(): + job_1 = Job(app_1,RunSettings()) + job_2 = Job(app_2,RunSettings()) + job_group = JobGroup([job_1,job_2]) + get_value = job_group[0].entity.name + assert get_value == job_1.entity.name -# cannot test setitem until Job is implemented since there is no comparison bc of the deep copy -# def test_setitem_JobGroup(): -# job_1 = BaseJob() -# job_2 = BaseJob() -# job_group = JobGroup([job_1,job_2]) -# job_3 = BaseJob() -# job_group[1] = job_3 -# get_value = job_group[1] -# assert get_value == job_3 +def test_setitem_JobGroup(): + job_1 = Job(app_1,RunSettings()) + job_2 = Job(app_2,RunSettings()) + job_group = JobGroup([job_1,job_2]) + job_3 = Job(app_3,RunSettings()) + job_group[1] = job_3 + assert len(job_group) == 2 + get_value = job_group[1] + assert get_value.entity.name == job_3.entity.name def test_delitem_JobGroup(): job_1 = BaseJob() diff --git a/tests/_legacy/test_launchable.py b/tests/temp_tests/test_launchable.py similarity index 64% rename from tests/_legacy/test_launchable.py rename to tests/temp_tests/test_launchable.py index 24648e80d0..2fcaa7d065 100644 --- a/tests/_legacy/test_launchable.py +++ b/tests/temp_tests/test_launchable.py @@ -48,31 +48,29 @@ def test_launchable_init(): def test_job_init(): - entity = SmartSimEntity("test_name", None, None) - launch_settings = RunSettings("echo", ["spam", "eggs"]) - job = Job(entity, launch_settings) + entity = Application("test_name", run_settings=RunSettings(), exe="echo", exe_args=["spam", "eggs"]) + job = Job(entity, RunSettings()) assert isinstance(job, Job) assert job.entity.name == "test_name" - assert "echo" in job.launch_settings.exe[0] - assert "spam" in job.launch_settings.exe_args - assert "eggs" in job.launch_settings.exe_args + assert "echo" in job.entity.exe[0] + assert "spam" in job.entity.exe_args + assert "eggs" in job.entity.exe_args def test_job_init_deepcopy(): - entity = SmartSimEntity("test_name", None, None) - launch_settings = RunSettings("echo", ["spam", "eggs"]) - job = Job(entity, launch_settings) - RunSettings("echo", ["hello", "world"]) - assert "hello" not in job.launch_settings.exe_args + entity = Application("test_name", run_settings=RunSettings(), exe="echo", exe_args=["spam", "eggs"]) + settings = RunSettings(run_args="test") + job = Job(entity, settings) + settings.run_args = "change" + assert "change" not in job.launch_settings.run_args def test_add_mpmd_pair(): - entity = SmartSimEntity("test_name", None, None) - launch_settings = RunSettings("echo", ["spam", "eggs"]) + entity = SmartSimEntity("test_name", "python", RunSettings()) mpmd_job = MPMDJob() - mpmd_job.add_mpmd_pair(entity, launch_settings) - mpmd_pair = MPMDPair(entity, launch_settings) + mpmd_job.add_mpmd_pair(entity, RunSettings()) + mpmd_pair = MPMDPair(entity, RunSettings()) assert len(mpmd_job.mpmd_pairs) == 1 assert str(mpmd_pair.entity) == str(mpmd_job.mpmd_pairs[0].entity) @@ -81,32 +79,31 @@ def test_add_mpmd_pair(): def test_mpmdpair_init(): """Test the creation of an MPMDPair""" - entity = SmartSimEntity("test_name", None, None) - launch_settings = RunSettings("echo", ["spam", "eggs"]) - mpmd_pair = MPMDPair(entity, launch_settings) + entity = Application("test_name", "echo", exe_args=["spam", "eggs"], run_settings=RunSettings()) + mpmd_pair = MPMDPair(entity, RunSettings()) assert isinstance(mpmd_pair, MPMDPair) assert mpmd_pair.entity.name == "test_name" - assert "echo" in mpmd_pair.launch_settings.exe[0] - assert "spam" in mpmd_pair.launch_settings.exe_args - assert "eggs" in mpmd_pair.launch_settings.exe_args + assert "echo" in mpmd_pair.entity.exe[0] + assert "spam" in mpmd_pair.entity.exe_args + assert "eggs" in mpmd_pair.entity.exe_args def test_mpmdpair_init_deepcopy(): """Test the creation of an MPMDPair""" - entity = SmartSimEntity("test_name", None, None) - launch_settings = RunSettings("echo", ["spam", "eggs"]) - mpmd_pair = MPMDPair(entity, launch_settings) - RunSettings("echo", ["hello", "world"]) - assert "hello" not in mpmd_pair.launch_settings.exe_args + entity = Application("test_name", "echo", run_settings=RunSettings(),exe_args=["spam", "eggs"]) + settings = RunSettings(run_args="test") + mpmd_pair = MPMDPair(entity, settings) + settings.run_args = "change" + assert "change" not in mpmd_pair.launch_settings.run_args def test_check_launcher(): """Test that mpmd pairs that have the same launcher type can be added to an MPMD Job""" - entity1 = SmartSimEntity("entity1", None, None) - launch_settings1 = RunSettings("echo", ["hello", "world"], run_command="mpirun") - entity2 = SmartSimEntity("entity2", None, None) - launch_settings2 = RunSettings("echo", ["spam", "eggs"], run_command="mpirun") + entity1 = Application("entity1", "echo", exe_args=["hello", "world"], run_settings=RunSettings()) + launch_settings1 = RunSettings() + entity2 = Application("entity2", "echo", exe_args=["hello", "world"], run_settings=RunSettings()) + launch_settings2 = RunSettings() mpmd_pairs = [] pair1 = MPMDPair(entity1, launch_settings1) @@ -115,19 +112,19 @@ def test_check_launcher(): # Add a second mpmd pair to the mpmd job mpmd_job.add_mpmd_pair(entity2, launch_settings2) - assert str(mpmd_job.mpmd_pairs[0].entity) == "entity1" - assert str(mpmd_job.mpmd_pairs[1].entity) == "entity2" + assert str(mpmd_job.mpmd_pairs[0].entity.name) == "entity1" + assert str(mpmd_job.mpmd_pairs[1].entity.name) == "entity2" def test_add_mpmd_pair_check_launcher_error(): """Test that an error is raised when a pairs is added to an mpmd job using add_mpmd_pair that does not have the same launcher type""" mpmd_pairs = [] - entity1 = SmartSimEntity("entity1", None, None) - launch_settings1 = RunSettings("echo", ["hello", "world"], run_command="srun") + entity1 = SmartSimEntity("entity1", "python", RunSettings()) + launch_settings1 = RunSettings(run_command="srun") - entity2 = SmartSimEntity("entity2", None, None) - launch_settings2 = RunSettings("echo", ["spam", "eggs"], run_command="mpirun") + entity2 = SmartSimEntity("entity2", "python", RunSettings()) + launch_settings2 = RunSettings(run_command="mpirun") pair1 = MPMDPair(entity1, launch_settings1) mpmd_pairs.append(pair1) @@ -141,11 +138,11 @@ def test_add_mpmd_pair_check_launcher_error(): def test_add_mpmd_pair_check_entity(): """Test that mpmd pairs that have the same entity type can be added to an MPMD Job""" mpmd_pairs = [] - entity1 = Application("entity1", None, None) - launch_settings1 = RunSettings("echo", ["hello", "world"], run_command="srun") + entity1 = Application("entity1", "python", RunSettings()) + launch_settings1 = RunSettings(run_command="srun") - entity2 = Application("entity2", None, None) - launch_settings2 = RunSettings("echo", ["spam", "eggs"], run_command="srun") + entity2 = Application("entity2", "python", RunSettings()) + launch_settings2 = RunSettings(run_command="srun") pair1 = MPMDPair(entity1, launch_settings1) mpmd_pairs.append(pair1) @@ -161,11 +158,11 @@ def test_add_mpmd_pair_check_entity_error(): """Test that an error is raised when a pairs is added to an mpmd job using add_mpmd_pair that does not have the same entity type""" mpmd_pairs = [] - entity1 = Application("entity1", None, None) - launch_settings1 = RunSettings("echo", ["hello", "world"], run_command="srun") + entity1 = Application("entity1", "python", RunSettings()) + launch_settings1 = RunSettings(run_command="srun") entity2 = FeatureStore("entity2") - launch_settings2 = RunSettings("echo", ["spam", "eggs"], run_command="srun") + launch_settings2 = RunSettings(run_command="srun") pair1 = MPMDPair(entity1, launch_settings1) mpmd_pairs.append(pair1) @@ -181,11 +178,11 @@ def test_create_mpmdjob_invalid_mpmdpairs(): does not have the same launcher type""" mpmd_pairs = [] - entity1 = Application("entity1", None, None) - launch_settings1 = RunSettings("echo", ["hello", "world"], run_command="srun") + entity1 = Application("entity1", "python", RunSettings()) + launch_settings1 = RunSettings(run_command="srun") - entity1 = Application("entity1", None, None) - launch_settings2 = RunSettings("echo", ["spam", "eggs"], run_command="mpirun") + entity1 = Application("entity1", "python", RunSettings()) + launch_settings2 = RunSettings(run_command="mpirun") pair1 = MPMDPair(entity1, launch_settings1) pair2 = MPMDPair(entity1, launch_settings2) @@ -202,10 +199,10 @@ def test_create_mpmdjob_valid_mpmdpairs(): """Test that all pairs have the same entity type is enforced when creating an MPMDJob""" mpmd_pairs = [] - entity1 = Application("entity1", None, None) - launch_settings1 = RunSettings("echo", ["hello", "world"], run_command="srun") - entity1 = Application("entity1", None, None) - launch_settings2 = RunSettings("echo", ["spam", "eggs"], run_command="srun") + entity1 = Application("entity1", "python", RunSettings()) + launch_settings1 = RunSettings(run_command="srun") + entity1 = Application("entity1", "python", RunSettings()) + launch_settings2 = RunSettings(run_command="srun") pair1 = MPMDPair(entity1, launch_settings1) pair2 = MPMDPair(entity1, launch_settings2) From 1a391efeee4d09aa4b00b8b1d413b831070f1a4c Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Tue, 11 Jun 2024 16:44:38 -0500 Subject: [PATCH 11/13] TODO --- tests/temp_tests/test_launchable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/temp_tests/test_launchable.py b/tests/temp_tests/test_launchable.py index 2fcaa7d065..738634ff04 100644 --- a/tests/temp_tests/test_launchable.py +++ b/tests/temp_tests/test_launchable.py @@ -35,7 +35,7 @@ from smartsim.launchable.mpmdjob import MPMDJob from smartsim.launchable.mpmdpair import MPMDPair from smartsim.settings.base import RunSettings - +# TODO replace with LaunchSettings def test_smartsimobject_init(): ss_object = SmartSimObject() From 0eea3b583824949695b75a5ce0396ab9dcf2538b Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Tue, 11 Jun 2024 17:03:12 -0500 Subject: [PATCH 12/13] chnages --- smartsim/launchable/__init__.py | 6 +-- smartsim/launchable/baseJobGroup.py | 31 +++++++------- smartsim/launchable/colocatedJobGroup.py | 11 +++-- smartsim/launchable/jobGroup.py | 11 +++-- smartsim/launchable/mpmdpair.py | 3 +- tests/temp_tests/test_colocatedJobGroup.py | 46 +++++++++++++-------- tests/temp_tests/test_jobGroup.py | 48 +++++++++++++--------- tests/temp_tests/test_launchable.py | 26 +++++++++--- 8 files changed, 110 insertions(+), 72 deletions(-) diff --git a/smartsim/launchable/__init__.py b/smartsim/launchable/__init__.py index 399084ed51..961032bf28 100644 --- a/smartsim/launchable/__init__.py +++ b/smartsim/launchable/__init__.py @@ -25,10 +25,10 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from .basejob import BaseJob +from .baseJobGroup import BaseJobGroup +from .colocatedJobGroup import ColocatedJobGroup from .job import Job +from .jobGroup import JobGroup from .launchable import Launchable from .mpmdjob import MPMDJob from .mpmdpair import MPMDPair -from .baseJobGroup import BaseJobGroup -from .jobGroup import JobGroup -from .colocatedJobGroup import ColocatedJobGroup diff --git a/smartsim/launchable/baseJobGroup.py b/smartsim/launchable/baseJobGroup.py index 3d727bd14a..cb9d7772db 100644 --- a/smartsim/launchable/baseJobGroup.py +++ b/smartsim/launchable/baseJobGroup.py @@ -3,13 +3,16 @@ from collections.abc import MutableSequence from copy import deepcopy -from .basejob import BaseJob from smartsim.launchable.launchable import Launchable +from .basejob import BaseJob + + class BaseJobGroup(Launchable, MutableSequence): - """Highest level ABC of a group of jobs that can be + """Highest level ABC of a group of jobs that can be launched """ + def __init__(self) -> None: super().__init__() @@ -21,7 +24,7 @@ def jobs(self) -> t.List[BaseJob]: instance of the BaseJobGroup abstract class. """ pass - + def insert(self, idx: int, value: BaseJob) -> None: """Inserts the given value at the specified index (idx) in the list of jobs. If the index is out of bounds, the method @@ -30,32 +33,26 @@ def insert(self, idx: int, value: BaseJob) -> None: self.jobs.insert(idx, value) def __iter__(self) -> t.Iterator[BaseJob]: - """Allows iteration over the jobs in the collection. - """ + """Allows iteration over the jobs in the collection.""" return iter(self.jobs) - + def __getitem__(self, idx: int) -> BaseJob: - """Retrieves the job at the specified index (idx). - """ + """Retrieves the job at the specified index (idx).""" return self.jobs[idx] def __setitem__(self, idx: int, value: BaseJob) -> None: - """Sets the job at the specified index (idx) to the given value. - """ + """Sets the job at the specified index (idx) to the given value.""" self.jobs[idx] = deepcopy(value) def __delitem__(self, idx: int) -> None: - """Deletes the job at the specified index (idx). - """ + """Deletes the job at the specified index (idx).""" del self.jobs[idx] def __len__(self) -> int: - """Returns the total number of jobs in the collection. - """ + """Returns the total number of jobs in the collection.""" return len(self.jobs) def __str__(self): # pragma: no-cover - """Returns a string representation of the collection of jobs. - """ + """Returns a string representation of the collection of jobs.""" string = "" - string += f"Jobs: {self.jobs}" \ No newline at end of file + string += f"Jobs: {self.jobs}" diff --git a/smartsim/launchable/colocatedJobGroup.py b/smartsim/launchable/colocatedJobGroup.py index 800cd4cfa2..e4a2d14720 100644 --- a/smartsim/launchable/colocatedJobGroup.py +++ b/smartsim/launchable/colocatedJobGroup.py @@ -1,13 +1,16 @@ import typing as t -from .baseJobGroup import BaseJobGroup -from .basejob import BaseJob from copy import deepcopy +from .basejob import BaseJob +from .baseJobGroup import BaseJobGroup + + class ColocatedJobGroup(BaseJobGroup): """A colocated job group holds references to multiple jobs that will be executed all at the same time when resources permit. Execution is blocked until resources are available. """ + def __init__( self, jobs: t.List[BaseJob], @@ -22,10 +25,10 @@ def jobs(self) -> t.List[BaseJob]: instance of the BaseJobGroup abstract class. """ return self._jobs - + def __str__(self): # pragma: no-cover """Returns a string representation of the collection of colocated job groups. """ string = "" - string += f"Colocated Jobs: {self.jobs}" \ No newline at end of file + string += f"Colocated Jobs: {self.jobs}" diff --git a/smartsim/launchable/jobGroup.py b/smartsim/launchable/jobGroup.py index 2ce9b2f9ca..b3bd82c530 100644 --- a/smartsim/launchable/jobGroup.py +++ b/smartsim/launchable/jobGroup.py @@ -1,13 +1,16 @@ import typing as t -from .baseJobGroup import BaseJobGroup -from .basejob import BaseJob from copy import deepcopy +from .basejob import BaseJob +from .baseJobGroup import BaseJobGroup + + class JobGroup(BaseJobGroup): """A job group holds references to multiple jobs that will be executed all at the same time when resources permit. Execution is blocked until resources are available. """ + def __init__( self, jobs: t.List[BaseJob], @@ -22,10 +25,10 @@ def jobs(self) -> t.List[BaseJob]: instance of the BaseJobGroup abstract class. """ return self._jobs - + def __str__(self): # pragma: no-cover """Returns a string representation of the collection of job groups. """ string = "" - string += f"Job Groups: {self.jobs}" \ No newline at end of file + string += f"Job Groups: {self.jobs}" diff --git a/smartsim/launchable/mpmdpair.py b/smartsim/launchable/mpmdpair.py index c79bcf34da..37b155cb11 100644 --- a/smartsim/launchable/mpmdpair.py +++ b/smartsim/launchable/mpmdpair.py @@ -24,9 +24,10 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import copy + from smartsim.entity.entity import SmartSimEntity from smartsim.settings.base import RunSettings -import copy class MPMDPair: diff --git a/tests/temp_tests/test_colocatedJobGroup.py b/tests/temp_tests/test_colocatedJobGroup.py index e081c8ce51..58dd66839c 100644 --- a/tests/temp_tests/test_colocatedJobGroup.py +++ b/tests/temp_tests/test_colocatedJobGroup.py @@ -1,55 +1,65 @@ -from smartsim.launchable.colocatedJobGroup import ColocatedJobGroup +from smartsim.entity.model import Application from smartsim.launchable.basejob import BaseJob +from smartsim.launchable.colocatedJobGroup import ColocatedJobGroup from smartsim.launchable.job import Job -from smartsim.entity.model import Application + + # TODO replace with LaunchSettings -class RunSettings: pass +class RunSettings: + pass + + +app_1 = Application("app_1", "python", RunSettings()) +app_2 = Application("app_2", "python", RunSettings()) +app_3 = Application("app_3", "python", RunSettings()) -app_1 = Application("app_1", "python",RunSettings()) -app_2 = Application("app_2", "python",RunSettings()) -app_3 = Application("app_3", "python",RunSettings()) def test_create_ColocatedJobGroup(): job_1 = BaseJob() job_group = ColocatedJobGroup([job_1]) assert len(job_group) == 1 + def test_getitem_ColocatedJobGroup(): - job_1 = Job(app_1,RunSettings()) - job_2 = Job(app_2,RunSettings()) - job_group = ColocatedJobGroup([job_1,job_2]) + job_1 = Job(app_1, RunSettings()) + job_2 = Job(app_2, RunSettings()) + job_group = ColocatedJobGroup([job_1, job_2]) get_value = job_group[0].entity.name assert get_value == job_1.entity.name + def test_setitem_JobGroup(): - job_1 = Job(app_1,RunSettings()) - job_2 = Job(app_2,RunSettings()) - job_group = ColocatedJobGroup([job_1,job_2]) - job_3 = Job(app_3,RunSettings()) + job_1 = Job(app_1, RunSettings()) + job_2 = Job(app_2, RunSettings()) + job_group = ColocatedJobGroup([job_1, job_2]) + job_3 = Job(app_3, RunSettings()) job_group[1] = job_3 assert len(job_group) == 2 get_value = job_group[1].entity.name assert get_value == job_3.entity.name + def test_delitem_ColocatedJobGroup(): job_1 = BaseJob() job_2 = BaseJob() - job_group = ColocatedJobGroup([job_1,job_2]) + job_group = ColocatedJobGroup([job_1, job_2]) assert len(job_group) == 2 - del(job_group[1]) + del job_group[1] assert len(job_group) == 1 + def test_len_ColocatedJobGroup(): job_1 = BaseJob() job_2 = BaseJob() - job_group = ColocatedJobGroup([job_1,job_2]) + job_group = ColocatedJobGroup([job_1, job_2]) assert len(job_group) == 2 + def test_insert_ColocatedJobGroup(): job_1 = BaseJob() job_2 = BaseJob() - job_group = ColocatedJobGroup([job_1,job_2]) + job_group = ColocatedJobGroup([job_1, job_2]) job_3 = BaseJob() job_group.insert(0, job_3) get_value = job_group[0] - assert get_value == job_3 \ No newline at end of file + assert get_value == job_3 diff --git a/tests/temp_tests/test_jobGroup.py b/tests/temp_tests/test_jobGroup.py index 6fc3d97036..cf8f5efe6e 100644 --- a/tests/temp_tests/test_jobGroup.py +++ b/tests/temp_tests/test_jobGroup.py @@ -1,55 +1,65 @@ -from smartsim.launchable.jobGroup import JobGroup +from smartsim.entity.model import Application from smartsim.launchable.basejob import BaseJob from smartsim.launchable.job import Job -from smartsim.entity.model import Application +from smartsim.launchable.jobGroup import JobGroup + + # TODO replace with LaunchSettings -class RunSettings: pass +class RunSettings: + pass + + +app_1 = Application("app_1", "python", RunSettings()) +app_2 = Application("app_2", "python", RunSettings()) +app_3 = Application("app_3", "python", RunSettings()) + -app_1 = Application("app_1", "python",RunSettings()) -app_2 = Application("app_2", "python",RunSettings()) -app_3 = Application("app_3", "python",RunSettings()) - def test_create_JobGroup(): job_1 = BaseJob() job_group = JobGroup([job_1]) assert len(job_group) == 1 + def test_getitem_JobGroup(): - job_1 = Job(app_1,RunSettings()) - job_2 = Job(app_2,RunSettings()) - job_group = JobGroup([job_1,job_2]) + job_1 = Job(app_1, RunSettings()) + job_2 = Job(app_2, RunSettings()) + job_group = JobGroup([job_1, job_2]) get_value = job_group[0].entity.name assert get_value == job_1.entity.name + def test_setitem_JobGroup(): - job_1 = Job(app_1,RunSettings()) - job_2 = Job(app_2,RunSettings()) - job_group = JobGroup([job_1,job_2]) - job_3 = Job(app_3,RunSettings()) + job_1 = Job(app_1, RunSettings()) + job_2 = Job(app_2, RunSettings()) + job_group = JobGroup([job_1, job_2]) + job_3 = Job(app_3, RunSettings()) job_group[1] = job_3 assert len(job_group) == 2 get_value = job_group[1] assert get_value.entity.name == job_3.entity.name + def test_delitem_JobGroup(): job_1 = BaseJob() job_2 = BaseJob() - job_group = JobGroup([job_1,job_2]) + job_group = JobGroup([job_1, job_2]) assert len(job_group) == 2 - del(job_group[1]) + del job_group[1] assert len(job_group) == 1 + def test_len_JobGroup(): job_1 = BaseJob() job_2 = BaseJob() - job_group = JobGroup([job_1,job_2]) + job_group = JobGroup([job_1, job_2]) assert len(job_group) == 2 + def test_insert_JobGroup(): job_1 = BaseJob() job_2 = BaseJob() - job_group = JobGroup([job_1,job_2]) + job_group = JobGroup([job_1, job_2]) job_3 = BaseJob() job_group.insert(0, job_3) get_value = job_group[0] - assert get_value == job_3 \ No newline at end of file + assert get_value == job_3 diff --git a/tests/temp_tests/test_launchable.py b/tests/temp_tests/test_launchable.py index 738634ff04..9d31ee5561 100644 --- a/tests/temp_tests/test_launchable.py +++ b/tests/temp_tests/test_launchable.py @@ -35,8 +35,10 @@ from smartsim.launchable.mpmdjob import MPMDJob from smartsim.launchable.mpmdpair import MPMDPair from smartsim.settings.base import RunSettings + # TODO replace with LaunchSettings + def test_smartsimobject_init(): ss_object = SmartSimObject() assert isinstance(ss_object, SmartSimObject) @@ -48,7 +50,9 @@ def test_launchable_init(): def test_job_init(): - entity = Application("test_name", run_settings=RunSettings(), exe="echo", exe_args=["spam", "eggs"]) + entity = Application( + "test_name", run_settings=RunSettings(), exe="echo", exe_args=["spam", "eggs"] + ) job = Job(entity, RunSettings()) assert isinstance(job, Job) assert job.entity.name == "test_name" @@ -58,7 +62,9 @@ def test_job_init(): def test_job_init_deepcopy(): - entity = Application("test_name", run_settings=RunSettings(), exe="echo", exe_args=["spam", "eggs"]) + entity = Application( + "test_name", run_settings=RunSettings(), exe="echo", exe_args=["spam", "eggs"] + ) settings = RunSettings(run_args="test") job = Job(entity, settings) settings.run_args = "change" @@ -79,7 +85,9 @@ def test_add_mpmd_pair(): def test_mpmdpair_init(): """Test the creation of an MPMDPair""" - entity = Application("test_name", "echo", exe_args=["spam", "eggs"], run_settings=RunSettings()) + entity = Application( + "test_name", "echo", exe_args=["spam", "eggs"], run_settings=RunSettings() + ) mpmd_pair = MPMDPair(entity, RunSettings()) assert isinstance(mpmd_pair, MPMDPair) assert mpmd_pair.entity.name == "test_name" @@ -90,7 +98,9 @@ def test_mpmdpair_init(): def test_mpmdpair_init_deepcopy(): """Test the creation of an MPMDPair""" - entity = Application("test_name", "echo", run_settings=RunSettings(),exe_args=["spam", "eggs"]) + entity = Application( + "test_name", "echo", run_settings=RunSettings(), exe_args=["spam", "eggs"] + ) settings = RunSettings(run_args="test") mpmd_pair = MPMDPair(entity, settings) settings.run_args = "change" @@ -100,9 +110,13 @@ def test_mpmdpair_init_deepcopy(): def test_check_launcher(): """Test that mpmd pairs that have the same launcher type can be added to an MPMD Job""" - entity1 = Application("entity1", "echo", exe_args=["hello", "world"], run_settings=RunSettings()) + entity1 = Application( + "entity1", "echo", exe_args=["hello", "world"], run_settings=RunSettings() + ) launch_settings1 = RunSettings() - entity2 = Application("entity2", "echo", exe_args=["hello", "world"], run_settings=RunSettings()) + entity2 = Application( + "entity2", "echo", exe_args=["hello", "world"], run_settings=RunSettings() + ) launch_settings2 = RunSettings() mpmd_pairs = [] From 74928c70f9453a6b2909d5cc6831263094b91706 Mon Sep 17 00:00:00 2001 From: Amanda Richardson Date: Tue, 11 Jun 2024 17:13:56 -0500 Subject: [PATCH 13/13] tehe --- tests/temp_tests/test_colocatedJobGroup.py | 12 ++++-------- tests/temp_tests/test_jobGroup.py | 6 +----- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/tests/temp_tests/test_colocatedJobGroup.py b/tests/temp_tests/test_colocatedJobGroup.py index 58dd66839c..3bd49dad74 100644 --- a/tests/temp_tests/test_colocatedJobGroup.py +++ b/tests/temp_tests/test_colocatedJobGroup.py @@ -2,16 +2,12 @@ from smartsim.launchable.basejob import BaseJob from smartsim.launchable.colocatedJobGroup import ColocatedJobGroup from smartsim.launchable.job import Job - +from smartsim.settings.base import RunSettings # TODO replace with LaunchSettings -class RunSettings: - pass - - -app_1 = Application("app_1", "python", RunSettings()) -app_2 = Application("app_2", "python", RunSettings()) -app_3 = Application("app_3", "python", RunSettings()) +app_1 = Application("app_1", "python", run_settings=RunSettings()) +app_2 = Application("app_2", "python", run_settings=RunSettings()) +app_3 = Application("app_3", "python", run_settings=RunSettings()) def test_create_ColocatedJobGroup(): diff --git a/tests/temp_tests/test_jobGroup.py b/tests/temp_tests/test_jobGroup.py index cf8f5efe6e..a5dd96d75f 100644 --- a/tests/temp_tests/test_jobGroup.py +++ b/tests/temp_tests/test_jobGroup.py @@ -2,13 +2,9 @@ from smartsim.launchable.basejob import BaseJob from smartsim.launchable.job import Job from smartsim.launchable.jobGroup import JobGroup - +from smartsim.settings.base import RunSettings # TODO replace with LaunchSettings -class RunSettings: - pass - - app_1 = Application("app_1", "python", RunSettings()) app_2 = Application("app_2", "python", RunSettings()) app_3 = Application("app_3", "python", RunSettings())