File size: 14,984 Bytes
886f2cc
3459700
 
886f2cc
 
 
 
 
 
 
 
 
 
 
 
 
 
3459700
 
 
 
 
 
 
 
 
886f2cc
 
3459700
886f2cc
3459700
 
 
 
 
 
 
 
 
 
 
 
 
 
886f2cc
 
 
 
 
 
 
 
 
3459700
 
886f2cc
 
 
 
 
3459700
 
 
 
 
 
 
 
 
886f2cc
 
3459700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886f2cc
 
 
3459700
886f2cc
 
 
 
ed49592
3459700
6c4abbd
 
886f2cc
 
 
 
 
3459700
886f2cc
 
84444f7
3459700
886f2cc
 
3459700
 
 
 
 
 
 
 
 
 
 
 
84444f7
3459700
886f2cc
3459700
 
886f2cc
3459700
 
 
886f2cc
3459700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886f2cc
 
3459700
886f2cc
3459700
886f2cc
 
3459700
 
 
 
886f2cc
3459700
886f2cc
3459700
 
 
 
 
 
 
886f2cc
3459700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886f2cc
 
 
3459700
 
 
 
 
 
 
 
 
 
 
 
 
 
886f2cc
 
3459700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886f2cc
 
3459700
 
886f2cc
3459700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886f2cc
3459700
 
 
 
886f2cc
3459700
886f2cc
 
3459700
 
886f2cc
3459700
886f2cc
3459700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886f2cc
 
3459700
 
886f2cc
3459700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
886f2cc
3459700
 
 
886f2cc
 
3459700
 
 
 
 
 
 
 
 
 
 
886f2cc
3459700
 
 
 
 
 
 
 
 
 
886f2cc
3459700
 
886f2cc
3459700
886f2cc
3459700
 
 
 
 
 
 
 
 
886f2cc
3459700
 
886f2cc
3459700
886f2cc
3459700
 
 
886f2cc
3459700
 
886f2cc
3459700
 
886f2cc
3459700
 
886f2cc
3459700
 
886f2cc
3459700
 
 
 
 
886f2cc
 
 
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
"""
Daugherty Engine - SAT & Ising Solver Demo
API-only interface for testing constraint satisfaction and optimization.

This demo calls the public API at https://1millionspins.originneural.ai
No proprietary code is exposed - only API interactions.
"""

import gradio as gr
import requests
import time

# Public API endpoint
API_BASE = "https://1millionspins.originneural.ai/api"

# Hardware specs (public information from DigitalOcean pricing)
HARDWARE_INFO = {
    "name": "NVIDIA RTX 6000 Ada",
    "vram": 48,  # GB
    "architecture": "Ada Lovelace",
    "cuda_cores": 18176,
    "tensor_cores": 568,
    "tdp": 300,  # Watts
    "typical_power": 195,  # Watts at ~65% utilization
    "cost_per_hour": 1.57,  # USD (DigitalOcean GPU Droplet)
    "source": "DigitalOcean GPU Droplet pricing, January 2026"
}

# Competitor reference data (all from public sources)
COMPETITORS = {
    "D-Wave Advantage": {
        "qubits": 5000,
        "power": 25000,  # Watts (system + cooling)
        "cost_per_hour": 13.20,  # AWS Braket pricing
        "type": "Quantum Annealer",
        "source": "AWS Braket pricing, D-Wave documentation"
    },
    "IBM Quantum (127Q)": {
        "qubits": 127,
        "power": 15000,  # Watts (dilution refrigerator)
        "cost_per_hour": 1.60,  # IBM Quantum Network
        "type": "Gate-based Quantum",
        "source": "IBM Quantum pricing documentation"
    }
}


def check_api_health():
    """Check if the API is online."""
    try:
        response = requests.get(f"{API_BASE}/health", timeout=10)
        if response.status_code == 200:
            data = response.json()
            gpu = data.get('gpu', 'Unknown')
            return f"Online ({gpu})"
        return "Offline"
    except Exception as e:
        return f"Error: {str(e)}"


def calculate_search_space(n):
    """Calculate and format the search space size."""
    space = 2 ** n
    if space > 1e100:
        return f"2^{n} (astronomical)"
    elif space > 1e30:
        return f"2^{n} ({space:.2e})"
    else:
        return f"2^{n} = {space:,.0f}"


