SilverSight/python/dna_webgpu.html
allaunthefox 7327775e16 feat(dna): add remaining source files and surface images
- python/dna_qubo_sort.py — QUBO-DNA sort with SAM/FASTA export
- python/dna_webgpu.html — WebGPU browser demo
- .openclaw/tmp/surface/*.bmp — rendered surface images
2026-06-23 02:27:40 +00:00

96 lines
3.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>DNA Braid Sort: WebGPU QUBO Solver</title>
<style>
body { font-family: monospace; background: #0a0a0a; color: #0f0; padding: 2em; }
h1 { color: #0ff; }
#output { white-space: pre; line-height: 1.4; }
.optimal { color: #ff0; }
.error { color: #f00; }
.info { color: #888; }
</style>
</head>
<body>
<h1>🧬 DNA Braid Sort — WebGPU QUBO Solver</h1>
<p class="info">Treats GPU actions as triangle math. Braid crossings = compare-swap. Eigensolid = sorted output.</p>
<div id="output">Initializing WebGPU...</div>
<script src="dna_webgpu.js"></script>
<script>
const output = document.getElementById('output');
function log(msg, cls = '') {
const span = document.createElement('span');
span.className = cls;
span.textContent = msg + '\n';
output.appendChild(span);
}
async function run() {
try {
if (!navigator.gpu) {
log('ERROR: WebGPU not supported in this browser.', 'error');
log('Try Chrome 113+ or Edge 113+ with --enable-unsafe-webgpu flag.', 'info');
return;
}
log('='.repeat(60));
log('DNA Braid Sort: WebGPU QUBO Solver');
log('='.repeat(60));
const solver = new DNABraidSolver();
await solver.init();
log('✓ WebGPU initialized');
// Run demos
for (const nVars of [10, 12, 14]) {
const Q = generateBandedQUBO(nVars, 42);
const n = 1 << nVars;
log(`\n--- ${nVars} variables, ${n.toLocaleString()} solutions ---`);
const result = await solver.solveQUBO(Q, nVars);
log(`Optimal: x=[${result.solution.slice(0, 8)}...], E=${result.energy.toFixed(4)}`, 'optimal');
log(`Encode: ${result.encodeTime.toFixed(1)}ms`);
log(`Sort: ${result.sortTime.toFixed(1)}ms`);
log(`Total: ${result.totalTime.toFixed(1)}ms`);
}
log('\n' + '='.repeat(60));
log('DONE');
} catch (e) {
log(`ERROR: ${e.message}`, 'error');
console.error(e);
}
}
function generateBandedQUBO(n, seed) {
const rng = mulberry32(seed);
const Q = Array.from({ length: n }, () => Array(n).fill(0));
for (let i = 0; i < n; i++) {
Q[i][i] = 2 + rng() * 6;
if (i + 1 < n) {
const c = -(0.5 + rng() * 2.5);
Q[i][i + 1] = c;
Q[i + 1][i] = c;
}
}
return Q;
}
function mulberry32(seed) {
return function() {
seed |= 0; seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
run();
</script>
</body>
</html>