lkb-pipeline/run.sh
allaun e5bfdc0492 feat: LKB compute pipeline + eigensolid receipts
Containerized LKB worker (Dockerfile.lkb), Postgres-backed queue,
auto-deploy timer, and eigensolid convergence check module.

Build: 0 jobs (no Lean build needed)
2026-07-08 20:01:29 -05:00

77 lines
No EOL
2.3 KiB
Bash
Executable file

#!/usr/bin/env Rscript
args <- commandArgs(trailingOnly = TRUE)
role <- if (length(args) >= 1) args[1] else "worker"
source("boot.R")
box_use("Rcpp")
Rcpp::sourceCpp("src/laurent_ops.cpp")
box_use("./core/laurent2")
box_use("./core/lkb")
DB_HOST <- Sys.getenv("PGHOST", "100.79.14.103")
box_use("DBI"); box_use("RPostgres")
con <- DBI::dbConnect(RPostgres::Postgres(),
host = DB_HOST, dbname = "research_stack",
user = "kaleidoscope", password = "kaleidoscope")
on.exit(DBI::dbDisconnect(con))
if (role == "seed") {
box_use("./core/lkb_store")
lkb_store$reap_stuck_jobs(con)
lkb_store$seed_generators(con, 4)
cat("[seed] generators seeded for B4\n")
q(save = "no", status = 0)
}
if (role == "eigensolid") {
box_use("./core/eigensolid")
eigensolid$run_eigensolid(con)
cat("[eigensolid] done\n")
q(save = "no", status = 0)
}
if (role != "worker") {
cat(sprintf("Unknown role: %s — try seed, worker, or eigensolid\n", role))
q(save = "no", status = 1)
}
n_jobs <- 0L
repeat {
row <- tryCatch({
DBI::dbGetQuery(con, "UPDATE lkb.compute_queue SET status = 'running', started_at = now()
WHERE equation_id = (SELECT equation_id FROM lkb.compute_queue
WHERE status = 'pending' ORDER BY word_length, equation_id LIMIT 1 FOR UPDATE SKIP LOCKED)
RETURNING *")
}, error = function(e) data.frame())
if (nrow(row) == 0) break
eq_id <- row$equation_id[[1]]
n <- row$n[[1]]
word_str <- row$braid_word[[1]]
cat(sprintf("[%s] B%d, %d gens\n", eq_id, n, nchar(word_str)))
tryCatch({
if (word_str == "ID" || is.na(word_str) || word_str == "") {
entry <- "1"
} else {
steps <- as.integer(strsplit(word_str, ",")[[1]])
gens <- lkb$lkb_generators(n)
N <- n * (n - 1) / 2
mat <- laurent2$l2_mat_identity(N)
for (g in steps) mat <- laurent2$l2_mat_mul(mat, gens[[g]])
entry <- laurent2$l2_str(mat[[1, 3]])
}
esc <- gsub("'", "''", entry)
DBI::dbExecute(con, sprintf(
"UPDATE lkb.compute_queue SET status = 'done', result_entry = '%s', finished_at = now() WHERE equation_id = '%s'",
esc, eq_id))
n_jobs <- n_jobs + 1
cat(sprintf(" done (%d)\n", n_jobs))
}, error = function(e) {
cat(sprintf(" ERROR: %s\n", conditionMessage(e)), file = stderr())
})
}
cat(sprintf("[worker] finished — %d jobs\n", n_jobs))
q(save = "no", status = 0)