def get_sat_difficulty(num_vars):
    """Analyze SAT problem difficulty."""
    clauses = int(num_vars * 4.27)

    if num_vars <= 50:
        difficulty, desc = "Easy", "Solvable in milliseconds"
    elif num_vars <= 150:
        difficulty, desc = "Medium", "Requires seconds"
    elif num_vars <= 300:
        difficulty, desc = "Hard", "May require minutes"
    else:
        difficulty, desc = "Very Hard", "Exponential blowup region"

    return f"""
### Problem Preview

| Parameter | Value |
|-----------|-------|
| Variables | {num_vars} |
| Clauses | {clauses} |
| Ratio (α) | 4.27 |
| Search Space | {calculate_search_space(num_vars)} |
| Difficulty | **{difficulty}** |

*{desc}*
"""


def get_ising_difficulty(size):
    """Analyze Ising problem difficulty."""
    interactions = size * (size - 1) // 2

    if size <= 30:
        difficulty, desc = "Easy", "Small spin glass"
    elif size <= 100:
        difficulty, desc = "Medium", "Moderate complexity"
    elif size <= 300:
        difficulty, desc = "Hard", "Large spin system"
    else:
        difficulty, desc = "Very Hard", "Massive optimization landscape"

    return f"""
### Problem Preview

| Parameter | Value |
|-----------|-------|
| Spins | {size} |
| Interactions | ~{interactions:,} |
| Configuration Space | {calculate_search_space(size)} |
| Difficulty | **{difficulty}** |

*{desc}*
"""


def run_sat_verification(num_variables: int, num_trials: int):
    """Run SAT verification through the public API."""
    num_variables = max(20, min(500, int(num_variables)))
    num_trials = max(1, min(20, int(num_trials)))

    num_clauses = int(num_variables * 4.27)
    start_time = time.time()

    try:
        response = requests.post(
            f"{API_BASE}/verify/sat",
            json={"size": num_variables, "trials": num_trials},
            timeout=120,
            headers={"Content-Type": "application/json"}
        )

        elapsed_time = time.time() - start_time

        if response.status_code != 200:
            return f"## Error\n\nAPI Error: {response.status_code}"

        data = response.json()
        if not data.get("success"):
            return f"## Error\n\n{data.get('error', 'Unknown error')}"

        results = data.get("data", {}).get("results", {})
        mean_sat = results.get("mean_satisfaction", 0)
        std_sat = results.get("std_satisfaction", 0)
        max_sat = results.get("max_satisfaction", 0)
        min_sat = results.get("min_satisfaction", 0)

        # Quality tier
        if mean_sat >= 95:
            tier = "EXCELLENT"
        elif mean_sat >= 85:
            tier = "GOOD"
        elif mean_sat >= 70:
            tier = "ACCEPTABLE"
        else:
            tier = "LOW"

        # Resource calculations
        energy_j = HARDWARE_INFO["typical_power"] * elapsed_time
        cost_usd = (HARDWARE_INFO["cost_per_hour"] / 3600) * elapsed_time
        dwave = COMPETITORS["D-Wave Advantage"]
        dwave_energy = dwave["power"] * elapsed_time
        power_ratio = round(dwave_energy / energy_j) if energy_j > 0 else 0

        return f"""
## SAT Verification Results

### Performance

| Metric | Value |
|--------|-------|
| Mean Satisfaction | **{mean_sat:.2f}%** |
| Std Deviation | ±{std_sat:.2f}% |
| Best/Worst Trial | {max_sat:.2f}% / {min_sat:.2f}% |
| Quality Tier | **{tier}** |

### Resources

| Metric | Daugherty | D-Wave Equivalent |
|--------|-----------|-------------------|
| Time | {elapsed_time:.3f}s | {elapsed_time:.3f}s |
| Energy | {energy_j:.1f} J | {dwave_energy:.1f} J |
| Cost | ${cost_usd:.6f} | ${(dwave["cost_per_hour"]/3600)*elapsed_time:.6f} |

**Efficiency: {power_ratio}x less power than D-Wave**

---
*{num_variables} variables, {num_clauses} clauses, {num_trials} trials*
"""

    except requests.exceptions.Timeout:
        return "## Error\n\nRequest timed out. Try smaller problem."
    except Exception as e:
        return f"## Error\n\n{str(e)}"


def run_ising_verification(size: int, trials: int):
    """Run Ising model verification through the public API."""
    size = max(10, min(500, int(size)))
    trials = max(1, min(20, int(trials)))

    start_time = time.time()

    try:
        response = requests.post(
            f"{API_BASE}/verify/ising",
            json={"size": size, "trials": trials},
            timeout=120,
            headers={"Content-Type": "application/json"}
        )

        elapsed_time = time.time() - start_time

        if response.status_code != 200:
            return f"## Error\n\nAPI Error: {response.status_code}"

        data = response.json()
        if not data.get("success"):
            return f"## Error\n\n{data.get('error', 'Unknown error')}"

        results = data.get("data", {}).get("results", {})
        quality_score = results.get("quality_score", 0)
        quality_tier = results.get("quality_tier", "UNKNOWN")
        solution_hash = results.get("solution_hash", "N/A")
        accelerator = data.get("data", {}).get("accelerator", "Unknown")

        # Resource calculations
        energy_j = HARDWARE_INFO["typical_power"] * elapsed_time
        cost_usd = (HARDWARE_INFO["cost_per_hour"] / 3600) * elapsed_time
        dwave = COMPETITORS["D-Wave Advantage"]
        dwave_energy = dwave["power"] * elapsed_time
        power_ratio = round(dwave_energy / energy_j) if energy_j > 0 else 0

        return f"""
## Ising Model Results

### Optimization Performance

| Metric | Value |
|--------|-------|
| Quality Score | **{quality_score:.1f}** |
| Quality Tier | **{quality_tier}** |
| Solution Hash | `{solution_hash}` |
| Accelerator | {accelerator} |

### Resources

| Metric | Daugherty | D-Wave Equivalent |
|--------|-----------|-------------------|
| Time | {elapsed_time:.3f}s | {elapsed_time:.3f}s |
| Energy | {energy_j:.1f} J | {dwave_energy:.1f} J |
| Cost | ${cost_usd:.6f} | ${(dwave["cost_per_hour"]/3600)*elapsed_time:.6f} |

**Efficiency: {power_ratio}x less power than D-Wave**

---
*{size} spins, {trials} trials*
"""

    except requests.exceptions.Timeout:
        return "## Error\n\nRequest timed out. Try smaller problem."
    except Exception as e:
        return f"## Error\n\n{str(e)}"


# Educational content
INTRO_MD = """
# Daugherty Engine

GPU-accelerated constraint satisfaction and combinatorial optimization.
Achieving quantum-competitive results on classical hardware.

## Available Tests

| Problem | Description | Quantum Equivalent |
|---------|-------------|-------------------|
| **3-SAT** | Boolean satisfiability at phase transition | Gate-based QC |
| **Ising** | Spin glass energy minimization | Quantum Annealing |
"""

ABOUT_SAT_MD = """
## Boolean Satisfiability (SAT)

### The Problem

Given a boolean formula in CNF (Conjunctive Normal Form):
```
(x₁ OR ¬x₂ OR x₃) AND (¬x₁ OR x₂ OR ¬x₄) AND ...
```

Find an assignment of TRUE/FALSE to each variable that satisfies ALL clauses.

### Why It Matters

- **First NP-Complete problem** (Cook-Levin theorem, 1971)
- **Universal reducer**: Most combinatorial problems can be encoded as SAT
- **Applications**: Circuit verification, AI planning, cryptanalysis, scheduling

### The Phase Transition

At α = 4.27 (clauses/variables ratio):
- **Below 4.27**: Almost always satisfiable
- **Above 4.27**: Almost always unsatisfiable
- **At 4.27**: Maximum uncertainty — **hardest instances**

We test at this critical threshold.
"""

ABOUT_ISING_MD = """
## Ising Model Optimization

### The Problem

The Ising model represents a system of interacting spins (±1):

```
H(s) = -Σᵢⱼ Jᵢⱼ sᵢ sⱼ - Σᵢ hᵢ sᵢ
```

Goal: Find spin configuration that minimizes total energy H.

### Why It Matters

- **Native to quantum annealers**: D-Wave's fundamental problem type
- **QUBO mapping**: Most optimization problems encode to Ising/QUBO
- **Applications**: Portfolio optimization, logistics, machine learning

### Connection to Quantum Computing

Quantum annealers (D-Wave) physically simulate the Ising model using superconducting qubits. Our approach achieves competitive results using GPU parallelism instead of quantum effects.
"""

HARDWARE_MD = f"""
## Hardware Comparison

### Daugherty Engine

| Spec | Value |
|------|-------|
| GPU | {HARDWARE_INFO["name"]} |
| VRAM | {HARDWARE_INFO["vram"]} GB |
| Architecture | {HARDWARE_INFO["architecture"]} |
| CUDA Cores | {HARDWARE_INFO["cuda_cores"]:,} |
| Power | {HARDWARE_INFO["typical_power"]}W typical |
| Cost | ${HARDWARE_INFO["cost_per_hour"]}/hour |

### Quantum Systems

| System | Qubits | Power | Cost/Hour |
|--------|--------|-------|-----------|
| D-Wave Advantage | 5,000 | ~25 kW | $13.20 |
| IBM Quantum | 127 | ~15 kW | $1.60 |
| Google Sycamore | 70 | ~25 kW | N/A |

### Key Insight

Quantum computers require:
- **Dilution refrigerators** (10-15 millikelvin)
- **Electromagnetic shielding**
- **Error correction overhead**

Our GPU approach avoids these requirements entirely.
"""

