Skip to content

Conversation

@refai06
Copy link
Owner

@refai06 refai06 commented Jun 10, 2025

Summary

This PR addresses issue securefederatedai#1565 by enabling the import of user-defined helper functions and utilities from separate Python scripts in FederatedRuntime notebooks.

Type of Change (Mandatory)

Specify the type of change being made.

  • Feature enhancement

Description (Mandatory)

PR enhances the CodeAnalyzer to support importing user-defined helper modules in FederatedRuntime notebooks by

  • Detecting user-defined imports in the exported script.
  • Resolving and copying relevant .py files or packages to generated_workspace/src.
  • Ensuring user-defined code is available during remote (i.e director/envoy) experiment execution.

Testing

  • Validated the FederatedRuntime tutorial with a user-defined module import.

@ishant162 ishant162 requested a review from Copilot June 10, 2025 04:48

This comment was marked as outdated.

@refai06 refai06 marked this pull request as ready for review June 12, 2025 13:15
Copy link
Collaborator

@ishant162 ishant162 left a comment

Choose a reason for hiding this comment

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

Overall looks OK but some error handling needs to be done to make it more robust

@ishant162 ishant162 requested a review from Copilot June 13, 2025 11:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances FederatedRuntime notebook support by enabling user-defined helper utilities to be imported and executed remotely.

  • Update workspace context manager to include both the experiment directory and its src subdirectory in sys.path.
  • Extend CodeAnalyzer to detect user-defined imports in the generated script and copy the corresponding .py files or packages into the workspace.
  • Add helper methods for checking and resolving module paths.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
openfl/utilities/workspace.py Enhanced __enter__/__exit__ to manage src directory on sys.path.
openfl/experimental/workflow/notebooktools/code_analyzer.py Implemented __extract_user_defined_imports, __copy_user_defined_modules, _is_user_defined_module, and _get_module_paths; updated imports and type hints.
Comments suppressed due to low confidence (1)

openfl/experimental/workflow/notebooktools/code_analyzer.py:92

  • Add unit tests for __extract_user_defined_imports and __copy_user_defined_modules to verify correct detection of user modules, including edge cases like nested packages, missing files, and different import styles.
def __extract_user_defined_imports(self, notebook_path) -> List[str]:

Copy link
Collaborator

@ishant162 ishant162 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. Please check the copilot review comments and incorporate if they make sense

Repository owner deleted a comment from Copilot AI Jun 17, 2025
Signed-off-by: refai06 <refai.ahamed06@gmail.com>
Signed-off-by: refai06 <refai.ahamed06@gmail.com>
Signed-off-by: refai06 <refai.ahamed06@gmail.com>
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