Draft
Conversation
This reverts commit a4181b0.
* refactor workgraph.py
Apply comprehensive refactoring patterns to workgraph.py to reduce
cognitive complexity, improve type safety, and enhance maintainability.
STRUCTURAL CHANGES
- Introduce frozen dataclasses to replace fragile tuple structures:
* DependencyInfo(dep_label, filename, data_label): replaces 3-element
tuples used throughout dependency tracking chain
* InputDataInfo: typed metadata for input data items (7 fields)
* OutputDataInfo: typed metadata for output data items (5 fields)
- Add type aliases for complex nested structures:
* PortToDependencies: dict[str, list[DependencyInfo]]
* ParentFolders, JobIds, TaskDepInfo, LauncherDependencies
COMPLEXITY REDUCTION
- Extract dependency processing helpers to reduce nesting:
* _resolve_icon_dependency(): encapsulates 3-case logic (filename
known, namelist resolution, workdir fallback)
* _create_shell_remote_data(): creates RemoteData with consistent
patterns
* Reduces maximum indentation from 5+ levels to 2-3 levels
- Apply early-continue pattern in dependency processing loops:
* load_icon_dependencies(): flattened control flow
* load_and_process_shell_dependencies(): reduced nested conditionals
DRY PRINCIPLE APPLICATION
- Consolidate SLURM dependency directive building:
* _build_slurm_dependency_directive(): single source of truth for
"#SBATCH --dependency=afterok:..." construction
* _add_custom_scheduler_command(): unified command appending logic
* Eliminates duplication between
build_icon_metadata_with_slurm_dependencies() and
build_shell_metadata_with_slurm_dependencies()
UTILITY FUNCTIONS
- Add mapping helpers to reduce boilerplate:
* _map_list_append(): replaces repeated setdefault().append() pattern
* _map_unique_set(): conditional insertion with existence check
* Applied in build_dependency_mapping() for cleaner intent
- Add logging wrappers to separate concerns:
* _log_dependency_processing(): consistent dependency logging
* _log_remote_data_details(): structured RemoteData creation logging
TYPE SAFETY IMPROVEMENTS
- Update build_shell_task_spec() to use dataclasses:
* Change input_data_info from list[dict] to list[InputDataInfo]
* Change output_data_info from list[dict] to list[OutputDataInfo]
* Replace dict access patterns (info["field"]) with attribute access
(info.field)
* Enables IDE autocomplete and static type checking
AFFECTED FUNCTIONS
Modified:
- build_dependency_mapping(): use DependencyInfo, mapping helpers
- load_icon_dependencies(): use helper, type aliases, early-continue
- load_and_process_shell_dependencies(): use helper, type aliases,
early-continue
- build_icon_metadata_with_slurm_dependencies(): use SLURM helpers
- build_shell_metadata_with_slurm_dependencies(): use SLURM helpers
- build_shell_task_spec(): use InputDataInfo/OutputDataInfo dataclasses
Added:
- _resolve_icon_dependency()
- _create_shell_remote_data()
- _build_slurm_dependency_directive()
- _add_custom_scheduler_command()
- _map_list_append()
- _map_unique_set()
- _log_dependency_processing()
- _log_remote_data_details()
REFACTORING PATTERNS APPLIED
1. Replace tuples with typed dataclasses for self-documentation
2. Extract per-dependency logic into focused helper functions
3. Precompute lookup tables to eliminate nested scanning (already
optimized)
4. Apply early-continue pattern to reduce indentation depth
5. Consolidate repeated logic following DRY principle
6. Separate logging concerns from business logic
7. Use type aliases to clarify complex nested structures
8. Add utility functions for common mapping operations
* Fix JSON-serialization and upgrade aiida-core
* add branch-independence test case
* nicer test-setup with env var substitution and `run_via_cli.sh`
* delete `large-local` directory
* wip; pre-submission seems to work nicely for the simpler branch-independence workflow
…m batch/extern/main job reporting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.