Download build_quantum.py from Snapkitty/bob-ide: direct link, hf CLI and curl.
- Browser
- Download file 10.8 kB
-
https://huggingface.co/Snapkitty/bob-ide/resolve/main/build_quantum.py
- Command line
-
hf download hf://Snapkitty/bob-ide/build_quantum.py
-
curl -L -o build_quantum.py https://huggingface.co/Snapkitty/bob-ide/resolve/main/build_quantum.py
10.8 kB
| #!/usr/bin/env python3 | |
| """ | |
| build_quantum.py — Generate all BOB quantum civilization binding files via Nemotron (free) | |
| and push directly to sov-kernel-monster. | |
| """ | |
| import requests, base64, os, json, re | |
| from concurrent.futures import ThreadPoolExecutor, as_completed | |
| PAT = os.environ.get("PAT_TOKEN", "GH_PAT_REDACTED") | |
| OR_KEY = os.environ.get("OPENROUTER_API_KEY", "OPENROUTER_KEY_REDACTED") | |
| ORG = "SNAPKITTYWEST" | |
| REPO = "sov-kernel-monster" | |
| HDR = {"Authorization": f"token {PAT}"} | |
| MODEL = "nvidia/nemotron-3-ultra-550b-a55b:free" | |
| def ask(prompt): | |
| for model in [MODEL, "qwen/qwen-2.5-coder-32b-instruct"]: | |
| try: | |
| r = requests.post("https://openrouter.ai/api/v1/chat/completions", | |
| headers={"Authorization": f"Bearer {OR_KEY}", "HTTP-Referer": "https://snapkittywest.io"}, | |
| json={"model": model, "messages": [{"role":"user","content":prompt}], | |
| "temperature": 0.1, "max_tokens": 8192}, timeout=300) | |
| data = r.json() | |
| if "error" not in data: | |
| return data["choices"][0]["message"]["content"] | |
| except: pass | |
| return "" | |
| def push(path, content, msg="feat(quantum): add binding file"): | |
| if isinstance(content, str): content = content.encode("utf-8") | |
| r = requests.get(f"https://api.github.com/repos/{ORG}/{REPO}/contents/{path}", headers=HDR) | |
| sha = r.json().get("sha","") if r.status_code == 200 else "" | |
| body = {"message": msg, "content": base64.b64encode(content).decode()} | |
| if sha: body["sha"] = sha | |
| r = requests.put(f"https://api.github.com/repos/{ORG}/{REPO}/contents/{path}", headers=HDR, json=body) | |
| return r.status_code | |
| def clean(result): | |
| m = re.search(r'```[\w]*\n(.*?)```', result, re.DOTALL) | |
| if m: return m.group(1).strip() | |
| m2 = re.search(r'^(import |from |module |defmodule |package |use |#include|<svg|\[package\]|cmake_minimum)', result, re.MULTILINE) | |
| if m2: return result[m2.start():].strip() | |
| return result.strip() | |
| TASKS = [ | |
| ("julia/bob_quantum.jl", """Write complete Julia bindings for BOB Quantum Civilization Engine (600+ lines). | |
| File: julia/bob_quantum.jl | |
| Zero-copy C ABI interop via ccall to libbob_quantum.so. | |
| module BobQuantum. Structs: BobRNG, BobLattice, BobState, BobHamiltonian (all with Ptr{Cvoid}). | |
| All ccall wrappers loading from const LIBBOB path. | |
| Base.finalize for RAII cleanup. | |
| Functions: RNG(seed), Lattice(nx,ny,nz,coupling,seed;periodic), State(num_qubits), Hamiltonian(num_qubits), | |
| evolve!(lat,dt) -> (energy,entropy), energy(lat), entropy(lat), | |
| measure(state,rng;collapse) -> Int64, measure_shots(state,num_shots,rng) -> (counts,probs), | |
| normalize!(state), add_term!(H,matrix,coeff,qubits), expectation(H,state), | |
| evolve_exact!(state,H,dt), evolve_trotter!(state,H,dt,order=2), evolve_krylov!(state,H,dt,k=20). | |
| export all. Output ONLY Julia code."""), | |
| ("elixir/lib/bob_quantum.ex", """Write complete Elixir OTP bridge for BOB Quantum Civilization Engine (500+ lines). | |
| File: elixir/lib/bob_quantum.ex | |
| Use Rustler NIF declarations for all C ABI functions. | |
| GenServer wrappers: BobQuantum.RNG, BobQuantum.Lattice, BobQuantum.State — each with start_link, init, handle_call. | |
| RNG: uniform/1, normal/2, integer/3. | |
| Lattice: evolve/2 -> {energy, entropy}, energy/1, entropy/1. | |
| State: measure/2, amplitudes/1, normalize/1. | |
| Module BobQuantum with @spec declarations and defdelegate. | |
| Output ONLY Elixir code."""), | |
| ("nats/bob_subjects.go", """Write complete NATS message bus schema for BOB Quantum Civilization Engine (400+ lines). | |
| File: nats/bob_subjects.go | |
| Package bob. All subject constants: bob.lattice.create/evolve/energy/entropy, bob.state.create/measure/measure_shots, bob.hamiltonian.create/add_term/expectation, bob.evolve.exact/trotter/krylov, bob.rng.create/uniform/normal, bob.circuit.qft/grover/qpe, bob.proof.check/compile, bob.plasma.enforce/verify, bob.swarm.task.claim/complete, bob.bifrost.log/verify. | |
| All JSON payload structs for request/response pairs. | |
| Client struct with NewClient(urls) and Request(subject, req, resp, timeout) methods. | |
| Output ONLY Go code."""), | |
| ("rust/bob-quantum-sys/src/lib.rs", """Write complete Rust FFI crate for BOB Quantum Civilization Engine (800+ lines). | |
| File: rust/bob-quantum-sys/src/lib.rs | |
| #![allow non_upper_case_globals, non_camel_case_types, non_snake_case] | |
| Opaque types: bob_rng_t, bob_lattice_t, bob_state_t, bob_hamiltonian_t as *mut c_void. | |
| Error constants BOB_SUCCESS through BOB_ERROR_INVALID_GATE. | |
| #[link(name="bob_quantum")] extern "C" block with ALL function signatures. | |
| Safe wrappers: RNG, Lattice, State, Hamiltonian structs with Drop impls. | |
| BobError enum with From<c_int> and Display. | |
| Complex64 = num_complex::Complex<f64>. | |
| All methods return Result<T, BobError>. | |
| Output ONLY Rust code."""), | |
| ("rust/bob-quantum-sys/Cargo.toml", """Write Cargo.toml for bob-quantum-sys crate. | |
| [package] name="bob-quantum-sys" version="0.1.0" edition="2021" | |
| [lib] link-lib="bob_quantum" | |
| [dependencies] num-complex="0.4" libc="0.2" | |
| [build-dependencies] cc="1.0" | |
| Output ONLY TOML."""), | |
| ("smalltalk/BobQuantum.st", """Write complete Smalltalk bindings for BOB Quantum Civilization Engine (800+ lines). | |
| Pharo-compatible. Classes: BobQuantumLibrary (singleton, loads libbob_quantum.so via FFI), | |
| BobRNG, BobLattice, BobState, BobHamiltonian, BobQuantumWorld. | |
| Use Pharo ExternalFunction and ExternalAddress for C ABI calls. | |
| BobQuantumWorld: createLattice:ny:nz:coupling:, runSimulation:steps:dt:, visualize. | |
| Output ONLY Smalltalk code."""), | |
| ("r/bob_quantum.R", """Write complete R bindings for BOB Quantum Civilization Engine (600+ lines). | |
| Use .Call() to C ABI. Functions: bob.rng.create(seed), bob.rng.uniform(rng), bob.rng.normal(rng,mean,sd), | |
| bob.lattice.create(nx,ny,nz,coupling,seed,periodic), bob.lattice.evolve(lattice,dt), | |
| bob.lattice.energy(lattice), bob.lattice.entropy(lattice), | |
| bob.state.create(num_qubits), bob.state.measure(state,rng,collapse), | |
| bob.state.measure_shots(state,num_shots,rng), bob.hamiltonian.create(num_qubits), | |
| bob.hamiltonian.add_term(h,matrix,coeff,qubits), bob.hamiltonian.expectation(h,state). | |
| ggplot2 visualization: plot_entropy_evolution(), plot_state_probabilities(), plot_lattice_energy(). | |
| Output ONLY R code."""), | |
| ("include/bob_quantum.h", """Write complete C header for BOB Quantum Civilization Engine. | |
| File: include/bob_quantum.h | |
| #pragma once, #include <stdint.h>, #include <stdbool.h> | |
| Opaque handle typedefs. Error code enum BOB_ERROR_*. | |
| ALL function declarations matching Fortran bind(C) exports: | |
| bob_rng_create/destroy/seed/uniform/normal/integer, | |
| bob_lattice_create/destroy/evolve/get_energy/entanglement_entropy, | |
| bob_state_create/destroy/normalize/get_amplitude/set_amplitude/measure/measure_qubit/measure_shots, | |
| bob_hamiltonian_create/destroy/add_term/expectation, | |
| bob_evolve_exact/trotter/krylov, bob_error_string/get_last_error. | |
| extern "C" guards. Output ONLY C header."""), | |
| ("CMakeLists.txt", """Write complete CMakeLists.txt for BOB Quantum Civilization Engine. | |
| cmake_minimum_required(VERSION 3.20). project(sov-kernel-monster Fortran C). | |
| Find gfortran. Build libbob_quantum.so from all src/*.f90 with -std=f2018 -O3 -fPIC -march=native. | |
| add_library(bob_quantum SHARED src/*.f90). | |
| set_target_properties with VERSION 1.0.0. | |
| install targets. enable_testing(). add_subdirectory(tests) if exists. | |
| Output ONLY CMake."""), | |
| ("fpm.toml", """Write fpm.toml for BOB Quantum Civilization Engine. | |
| name = "sov-kernel-monster" | |
| version = "1.0.0" | |
| license = "Apache-2.0" | |
| [build] auto-executables=false auto-tests=true | |
| [fortran] implicit-typing=false implicit-external=false source-form="free" | |
| [library] source-dir="src" | |
| Extra flags: -O3 -march=native -fPIC -std=f2018 | |
| Output ONLY TOML."""), | |
| ("build.py", """Write build.py — master build orchestrator for BOB Quantum Civilization Engine. | |
| Builds: 1) libbob_quantum.so via cmake, 2) Rust crate via cargo, 3) Fortran tests via fpm, | |
| 4) Julia package test, 5) Elixir mix compile, 6) R CMD build, 7) Lean4 lake build, 8) Go NATS build. | |
| argparse: --release, --test, --lang LANG (build single language), --all. | |
| Uses subprocess, pathlib, shutil. Colored output via print with ANSI codes. | |
| Output ONLY Python code."""), | |
| (".github/workflows/build.yml", """Write .github/workflows/build.yml for BOB Quantum Civilization Engine. | |
| name: Build All Languages. on: push, pull_request. | |
| jobs: build on ubuntu-latest. | |
| Steps: checkout, setup gfortran (sudo apt-get install gfortran), | |
| setup rust (rustup), setup julia (julia-actions/setup-julia@v1), | |
| setup elixir (erlef/setup-beam@v1), setup R (r-lib/actions/setup-r@v2), | |
| install lake via elan, setup go, cmake build, cargo build, fpm test, | |
| julia test, mix test, R CMD check, lake build. | |
| Cache: cargo, julia depot, R packages. | |
| Output ONLY YAML."""), | |
| ("docs/quantum_world.svg", """Create an interactive animated SVG for BOB Quantum Civilization Engine. | |
| viewBox="0 0 1200 800". Self-contained. Use SMIL animations. | |
| Show: | |
| 1. Central Fortran quantum kernel (gold hexagon, pulsing glow animation) | |
| 2. 7 language bindings in orbit: Julia (purple), Elixir (violet), Rust (orange), Lean4 (green), Smalltalk (blue), R (teal), NATS/Go (cyan) — each as labeled circle orbiting the center | |
| 3. Animated data flow arrows between them (animateMotion along orbit paths) | |
| 4. 4x4 quantum lattice grid in bottom-left with vortex nodes (circles changing color based on quantum state) | |
| 5. Born rule probability bars animating in bottom-right | |
| 6. PLASMA GATE hexagon barrier in top-right with particle flow animation | |
| 7. Title: BOB Quantum Civilization Engine | |
| Colors: quantum blue #0A84FF, gold #FFD60A, green #30D158, red #FF453A, background #000000 | |
| Output ONLY SVG starting with <svg."""), | |
| ] | |
| def process(task): | |
| path, prompt = task | |
| print(f" -> {path}") | |
| result = ask(prompt) | |
| if not result or len(result) < 50: | |
| print(f" ✗ {path}: empty response") | |
| return path, False | |
| code = clean(result) | |
| status = push(path, code, f"feat(quantum): {path} — BOB civilization engine") | |
| ok = status in (200, 201) | |
| print(f" {'OK' if ok else 'FAIL'} {path}: HTTP {status} ({len(code)} chars)") | |
| return path, ok | |
| print(f"BOB Quantum Civilization Engine — {len(TASKS)} files") | |
| print(f"Target: https://github.com/{ORG}/{REPO}") | |
| print() | |
| results = {} | |
| with ThreadPoolExecutor(max_workers=4) as pool: | |
| futures = {pool.submit(process, t): t[0] for t in TASKS} | |
| for f in as_completed(futures): | |
| path, ok = f.result() | |
| results[path] = ok | |
| pushed = sum(1 for v in results.values() if v) | |
| print(f"\nDone: {pushed}/{len(TASKS)} files pushed to {ORG}/{REPO}") | |