Spaces:
Sleeping
Sleeping
| """ | |
| Daugherty Engine - SAT Solver Demo | |
| API-only interface for testing constraint satisfaction solving. | |
| 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 | |
| import json | |
| # Public API endpoint | |
| API_BASE = "https://1millionspins.originneural.ai/api" | |
| # Hardware specs (public information from DigitalOcean pricing) | |
| HARDWARE_INFO = { | |
| "accelerator": "NVIDIA RTX 6000 Ada (48GB VRAM)", | |
| "cost_per_hour": 1.57, | |
| "typical_power": 195, # Watts | |
| } | |
| # Competitor reference data (public sources) | |
| COMPETITORS = { | |
| "D-Wave Advantage": {"power": 25000, "cost_per_hour": 13.20}, | |
| "IBM Quantum": {"power": 15000, "cost_per_hour": 1.60}, | |
| } | |
| 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() | |
| return f"Online - GPU: {data.get('gpu', 'Unknown')}" | |
| return "Offline" | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| def run_verification(num_variables: int, num_trials: int, progress=gr.Progress()): | |
| """ | |
| Run SAT verification through the public API. | |
| Args: | |
| num_variables: Number of variables (20-500) | |
| num_trials: Number of verification trials (1-20) | |
| Returns: | |
| Results dictionary with metrics and comparisons | |
| """ | |
| # Validate inputs | |
| num_variables = max(20, min(500, int(num_variables))) | |
| num_trials = max(1, min(20, int(num_trials))) | |
| progress(0.1, desc="Generating SAT problem...") | |
| # Calculate problem parameters | |
| alpha = 4.27 # Phase transition ratio | |
| num_clauses = int(num_variables * alpha) | |
| start_time = time.time() | |
| try: | |
| progress(0.3, desc="Sending to Daugherty Engine API...") | |
| response = requests.post( | |
| f"{API_BASE}/verify", | |
| json={ | |
| "size": num_variables, | |
| "trials": num_trials | |
| }, | |
| timeout=120 | |
| ) | |
| elapsed_time = time.time() - start_time | |
| if response.status_code != 200: | |
| return format_error(f"API Error: {response.status_code}") | |
| data = response.json() | |
| if data.get("status") != "success": | |
| return format_error(data.get("error", "Unknown error")) | |
| progress(0.8, desc="Processing results...") | |
| results = data.get("data", {}).get("results", {}) | |
| # Calculate metrics | |
| mean_satisfaction = results.get("mean_satisfaction", 0) | |
| std_satisfaction = results.get("std_satisfaction", 0) | |
| quality_tier = results.get("quality_tier", "UNKNOWN") | |
| # Energy calculation | |
| energy_joules = HARDWARE_INFO["typical_power"] * elapsed_time | |
| cost_usd = (HARDWARE_INFO["cost_per_hour"] / 3600) * elapsed_time | |
| # Competitor comparisons | |
| dwave_energy = COMPETITORS["D-Wave Advantage"]["power"] * elapsed_time | |
| power_ratio = round(dwave_energy / energy_joules) if energy_joules > 0 else 0 | |
| cost_ratio = round(COMPETITORS["D-Wave Advantage"]["cost_per_hour"] / HARDWARE_INFO["cost_per_hour"]) | |
| progress(1.0, desc="Complete!") | |
| return format_results( | |
| num_variables=num_variables, | |
| num_clauses=num_clauses, | |
| num_trials=num_trials, | |
| mean_satisfaction=mean_satisfaction, | |
| std_satisfaction=std_satisfaction, | |
| quality_tier=quality_tier, | |
| elapsed_time=elapsed_time, | |
| energy_joules=energy_joules, | |
| cost_usd=cost_usd, | |
| power_ratio=power_ratio, | |
| cost_ratio=cost_ratio, | |
| blockchain=data.get("data", {}).get("blockchain", {}) | |
| ) | |
| except requests.exceptions.Timeout: | |
| return format_error("Request timed out. Try a smaller problem size.") | |
| except requests.exceptions.ConnectionError: | |
| return format_error("Could not connect to API. Check your internet connection.") | |
| except Exception as e: | |
| return format_error(f"Unexpected error: {str(e)}") | |
| def format_results(**kwargs): | |
| """Format results as markdown.""" | |
| blockchain = kwargs.get("blockchain", {}) | |
| txid = blockchain.get("txid", "") | |
| bsv_link = "" | |
| if txid: | |
| bsv_link = f"\n\n**Blockchain Proof:** [{txid[:16]}...](https://whatsonchain.com/tx/{txid})" | |
| return f""" | |
| ## Verification Results | |
| ### Problem Configuration | |
| - **Variables:** {kwargs['num_variables']} | |
| - **Clauses:** {kwargs['num_clauses']} (ratio: 4.27) | |
| - **Trials:** {kwargs['num_trials']} | |
| ### Performance | |
| | Metric | Value | | |
| |--------|-------| | |
| | Satisfaction | **{kwargs['mean_satisfaction']:.1f}%** (std: {kwargs['std_satisfaction']:.2f}) | | |
| | Quality Tier | **{kwargs['quality_tier']}** | | |
| | Solve Time | {kwargs['elapsed_time']:.3f}s | | |
| | Energy | {kwargs['energy_joules']:.1f}J | | |
| | Cost | ${kwargs['cost_usd']:.6f} | | |
| ### Efficiency vs Quantum Computers | |
| | Comparison | Ratio | | |
| |------------|-------| | |
| | Power Efficiency vs D-Wave | **{kwargs['power_ratio']}x** less power | | |
| | Cost Efficiency vs D-Wave | **{kwargs['cost_ratio']}x** cheaper | | |
| {bsv_link} | |
| --- | |
| *Computed on {HARDWARE_INFO['accelerator']}* | |
| """ | |
| def format_error(message: str): | |
| """Format error message.""" | |
| return f""" | |
| ## Error | |
| {message} | |
| Please try again or reduce the problem size. | |
| """ | |
| def get_problem_info(num_variables: int): | |
| """Get information about the problem that will be generated.""" | |
| num_variables = max(20, min(500, int(num_variables))) | |
| num_clauses = int(num_variables * 4.27) | |
| search_space = 2 ** num_variables | |
| return f""" | |
| **Problem Preview:** | |
| - Variables: {num_variables} | |
| - Clauses: {num_clauses} | |
| - Search Space: 2^{num_variables} = {search_space:.2e} possibilities | |
| - Difficulty: {"Easy" if num_variables < 100 else "Medium" if num_variables < 300 else "Hard"} | |
| """ | |
| # Build Gradio Interface | |
| with gr.Blocks( | |
| title="Daugherty Engine - SAT Solver Demo", | |
| theme=gr.themes.Base( | |
| primary_hue="green", | |
| secondary_hue="gray", | |
| neutral_hue="gray", | |
| ), | |
| css=""" | |
| .gradio-container { max-width: 900px !important; } | |
| .result-box { font-family: monospace; } | |
| """ | |
| ) as demo: | |
| gr.Markdown(""" | |
| # Daugherty Engine - Constraint Satisfaction Solver | |
| Test our GPU-accelerated SAT solver through the public API. | |
| No code is exposed - this interface simply calls the verification endpoint. | |
| **What it does:** Generates random 3-SAT problems at the phase transition (hardest region) | |
| and attempts to find satisfying assignments using our proprietary solver. | |
| """) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| api_status = gr.Textbox( | |
| label="API Status", | |
| value=check_api_health(), | |
| interactive=False | |
| ) | |
| refresh_btn = gr.Button("Refresh Status", size="sm") | |
| refresh_btn.click(fn=check_api_health, outputs=api_status) | |
| gr.Markdown("---") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| num_vars = gr.Slider( | |
| minimum=20, | |
| maximum=500, | |
| value=100, | |
| step=10, | |
| label="Number of Variables", | |
| info="More variables = harder problem" | |
| ) | |
| num_trials = gr.Slider( | |
| minimum=1, | |
| maximum=20, | |
| value=5, | |
| step=1, | |
| label="Verification Trials", | |
| info="More trials = higher confidence" | |
| ) | |
| problem_info = gr.Markdown(get_problem_info(100)) | |
| num_vars.change(fn=get_problem_info, inputs=num_vars, outputs=problem_info) | |
| run_btn = gr.Button("Run Verification", variant="primary", size="lg") | |
| with gr.Column(scale=2): | |
| results = gr.Markdown( | |
| value="*Click 'Run Verification' to test the solver*", | |
| elem_classes=["result-box"] | |
| ) | |
| run_btn.click( | |
| fn=run_verification, | |
| inputs=[num_vars, num_trials], | |
| outputs=results | |
| ) | |
| gr.Markdown(""" | |
| --- | |
| ### About | |
| The Daugherty Engine is a novel approach to constraint satisfaction that achieves | |
| quantum-competitive results on classical GPU hardware. This demo provides API access | |
| only - no proprietary algorithms or source code are exposed. | |
| **Links:** | |
| - [Full Demo Site](https://1millionspins.originneural.ai) | |
| - [Origin Neural](https://originneural.ai) | |
| **Hardware:** NVIDIA RTX 6000 Ada (48GB VRAM) @ $1.57/hour | |
| """) | |
| if __name__ == "__main__": | |
| demo.launch() | |