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

Workspace context manager #148

Conversation

aleksandr-mokrov
Copy link
Contributor

Use context managers to manage experiment workspaces
Fix plan.config['task_runner'] filling.

Copy link
Contributor

@igor-davidyuk igor-davidyuk left a comment

Choose a reason for hiding this comment

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

Could we combine CollaboratorWorkspace and AggregatorWorkspace, maybe introduce an additional parameter.
At least make a base ActorWorkspace class with common functionality?

Also could you please remove the old version in this PR?
https://github.com/aleksandr-mokrov/openfl/blob/e04c2e00b3bd072ff23e06b4c5a36e4de768020d/openfl/utilities/utils.py#L56

from pathlib import Path


class AggregatorWorkspace:
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest moving this away from the components package, to the utilities probably

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to utilities/workspace.py

logger = logging.getLogger(__name__)


class CollaboratorWorkspace:
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest moving this away from the components package too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to utilities/workspace.py

@aleksandr-mokrov
Copy link
Contributor Author

Could we combine CollaboratorWorkspace and AggregatorWorkspace, maybe introduce an additional parameter.
At least make a base ActorWorkspace class with common functionality?

Also could you please remove the old version in this PR?
https://github.com/aleksandr-mokrov/openfl/blob/e04c2e00b3bd072ff23e06b4c5a36e4de768020d/openfl/utilities/utils.py#L56
The old version was removed. CollaboratorWorkspace and AggregatorWorkspace were merged to ExperimentWorkspace context manager.

@aleksandr-mokrov aleksandr-mokrov mentioned this pull request Aug 13, 2021
22 tasks
Copy link
Contributor

@igor-davidyuk igor-davidyuk left a comment

Choose a reason for hiding this comment

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

Nice!

self,
experiment_name: str,
data_file_path: Path,
is_install_requirements: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

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

is_install_requirements -> install_requirements
probably this will look better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's boolean flag. It will be strange:

if self.install_requirements:
            self._install_requirements()

Probably is_install_requirements_required would be better, but too long.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think that requirements will be better. You still can rename it inside __init__.

Comment on lines +59 to +61
with ExperimentWorkspace(
experiment_name, data_file_path, is_install_requirements=True
):
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe rename is_install_requirements => requirements in order to avoid so long line.

Comment on lines +67 to +68
def wait_experiment(self):
"""Wait an experiment data from the director."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe wait_experiment should be get_experiment_name?

self,
experiment_name: str,
data_file_path: Path,
is_install_requirements: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

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

I also think that requirements will be better. You still can rename it inside __init__.


def _install_requirements(self):
"""Install experiment requirements."""
requirements_filename = f'{self.experiment_work_dir}/requirements.txt'
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to use pathlib.Path here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This variable is used in 3 places in this method, some of them are converted to a string, and some must be converted to a string manually. None of them use type Path.

@alexey-gruzdev alexey-gruzdev merged commit f821836 into securefederatedai:develop Aug 17, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2021

if os.path.isfile(requirements_filename):
attempts = 10
for _ in range(attempts):
Copy link
Contributor

Choose a reason for hiding this comment

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

@aleksandr-mokrov Shouldn't we raise an exception when all attempts to install the requirements failed?

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

Successfully merging this pull request may close these issues.

None yet

5 participants