Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime value checking for LaunchSettings and BatchSettings #740

Open
wants to merge 5 commits into
base: v1.0
Choose a base branch
from

Conversation

juliaputko
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 15.38462% with 11 lines in your changes missing coverage. Please review.

Project coverage is 37.90%. Comparing base (cce16e6) to head (acd56da).
Report is 19 commits behind head on smartsim-refactor.

Files with missing lines Patch % Lines
smartsim/settings/batch_settings.py 0.00% 5 Missing ⚠️
smartsim/settings/launch_settings.py 40.00% 3 Missing ⚠️
smartsim/settings/arguments/launch/dragon.py 0.00% 1 Missing ⚠️
smartsim/settings/arguments/launch/local.py 0.00% 1 Missing ⚠️
smartsim/settings/arguments/launch/mpi.py 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                  Coverage Diff                  @@
##           smartsim-refactor     #740      +/-   ##
=====================================================
- Coverage              40.45%   37.90%   -2.56%     
=====================================================
  Files                    110      109       -1     
  Lines                   7326     6583     -743     
=====================================================
- Hits                    2964     2495     -469     
+ Misses                  4362     4088     -274     
Files with missing lines Coverage Δ
smartsim/settings/arguments/launch/dragon.py 54.83% <0.00%> (-25.81%) ⬇️
smartsim/settings/arguments/launch/local.py 50.00% <0.00%> (-37.50%) ⬇️
smartsim/settings/arguments/launch/mpi.py 43.02% <0.00%> (-52.33%) ⬇️
smartsim/settings/launch_settings.py 64.93% <40.00%> (ø)
smartsim/settings/batch_settings.py 46.42% <0.00%> (ø)

... and 28 files with indirect coverage changes

Copy link
Member

@MattToast MattToast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great so far! Just some initial feedback for you to take a look at while we expand this out into {Batch,Launch}Arguments classes as well!

smartsim/settings/batch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/batch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/batch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/launch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/launch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/launch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/launch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/launch_settings.py Outdated Show resolved Hide resolved
tests/temp_tests/test_settings/test_batchSettings.py Outdated Show resolved Hide resolved
tests/temp_tests/test_settings/test_launchSettings.py Outdated Show resolved Hide resolved
Copy link
Contributor

@amandarichardsonn amandarichardsonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work as always! One larger suggestion is to move the setter testing to the associated launcher and scheduler test files!

smartsim/settings/arguments/batch/lsf.py Show resolved Hide resolved
smartsim/settings/arguments/batch/pbs.py Show resolved Hide resolved
smartsim/settings/arguments/batch/pbs.py Outdated Show resolved Hide resolved
smartsim/settings/arguments/batch/pbs.py Outdated Show resolved Hide resolved
smartsim/settings/arguments/batch/slurm.py Show resolved Hide resolved
smartsim/settings/arguments/batch/slurm.py Show resolved Hide resolved
smartsim/settings/arguments/batch/slurm.py Show resolved Hide resolved
tests/temp_tests/test_settings/test_batchSettings.py Outdated Show resolved Hide resolved
Copy link
Member

@MattToast MattToast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of small nits, but otherwise looks about ready to go!!

smartsim/settings/arguments/batch/pbs.py Outdated Show resolved Hide resolved
smartsim/settings/batch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/batch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/launch_settings.py Outdated Show resolved Hide resolved
smartsim/settings/launch_settings.py Outdated Show resolved Hide resolved
tests/temp_tests/test_settings/test_batchSettings.py Outdated Show resolved Hide resolved
tests/temp_tests/test_settings/test_launchSettings.py Outdated Show resolved Hide resolved
tests/temp_tests/test_settings/test_launchSettings.py Outdated Show resolved Hide resolved
Copy link
Contributor

@amandarichardsonn amandarichardsonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments! One larger comment is that the arguments/launch modules haven't been given runtime value checks, consider adding to this PR! Unless this is only the batch PR

