Metadata-Version: 2.1
Name: meinsweeper
Version: 0.3.6
Summary: MeinSweeper is a light-weight framework for running experiments on arbitrary compute nodes
Author-email: Alex Spies <alex@afspies.com>
License: The MIT License (MIT)
        
        Copyright (c) 2022, Alex Spies
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
Project-URL: Homepage, https://github.com/afspies/meinsweeper
Project-URL: Bug Tracker, https://github.com/afspies/meinsweeper/issues
Project-URL: Icon, https://raw.githubusercontent.com/afspies/meinsweeper/master/meinsweeper/logo.png
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: asyncssh
Requires-Dist: rich
Requires-Dist: psutil
Requires-Dist: duecredit

# MeinSweeper
<img src="meinsweeper/logo.png" align="right"
     alt="Minesweeper image taken from https://www.pngwing.com/en/free-png-vxhwi" width="80" height="80">

MeinSweeper is a lightweight framework for running experiments on arbitrary compute nodes, with built-in support for GPU management and job distribution.

```diff
- This is still in alpha, and was written for research
- I.e. expect bugs and smelly code!
```

## Installation
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install MeinSweeper:

  ```bash
  pip install meinsweeper
  ```

## Features
- Asynchronous job execution
- Support for multiple node types (SSH and Local)
- Automatic GPU management and allocation
- Retry mechanism for failed jobs and unavailable nodes
- Configurable via environment variables

## Usage
### Basic Usage
  ```python
  import meinsweeper

  targets = {
      'local_gpu': {'type': 'local_async', 'params': {'gpus': ['0', '1']}},
      'remote_server': {'type': 'ssh', 'params': {'address': 'example.com', 'username': 'user', 'key_path': '/path/to/key'}}
  }

  commands = [
      ("python script1.py", "job1"), 
      ("python script2.py", "job2"),
      # ... more commands
  ]

  meinsweeper.run_sweep(commands, targets)
  ```

### Node Types
1. **Local Async Node**: Executes jobs on the local machine, managing GPU allocation.
2. **SSH Node**: Connects to remote machines via SSH, manages GPU allocation, and executes jobs.

Both node types handle GPU checking, allocation, and release automatically.

### Configuration
MeinSweeper can be configured using environment variables:

- `MINIMUM_VRAM`: Minimum free VRAM required for a GPU to be considered available (in GB, default: 8)
- `USAGE_CRITERION`: Maximum GPU utilization for a GPU to be considered available (0-1, default: 0.8)
- `MAX_PROCESSES`: Maximum number of concurrent processes (-1 for no limit, default: -1)
- `RUN_TIMEOUT`: Timeout for each job execution (in seconds, default: 1200)
- `MAX_RETRIES`: Maximum number of retries for failed jobs (default: 3)
- `MEINSWEEPER_RETRY_INTERVAL`: Interval between retrying unavailable nodes (in seconds, default: 450)
- `MEINSWEEPER_DEBUG`: Enable debug logging (set to 'True' for verbose output)

Example:
  ```bash
  export MINIMUM_VRAM=10
  export USAGE_CRITERION=0.5
  export MEINSWEEPER_RETRY_INTERVAL=300
  python your_script.py
  ```

## Advanced Usage
### Custom Node Types
You can create custom node types by subclassing the `ComputeNode` abstract base class:

  ```python
  from meinsweeper.modules.nodes.abstract import ComputeNode

  class MyCustomNode(ComputeNode):
      async def open_connection(self):
          # Implementation
      
      async def run(self, command, label):
          # Implementation

  # Usage
  targets = {
      'custom_node': {'type': 'my_custom_node', 'params': {...}}
  }
  ```

## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.

## License
[MIT](https://choosealicense.com/licenses/mit/)
