Skip to content

Commit 0c1ed0d

Browse files
authored
Merge pull request #189 from Sahil-u07/fix-exception-handling-and-logging
Add CLI for concore (#183)
2 parents 22c9f31 + 2c6ae72 commit 0c1ed0d

13 files changed

Lines changed: 941 additions & 1 deletion

File tree

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,35 @@ Please follow the [ReadTheDocs](https://control-core.readthedocs.io/en/latest/in
2828

2929
Installation instructions for concore can be found [here](https://control-core.readthedocs.io/en/latest/installation.html). Usage instructions can be found [here](https://control-core.readthedocs.io/en/latest/usage.html).
3030

31+
## Command-Line Interface (CLI)
32+
33+
_concore_ now includes a command-line interface for easier workflow management. Install it with:
34+
35+
```bash
36+
pip install -e .
37+
```
38+
39+
Quick start with the CLI:
40+
41+
```bash
42+
# Create a new project
43+
concore init my-project
44+
45+
# Validate your workflow
46+
concore validate workflow.graphml
47+
48+
# Run your workflow
49+
concore run workflow.graphml --auto-build
50+
51+
# Monitor running processes
52+
concore status
53+
54+
# Stop all processes
55+
concore stop
56+
```
57+
58+
For detailed CLI documentation, see [concore_cli/README.md](concore_cli/README.md).
59+
3160
For a detailed and more scientific documentation, please read our extensive [open-access research paper on CONTROL-CORE](https://doi.org/10.1109/ACCESS.2022.3161471). This paper has a complete discussion on the CONTROL-CORE architecture and deployment, together with the commands to execute the studies in different programming languages and programming environments (Ubuntu, Windows, MacOS, Docker, and distributed execution).
3261

3362

concore_cli/README.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Concore CLI
2+
3+
A command-line interface for managing concore neuromodulation workflows.
4+
5+
## Installation
6+
7+
```bash
8+
pip install -e .
9+
```
10+
11+
## Quick Start
12+
13+
```bash
14+
# Create a new project
15+
concore init my-project
16+
17+
# Navigate to your project
18+
cd my-project
19+
20+
# Validate your workflow
21+
concore validate workflow.graphml
22+
23+
# Run your workflow
24+
concore run workflow.graphml
25+
26+
# Check running processes
27+
concore status
28+
29+
# Stop all processes
30+
concore stop
31+
```
32+
33+
## Commands
34+
35+
### `concore init <name>`
36+
37+
Creates a new concore project with a basic structure.
38+
39+
**Options:**
40+
- `--template` - Template type to use (default: basic)
41+
42+
**Example:**
43+
```bash
44+
concore init my-workflow
45+
```
46+
47+
Creates:
48+
```
49+
my-workflow/
50+
├── workflow.graphml # Sample workflow definition
51+
├── src/
52+
│ └── script.py # Sample processing script
53+
└── README.md # Project documentation
54+
```
55+
56+
### `concore run <workflow_file>`
57+
58+
Generates and optionally builds a workflow from a GraphML file.
59+
60+
**Options:**
61+
- `-s, --source <dir>` - Source directory (default: src)
62+
- `-o, --output <dir>` - Output directory (default: out)
63+
- `-t, --type <type>` - Execution type: windows, posix, or docker (default: windows)
64+
- `--auto-build` - Automatically run build script after generation
65+
66+
**Example:**
67+
```bash
68+
concore run workflow.graphml --source ./src --output ./build --auto-build
69+
```
70+
71+
### `concore validate <workflow_file>`
72+
73+
Validates a GraphML workflow file before running.
74+
75+
Checks:
76+
- Valid XML structure
77+
- GraphML format compliance
78+
- Node and edge definitions
79+
- File references and naming conventions
80+
- ZMQ vs file-based communication
81+
82+
**Example:**
83+
```bash
84+
concore validate workflow.graphml
85+
```
86+
87+
### `concore status`
88+
89+
Shows all currently running concore processes with details:
90+
- Process ID (PID)
91+
- Process name
92+
- Uptime
93+
- Memory usage
94+
- Command
95+
96+
**Example:**
97+
```bash
98+
concore status
99+
```
100+
101+
### `concore stop`
102+
103+
Stops all running concore processes. Prompts for confirmation before proceeding.
104+
105+
**Example:**
106+
```bash
107+
concore stop
108+
```
109+
110+
## Development Workflow
111+
112+
1. **Create a new project**
113+
```bash
114+
concore init my-neuro-study
115+
cd my-neuro-study
116+
```
117+
118+
2. **Edit your workflow**
119+
- Open `workflow.graphml` in yEd or similar GraphML editor
120+
- Add nodes for your processing steps
121+
- Connect nodes with edges to define data flow
122+
123+
3. **Add processing scripts**
124+
- Place your Python/C++/MATLAB/Verilog files in the `src/` directory
125+
- Reference them in your workflow nodes
126+
127+
4. **Validate before running**
128+
```bash
129+
concore validate workflow.graphml
130+
```
131+
132+
5. **Generate and run**
133+
```bash
134+
concore run workflow.graphml --auto-build
135+
cd out
136+
./run.bat # or ./run on Linux/Mac
137+
```
138+
139+
6. **Monitor execution**
140+
```bash
141+
concore status
142+
```
143+
144+
7. **Stop when done**
145+
```bash
146+
concore stop
147+
```
148+
149+
## Workflow File Format
150+
151+
Nodes should follow the format: `ID:filename.ext`
152+
153+
Example:
154+
```
155+
N1:controller.py
156+
N2:processor.cpp
157+
M1:analyzer.m
158+
```
159+
160+
Supported file types:
161+
- `.py` - Python
162+
- `.cpp` - C++
163+
- `.m` - MATLAB/Octave
164+
- `.v` - Verilog
165+
- `.java` - Java
166+
167+
## Troubleshooting
168+
169+
**Issue: "Output directory already exists"**
170+
- Remove the existing output directory or choose a different name
171+
- Use `concore stop` to terminate any running processes first
172+
173+
**Issue: Validation fails**
174+
- Check that your GraphML file is properly formatted
175+
- Ensure all nodes have labels in the format `ID:filename.ext`
176+
- Verify that edge connections reference valid nodes
177+
178+
**Issue: Processes won't stop**
179+
- Try running `concore stop` with administrator/sudo privileges
180+
- Manually kill processes using Task Manager (Windows) or `kill` command (Linux/Mac)

concore_cli/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .cli import cli
2+
3+
__all__ = ['cli']

concore_cli/cli.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import click
2+
from rich.console import Console
3+
from rich.table import Table
4+
from rich.panel import Panel
5+
from rich import print as rprint
6+
import sys
7+
import os
8+
from pathlib import Path
9+
10+
from .commands.init import init_project
11+
from .commands.run import run_workflow
12+
from .commands.validate import validate_workflow
13+
from .commands.status import show_status
14+
from .commands.stop import stop_all
15+
16+
console = Console()
17+
18+
@click.group()
19+
@click.version_option(version='1.0.0', prog_name='concore')
20+
def cli():
21+
pass
22+
23+
@cli.command()
24+
@click.argument('name', required=True)
25+
@click.option('--template', default='basic', help='Template type to use')
26+
def init(name, template):
27+
"""Create a new concore project"""
28+
try:
29+
init_project(name, template, console)
30+
except Exception as e:
31+
console.print(f"[red]Error:[/red] {str(e)}")
32+
sys.exit(1)
33+
34+
@cli.command()
35+
@click.argument('workflow_file', type=click.Path(exists=True))
36+
@click.option('--source', '-s', default='src', help='Source directory')
37+
@click.option('--output', '-o', default='out', help='Output directory')
38+
@click.option('--type', '-t', default='windows', type=click.Choice(['windows', 'posix', 'docker']), help='Execution type')
39+
@click.option('--auto-build', is_flag=True, help='Automatically run build after generation')
40+
def run(workflow_file, source, output, type, auto_build):
41+
"""Run a concore workflow"""
42+
try:
43+
run_workflow(workflow_file, source, output, type, auto_build, console)
44+
except Exception as e:
45+
console.print(f"[red]Error:[/red] {str(e)}")
46+
sys.exit(1)
47+
48+
@cli.command()
49+
@click.argument('workflow_file', type=click.Path(exists=True))
50+
def validate(workflow_file):
51+
"""Validate a workflow file"""
52+
try:
53+
validate_workflow(workflow_file, console)
54+
except Exception as e:
55+
console.print(f"[red]Error:[/red] {str(e)}")
56+
sys.exit(1)
57+
58+
@cli.command()
59+
def status():
60+
"""Show running concore processes"""
61+
try:
62+
show_status(console)
63+
except Exception as e:
64+
console.print(f"[red]Error:[/red] {str(e)}")
65+
sys.exit(1)
66+
67+
@cli.command()
68+
@click.confirmation_option(prompt='Stop all running concore processes?')
69+
def stop():
70+
"""Stop all running concore processes"""
71+
try:
72+
stop_all(console)
73+
except Exception as e:
74+
console.print(f"[red]Error:[/red] {str(e)}")
75+
sys.exit(1)
76+
77+
if __name__ == '__main__':
78+
cli()

concore_cli/commands/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from .init import init_project
2+
from .run import run_workflow
3+
from .validate import validate_workflow
4+
from .status import show_status
5+
from .stop import stop_all
6+
7+
__all__ = ['init_project', 'run_workflow', 'validate_workflow', 'show_status', 'stop_all']

0 commit comments

Comments
 (0)