smartsim/settings/arguments/batch/lsf.py Show resolved Hide resolved
smartsim/settings/arguments/batch/pbs.py Show resolved Hide resolved
smartsim/settings/arguments/batch/slurm.py Show resolved Hide resolved
@@ -126,6 +126,18 @@ def __init__(
"""The launcher type"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the modules arguments/launch/... there is a spelling error where Overwriting is written as Overwritting - could you fix this in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant find this error

@@ -126,6 +126,18 @@ def __init__(
"""The launcher type"""
except ValueError:
raise ValueError(f"Invalid launcher type: {launcher}")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that there hasnt been Value Checking added to arguments/launch/ modules, but all Value checking has been added to batch modules, is launch_setting value checking also going into this PR?

def test_batch_arguments_type_set_smts():
bs = BatchSettings(batch_scheduler="lsf", env_vars={"ENV": "VAR"})
with pytest.raises(TypeError, match="smts argument was not of type int"):
bs.batch_args.set_smts("invalid")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using pytest.parameterize (I spelt it so wrong) but tests look great!

@juliaputko juliaputko changed the base branch from smartsim-refactor to v1.0 October 31, 2024 23:17
Copy link
Member

@MattToast MattToast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question to Amanda about whether or not we want to cover smartsim.settings.arguments.* in this PR as well, and a couple of small nits, but otherwise looks about ready to go on my end!

Comment on lines +193 to +194
if key in self._batch_args and key != self._batch_args[key]:
logger.warning(f"Overwriting argument '{key}' with value '{value}'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just sanity checking, should this be

Suggested change
if key in self._batch_args and key != self._batch_args[key]:
logger.warning(f"Overwriting argument '{key}' with value '{value}'")
if key in self._batch_args and value != self._batch_args[key]:
logger.warning(f"Overwriting argument '{key}' with value '{value}'")

?

Comment on lines +216 to +217
if key in self._batch_args and key != self._batch_args[key]:
logger.warning(f"Overwriting argument '{key}' with value '{value}'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here

Suggested change
if key in self._batch_args and key != self._batch_args[key]:
logger.warning(f"Overwriting argument '{key}' with value '{value}'")
if key in self._batch_args and value != self._batch_args[key]:
logger.warning(f"Overwriting argument '{key}' with value '{value}'")

?

Comment on lines +186 to +187
if key in self._batch_args and key != self._batch_args[key]:
logger.warning(f"Overwriting argument '{key}' with value '{value}'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more here

Suggested change
if key in self._batch_args and key != self._batch_args[key]:
logger.warning(f"Overwriting argument '{key}' with value '{value}'")
if key in self._batch_args and value != self._batch_args[key]:
logger.warning(f"Overwriting argument '{key}' with value '{value}'")

?

@@ -224,5 +224,5 @@ def set(self, key: str, value: str | None) -> None:
)
return
if key in self._launch_args and key != self._launch_args[key]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not technically part of this PR, but I think this should also read

Suggested change
if key in self._launch_args and key != self._launch_args[key]:
if key in self._launch_args and value != self._launch_args[key]:

?

@@ -71,7 +71,7 @@ def set(self, key: str, value: str | None) -> None:
"""
set_check_input(key, value)
if key in self._launch_args and key != self._launch_args[key]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also somehow got past a previous review

Suggested change
if key in self._launch_args and key != self._launch_args[key]:
if key in self._launch_args and value != self._launch_args[key]:

?

@@ -349,5 +351,5 @@ def set(self, key: str, value: str | None) -> None:
)
return
if key in self._launch_args and key != self._launch_args[key]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! I lied!! Last one for real

Suggested change
if key in self._launch_args and key != self._launch_args[key]:
if key in self._launch_args and value != self._launch_args[key]:

@@ -140,6 +152,16 @@ def env_vars(self) -> StringArgument:
@env_vars.setter
def env_vars(self, value: t.Dict[str, str | None]) -> None:
"""Set the environment variables."""

if not (
isinstance(value, t.Dict)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: for runtime checks (and static checks with python>=3.9), it is generally preferred to use dict over t.Dict

Suggested change
isinstance(value, t.Dict)
isinstance(value, dict)


if launch_args is not None:
if not (
isinstance(launch_args, t.Dict)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto pedantic "dict v t.Dict" nit

Suggested change
isinstance(launch_args, t.Dict)
isinstance(launch_args, dict)

Comment on lines +158 to +163
and all(
isinstance(key, str) and isinstance(val, (str, type(None)))
for key, val in value.items()
)
):
raise TypeError("env_vars argument was not of type dict of str and str")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: runtime check takes a dict[str, str | None], but the error message claims to only take a dict[str, str]

Suggested change
and all(
isinstance(key, str) and isinstance(val, (str, type(None)))
for key, val in value.items()
)
):
raise TypeError("env_vars argument was not of type dict of str and str")
and all(
isinstance(key, str) and isinstance(val, (str, type(None)))
for key, val in value.items()
)
):
raise TypeError("env_vars argument was not of type dict of str and str or None")

Comment on lines +182 to +187
and all(
isinstance(key, str) and isinstance(val, (str, type(None)))
for key, val in value.items()
)
):
raise TypeError("env_vars argument was not of type dict of str and str")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto dict[str, str | None] vs dict[str, str] discrepancy

Suggested change
and all(
isinstance(key, str) and isinstance(val, (str, type(None)))
for key, val in value.items()
)
):
raise TypeError("env_vars argument was not of type dict of str and str")
and all(
isinstance(key, str) and isinstance(val, (str, type(None)))
for key, val in value.items()
)
):
raise TypeError("env_vars argument was not of type dict of str and str or None")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants