Skip to content

refactor: launcher according to modules#4416

Open
germa89 wants to merge 35 commits intomainfrom
refactor/launcher.py
Open

refactor: launcher according to modules#4416
germa89 wants to merge 35 commits intomainfrom
refactor/launcher.py

Conversation

@germa89
Copy link
Collaborator

@germa89 germa89 commented Feb 13, 2026

Description

  • Introduced new modules for error handling, HPC integration, network management, and process management.
  • Implemented custom exceptions for configuration and launch errors.
  • Added functionality to launch MAPDL on HPC clusters using SLURM scheduler.
  • Created data models for launch configuration, process information, and validation results.
  • Implemented port management functions to check availability and find free ports.
  • Developed validation functions to ensure proper configuration before launching MAPDL.
  • Enhanced process management with subprocess handling and monitoring for startup readiness.

Issue linked

NA

Checklist

- Introduced new modules for error handling, HPC integration, network management, and process management.
- Implemented custom exceptions for configuration and launch errors.
- Added functionality to launch MAPDL on HPC clusters using SLURM scheduler.
- Created data models for launch configuration, process information, and validation results.
- Implemented port management functions to check availability and find free ports.
- Developed validation functions to ensure proper configuration before launching MAPDL.
- Enhanced process management with subprocess handling and monitoring for startup readiness.
@github-actions github-actions bot added the enhancement Improve any current implemented feature label Feb 13, 2026
Copy link
Contributor

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 pull request refactors the MAPDL launcher into a modular, domain-driven architecture. The refactoring separates concerns into distinct modules: configuration resolution, validation, environment detection, network management, process handling, HPC integration, and client connection. The legacy launcher code is preserved in _launcher_legacy.py for backward compatibility.

Changes:

  • Introduced modular architecture with separate modules for different launcher concerns (config, validation, environment, network, process, hpc, connection)
  • Implemented immutable data models using frozen dataclasses for configuration and results
  • Added comprehensive validation logic separate from configuration resolution
  • Created HPC-specific module for SLURM cluster support

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
src/ansys/mapdl/core/launcher/models.py Defines immutable data structures for configuration, process info, validation results, and HPC job info
src/ansys/mapdl/core/launcher/errors.py Introduces ConfigurationError and LaunchError custom exceptions
src/ansys/mapdl/core/launcher/config.py Implements pure functions for resolving configuration from arguments, environment variables, and defaults
src/ansys/mapdl/core/launcher/validation.py Provides validation functions that return ValidationResult objects without raising exceptions
src/ansys/mapdl/core/launcher/environment.py Handles platform detection (WSL, Ubuntu) and environment variable preparation
src/ansys/mapdl/core/launcher/network.py Manages port availability checking and free port discovery
src/ansys/mapdl/core/launcher/process.py Handles subprocess creation, monitoring, and startup verification
src/ansys/mapdl/core/launcher/hpc.py Provides SLURM scheduler integration for HPC cluster launches
src/ansys/mapdl/core/launcher/connection.py Creates MapdlGrpc and MapdlConsole client instances
src/ansys/mapdl/core/launcher/init.py Main entry point that orchestrates the launch process and re-exports legacy functions
src/ansys/mapdl/core/_launcher_legacy.py Preserved legacy launcher code (renamed from launcher.py) for backward compatibility

Comment on lines 167 to 189
@dataclass
class ValidationResult:
"""Result of configuration validation.

Attributes:
valid: Whether configuration is valid
errors: List of error messages (prevent launch)
warnings: List of warning messages (allow launch)
"""

valid: bool
errors: List[str] = field(default_factory=list)
warnings: List[str] = field(default_factory=list)

def add_error(self, message: str) -> None:
"""Add an error message and mark as invalid."""
self.valid = False
self.errors.append(message)

def add_warning(self, message: str) -> None:
"""Add a warning message."""
self.warnings.append(message)

Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

The ValidationResult class is mutable (using regular dataclass with mutable fields), but the docstring states "All models are immutable (where practical)" on line 26. Consider either making ValidationResult frozen=True and returning a new instance from add_error/add_warning methods, or clarifying in the module docstring that ValidationResult is intentionally mutable for collecting validation results.

Copilot uses AI. Check for mistakes.
Comment on lines +214 to +221
except ImportError as e:
# If legacy launcher doesn't exist or has errors, warn but continue
import warnings

warnings.warn(
f"Could not import legacy launcher functions: {e}. "
f"Some backward compatibility may be limited."
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
except ImportError as e:
# If legacy launcher doesn't exist or has errors, warn but continue
import warnings
warnings.warn(
f"Could not import legacy launcher functions: {e}. "
f"Some backward compatibility may be limited."
)

germa89 and others added 9 commits February 16, 2026 10:54
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Implement unit tests for the `launcher` module, covering orchestration, models, network, process, and validation functionalities.
- Create tests for `launch_mapdl` orchestration, including connection modes, error handling, and environment preparation.
- Add tests for `LaunchConfig`, `ProcessInfo`, `ValidationResult`, and `PortStatus` models to ensure proper functionality and immutability.
- Develop network tests for checking port status and finding available ports.
- Introduce process tests for launching, command generation, and process management.
- Implement validation tests for configuration checks, resource availability, and conflicting options.
- Ensure comprehensive coverage of edge cases and internal function validations.
@github-actions github-actions bot added dependencies maintenance General maintenance of the repo (libraries, cicd, etc) labels Feb 16, 2026
@github-actions github-actions bot added the CI/CD Related with CICD, Github Actions, etc label Feb 17, 2026
- Improved docstrings for `check_port_status`, `find_available_port`, and related functions in `network.py` to provide clearer usage examples, parameter descriptions, and return values.
- Updated docstrings in `process.py` for functions like `launch_mapdl_process`, `wait_for_process_ready`, and others to clarify their purpose, parameters, and return types.
- Enhanced validation function documentation in `validation.py` to detail the checks performed, parameters, and examples for better understanding.
- Added notes and examples to internal utility functions to aid developers in understanding their usage and context.
germa89 and others added 16 commits February 17, 2026 13:34
…rehensive command generation and subprocess management
… of instance creation, connection, and error handling
…4422)

* build: update ansys-tools-visualization-interface version constraint

* chore: adding changelog file 4422.dependencies.md [dependabot-skip]

---------

Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
#4424)

* build: adding python 3.10 versions on dependencies to fix uv run issue

* chore: adding changelog file 4424.dependencies.md [dependabot-skip]

---------

Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
@github-actions github-actions bot added the documentation Documentation related (improving, adding, etc) label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD Related with CICD, Github Actions, etc dependencies documentation Documentation related (improving, adding, etc) enhancement Improve any current implemented feature maintenance General maintenance of the repo (libraries, cicd, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments