Spaces:
Running
Running
| """ | |
| 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() | |