Skip to content

Compatibility with IconBaseRestartWorkChain#243

Draft
GeigerJ2 wants to merge 48 commits intomainfrom
workgraph-with-restart
Draft

Compatibility with IconBaseRestartWorkChain#243
GeigerJ2 wants to merge 48 commits intomainfrom
workgraph-with-restart

Conversation

@GeigerJ2
Copy link
Collaborator

No description provided.

GeigerJ2 and others added 30 commits October 31, 2025 12:16
* 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
Base automatically changed from workgraph to main February 26, 2026 10:52
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.

1 participant