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

Ensemble.files refactor #746

Open
wants to merge 45 commits into
base: smartsim-refactor
Choose a base branch
from

Conversation

amandarichardsonn
Copy link
Contributor

@amandarichardsonn amandarichardsonn commented Oct 15, 2024

Attaching files to an Application and Ensemble has been refactored.

There is now two operations files, an operations.py file that holds the tools to attach files to an Application and an ensemble_operations.py file that holds the tools to attach files to an Ensemble. These two operation files are covered in individual test files: test_operations.py and test_ensemble_operations.py.

Additionally, building the file operation commands in the Generator has been refactored to support the removal of EntityFiles and replacement of the operations.FileSysOpSet. Tests for generator.py have been updated in test_generator.py.

Additionally, the function Ensemble._create_applications has been reworked to support the new Ensemble.files type.

Files to investigate:
smartsim/generation/operations/ensemble_operations.py
smartsim/generation/operations/operations.py
smartsim/generation/operations/utils/helpers.py
smartsim/builders/ensemble.py
smartsim/entity/application.py

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files

Impacted file tree graph

@@                  Coverage Diff                  @@
##           smartsim-refactor     #746      +/-   ##
=====================================================
+ Coverage              40.45%   47.79%   +7.33%     
=====================================================
  Files                    110      109       -1     
  Lines                   7326     6576     -750     
=====================================================
+ Hits                    2964     3143     +179     
+ Misses                  4362     3433     -929     
Files with missing lines Coverage Δ
..._core/generation/operations/ensemble_operations.py 100.00% <100.00%> (ø)
smartsim/builders/ensemble.py 99.15% <100.00%> (ø)
smartsim/entity/application.py 90.00% <ø> (ø)

... and 11 files with indirect coverage changes

@amandarichardsonn
Copy link
Contributor Author

amandarichardsonn commented Oct 15, 2024

Question for @juliaputko ! In application.py you placed the TODO about 2 months ago in the remove dead attrs in application PR, is this safe to remove now?

# TODO: Remove this supression when we strip fileds/functionality
#       (run-settings/batch_settings/params_as_args/etc)!
# pylint: disable-next=too-many-public-methods

@amandarichardsonn amandarichardsonn marked this pull request as draft October 15, 2024 23:12
@amandarichardsonn amandarichardsonn changed the title Ensemble File refactor Ensemble.files refactor Oct 16, 2024
@amandarichardsonn amandarichardsonn marked this pull request as ready for review October 16, 2024 22:22
Copy link
Contributor

@juliaputko juliaputko left a comment

Choose a reason for hiding this comment

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

lookin great! You can also add a '''match="error message"''' to pytest to make sure you are failing on the right valueerror/type error that you are expecting. Up to you!

:param tag: Tag to use for find and replacement
"""
self.operations.append(
EnsembleConfigureOperation(src, file_parameters, dest, tag)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we change the order of these so that it matches the configure method?

Copy link
Contributor

Choose a reason for hiding this comment

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

also I dont know if file_parameters is the best name for what is going in? This is a mapping of the items that need to be found and replaced right?

@@ -424,8 +431,8 @@ def build_jobs(self, settings: LaunchSettings) -> tuple[Job, ...]:
:raises TypeError: if the ids argument is not type LaunchSettings
:raises ValueError: if the LaunchSettings provided are empty
"""
if not isinstance(settings, LaunchSettings):
raise TypeError("ids argument was not of type LaunchSettings")
# if not isinstance(settings, LaunchSettings):
Copy link
Contributor

Choose a reason for hiding this comment

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

remove commented lines?


pytestmark = pytest.mark.group_a

# TODO missing test for _filter
Copy link
Contributor

Choose a reason for hiding this comment

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

address todo?

Copy link
Contributor

@ankona ankona left a comment

Choose a reason for hiding this comment

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

Looks good. As an outsider to the core refactor, I went through and focused on the docstrings and how clear they were to me. Added some suggestions that may/may not be included based on your opinions.



class EnsembleCopyOperation(EnsembleGenerationProtocol):
"""Ensemble Copy Operation"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider describing the functionality.

"""
A file generation operation used to specify parameters
for copying a file into a location accessible to the Ensemble.
"""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

better description than my three words eep! will change

"""
check_src_and_dest_path(src, dest)
self.src = src
"""Path to source"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider being explicit Path to the file that will be copied

def __init__(
self, src: pathlib.Path, dest: t.Optional[pathlib.Path] = None
) -> None:
"""Initialize a EnsembleCopyOperation object
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the result if the destination path is not supplied. Should this behavior be specified in this docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes I will specify

"""Initialize a EnsembleSymlinkOperation object

:param src: Path to source
:param dest: Path to destination
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the result if the destination path is not supplied. Should this behavior be specified in this docstring?

"""
check_src_and_dest_path(src, dest)
self.src = src
"""Path to source"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider being explicit: Path to the file that will be symlink'ed

class Ensemble(entity.CompoundEntity):
"""An Ensemble is a builder class that parameterizes the creation of multiple
"""An Ensemble is a builder class to parameterize the creation of multiple
Copy link
Contributor

Choose a reason for hiding this comment

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

omit "an ensemble..."

Suggested change
"""An Ensemble is a builder class to parameterize the creation of multiple
"""A builder class used to create parameterized versions of an Application.

Copy link
Contributor

Choose a reason for hiding this comment

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

if we say "i don't know what a builder class is" after reading the description, do we need more information?

file: EnsembleConfigureOperation,
permutation_strategy: strategies.PermutationStrategyType,
) -> list[FileSet]:
"""Generate all possible permutations of file parameters using the provided strategy,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""Generate all possible permutations of file parameters using the provided strategy,
"""Generate the permutations of file parameters using the provided strategy,

no need to say all possible since that is implied in using the provided strategy - i wouldn't expect you to generate only some of the possibilities or you'd give me a new strategy that does that...

"""Generate all possible permutations of file parameters using the provided strategy,
and create FileSet objects.

This method applies the provided permutation strategy to the file's parameters,
Copy link
Contributor

Choose a reason for hiding this comment

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

avoid repeating the same thing as the first sentence of the docstring.

File and execution argument parameters are distributed using the supplied strategy. When a permutation limit is specified, the .... fill in unknown behavior here ... <maybe>permutations returned are randomly sampled from the complete set of permutations</maybe>

def _attach_files(
self, app: Application, file_set_tuple: tuple[FileSet, ...]
) -> None:
"""Attach files to an Application.
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: again, we're attaching the operations, not the files themselves

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all nitpicks welcome always!

if not isinstance(settings, LaunchSettings):
raise TypeError("ids argument was not of type LaunchSettings")
# if not isinstance(settings, LaunchSettings):
# raise TypeError("ids argument was not of type LaunchSettings")
apps = self._create_applications()
if not apps:
raise ValueError("There are no members as part of this ensemble")
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider "The ensemble has no members."

@MattToast MattToast self-requested a review October 31, 2024 17:30
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.

3 participants