METHODOLOGY_MD = """
## Methodology

### SAT Verification

We measure **satisfaction rate** — percentage of clauses satisfied.

| Tier | Satisfaction | Meaning |
|------|-------------|---------|
| EXCELLENT | ≥95% | Near-optimal |
| GOOD | ≥85% | High quality |
| ACCEPTABLE | ≥70% | Reasonable |
| LOW | <70% | Very hard instance |

### Ising Verification

We measure **quality score** — normalized energy minimization quality.

| Tier | Meaning |
|------|---------|
| EXCELLENT | Ground state or near |
| GOOD | Low energy solution |
| ACCEPTABLE | Local minimum |
| POOR | High energy state |

### Why These Metrics?

At the phase transition, problems may be unsatisfiable. Satisfaction percentage captures solution quality even for UNSAT instances (MAX-SAT interpretation).
"""

LINKS_MD = """
## Resources

### Live Demos
- [Full Interactive Demo](https://1millionspins.originneural.ai) — Animated visualizations
- [Origin Neural](https://originneural.ai) — Company site

### Academic References
- Cook (1971) — "The Complexity of Theorem-Proving Procedures"
- Mézard et al. (2002) — "Random Satisfiability Problems"
- Kirkpatrick & Selman (1994) — "Critical Behavior in SAT"
- Barahona (1982) — "On the computational complexity of Ising spin glass models"

### Contact
**Shawn@smartledger.solutions**
"""


# Build Interface
with gr.Blocks(
    title="Daugherty Engine",
    theme=gr.themes.Soft(primary_hue="emerald"),
    css=".gradio-container { max-width: 1100px !important; }"
) as demo:

    gr.Markdown(INTRO_MD)

    with gr.Row():
        api_status = gr.Textbox(
            label="API Status",
            value=check_api_health(),
            interactive=False,
            scale=3
        )
        refresh_btn = gr.Button("Refresh", size="sm", scale=1)
        refresh_btn.click(fn=check_api_health, outputs=api_status)

    with gr.Tabs():
        # SAT Tab
        with gr.TabItem("3-SAT Solver"):
            with gr.Row():
                with gr.Column(scale=1):
                    sat_vars = gr.Slider(20, 500, 100, step=10, label="Variables")
                    sat_trials = gr.Slider(1, 20, 5, step=1, label="Trials")
                    sat_info = gr.Markdown(get_sat_difficulty(100))
                    sat_vars.change(get_sat_difficulty, sat_vars, sat_info)
                    sat_btn = gr.Button("Run SAT Verification", variant="primary")

                with gr.Column(scale=2):
                    sat_results = gr.Markdown("*Click 'Run SAT Verification' to test*")

            sat_btn.click(run_sat_verification, [sat_vars, sat_trials], sat_results)

        # Ising Tab
        with gr.TabItem("Ising Model"):
            with gr.Row():
                with gr.Column(scale=1):
                    ising_size = gr.Slider(10, 500, 50, step=10, label="Spins")
                    ising_trials = gr.Slider(1, 20, 5, step=1, label="Trials")
                    ising_info = gr.Markdown(get_ising_difficulty(50))
                    ising_size.change(get_ising_difficulty, ising_size, ising_info)
                    ising_btn = gr.Button("Run Ising Verification", variant="primary")

                with gr.Column(scale=2):
                    ising_results = gr.Markdown("*Click 'Run Ising Verification' to test*")

            ising_btn.click(run_ising_verification, [ising_size, ising_trials], ising_results)

        # Info Tabs
        with gr.TabItem("About SAT"):
            gr.Markdown(ABOUT_SAT_MD)

        with gr.TabItem("About Ising"):
            gr.Markdown(ABOUT_ISING_MD)

        with gr.TabItem("Hardware"):
            gr.Markdown(HARDWARE_MD)

        with gr.TabItem("Methodology"):
            gr.Markdown(METHODOLOGY_MD)

        with gr.TabItem("Links"):
            gr.Markdown(LINKS_MD)

    gr.Markdown("---")
    gr.Markdown(
        "*API-only demo — no proprietary code exposed. "
        "Built with [Gradio](https://gradio.app).*"
    )

if __name__ == "__main__":
    demo.launch()