File size: 10,218 Bytes
1556404
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# Shinka WebUI Guide 🎨

The Shinka WebUI provides an interactive, real-time visualization of the evolutionary process, allowing you to monitor experiments, explore solution genealogies, and analyze performance metrics.

## Table of Contents

1. [Overview](#overview)
2. [Quick Start](#quick-start)
3. [Setup and Launch](#setup-and-launch)
4. [WebUI Features](#webui-features)
5. [Remote Access](#remote-access)
6. [Troubleshooting](#troubleshooting)
7. [Advanced Usage](#advanced-usage)

## Overview

The WebUI serves as a dashboard for monitoring Shinka evolution experiments, providing:

- **Real-time Updates**: Live monitoring of ongoing experiments
- **Evolution Tree**: Interactive visualization of solution genealogies
- **Performance Metrics**: Charts and graphs of fitness over generations
- **Code Diff Viewer**: Side-by-side comparison of evolved solutions
- **Island Visualization**: Multi-island evolution monitoring
- **Database Browser**: Explore archived solutions and metadata

![WebUI Screenshot](webui.png)

## Quick Start

### Local Experiment

```bash
# Start your evolution experiment
shinka_launch variant=circle_packing_example

# In another terminal, launch the WebUI
shinka_visualize --port 8888 --open

# Or specify a results directory
shinka_visualize results_20241201_120000/ --port 8888 --open

# Or target a specific database file
shinka_visualize --db results_20241201_120000/evolution_db.sqlite --port 8888 --open

# Open browser to http://localhost:8888 (if not auto-opened)
```

### Remote Experiment

```bash
# On remote machine (where experiment runs)
shinka_visualize --port 8888

# On local machine (create SSH tunnel)
ssh -L 8888:localhost:8888 username@remote-host

# Open browser to http://localhost:8888
```

### Async Runner Support

The WebUI works seamlessly with both sync and async evolution runners:

```bash
# For async experiments
python run_evo_async.py  # Start async evolution

# Launch WebUI (auto-detects database in current directory)
shinka_visualize --open

# For sync experiments  
python run_evo.py        # Start sync evolution

# Launch WebUI with specific results directory
shinka_visualize results_20241201_120000/ --open

# Or with specific database file
shinka_visualize --db results_20241201_120000/evolution_db.sqlite --open
```

## Setup and Launch

### Prerequisites

The WebUI requires:
- Python 3.8+
- Access to the experiment's SQLite database
- Network access to the machine running the experiment

### Launch Options

#### Basic Launch
```bash
shinka_visualize
```

#### Custom Port
```bash
shinka_visualize --port 9000
```

#### Custom Database Path
```bash
shinka_visualize --db /path/to/evolution_db.sqlite
```

#### Auto-open Browser
```bash
shinka_visualize --open
```

#### Specify Results Directory
```bash
shinka_visualize /path/to/results_directory/ --port 8888 --open
```

### Command Line Arguments

| Argument | Default | Description |
|----------|---------|-------------|
| `root_directory` | Current directory | Root directory to search for database files |
| `-p, --port` | `8000` | Port for the web server |
| `--db` | Auto-detect | Path to specific SQLite database file |
| `--open` | `False` | Automatically open browser |

## WebUI Features

### 1. Evolution Tree Visualization

The evolution tree shows the genealogical relationships between solutions:

- **Nodes**: Individual solutions with fitness scores
- **Edges**: Parent-child relationships
- **Colors**: Performance-based color coding
- **Interactive**: Click nodes to view details
- **Filtering**: Filter by generation, island, or fitness

**Navigation:**
- **Zoom**: Mouse wheel or pinch gestures
- **Pan**: Click and drag
- **Select**: Click nodes to view details
- **Reset View**: Double-click empty space

### 2. Performance Metrics Dashboard

Track evolution progress with various metrics:

- **Fitness Over Time**: Line charts showing best/average fitness
- **Generation Statistics**: Distribution plots for each generation
- **Island Comparison**: Performance across different islands
- **Convergence Analysis**: Diversity and convergence metrics

**Available Metrics:**
- Best fitness per generation
- Average fitness per generation
- Population diversity measures
- Success rate of mutations
- Computational time per generation

### 3. Code Diff Viewer

Compare solutions to understand evolutionary changes:

- **Side-by-Side View**: Parent vs child code comparison
- **Syntax Highlighting**: Language-specific highlighting
- **Change Highlighting**: Added, removed, and modified lines
- **Diff Statistics**: Lines changed, complexity metrics
- **Navigation**: Jump between changes

**Features:**
- Unified or split view options
- Line-by-line change tracking
- Code complexity analysis
- Search within diffs

### 4. Solution Browser

Explore the archive of evolved solutions:

- **Search and Filter**: Find solutions by criteria
- **Sort Options**: By fitness, generation, or date
- **Metadata View**: Detailed solution information
- **Export Options**: Download solutions as files
- **Comparison Tools**: Compare multiple solutions

**Filter Options:**
- Generation range
- Fitness threshold
- Island ID
- Success status
- Code complexity

### 5. Island Visualization

For multi-island evolution experiments:

- **Island Overview**: Status and performance of each island
- **Migration Tracking**: Visualize solution migrations
- **Population Diversity**: Compare diversity across islands
- **Resource Usage**: Monitor computational resources per island

### 6. Real-time Updates

The WebUI automatically refreshes to show new data:

- **Live Refresh**: Configurable refresh intervals
- **Progress Indicators**: Show ongoing evaluations
- **Notifications**: Alerts for significant events
- **Auto-scroll**: Follow latest generations

## Remote Access

### SSH Tunneling

For experiments running on remote machines:

```bash
# Create SSH tunnel (local port 8888 -> remote port 8888)
ssh -L 8888:localhost:8888 username@remote-host

# For persistent connection
ssh -L 8888:localhost:8888 -N username@remote-host
```

### Cluster Access

For Slurm cluster experiments:

```bash
# Connect to cluster login node
ssh username@cluster-login-node

# Create tunnel through login node to compute node
ssh -L 8888:compute-node:8888 username@cluster-login-node

# Alternative: Direct tunnel if compute node is accessible
ssh -L 8888:localhost:8888 username@compute-node
```

### Multiple Experiments

Monitor multiple experiments simultaneously:

```bash
# Experiment 1 on port 8888
shinka_visualize exp1/ --port 8888

# Experiment 2 on port 8889  
shinka_visualize exp2/ --port 8889

# Or with specific database files
shinka_visualize --db exp1/evolution_db.sqlite --port 8888
shinka_visualize --db exp2/evolution_db.sqlite --port 8889

# Access at http://localhost:8888 and http://localhost:8889
```

## Troubleshooting

### Common Issues

#### 1. Database Not Found
```bash
# Error: Cannot find evolution_db.sqlite
# Solution: Specify database path explicitly
shinka_visualize --db /full/path/to/evolution_db.sqlite
```

#### 2. Port Already in Use
```bash
# Error: Address already in use
# Solution: Use different port
shinka_visualize --port 9000
```

#### 3. No Data Displayed
- **Check database**: Ensure experiment has started and created data
- **Verify path**: Confirm database path is correct
- **Check permissions**: Ensure read access to database file

#### 4. SSH Tunnel Issues
```bash
# Test tunnel connectivity
curl http://localhost:8888

# Debug SSH tunnel
ssh -v -L 8888:localhost:8888 username@remote-host
```

#### 5. Browser Connection Issues
- **Clear cache**: Hard refresh (Ctrl+F5 or Cmd+Shift+R)
- **Check firewall**: Ensure port is not blocked
- **Try different browser**: Some features require modern browsers

### Debug Mode

Enable verbose logging:

```bash
# Launch with verbose output (check console for debug info)
shinka_visualize --port 8888

# The server provides detailed logging in the console
```

### Performance Issues

For large experiments with many generations:

```bash
# For large experiments, the new shinka_visualize handles performance automatically
# Simply launch with your results directory
shinka_visualize large_experiment_results/ --port 8888 --open

# Or specify a specific database if needed
shinka_visualize --db large_experiment_results/evolution_db.sqlite --port 8888
```

## Advanced Usage

### Custom Styling

Modify the WebUI appearance by editing `viz_tree.html`:

```html
<!-- Custom CSS -->
<style>
.node-high-fitness { fill: #00ff00; }
.node-low-fitness { fill: #ff0000; }
</style>
```

### API Endpoints

The WebUI server provides REST API endpoints:

- `GET /api/generations`: List all generations
- `GET /api/generation/{id}`: Get specific generation data
- `GET /api/solutions/{id}`: Get solution details
- `GET /api/metrics`: Get performance metrics
- `GET /api/islands`: Get island information

### Embedding in Jupyter

Use the WebUI in Jupyter notebooks:

```python
from IPython.display import IFrame
import subprocess
import time

# Start WebUI server
subprocess.Popen(['shinka_visualize', '--port', '8888'])
time.sleep(2)  # Wait for server to start

# Embed in notebook
IFrame('http://localhost:8888', width=1000, height=600)
```

## Best Practices

### 1. Resource Management
- Monitor memory usage for large experiments
- Use appropriate refresh intervals
- Close unused browser tabs

### 2. Security
- Use SSH tunnels for remote access
- Don't expose WebUI ports publicly
- Limit access to trusted networks

### 3. Performance Optimization
- Reduce refresh frequency for large experiments
- Use filtering to focus on relevant data
- Close WebUI when not actively monitoring

### 4. Data Backup
- Regularly backup evolution databases
- Export important results before cleanup
- Keep logs of significant experiments

## WebUI Architecture

The WebUI consists of:

- **Backend Server**: Python HTTP server (`open_visualization.py`)
- **Frontend**: HTML/JavaScript visualization (`viz_tree.html`)
- **Database**: SQLite database with experiment data
- **Assets**: Icons, stylesheets, and images

For customization and development details, see the source code in the `webui/` directory.