aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
GitHub aien-dev/aien-train#47 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/aien-train/patches/8bbecd6de57e85e2.bundle -o 8bbecd6de57e85e2.bundle git fetch 8bbecd6de57e85e2.bundle refs/pull/47/head
Provenance
github-import 1
aien-dev/aien-train
47
96f8aafc746098e1b5a972f8f0cee10dfb0eb995
{"kind":"github-import","owner":"aien-dev","repo":"aien-train","number":47,"url":"https://github.com/aien-dev/aien-train/pull/47","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:34Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/docs/omegese45/TRANSLATOR.md b/docs/omegese45/TRANSLATOR.md new file mode 100644 index 0000000..39f3e43 --- /dev/null +++ b/docs/omegese45/TRANSLATOR.md @@ -0,0 +1,160 @@ +# Omegese #45 translator (en2goal, goal2en, rep2en) + +Issue: [aien-dev/aien-train#45](https://github.com/aien-dev/aien-train/issues/45). The translator is the only place English exists in the product path. It is deterministic, rule-based `.om`. It loads no model and no checkpoint, and it is built and tested separately from the core (`tests/omegese45/translator/run-translator.sh` builds only the units listed below). + +Status: IMPLEMENTED and EXERCISED on the GB10 Spark Grace CPU, cores 10-14, nice 19. Receipt: [`evidence/OMEGESE45/translator/`](../../evidence/OMEGESE45/translator/). + +## Build units (concatenation, pinned omc bf54b19f, sha256 `62775d2a…3712b`) + +| Binary | Units, in order | +| --- | --- | +| en2goal | `translate/otio.om translate/en2goal.om translate/otfrag.om translate/main-en2goal.om` | +| goal2en | `translate/otio.om vocab.om msg.om translate/otmsg.om translate/goal2en.om translate/otfrag.om translate/main-goal2en.om` | +| rep2en | `translate/otio.om vocab.om msg.om translate/otmsg.om translate/rep2en.om translate/otfrag.om translate/main-rep2en.om` | + +All paths are under `native/omegese45/`. goal2en and rep2en validate every G and P line with the contract lane's `ocsetgl` and `ocvline` (`vocab.om`, `msg.om`, contract commit fa57fdf). The translator does not re-implement the R45 grammar. All translator names start with `ot`. + +## Exit codes + +| Code | Tool | Meaning | stdout | +| --- | --- | --- | --- | +| 0 | all | success | the G line or the English sentence | +| 2 | all | usage, or a stdin read or stdout write error | usage line | +| 20 EN_UNSUPPORTED | en2goal | no rule matches, empty or blank input, over 512 bytes, or a byte outside TAB and 0x20..0x7e | `EN_UNSUPPORTED` | +| 21 EN_RANGE | en2goal | a dim above 4095, a seed above 65535, or a malformed number (interface v1.2 §4; dim 0 is accepted) | `EN_RANGE` | +| 22 EN_SHAPE | en2goal | the inner dims differ (k of the left matrix ≠ rows of the right) | `EN_SHAPE` | +| 23 EN_AMBIG | en2goal | more than one reading | `EN_AMBIG` | +| 30 G2E_CONTRADICT | rep2en | P contradicts G or the runtime facts; no success is printed | `G2E_CONTRADICT <what>` | +| 31 G2E_INVALID | goal2en, rep2en | an input is invalid | `G2E_INVALID <what>` | + +Dims 0 and 257..4095 pass through en2goal: D can encode 0x000..0xfff, and the core refuses those dims (code `bound`), not the translator (interface v1.2 §4, review finding T3). + +## en2goal grammar + +**Normalization** (`otnorm`): +- A-Z are lowercased. +- Space, TAB and `, ; : ? ! ( ) "` separate words. +- `.` separates words unless a digit is on both sides. In that case it stays inside the word, so `2.5` is a malformed number. +- An `x` next to a digit becomes a word of its own, so `4x8x2` reads as `4 x 8 x 2`. + +**Numbers:** a word that starts with a digit, or with `+`/`-` followed by a digit, fills a number slot. The word must be 1..9 decimal digits; anything else is malformed and gives 21. Leading zeros are accepted. + +**Rules:** this is the `text otrules` table in `en2goal.om`, verbatim. A rule must match the whole word sequence. `a/b` lists literal alternatives, and `?` marks the word as optional. `#m #k` are the left matrix dims, `#j #n` the right matrix dims, `#s` the seed and `#t` the second seed. + +``` +m ?please multiply a/an #m by #k matrix by/with/times a/an #j by #n matrix with seed #s +m ?please ?run/do/compute/submit ?a/an/one matmul/matmul_u32 ?job ?of ?size #m x #k x #n ?with seed #s +m goal for review one matmul_u32 job multiplying a/an #m by #k matrix by a/an #j by #n matrix with seed #s +p ?please ?run/do/compute/submit two matmuls/matmul/matmul_u32s/matmul_u32 ?jobs ?of ?size #m x #k x #n ?with seeds #s and #t +p matmuls #m x #k x #n ?with seeds #s ?and #t +p ?please multiply a/an #m by #k matrix by/with/times a/an #j by #n matrix twice with seeds #s and #t +p goal for review two matmul_u32 jobs each multiplying a/an #m by #k matrix by a/an #j by #n matrix with seeds #s and #t in that order +x ?please ?run/do/compute/submit ?a/an/one matmul/matmul_u32 ?job ?of ?size #m x #k x #n ?with seeds #s ?and #t +x ?please ?run/do/compute/submit two matmuls/matmul/matmul_u32s/matmul_u32 ?jobs ?of ?size #m x #k x #n ?with seed #s +x ?please multiply a/an #m by #k matrix by/with/times a/an #j by #n matrix with seeds #s and #t +x ?please ?run/do/compute/submit ?a/an/one matmul/matmul_u32 ?job ?of ?size #m x #k x #n ?with seed #s and/or ?seed #t +x ?please ?run/do/compute/submit ?a/an/one matmul/matmul_u32 ?job ?of ?size #m x #k x #n ?with seed #s seed #t +``` + +**Decision:** +1. If any `x` rule matches, or two `m`/`p` rules give different readings, the result is 23. +2. If no rule matches, the result is 20. +3. Otherwise a range or malformed-number failure gives 21. +4. Otherwise `j ≠ k` gives 22. +5. Otherwise the G line is printed: `goal mm ushort 0xMMM ushort 0xKKK ushort 0xNNN ulong 0xSSSS end` or `goal pair … ulong 0xSSSS ulong 0xTTTT end`, in lowercase hex. + +## goal2en templates (fixed) + +- mm: `Goal for review: one matmul_u32 job multiplying a {m} by {k} matrix by a {k} by {n} matrix with seed {s}.` +- pair: `Goal for review: two matmul_u32 jobs, each multiplying a {m} by {k} matrix by a {k} by {n} matrix, with seeds {s1} and {s2} in that order.` +- Invalid G: `G2E_INVALID goal <reason>`, where the reason is the contract reason word (for example `grammar`); exit 31. + +The article is always `a`. Every value is decimal. Both sentences are in the en2goal grammar, and the suite checks that re-parsing them gives the same G. + +## rep2en + +**CLI:** `rep2en FACTS_TSV`. stdin carries the G line, then the P line. + +**Facts format** (interface v1.2 §5): facts.tsv has 13 TAB-separated columns: job attempt m k n seed exit class code dag_id mjr1_sha256 mjr1_outcome verifier. +- The first line must be exactly the header `job attempt m k n seed exit class code dag_id mjr1_sha256 mjr1_outcome verifier` (TAB-separated, LF). +- A file with only the header means nothing was dispatched. + +**Validity:** any of the following gives `G2E_INVALID facts` with exit 31: +- a missing or different header line; +- a row that is not 13 fields; +- job, attempt, m, k, n, seed or exit that is not 1..9 decimal digits; +- a class not in ok/refused/fail; +- an ok row whose exit is not 0, whose code is not `-`, whose dag_id/mjr1_sha256 is not 64 lowercase hex, whose mjr1_outcome is not `1` (MJR1 completed), or whose verifier is not 66 lowercase hex starting `02` or `03` (P-256 compressed key); +- a refused/fail row whose code is `-` or not one of replay budget worker transport receipt recomp verdict io, whose mjr1_outcome or verifier is not `-`, or whose dag_id or mjr1_sha256 is neither `-` nor 64 lowercase hex (a non-ok row may carry a real dag_id, and a receipt digest when a receipt exists); +- a class/code/exit triple outside the aienet0-run map: `refused` replay, budget or worker with exit 11; `fail` transport 10, receipt 12, recomp 13, verdict 14, io 15 (an ok row has exit 0); +- an illegal history: jobs must appear in order starting at job 1, each starting with attempt 1; a second row for the same job is legal only as attempt 2 right after an attempt-1 `fail transport`; a row for the next job is legal only after the previous job's last row was ok. So no row follows a job's ok row, every attempt is 1 or 2 and increases within a job, every non-ok row other than one retried transport failure is the last row, and in a refused/fail report every earlier job ended ok; +- an empty interior line; +- more than 64 rows or 65536 bytes; +- an unreadable file. + +**Templates** (fixed; values come only from G and facts.tsv): + +| Case | Sentence | +| --- | --- | +| ok mm | `Completed and verified: one matmul_u32 job multiplying a {m} by {k} matrix by a {k} by {n} matrix with seed {s}; job 1 dag_id {dag1} mjr1_sha256 {sha1}.` | +| ok pair | `Completed and verified: two matmul_u32 jobs, each multiplying a {m} by {k} matrix by a {k} by {n} matrix, with seeds {s1} and {s2}; job 1 dag_id {dag1} mjr1_sha256 {sha1}; job 2 dag_id {dag2} mjr1_sha256 {sha2}.` | +| refused bound | `Not completed: refused before dispatch (code bound): the goal asks for a {m} by {k} by {n} matmul and a dimension is outside the admitted range 1 to 256; nothing was dispatched.` | +| refused C | `Not completed: job {j} was refused (code {C}): {plain}.` | +| fail C | `Not completed: job {j} failed (code {C}): {plain}.` | + +{dag}/{sha} are the dag_id/mjr1_sha256 of that job's last facts row; {j} is the job of the last facts row. + +**Plain words:** + +| Code | Plain words | +| --- | --- | +| replay | the worker refused a replay of an already executed job | +| budget | the job was refused for budget or fuel | +| worker | the worker refused the job | +| transport | the connection to the worker failed | +| receipt | the verifier refused the worker receipt | +| recomp | the verifier recompute failed | +| verdict | the recomputed result did not match the worker result | +| io | a local input or output error occurred | + +**Checks, in order:** +1. An invalid G gives `G2E_INVALID goal <reason>`, an invalid P `G2E_INVALID report <reason>`, malformed stdin `G2E_INVALID input` and an invalid facts file (every rule under **Validity**, header and history included) `G2E_INVALID facts`, all with exit 31. +2. P ok whose kind or operands differ from G gives `G2E_CONTRADICT operands`. +3. Every facts row: + - a job outside 1..(1 or 2) gives `G2E_CONTRADICT jobs`; + - m/k/n differing from G, or a seed differing from G's seed for that job, gives `G2E_CONTRADICT operands`. +4. P ok: + - every job of G needs a last row with class ok (hence exit 0), otherwise `jobs` (missing) or `class`; + - if the check passes, the success template is printed. +5. P refused bound: facts must have no rows (`bound` otherwise) and a G dim must be outside 1..256 (`bound` otherwise). +6. P refused/fail C: + - facts must have rows (`dispatch` otherwise); + - the last row must have the same class (`class` otherwise) and the same code (`code` otherwise). + +A retried job (an attempt-1 `fail transport` row, then an attempt-2 row for the same job) is decided by its attempt-2 row. + +## Measured accuracy and cost (receipt: `evidence/OMEGESE45/translator/suite.txt`) + +- **Dev cases** (`tests/omegese45/translator/cases.tsv`; the four required phrasings, boundaries dims 0 (accepted, G with `0x000`), 1, 256, 257, 4095, 4096, seeds 65535/65536, and every refusal code): exact 18 of 18. +- **Held-out set** (`tests/omegese45/translator/heldout.tsv`, committed in faeb7ad before the parser existed and never edited after): + - Raw, against the committed file (primary number): exact 38, refused differently 6, wrong 1, total 45 (84.44% / 13.33% / 2.22%; WolframLanguageEvaluator: `N[{38/45, 6/45, 1/45}*100, 4]`). + - The 1 wrong row is row 12 ("a 0 by 6 matrix"), written as `refuse 21` under the old rule. Interface v1.2 §4 then pinned that dim 0 is accepted and refused by the core, so en2goal now emits `goal mm ushort 0x000 ushort 0x006 ushort 0x008 ulong 0x0003 end`. The dated erratum, with its reason, is in [`heldout-errata.tsv`](../../tests/omegese45/translator/heldout-errata.tsv); the suite checks that each erratum's original equals the committed expectation. + - With the errata applied: exact 39, refused differently 6, wrong 0 (86.67% exact). PASS requires raw wrong ≤ the number of errata rows and wrong 0 with the errata, and the receipt prints both numbers and every erratum. + - Five supported-in-intent phrasings are refused with 20: "using seed", "two 4 by 4 matrices", "run 2 matmuls", a trailing "please", "4 by 8 by 2". + - "seed 0x10" gets 20 where 21 was expected. +- **Stability:** 29 distinct G lines (dev plus errata-corrected held-out); goal2en then en2goal reproduces each one. +- **rep2en:** + - 9 English cases: ok mm, ok pair, retry-then-ok, retry-then-fail, bound, refused replay, fail transport, pair with job 2 refused, a fail row carrying dag_id and digest; + - 10 contradiction cases (exit 30), including `x-bound-dispatched`, whose facts row matches G (300 2 2, seed 1) so it reaches the `bound` check (`G2E_CONTRADICT bound`; review finding T5); + - 30 invalid cases (exit 31): invalid G, invalid P and an ok row without digests, then header missing/wrong and one case per v1.2 facts probe of review findings T1 (8: ok outcome, ok verifier forms, non-ok `-` and dag form), T2 (7: exit map, including the old fixture exits 3 and 4) and T4 (10: history and attempts). +- **Cost per call** (`/usr/bin/time -v`, GB10 Spark Grace CPU, cores 10-14, nice 19): wall 0:00.00 (below the tool's 10 ms resolution) and max RSS 192 KB for each of en2goal, goal2en and rep2en. +- **Negative controls:** + - A mutant en2goal with k and n swapped in the emitted G gives 5 wrong of 18 dev cases, and the suite catches it (`MUTANT_CAUGHT`). + - Ten rep2en mutants, each disabling one facts check (header, ok outcome, ok verifier, non-ok `-` pair, non-ok dag/digest form, code→class, code→exit, same-job history, next-job history, previous-job-ok history), are each caught by at least one fixture (`REPMUTANT … CAUGHT`). + - The suite refuses to build with any omc whose sha256 differs from the pin (`OMC_PIN_MISMATCH`, exit 1; receipt `evidence/OMEGESE45/translator/omc-pin-refusal.txt`, review finding T6). + +## Not covered (NOT_RUN or out of scope) + +- The translator is not trained; there is no model in it by design. +- Phrasings outside the rule table are refused (20), not guessed. +- The demo-side end-to-end use of rep2en with real aienet0-run facts belongs to the demo lane's receipts. diff --git a/docs/omegese45/vocab.tsv b/docs/omegese45/vocab.tsv new file mode 100644 index 0000000..08bec78 --- /dev/null +++ b/docs/omegese45/vocab.tsv @@ -0,0 +1,41 @@ +0 <pad> reserved context padding only; never emitted, never in a message +1 goal frame profile word +2 act frame profile word +3 res frame profile word, runtime-only (the model never emits it) +4 rep frame profile word +5 end frame Omega keyword `end` (block terminator) +6 mm kind profile word: one `matmul_u32` job +7 pair kind profile word: two `matmul_u32` jobs, same dims, seeds in order +8 job action profile word: submit one admitted microjob +9 refuse action profile word: refuse before submission +10 ok outcome profile word +11 refused outcome profile word +12 fail outcome profile word +13 bound code goal outside the admitted bounds (a dim not in 1..256); decided by the model +14 replay code worker refusal AN0_REPLAY +15 budget code worker refusal: budget/fuel +16 worker code any other worker refusal (aienet0-run exit 11) +17 transport code aienet0-run exit 10 +18 receipt code aienet0-run exit 12 +19 recomp code aienet0-run exit 13 +20 verdict code aienet0-run exit 14 +21 io code aienet0-run exit 15 +22 ushort type Omega type keyword (u16), OMEGESE.md:114 +23 ulong type Omega type keyword (u64), OMEGESE.md:114 +24 0x literal Omega hex-literal prefix, OMEGESE.md:691 +25 0 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +26 1 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +27 2 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +28 3 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +29 4 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +30 5 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +31 6 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +32 7 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +33 8 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +34 9 literal digit Omega hex digits (lowercase), OMEGESE.md:691 +35 a literal digit Omega hex digits (lowercase), OMEGESE.md:691 +36 b literal digit Omega hex digits (lowercase), OMEGESE.md:691 +37 c literal digit Omega hex digits (lowercase), OMEGESE.md:691 +38 d literal digit Omega hex digits (lowercase), OMEGESE.md:691 +39 e literal digit Omega hex digits (lowercase), OMEGESE.md:691 +40 f literal digit Omega hex digits (lowercase), OMEGESE.md:691 diff --git a/evidence/OMEGESE45/translator/binaries-and-cost.txt b/evidence/OMEGESE45/translator/binaries-and-cost.txt new file mode 100644 index 0000000..a935c84 --- /dev/null +++ b/evidence/OMEGESE45/translator/binaries-and-cost.txt @@ -0,0 +1,92 @@ +binaries built by the suite in the fresh clone at 99289520 (omc bf54b19f sha256 62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b) +90a93182bdf628a26d4cee6a3a98370e25b445ae1197dabee76b1f3c93925045 en2goal +7e1d6fd5743414ee51b92884c3491f8d97e0a3a294dc742b2c01b3b6de316290 goal2en +4b57fa73c96f59b036fd02184f2a64e54f31bf80a37ab5cb2a1f3fad48c8212a rep2en +b7c3a1042b7633a7bb7db320afcb342899dd4eac96337d89c698a23c2cebb491 en2goal-mut +4370248602d5f3c744f79178d61ceff4bfa63fa3f8f893c566677916975d3451 rep2en-header +7f1fe0ef8fdcfe33518bef209dbcb3bb793e8b95e8b05e3aea0b0c4e5454a041 rep2en-ok-outcome +fb6e7156acf11f01353b3d8659418383031dcddaedbb04504de1b285fbc6ecd1 rep2en-ok-verifier +a1f8189c7e93aaefd70377e0d459a5db3a234b590180a09230e7b498723b1245 rep2en-nonok-dashes +bca651a2b1870085f5e9c9f7721dff5f8b0712e9552569a16b5fd2b6b0ee2aa4 rep2en-nonok-dag-sha +6173ffa2856860861f6058e899afdeb1ce2c833932b9ec8615c1484fef10385e rep2en-code-class +3c79f0513971e1545bab7cbc598d69d958edeb96c2bbecad42f322a7470f8d38 rep2en-code-exit +b2262819b2ec341da6dea5270e5302c59b1eb09985ba14577e772be865eb459a rep2en-hist-same-job +a5bbf03e8b7478ac09f78eb74da5f4eaef8fa1a873184634f9d24349cd784b17 rep2en-hist-next-job +c3d1d38323bb6bdec205d814f96ff53d4a8e7f53c98dcadc8111737672e95ee5 rep2en-hist-prev-ok + +accuracy percentages (WolframLanguageEvaluator: N[{38/45, 6/45, 1/45, 39/45, 18/18, 5/18}*100, 4] -> {84.44, 13.33, 2.222, 86.67, 100.0, 27.78}) +held-out raw (committed heldout.tsv): exact 84.44% refused-differently 13.33% wrong 2.22% (row 12, erratum in heldout-errata.tsv) +held-out with errata: exact 86.67% refused-differently 13.33% wrong 0%; dev exact 100%; en2goal mutant wrong on 27.78% of dev cases + +== /usr/bin/time -v en2goal (GB10 Spark Grace CPU, cores 10-14, nice 19) + Command being timed: "/tmp/oe45-tr-build2/en2goal" + User time (seconds): 0.00 + System time (seconds): 0.00 + Percent of CPU this job got: 68% + Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00 + Average shared text size (kbytes): 0 + Average unshared data size (kbytes): 0 + Average stack size (kbytes): 0 + Average total size (kbytes): 0 + Maximum resident set size (kbytes): 192 + Average resident set size (kbytes): 0 + Major (requiring I/O) page faults: 0 + Minor (reclaiming a frame) page faults: 19 + Voluntary context switches: 1 + Involuntary context switches: 1 + Swaps: 0 + File system inputs: 0 + File system outputs: 0 + Socket messages sent: 0 + Socket messages received: 0 + Signals delivered: 0 + Page size (bytes): 4096 + Exit status: 0 +== /usr/bin/time -v goal2en (GB10 Spark Grace CPU, cores 10-14, nice 19) + Command being timed: "/tmp/oe45-tr-build2/goal2en" + User time (seconds): 0.00 + System time (seconds): 0.00 + Percent of CPU this job got: 73% + Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00 + Average shared text size (kbytes): 0 + Average unshared data size (kbytes): 0 + Average stack size (kbytes): 0 + Average total size (kbytes): 0 + Maximum resident set size (kbytes): 192 + Average resident set size (kbytes): 0 + Major (requiring I/O) page faults: 0 + Minor (reclaiming a frame) page faults: 23 + Voluntary context switches: 0 + Involuntary context switches: 0 + Swaps: 0 + File system inputs: 0 + File system outputs: 0 + Socket messages sent: 0 + Socket messages received: 0 + Signals delivered: 0 + Page size (bytes): 4096 + Exit status: 0 +== /usr/bin/time -v rep2en (GB10 Spark Grace CPU, cores 10-14, nice 19) + Command being timed: "/tmp/oe45-tr-build2/rep2en /tmp/oe45-tr-build2/f.ok-pair.tsv" + User time (seconds): 0.00 + System time (seconds): 0.00 + Percent of CPU this job got: 79% + Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00 + Average shared text size (kbytes): 0 + Average unshared data size (kbytes): 0 + Average stack size (kbytes): 0 + Average total size (kbytes): 0 + Maximum resident set size (kbytes): 192 + Average resident set size (kbytes): 0 + Major (requiring I/O) page faults: 0 + Minor (reclaiming a frame) page faults: 29 + Voluntary context switches: 1 + Involuntary context switches: 0 + Swaps: 0 + File system inputs: 0 + File system outputs: 0 + Socket messages sent: 0 + Socket messages received: 0 + Signals delivered: 0 + Page size (bytes): 4096 + Exit status: 0 diff --git a/evidence/OMEGESE45/translator/omc-pin-refusal.txt b/evidence/OMEGESE45/translator/omc-pin-refusal.txt new file mode 100644 index 0000000..92ab687 --- /dev/null +++ b/evidence/OMEGESE45/translator/omc-pin-refusal.txt @@ -0,0 +1,7 @@ +command: env OMC=/tmp/oe45tf-omc-bad sh tests/omegese45/translator/run-translator.sh (omc copy with one NUL byte appended) +clone: /tmp/oe45-tr-fresh2 at 9928952079bc1220d7f3e8e6604c937befd09129 +date: 2026-10-29T23:20:44Z +omc sha256 05016892599a9c71f8629a45985f846b336523992c24c4e25a35cc4524258ef1 +OMC_PIN_MISMATCH want 62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b (/tmp/oe45tf-omc-bad) +OE45_TRANSLATOR_FAIL +rc=1 diff --git a/evidence/OMEGESE45/translator/suite.txt b/evidence/OMEGESE45/translator/suite.txt new file mode 100644 index 0000000..4e1968d --- /dev/null +++ b/evidence/OMEGESE45/translator/suite.txt @@ -0,0 +1,85 @@ +command: env OMC=/tmp/om-main/seed/out/omc WORK=/tmp/oe45-tr-build2 taskset -c 10-14 nice -n 19 ionice -c3 sh tests/omegese45/translator/run-translator.sh +clone: /tmp/oe45-tr-fresh2 (git clone https://github.com/aien-dev/aien-train -b feat/45-chat-translator) at 9928952079bc1220d7f3e8e6604c937befd09129 +host: spark-b87b Linux aarch64 +date: 2026-10-29T23:20:34Z +omc sha256 62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b +DEV exact=18 refused_differently=0 wrong=0 total=18 + wrong: [multiply a 0 by 6 matrix by a 6 by 8 matrix with seed 3] -> goal mm ushort 0x000 ushort 0x006 ushort 0x008 ulong 0x0003 end + refused-differently: [multiply a 4 by 8 matrix with an 8 by 2 matrix using seed 7] rc=20 + refused-differently: [multiply two 4 by 4 matrices with seed 3] rc=20 + refused-differently: [run 2 matmuls of size 4x4x4 with seeds 5 and 6] rc=20 + refused-differently: [matmul 4x8x2 seed 7 please] rc=20 + refused-differently: [run a matmul of size 4 by 8 by 2 with seed 7] rc=20 + refused-differently: [matmul 4x8x2 seed 0x10] rc=20 want=21 +HELDOUT exact=38 refused_differently=6 wrong=1 total=45 (raw, committed heldout.tsv) +ERRATUM row=12 original=[refuse 21] corrected=[goal mm ushort 0x000 ushort 0x006 ushort 0x008 ulong 0x0003 end] date=2026-10-29 reason: interface v1.2 section 4: EN_RANGE is only dim > 4095, seed > 65535 or malformed, never dim 0; dim 0 is representable (D 0x000) and the core refuses it with bound. Review45CT finding T3. heldout.tsv (faeb7ad) is not rewritten. +HELDOUT_CORRECTED exact=39 refused_differently=6 wrong=0 total=45 (errata=1) +REFUSAL long-input rc=20 +STABLE count=29 +GOAL2EN invalid rc=31 [G2E_INVALID goal grammar] +REP2EN ok-mm rc=0 Completed and verified: one matmul_u32 job multiplying a 4 by 8 matrix by a 8 by 2 matrix with seed 7; job 1 dag_id aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa mjr1_sha256 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb. +REP2EN ok-pair rc=0 Completed and verified: two matmul_u32 jobs, each multiplying a 4 by 8 matrix by a 8 by 2 matrix, with seeds 7 and 8; job 1 dag_id aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa mjr1_sha256 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; job 2 dag_id bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb mjr1_sha256 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa. +REP2EN retry-ok rc=0 Completed and verified: one matmul_u32 job multiplying a 4 by 8 matrix by a 8 by 2 matrix with seed 7; job 1 dag_id aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa mjr1_sha256 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb. +REP2EN retry-fail rc=0 Not completed: job 1 failed (code transport): the connection to the worker failed. +REP2EN bound rc=0 Not completed: refused before dispatch (code bound): the goal asks for a 300 by 2 by 2 matmul and a dimension is outside the admitted range 1 to 256; nothing was dispatched. +REP2EN refused-replay rc=0 Not completed: job 1 was refused (code replay): the worker refused a replay of an already executed job. +REP2EN fail-transport rc=0 Not completed: job 1 failed (code transport): the connection to the worker failed. +REP2EN pair-job2-refused rc=0 Not completed: job 2 was refused (code budget): the job was refused for budget or fuel. +REP2EN fail-receipt-digest rc=0 Not completed: job 1 failed (code verdict): the recomputed result did not match the worker result. +REP2EN x-ok-vs-fail rc=30 G2E_CONTRADICT class +REP2EN x-operands rc=30 G2E_CONTRADICT operands +REP2EN x-code rc=30 G2E_CONTRADICT code +REP2EN x-class rc=30 G2E_CONTRADICT class +REP2EN x-fail-vs-ok rc=30 G2E_CONTRADICT class +REP2EN x-retry-unreported rc=30 G2E_CONTRADICT class +REP2EN x-pair-missing rc=30 G2E_CONTRADICT jobs +REP2EN x-bound-dispatched rc=30 G2E_CONTRADICT bound +REP2EN x-facts-operands rc=30 G2E_CONTRADICT operands +REP2EN x-nothing rc=30 G2E_CONTRADICT dispatch +REP2EN bad-report rc=31 G2E_INVALID report grammar +REP2EN bad-goal rc=31 G2E_INVALID goal grammar +REP2EN bad-facts rc=31 G2E_INVALID facts +REP2EN i-no-header rc=31 G2E_INVALID facts +REP2EN i-header-wrong rc=31 G2E_INVALID facts +REP2EN i-ok-outcome-zzz rc=31 G2E_INVALID facts +REP2EN i-ok-outcome-2 rc=31 G2E_INVALID facts +REP2EN i-ok-verifier-64 rc=31 G2E_INVALID facts +REP2EN i-ok-verifier-04 rc=31 G2E_INVALID facts +REP2EN i-ok-verifier-upper rc=31 G2E_INVALID facts +REP2EN i-nonok-outcome rc=31 G2E_INVALID facts +REP2EN i-nonok-verifier rc=31 G2E_INVALID facts +REP2EN i-nonok-dag rc=31 G2E_INVALID facts +REP2EN i-exit14-transport rc=31 G2E_INVALID facts +REP2EN i-exit3-transport rc=31 G2E_INVALID facts +REP2EN i-exit4-replay rc=31 G2E_INVALID facts +REP2EN i-exit10-replay rc=31 G2E_INVALID facts +REP2EN i-exit11-receipt rc=31 G2E_INVALID facts +REP2EN i-refused-transport rc=31 G2E_INVALID facts +REP2EN i-fail-replay rc=31 G2E_INVALID facts +REP2EN i-ok-then-transport rc=31 G2E_INVALID facts +REP2EN i-ok-then-transport-a1 rc=31 G2E_INVALID facts +REP2EN i-refused-then-job2 rc=31 G2E_INVALID facts +REP2EN i-transport-then-job2 rc=31 G2E_INVALID facts +REP2EN i-job2-first rc=31 G2E_INVALID facts +REP2EN i-attempt0 rc=31 G2E_INVALID facts +REP2EN i-attempt2-first rc=31 G2E_INVALID facts +REP2EN i-attempt-repeat rc=31 G2E_INVALID facts +REP2EN i-attempt3 rc=31 G2E_INVALID facts +REP2EN i-retry-after-receipt rc=31 G2E_INVALID facts +COST en2goal wall=0:00.00 maxrss_kb=192 chip=GB10-Spark-Grace-CPU cores=10-14 nice=19 +COST goal2en wall=0:00.00 maxrss_kb=192 chip=GB10-Spark-Grace-CPU cores=10-14 nice=19 +COST rep2en wall=0:00.00 maxrss_kb=192 chip=GB10-Spark-Grace-CPU cores=10-14 nice=19 +MUTANT exact=13 refused_differently=0 wrong=5 total=18 +MUTANT_CAUGHT +REPMUTANT header missed=1 first=i-header-wrong(rc=0,want=31) CAUGHT +REPMUTANT ok-outcome missed=1 first=i-ok-outcome-2(rc=0,want=31) CAUGHT +REPMUTANT ok-verifier missed=3 first=i-ok-verifier-64(rc=0,want=31) CAUGHT +REPMUTANT nonok-dashes missed=2 first=i-nonok-outcome(rc=0,want=31) CAUGHT +REPMUTANT nonok-dag-sha missed=1 first=i-nonok-dag(rc=0,want=31) CAUGHT +REPMUTANT code-class missed=2 first=i-refused-transport(rc=0,want=31) CAUGHT +REPMUTANT code-exit missed=5 first=i-exit14-transport(rc=0,want=31) CAUGHT +REPMUTANT hist-same-job missed=5 first=i-ok-then-transport(rc=0,want=31) CAUGHT +REPMUTANT hist-next-job missed=3 first=i-job2-first(rc=0,want=31) CAUGHT +REPMUTANT hist-prev-ok missed=2 first=i-refused-then-job2(rc=0,want=31) CAUGHT +OE45_TRANSLATOR_PASS +rc=0 diff --git a/native/omegese45/mjr1.om b/native/omegese45/mjr1.om new file mode 100644 index 0000000..17b40e7 --- /dev/null +++ b/native/omegese45/mjr1.om @@ -0,0 +1,174 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note MJR1 receipt parser (aien-train #45, contract lane). Requires vocab.om before it. +note Layout and static rules follow aien-dev/aien-protocols-mv e705fdc9 +note crates/aien-microjob/src/lib.rs: RECEIPT_MAGIC L34, VERSION L36, RECEIPT_LEN L38, +note mod outcome L103-109, encode_receipt L857-883, decode_receipt L885-928; +note specs/microjob/SPEC.md section 5 (L162-206). Integers are big-endian. +note The signature (bytes 340..404 over [0,340)) is NOT verified here. +note Public API: fn ocmjr n ulong to long (ocrb[0,n)) -> outcome 1..5 | -reason; +note fn ocmjrf plen ulong to long (path ocpath[0,plen)) -> same; ocmv = outcome attempt generation. +note Every refusal maps to exit 43 MJR1_INVALID in callers. +const ocmlen ulong 404 +const ocmrlen long 1 +const ocmrmag long 2 +const ocmrver long 3 +const ocmrres long 4 +const ocmrout long 5 +const ocmratt long 6 +const ocmrsig long 7 +const ocmrzero long 8 +const ocmrdig long 9 +const ocmrvrd long 10 +const ocmrio long 11 +text ocmtx "length magic version reservedoutcome attempt signer zerohashoutput verdict io " +text ocmotx "completedrefused failed cancelleduncertain" +global ocrb uchar 512 +global ocpath uchar 4096 +global ocmv ulong 3 + +fn ocmz a ulong b ulong to bool +for i ulong sub b a +if ne get ocrb add a i 0 +ret false +end +end +ret true +end + +fn ocmu32 a ulong to ulong +v = ulong 0 +for i ulong 4 +v = add mul v 256 ulong get ocrb add a i +end +ret v +end + +fn ocmjr n ulong to long +if ne n ocmlen +ret ocerrset n ocmrlen +end +note magic "MJR1" +mg = true +if ne get ocrb 0 77 +mg = false +end +if ne get ocrb 1 74 +mg = false +end +if ne get ocrb 2 82 +mg = false +end +if ne get ocrb 3 49 +mg = false +end +if not mg +ret ocerrset 0 ocmrmag +end +if ne get ocrb 4 1 +ret ocerrset 4 ocmrver +end +if ne get ocrb 7 0 +ret ocerrset 7 ocmrres +end +if not ocmz 84 88 +ret ocerrset 84 ocmrres +end +if not ocmz 337 340 +ret ocerrset 337 ocmrres +end +oc = get ocrb 5 +if or lt oc 1 gt oc 5 +ret ocerrset 5 ocmrout +end +if eq get ocrb 6 0 +ret ocerrset 6 ocmratt +end +sg = get ocrb 304 +if and ne sg 2 ne sg 3 +ret ocerrset 304 ocmrsig +end +if ocmz 176 208 +ret ocerrset 176 ocmrzero +end +if ocmz 240 272 +ret ocerrset 240 ocmrzero +end +done = eq oc 1 +if eq done ocmz 144 176 +ret ocerrset 144 ocmrdig +end +if done +if ocmz 272 304 +ret ocerrset 272 ocmrvrd +end +end +put ocmv 0 ulong oc +put ocmv 1 ulong get ocrb 6 +put ocmv 2 ocmu32 72 +ret long oc +end + +note Read at most 512 bytes of the file named by ocpath[0,plen), then parse. +fn ocmjrf plen ulong to long +if or eq plen 0 gt plen 4096 +ret ocerrset 0 ocmrio +end +fd = fopen ocpath 0 plen 0 0 +if lt fd 0 +ret ocerrset 0 ocmrio +end +t = ulong 0 +fin = false +while and lt t 512 not fin bound 600 +r = read int fd ocrb t sub 512 t +if lt r 0 +c = fclose int fd +ret ocerrset t ocmrio +end +if eq r 0 +fin = true +end +t = add t ulong r +end +c = fclose int fd +ret ocmjr t +end + +fn ocmputrs r ulong to void +o = mul sub r 1 8 +for j ulong 8 +ch = get ocmtx add o j +if ne ch 32 +ocputc ch +end +end +end + +fn ocmputo oc ulong to void +o = mul sub oc 1 9 +for j ulong 9 +ch = get ocmotx add o j +if ne ch 32 +ocputc ch +end +end +end + +note Print ocrb[a,b) as lowercase hex. +fn ocmhex a ulong b ulong to void +for i ulong sub b a +v = get ocrb add a i +h = div v 16 +l = rem v 16 +if lt h 10 +ocputc add h 48 +else +ocputc add h 87 +end +if lt l 10 +ocputc add l 48 +else +ocputc add l 87 +end +end +end diff --git a/native/omegese45/msg.om b/native/omegese45/msg.om new file mode 100644 index 0000000..b086139 --- /dev/null +++ b/native/omegese45/msg.om @@ -0,0 +1,409 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note R45 message grammar automaton, validator, binding check and lowering +note (aien-train #45, contract lane). Requires vocab.om before it in the cat order. +note DFA states: 0 dead, 1 accept (after end), 2.. trie states built once by ocdinit. +note Start kinds: 1 G, 2 A, 3 R, 4 P, 5 model message (act|rep, then the A or P rules). +note Public API (stable, documented in CONTRACT.md): +note fn ocstart kind ulong to ulong fn ocstep st ulong id ulong to ulong +note fn oclegal st ulong id ulong to bool fn ocfinal st ulong to bool +note fn ocmask st ulong to ulong (ocmk[id] = 1 when legal; returns the count) +note fn ocvids n ulong kind ulong to long (ocids; kind 0 = from the first id) -> kind | -reason +note fn ocvline n ulong kind ulong to long (ocin text; ocnids = id count) -> kind | -reason +note fn ocsetg n / ocsetgl n -> 0 | -reason (store G operands in ocgv) +note fn ocbind n job / ocbindl n job -> 0 | 41 | 42 | -reason +note fn oclower n / oclowerl n -> 0 (oclv = m k n seed) | 41 | -reason +const ocdead ulong 0 +const ocacc ulong 1 +const ocns ulong 256 +const ocadmax ulong 256 +global ocdt uchar 10496 +global ocdn ulong 1 +global ocdk ulong 6 +global ocdok ulong 1 +global ocmk uchar 41 +global ocnids ulong 1 +global ocgv ulong 6 +global ocgok ulong 1 +global oclv ulong 4 + +fn ocdnew to ulong +s = get ocdn 0 +if ge s ocns +trap 3 +end +put ocdn 0 add s 1 +ret s +end + +fn ocdset s ulong id ulong t ulong to void +put ocdt add mul s ocv id uchar t +end + +note Follow or create the transition s --id-->. +fn ocdadd s ulong id ulong to ulong +x = add mul s ocv id +t = ulong get ocdt x +if eq t 0 +t = ocdnew +put ocdt x uchar t +end +ret t +end + +fn ocdacc s ulong to void +ocdset s 5 ocacc +end + +note All 16 digit ids share one successor. +fn ocddig s ulong to ulong +t = ocdadd s 25 +for d ulong 15 +ocdset s add 26 d t +end +ret t +end + +fn ocdhex s ulong nd ulong to ulong +t = ocdadd s 24 +for i ulong nd +t = ocddig t +end +ret t +end + +note D := ushort 0x H H H +fn ocdd s ulong to ulong +t = ocdadd s 22 +ret ocdhex t 3 +end + +note S := ulong 0x H H H H +fn ocds s ulong to ulong +t = ocdadd s 23 +ret ocdhex t 4 +end + +note Code ids lo..21 share one successor (lo 13 = C, lo 14 = C'). +fn ocdcode s ulong lo ulong to ulong +t = ocdadd s lo +for i ulong sub 21 lo +ocdset s add add lo 1 i t +end +ret t +end + +note D D D S [S] end +fn ocdops s ulong two bool to void +t = ocdd s +t = ocdd t +t = ocdd t +t = ocds t +if two +t = ocds t +end +ocdacc t +end + +fn ocdinit to void +if eq get ocdok 0 1 +ret +end +put ocdn 0 2 +g = ocdnew +put ocdk 1 g +g1 = ocdadd g 1 +x = ocdadd g1 6 +ocdops x false +x = ocdadd g1 7 +ocdops x true +a = ocdnew +put ocdk 2 a +a1 = ocdadd a 2 +x = ocdadd a1 8 +x = ocdadd x 6 +ocdops x false +x = ocdadd a1 9 +x = ocdadd x 13 +ocdacc x +r = ocdnew +put ocdk 3 r +r1 = ocdadd r 3 +x = ocdadd r1 10 +ocdacc x +x = ocdadd r1 11 +x = ocdcode x 14 +ocdacc x +x = ocdadd r1 12 +x = ocdcode x 14 +ocdacc x +p = ocdnew +put ocdk 4 p +p1 = ocdadd p 4 +o = ocdadd p1 10 +x = ocdadd o 6 +ocdops x false +x = ocdadd o 7 +ocdops x true +x = ocdadd p1 11 +x = ocdcode x 13 +ocdacc x +x = ocdadd p1 12 +x = ocdcode x 13 +ocdacc x +m = ocdnew +put ocdk 5 m +ocdset m 2 a1 +ocdset m 4 p1 +put ocdok 0 1 +end + +fn ocstart kind ulong to ulong +ocdinit +if or eq kind 0 gt kind 5 +ret ocdead +end +ret get ocdk kind +end + +fn ocstep st ulong id ulong to ulong +ocdinit +if or ge st ocns ge id ocv +ret ocdead +end +ret ulong get ocdt add mul st ocv id +end + +fn oclegal st ulong id ulong to bool +t = ocstep st id +ret ne t ocdead +end + +fn ocfinal st ulong to bool +ret eq st ocacc +end + +fn ocmask st ulong to ulong +c = ulong 0 +for id ulong ocv +put ocmk id 0 +if oclegal st id +put ocmk id 1 +c = add c 1 +end +end +ret c +end + +note Message kind of a frame id: goal 1, act 2, res 3, rep 4, else 0. +fn ockind id ulong to ulong +if and ge id 1 le id 4 +ret id +end +ret 0 +end + +fn ocvids n ulong kind ulong to long +ocvinit +ocdinit +if eq n 0 +ret ocerrset 0 ocrempty +end +if gt n ocmaxi +ret ocerrset ocmaxi ocrlong +end +if gt kind 5 +ret ocerrset 0 ocrkind +end +k = kind +if eq k 0 +k = ockind get ocids 0 +if eq k 0 +ret ocerrset 0 ocrkind +end +end +st = ocstart k +for i ulong n +if eq st ocacc +ret ocerrset i ocrtrail +end +st = ocstep st get ocids i +if eq st ocdead +ret ocerrset i ocrgram +end +end +if ne st ocacc +ret ocerrset n ocrnoend +end +if eq k 5 +k = ockind get ocids 0 +end +ret long k +end + +fn ocvline n ulong kind ulong to long +put ocnids 0 0 +r = ocenc n +if lt r 0 +ret r +end +c = ulong r +put ocnids 0 c +v = ocvids c kind +if lt v 0 +i = get ocerr 0 +if lt i c +put ocerr 0 get ocipos i +else +put ocerr 0 n +end +end +ret v +end + +note Value of the hex digits of the D or S slot that starts at id index b. +fn ochexv b ulong nd ulong to ulong +v = ulong 0 +for i ulong nd +v = add mul v 16 sub get ocids add add b 2 i 25 +end +ret v +end + +fn ocgfill to void +put ocgv 0 get ocids 1 +put ocgv 1 ochexv 2 3 +put ocgv 2 ochexv 7 3 +put ocgv 3 ochexv 12 3 +put ocgv 4 ochexv 17 4 +put ocgv 5 0 +if eq get ocids 1 7 +put ocgv 5 ochexv 23 4 +end +put ocgok 0 1 +end + +fn ocsetg n ulong to long +put ocgok 0 0 +v = ocvids n 1 +if lt v 0 +ret v +end +ocgfill +ret 0 +end + +fn ocsetgl n ulong to long +put ocgok 0 0 +v = ocvline n 1 +if lt v 0 +ret v +end +ocgfill +ret 0 +end + +fn ocadm d ulong to bool +ret and ge d 1 le d ocadmax +end + +note ocids holds a valid A. Mismatch (41) is decided before bound (42). +fn ocbcore job ulong to long +if eq get ocgok 0 0 +ret ocerrset 0 ocrkind +end +put ocerr 0 0 +if eq get ocids 1 9 +put ocerr 1 ulong ocrnjob +ret 41 +end +nj = ulong 1 +if eq get ocgv 0 7 +nj = 2 +end +if or eq job 0 gt job nj +put ocerr 1 ulong ocrjobix +ret 41 +end +bad = false +m = ochexv 3 3 +if ne m get ocgv 1 +bad = true +end +k = ochexv 8 3 +if ne k get ocgv 2 +bad = true +end +n = ochexv 13 3 +if ne n get ocgv 3 +bad = true +end +if bad +put ocerr 1 ulong ocrdims +ret 41 +end +sd = ochexv 18 4 +if ne sd get ocgv add 3 job +put ocerr 1 ulong ocrseed +ret 41 +end +ok = true +if not ocadm m +ok = false +end +if not ocadm k +ok = false +end +if not ocadm n +ok = false +end +if not ok +put ocerr 1 ulong ocrdims +ret 42 +end +ret 0 +end + +fn ocbind n ulong job ulong to long +v = ocvids n 2 +if lt v 0 +ret v +end +ret ocbcore job +end + +fn ocbindl n ulong job ulong to long +v = ocvline n 2 +if lt v 0 +ret v +end +ret ocbcore job +end + +fn oclcore to long +if eq get ocids 1 9 +put ocerr 0 0 +put ocerr 1 ulong ocrnjob +ret 41 +end +put oclv 0 ochexv 3 3 +put oclv 1 ochexv 8 3 +put oclv 2 ochexv 13 3 +put oclv 3 ochexv 18 4 +ret 0 +end + +fn oclower n ulong to long +v = ocvids n 2 +if lt v 0 +ret v +end +ret oclcore +end + +fn oclowerl n ulong to long +v = ocvline n 2 +if lt v 0 +ret v +end +ret oclcore +end diff --git a/native/omegese45/translate/en2goal.om b/native/omegese45/translate/en2goal.om new file mode 100644 index 0000000..343ced8 --- /dev/null +++ b/native/omegese45/translate/en2goal.om @@ -0,0 +1,446 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note en2goal: deterministic rule-based English request -> R45 goal line G. +note No model. The grammar is the rule table otrules below, documented +note verbatim in docs/omegese45/TRANSLATOR.md. Needs otio.om before it. +note +note Rule table format: one rule per line, `<class> <pattern word> ...`. +note class m = one mm job, p = a pair, x = has more than one reading (23). +note A pattern word is literal alternatives joined by `/`, optional when it +note starts with `?`, or a number slot `#m #k #j #n #s #t` (m, k of the left +note matrix, j, n of the right matrix, seed, second seed). A rule matches when +note the whole normalized token sequence matches the whole pattern. +text otrules "m ?please multiply a/an #m by #k matrix by/with/times a/an #j by #n matrix with seed #s\nm ?please ?run/do/compute/submit ?a/an/one matmul/matmul_u32 ?job ?of ?size #m x #k x #n ?with seed #s\nm goal for review one matmul_u32 job multiplying a/an #m by #k matrix by a/an #j by #n matrix with seed #s\np ?please ?run/do/compute/submit two matmuls/matmul/matmul_u32s/matmul_u32 ?jobs ?of ?size #m x #k x #n ?with seeds #s and #t\np matmuls #m x #k x #n ?with seeds #s ?and #t\np ?please multiply a/an #m by #k matrix by/with/times a/an #j by #n matrix twice with seeds #s and #t\np goal for review two matmul_u32 jobs each multiplying a/an #m by #k matrix by a/an #j by #n matrix with seeds #s and #t in that order\nx ?please ?run/do/compute/submit ?a/an/one matmul/matmul_u32 ?job ?of ?size #m x #k x #n ?with seeds #s ?and #t\nx ?please ?run/do/compute/submit two matmuls/matmul/matmul_u32s/matmul_u32 ?jobs ?of ?size #m x #k x #n ?with seed #s\nx ?please multiply a/an #m by #k matrix by/with/times a/an #j by #n matrix with seeds #s and #t\nx ?please ?run/do/compute/submit ?a/an/one matmul/matmul_u32 ?job ?of ?size #m x #k x #n ?with seed #s and/or ?seed #t\nx ?please ?run/do/compute/submit ?a/an/one matmul/matmul_u32 ?job ?of ?size #m x #k x #n ?with seed #s seed #t\n" +text otfr "goal |mm |pair |ushort 0x|ulong 0x|end\n|EN_UNSUPPORTED\n|EN_RANGE\n|EN_SHAPE\n|EN_AMBIG\n|usage: en2goal < request\n" + +note Normalized request: lowercase words joined by single spaces. +global otn uchar 2048 +global otnl ulong 1 +global ottb ulong 1024 +global ottl ulong 1024 +global otnt ulong 1 +note Slot values and set flags for the rule being matched (m k j n s t). +global otsv ulong 6 +global otss ulong 6 +note Accepted reading: kind (1 mm, 2 pair), code, slots m k n s t. +global otrd ulong 8 + +const OTBAD ulong 1099511627776 + +fn otisdg c uchar to bool +ret and ge c 48 le c 57 +end + +note Raw input byte i of otin[0..n) is a digit; false outside the range. +fn otdgat i ulong n ulong to bool +if ge i n +ret false +end +ret otisdg get otin i +end + +fn otnemit c uchar to void +o = get otnl 0 +put otn o c +put otnl 0 add o 1 +end + +note Emit a separator: one space, never leading, never doubled. +fn otnsep to void +o = get otnl 0 +if eq o 0 +ret +end +if eq get otn sub o 1 32 +ret +end +otnemit 32 +end + +note Normalize otin[0..n) into otn. Returns false for a byte outside the +note request alphabet (TAB and 0x20..0x7e). Rules: A-Z lowercased; space, +note TAB and , ; : ? ! ( ) " separate words; `.` separates words unless a +note digit is on both sides; `x` next to a digit is a word of its own. +fn otnorm n ulong to bool +put otnl 0 0 +for i ulong n +c = get otin i +if or lt c 32 gt c 126 +if ne c 9 +ret false +end +end +if and ge c 65 le c 90 +c = add c 32 +end +sep = false +if or eq c 9 eq c 32 +sep = true +end +if or or eq c 44 eq c 59 or eq c 58 eq c 63 +sep = true +end +if or or eq c 33 eq c 40 or eq c 41 eq c 34 +sep = true +end +if eq c 46 +pd = otdgat sub i 1 n +nd = otdgat add i 1 n +if not and pd nd +sep = true +end +end +if eq c 120 +pd = otdgat sub i 1 n +nd = otdgat add i 1 n +if or pd nd +otnsep +otnemit c +otnsep +continue +end +end +if sep +otnsep +else +otnemit c +end +end +o = get otnl 0 +if gt o 0 +if eq get otn sub o 1 32 +put otnl 0 sub o 1 +end +end +ret true +end + +note Split otn into tokens (start, length). +fn ottoken to void +n = get otnl 0 +t = ulong 0 +b = ulong 0 +for i ulong n +if eq get otn i 32 +put ottb t b +put ottl t sub i b +t = add t 1 +b = add i 1 +end +end +if gt n 0 +put ottb t b +put ottl t sub n b +t = add t 1 +end +put otnt 0 t +end + +note Token ti is a number word: starts with a digit, or + or - then a digit. +fn otisnum ti ulong to bool +b = get ottb ti +l = get ottl ti +c = get otn b +if otisdg c +ret true +end +if and gt l 1 or eq c 43 eq c 45 +ret otisdg get otn add b 1 +end +ret false +end + +note Decimal value of number token ti; OTBAD when malformed (a sign, a +note non-digit, or more than 9 digits). OTBAD is outside every range. +fn otnumv ti ulong to ulong +b = get ottb ti +l = get ottl ti +if gt l 9 +ret OTBAD +end +v = ulong 0 +for i ulong l +c = get otn add b i +if not otisdg c +ret OTBAD +end +v = add mul v 10 ulong sub c 48 +end +ret v +end + +note Token ti equals rule text bytes [ps, pe). +fn oteqw ti ulong ps ulong pe ulong to bool +b = get ottb ti +l = get ottl ti +if ne l sub pe ps +ret false +end +for i ulong l +if ne get otn add b i get otrules add ps i +ret false +end +end +ret true +end + +note Token ti equals one of the `/`-separated alternatives in [ps, pe). +fn otalt ti ulong ps ulong pe ulong to bool +a = ps +p = ps +while le p pe bound 4096 +e = eq p pe +if not e +e = eq get otrules p 47 +end +if e +if oteqw ti a p +ret true +end +a = add p 1 +end +p = add p 1 +end +ret false +end + +fn otslix c uchar to ulong +if eq c 109 +ret 0 +end +if eq c 107 +ret 1 +end +if eq c 106 +ret 2 +end +if eq c 110 +ret 3 +end +if eq c 115 +ret 4 +end +ret 5 +end + +note Match the rule pattern from byte pi against tokens from ti to the end. +fn otmat pi ulong ti ulong to bool +if eq get otrules pi 10 +ret eq ti get otnt 0 +end +pe = pi +while true bound 4096 +c = get otrules pe +if or eq c 32 eq c 10 +break +end +pe = add pe 1 +end +np = pe +if eq get otrules pe 32 +np = add pe 1 +end +ps = pi +if eq get otrules pi 63 +ps = add pi 1 +if otmat np ti +ret true +end +end +if ge ti get otnt 0 +ret false +end +if eq get otrules ps 35 +if not otisnum ti +ret false +end +si = otslix get otrules add ps 1 +put otsv si otnumv ti +put otss si 1 +ret otmat np add ti 1 +end +if not otalt ti ps pe +ret false +end +ret otmat np add ti 1 +end + +note A dim is representable in D (0x000..0xfff). Dim 0 and 257..4095 reach +note the core, which refuses them with `bound` (interface v1.2 section 4). +fn otdimok v ulong to bool +ret le v 4095 +end + +note Decide one matched m/p rule: 0 ok, 21 range, 22 shape. +fn otdecide pair bool to ulong +bad = false +if not otdimok get otsv 0 +bad = true +end +if not otdimok get otsv 1 +bad = true +end +if not otdimok get otsv 3 +bad = true +end +if gt get otsv 4 65535 +bad = true +end +if pair +if gt get otsv 5 65535 +bad = true +end +end +if eq get otss 2 1 +if not otdimok get otsv 2 +bad = true +end +end +if bad +ret 21 +end +if eq get otss 2 1 +if ne get otsv 2 get otsv 1 +ret 22 +end +end +ret 0 +end + +note Parse the normalized tokens. Returns the exit code; on 0 the reading +note is in otrd (kind, m, k, n, s, t). +fn otparse to ulong +nr = ulong 0 +amb = false +r = ulong 0 +while lt r len otrules bound 64 +cl = get otrules r +for i ulong 6 +put otsv i 0 +put otss i 0 +end +hit = otmat add r 2 0 +if hit +if eq cl 120 +amb = true +else +pair = eq cl 112 +code = otdecide pair +kind = ulong 1 +if pair +kind = 2 +end +if eq nr 0 +put otrd 0 kind +put otrd 1 code +put otrd 2 get otsv 0 +put otrd 3 get otsv 1 +put otrd 4 get otsv 3 +put otrd 5 get otsv 4 +put otrd 6 get otsv 5 +else +if not otsame kind code +amb = true +end +end +nr = add nr 1 +end +end +while ne get otrules r 10 bound 4096 +r = add r 1 +end +r = add r 1 +end +if amb +ret 23 +end +if eq nr 0 +ret 20 +end +ret get otrd 1 +end + +note The current match gives the same reading as the stored one. +fn otsame kind ulong code ulong to bool +if ne kind get otrd 0 +ret false +end +if ne code get otrd 1 +ret false +end +if ne get otsv 0 get otrd 2 +ret false +end +if ne get otsv 1 get otrd 3 +ret false +end +if ne get otsv 3 get otrd 4 +ret false +end +if ne get otsv 4 get otrd 5 +ret false +end +if eq kind 2 +if ne get otsv 5 get otrd 6 +ret false +end +end +ret true +end + +fn otemd v ulong to void +otpfr 3 +otphex v 3 +otpb 32 +end + +fn otems v ulong to void +otpfr 4 +otphex v 4 +otpb 32 +end + +note Append the G line for the reading in otrd. +fn otemitg to void +mv = get otrd 2 +kv = get otrd 3 +nv = get otrd 4 +otpfr 0 +if eq get otrd 0 2 +otpfr 2 +else +otpfr 1 +end +otemd mv +otemd kv +otemd nv +otems get otrd 5 +if eq get otrd 0 2 +otems get otrd 6 +end +otpfr 5 +end + +note en2goal on otin[0..n): fills otob with the G line or the typed refusal +note line and returns the exit code (0, 20, 21, 22, 23). +fn otengoal n ulong to int +if gt n 0 +if eq get otin sub n 1 10 +n = sub n 1 +end +end +code = ulong 20 +if le n 512 +if otnorm n +ottoken +if gt get otnt 0 0 +code = otparse +end +end +end +if eq code 0 +otemitg +ret 0 +end +otpfr sub code 14 +ret int code +end diff --git a/native/omegese45/translate/goal2en.om b/native/omegese45/translate/goal2en.om new file mode 100644 index 0000000..687f578 --- /dev/null +++ b/native/omegese45/translate/goal2en.om @@ -0,0 +1,60 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note goal2en: R45 goal line G -> one fixed-template English review sentence +note that states every operand. G is validated by the contract lane's +note ocsetgl (msg.om); an invalid G prints `G2E_INVALID goal <reason>` and +note returns 31. Needs otio.om, vocab.om, msg.om, otmsg.om before it and +note otfrag.om after it. Templates are documented in TRANSLATOR.md. +text otfr "Goal for review: one matmul_u32 job multiplying a | by | matrix by a | matrix with seed |.\n|Goal for review: two matmul_u32 jobs, each multiplying a | matrix, with seeds | and | in that order.\n|G2E_INVALID goal |usage: goal2en < goal\n" + +note "a {m} by {k} matrix by a {k} by {n}" after fragment 0 or 5. +fn otgdims m ulong k ulong n ulong to void +otpdec m +otpfr 1 +otpdec k +otpfr 2 +otpdec k +otpfr 1 +otpdec n +end + +note goal2en on otin[0..n): fills otob, returns 0 or 31. +fn otgoalen n ulong to int +if gt n 0 +if eq get otin sub n 1 10 +n = sub n 1 +end +end +ok = otcopy 0 n +if not ok +otpfr 9 +otprs neg long 10 +otpb 10 +ret 31 +end +v = ocsetgl n +if lt v 0 +otpfr 9 +otprs v +otpb 10 +ret 31 +end +m = get ocgv 1 +k = get ocgv 2 +nn = get ocgv 3 +if eq get ocgv 0 7 +otpfr 5 +otgdims m k nn +otpfr 6 +otpdec get ocgv 4 +otpfr 7 +otpdec get ocgv 5 +otpfr 8 +ret 0 +end +otpfr 0 +otgdims m k nn +otpfr 3 +otpdec get ocgv 4 +otpfr 4 +ret 0 +end diff --git a/native/omegese45/translate/main-en2goal.om b/native/omegese45/translate/main-en2goal.om new file mode 100644 index 0000000..5db0428 --- /dev/null +++ b/native/omegese45/translate/main-en2goal.om @@ -0,0 +1,22 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note en2goal driver: stdin one English request line, stdout one G line +note (exit 0) or one typed refusal line (exit 20 21 22 23). Exit 2: usage +note (any argument) or a stdin read/stdout write error. +fn main to int +if ne argcnt 1 +otpfr 10 +otflush +ret 2 +end +k = otrdin +if eq k neg long 2 +ret 2 +end +n = ulong 1024 +if ge k 0 +n = ulong k +end +code = otengoal n +otflush +ret code +end diff --git a/native/omegese45/translate/main-goal2en.om b/native/omegese45/translate/main-goal2en.om new file mode 100644 index 0000000..8f31417 --- /dev/null +++ b/native/omegese45/translate/main-goal2en.om @@ -0,0 +1,22 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note goal2en driver: stdin one G line, stdout one English review sentence +note (exit 0) or `G2E_INVALID goal <reason>` (exit 31). Exit 2: usage (any +note argument) or a stdin read/stdout write error. +fn main to int +if ne argcnt 1 +otpfr 10 +otflush +ret 2 +end +k = otrdin +if eq k neg long 2 +ret 2 +end +n = ulong 1024 +if ge k 0 +n = ulong k +end +code = otgoalen n +otflush +ret code +end diff --git a/native/omegese45/translate/main-rep2en.om b/native/omegese45/translate/main-rep2en.om new file mode 100644 index 0000000..7209e47 --- /dev/null +++ b/native/omegese45/translate/main-rep2en.om @@ -0,0 +1,26 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note rep2en driver: rep2en FACTS_TSV, stdin = the G line then the P line. +note stdout: one English sentence (exit 0), `G2E_CONTRADICT <what>` (exit +note 30) or `G2E_INVALID <what>` (exit 31). Exit 2: usage (not exactly one +note argument) or a stdin read/stdout write error. +fn main to int +if ne argcnt 2 +otpfr 19 +otflush +ret 2 +end +k = otrdin +if eq k neg long 2 +ret 2 +end +if lt k 0 +put otol 0 0 +otpfr 18 +otpfr 31 +otflush +ret 31 +end +code = otrepen ulong k +otflush +ret code +end diff --git a/native/omegese45/translate/otfrag.om b/native/omegese45/translate/otfrag.om new file mode 100644 index 0000000..1796d08 --- /dev/null +++ b/native/omegese45/translate/otfrag.om @@ -0,0 +1,23 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note otfrag: fixed-text emitter. Concatenate AFTER the tool file that +note defines `text otfr` (a text must be declared before it is read). +note Append fragment number fi of otfr; fragments are separated by byte +note 124 (|) and fragment 0 starts at offset 0. +fn otpfr fi ulong to void +p = ulong 0 +c = ulong 0 +while lt c fi bound 4096 +if eq get otfr p 124 +c = add c 1 +end +p = add p 1 +end +while lt p len otfr bound 4096 +b = get otfr p +if eq b 124 +ret +end +otpb b +p = add p 1 +end +end diff --git a/native/omegese45/translate/otio.om b/native/omegese45/translate/otio.om new file mode 100644 index 0000000..5251dc0 --- /dev/null +++ b/native/omegese45/translate/otio.om @@ -0,0 +1,85 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note otio: byte I/O helpers shared by the #45 translator units (prefix ot). +note Output is collected in otob and written once by otflush, so a refusal +note never leaves a partial success line on stdout. Fixed texts are emitted +note by otfrag.om (concatenated after the tool file that defines otfr). +global otob uchar 8192 +global otol ulong 1 +global otin uchar 1024 +global otinl ulong 1 +global otdb uchar 24 + +note Read all of fd 0 into otin. Returns the byte count, -1 when the input +note does not fit (1024 bytes or more), -2 on a read error. Every pass adds +note at least one byte, so 1024 passes bound the loop. +fn otrdin to long +put otinl 0 0 +n = ulong 0 +while true bound 1025 +if ge n 1024 +ret neg long 1 +end +k = read 0 otin n sub 1024 n +if lt k 0 +ret neg long 2 +end +if eq k 0 +put otinl 0 n +ret long n +end +n = add n ulong k +end +ret neg long 2 +end + +fn otpb c uchar to void +o = get otol 0 +put otob o c +put otol 0 add o 1 +end + +note Append decimal v. +fn otpdec v ulong to void +if eq v 0 +otpb 48 +ret +end +p = ulong 24 +while gt v 0 bound 24 +p = sub p 1 +put otdb p uchar add 48 rem v 10 +v = div v 10 +end +while lt p 24 bound 24 +otpb get otdb p +p = add p 1 +end +end + +note Append v as exactly nd lowercase hex digits (nd 1..16). +fn otphex v ulong nd ulong to void +i = nd +while gt i 0 bound 16 +i = sub i 1 +d = and shr v mul i 4 15 +if lt d 10 +otpb uchar add d 48 +else +otpb uchar add d 87 +end +end +end + +note Write otob to fd 1. A short or failed write exits 2. +fn otflush to void +n = get otol 0 +o = ulong 0 +while lt o n bound 8193 +w = write 1 otob o sub n o +if le w 0 +exit 2 +end +o = add o ulong w +end +put otol 0 0 +end diff --git a/native/omegese45/translate/otmsg.om b/native/omegese45/translate/otmsg.om new file mode 100644 index 0000000..a203594 --- /dev/null +++ b/native/omegese45/translate/otmsg.om @@ -0,0 +1,42 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note otmsg: glue from the translator to the contract lane's codec and +note validator (native/omegese45/vocab.om and msg.om, concatenated before +note this file). The translator never re-implements the R45 grammar: every +note G and P line is validated by ocsetgl / ocvline. + +note Copy otin[o, o+n) into the contract input buffer ocin. False when the +note line does not fit. +fn otcopy o ulong n ulong to bool +if gt n len ocin +ret false +end +for i ulong n +put ocin i get otin add o i +end +ret true +end + +note Append the contract reason word for -v (v < 0 from ocvline/ocsetgl). +fn otprs v long to void +r = ulong neg v +if or lt r 1 gt r 20 +otpdec r +ret +end +o = mul sub r 1 8 +for j ulong 8 +c = get ocrtx add o j +if ne c 32 +otpb c +end +end +end + +note Append the surface word of vocabulary id. +fn otpword id ulong to void +ocvinit +o = get ocwo id +for j ulong get ocwl id +otpb get ocvtsv add o j +end +end diff --git a/native/omegese45/translate/rep2en.om b/native/omegese45/translate/rep2en.om new file mode 100644 index 0000000..a6dc403 --- /dev/null +++ b/native/omegese45/translate/rep2en.om @@ -0,0 +1,625 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note rep2en: goal G + model report P + runtime facts.tsv -> fixed-template +note English built only from the runtime facts. Success is printed only when +note every job of G has, as its last facts row, class ok and exit 0, and P +note agrees with G and with the facts. A P that contradicts the facts gives +note `G2E_CONTRADICT <what>` and 30; an invalid input `G2E_INVALID <what>` +note and 31. Facts follow interface v1.2 section 5: exact header line, exit +note to class/code map, ok rows with mjr1_outcome 1 and a P-256 compressed +note verifier key, and a legal job/attempt history (otfrows, othist). +note Needs otio.om, vocab.om, msg.om, otmsg.om before it and otfrag.om +note after it. Templates are documented in TRANSLATOR.md. +text otfr "Completed and verified: one matmul_u32 job multiplying a | by | matrix by a | matrix with seed |; job | dag_id | mjr1_sha256 |.\n|Completed and verified: two matmul_u32 jobs, each multiplying a | matrix, with seeds | and |Not completed: refused before dispatch (code bound): the goal asks for a | matmul and a dimension is outside the admitted range 1 to 256; nothing was dispatched.\n|Not completed: job | was refused (code | failed (code |): |G2E_CONTRADICT |G2E_INVALID |usage: rep2en FACTS_TSV < goal-and-report\n|the worker refused a replay of an already executed job|the job was refused for budget or fuel|the worker refused the job|the connection to the worker failed|the verifier refused the worker receipt|the verifier recompute failed|the recomputed result did not match the worker result|a local input or output error occurred|goal |report |facts\n|input\n|operands\n|jobs\n|class\n|code\n|dispatch\n|bound\n" +text othdt "job\tattempt\tm\tk\tn\tseed\texit\tclass\tcode\tdag_id\tmjr1_sha256\tmjr1_outcome\tverifier\n" + +const OTFMAX ulong 65536 +const OTRMAX ulong 64 +note facts.tsv bytes, row field offsets/lengths (13 per row), row values +note (job attempt m k n seed exit class code; class 1 ok 2 refused 3 fail; +note code = vocabulary id 14..21 or 0 for `-`). +global otfb uchar 65536 +global otfo ulong 832 +global otfl ulong 832 +global otrv ulong 576 +global otnr ulong 1 +global otpath uchar 4096 +note Goal: kind (6 mm, 7 pair), m, k, n, s, t. Report: outcome id (10 ok, +note 11 refused, 12 fail), kind, m, k, n, s, t, code id. +global otg ulong 6 +global otp ulong 8 + +note Field f of facts row r equals the vocabulary word id. +fn otfeqw r ulong f ulong id ulong to bool +ocvinit +x = add mul r 13 f +o = get otfo x +l = get otfl x +if ne l get ocwl id +ret false +end +w = get ocwo id +for i ulong l +if ne get otfb add o i get ocvtsv add w i +ret false +end +end +ret true +end + +note Field is exactly `-`. +fn otfdash r ulong f ulong to bool +x = add mul r 13 f +if ne get otfl x 1 +ret false +end +ret eq get otfb get otfo x 45 +end + +note Field is n lowercase hex digits. +fn otfhex r ulong f ulong n ulong to bool +x = add mul r 13 f +if ne get otfl x n +ret false +end +o = get otfo x +for i ulong n +c = get otfb add o i +ok = or and ge c 48 le c 57 and ge c 97 le c 102 +if not ok +ret false +end +end +ret true +end + +note Field is 64 lowercase hex digits or exactly `-`. +fn otfhod r ulong f ulong to bool +if otfdash r f +ret true +end +ret otfhex r f 64 +end + +note Field is exactly `1` (MJR1 outcome byte 1, completed). +fn otfone r ulong f ulong to bool +x = add mul r 13 f +if ne get otfl x 1 +ret false +end +ret eq get otfb get otfo x 49 +end + +note Field is a P-256 compressed public key: 66 lowercase hex digits +note starting `02` or `03`. +fn otfkey r ulong f ulong to bool +if not otfhex r f 66 +ret false +end +o = get otfo add mul r 13 f +if ne get otfb o 48 +ret false +end +c = get otfb add o 1 +ret or eq c 50 eq c 51 +end + +note Decimal value of field f of row r; OTBAD2 when not 1..9 digits. +const OTBAD2 ulong 1099511627776 +fn otfnum r ulong f ulong to ulong +x = add mul r 13 f +o = get otfo x +l = get otfl x +if or eq l 0 gt l 9 +ret OTBAD2 +end +v = ulong 0 +for i ulong l +c = get otfb add o i +if or lt c 48 gt c 57 +ret OTBAD2 +end +v = add mul v 10 ulong sub c 48 +end +ret v +end + +note Append field f of row r. +fn otpfld r ulong f ulong to void +x = add mul r 13 f +o = get otfo x +for i ulong get otfl x +otpb get otfb add o i +end +end + +note otfb[0, n) starts with the exact header line othdt. +fn othdrok n ulong to bool +h = len othdt +if lt n h +ret false +end +for i ulong h +if ne get otfb i get othdt i +ret false +end +end +ret true +end + +note Split otfb[h, n), h = the header length, into rows of 13 +note TAB-separated fields. False when a row is malformed, a line is empty +note (other than the final newline), or there are more than OTRMAX rows. +fn otfsplit n ulong to bool +put otnr 0 0 +r = ulong 0 +f = ulong 0 +p = len othdt +b = p +while le p n bound 65537 +c = uchar 10 +if lt p n +c = get otfb p +end +if or eq c 9 eq c 10 +if eq c 10 +if and eq p b eq f 0 +if lt p n +ret false +end +p = add p 1 +continue +end +end +if ge r OTRMAX +ret false +end +if ge f 13 +ret false +end +x = add mul r 13 f +put otfo x b +put otfl x sub p b +f = add f 1 +b = add p 1 +if eq c 10 +if ne f 13 +ret false +end +r = add r 1 +f = 0 +end +end +p = add p 1 +end +if ne f 0 +ret false +end +put otnr 0 r +ret true +end + +note Decode and check each row's values into otrv (9 per row). False on a +note row that is not a well-formed facts row (see TRANSLATOR.md). +fn otfrows to bool +for r ulong get otnr 0 +v = mul r 9 +for f ulong 7 +x = otfnum r f +if eq x OTBAD2 +ret false +end +put otrv add v f x +end +cl = ulong 0 +if otfeqw r 7 10 +cl = 1 +end +if otfeqw r 7 11 +cl = 2 +end +if otfeqw r 7 12 +cl = 3 +end +if eq cl 0 +ret false +end +put otrv add v 7 cl +cd = ulong 0 +if not otfdash r 8 +for id ulong 8 +if otfeqw r 8 add id 14 +cd = add id 14 +end +end +if eq cd 0 +ret false +end +end +put otrv add v 8 cd +ex = get otrv add v 6 +if eq cl 1 +if or ne ex 0 ne cd 0 +ret false +end +if not and otfhex r 9 64 otfhex r 10 64 +ret false +end +if not otfone r 11 +ret false +end +if not otfkey r 12 +ret false +end +else +if eq cd 0 +ret false +end +if not and otfdash r 11 otfdash r 12 +ret false +end +note A non-ok row may carry a real dag_id or a receipt digest: each is +note 64 lowercase hex or `-` (interface v1.2 section 5). +if not and otfhod r 9 otfhod r 10 +ret false +end +note Code -> class and exit (interface v1.2 section 5): replay, budget, +note worker (ids 14..16) are refused with exit 11; transport (17) fails +note with exit 10; receipt, recomp, verdict, io (18..21) fail with 12..15. +wc = ulong 3 +wx = sub cd 6 +if le cd 16 +wc = 2 +wx = 11 +end +if eq cd 17 +wx = 10 +end +if ne cl wc +ret false +end +if ne ex wx +ret false +end +end +end +ret true +end + +fn otrval r ulong f ulong to ulong +ret get otrv add mul r 9 f +end + +note Job/attempt history (interface v1.2 section 5). Jobs appear in order +note starting at 1, each with attempt 1 first. A second row for the same +note job is legal only as attempt 2 right after an attempt-1 `fail +note transport`. A row for the next job is legal only after the previous +note job's last row was ok. So nothing follows a job's ok row, every +note non-ok row other than one retried transport failure is the last row, +note and every attempt is 1 or 2, increasing within a job. +note pt: the previous row was an attempt-1 `fail transport`; pk: it was ok. +fn othist to bool +pj = ulong 0 +pt = false +pk = false +for r ulong get otnr 0 +j = otrval r 0 +a = otrval r 1 +if eq j pj +if not and eq a 2 pt +ret false +end +else +if not and eq j add pj 1 eq a 1 +ret false +end +if and gt pj 0 not pk +ret false +end +end +c7 = otrval r 7 +c8 = otrval r 8 +pj = j +pt = and eq a 1 and eq c7 3 eq c8 17 +pk = eq c7 1 +end +ret true +end + +note Row r states the goal dims and seed sd. +fn otrowok r ulong sd ulong to bool +if ne otrval r 2 get otg 1 +ret false +end +if ne otrval r 3 get otg 2 +ret false +end +if ne otrval r 4 get otg 3 +ret false +end +ret eq otrval r 5 sd +end + +note Emit `G2E_CONTRADICT <what>` (fragment fw) and return 30. +fn otcontra fw ulong to int +put otol 0 0 +otpfr 17 +otpfr fw +ret 30 +end + +note Emit `G2E_INVALID <what>` and return 31. +fn otinval fw ulong to int +put otol 0 0 +otpfr 18 +otpfr fw +ret 31 +end + +fn otrdims to void +otpdec get otg 1 +otpfr 1 +otpdec get otg 2 +otpfr 2 +otpdec get otg 2 +otpfr 1 +otpdec get otg 3 +end + +note Index of the last facts row of job j, or OTRMAX when there is none. +fn otlast j ulong to ulong +x = OTRMAX +for r ulong get otnr 0 +if eq otrval r 0 j +x = r +end +end +ret x +end + +note "; job {j} dag_id {dag} mjr1_sha256 {sha}" +fn otpjob j ulong r ulong to void +otpfr 4 +otpdec j +otpfr 5 +otpfld r 9 +otpfr 6 +otpfld r 10 +end + +note Read the facts file named by argument 1 into otfb. Returns the byte +note count or -1. +fn otrdfacts to long +an = argread 1 otpath 0 4096 +if le an 0 +ret neg long 1 +end +fd = fopen otpath 0 ulong an 0 0 +if lt fd 0 +ret neg long 1 +end +n = ulong 0 +while true bound 65537 +if ge n OTFMAX +ret neg long 1 +end +k = read int fd otfb n sub OTFMAX n +if lt k 0 +ret neg long 1 +end +if eq k 0 +break +end +n = add n ulong k +end +c = fclose int fd +ret long n +end + +note rep2en on otin[0, n): first line G, second line P. Returns the exit +note code with otob holding the English sentence or the typed line. +fn otrepen n ulong to int +note Split stdin into two lines. +e1 = n +for i ulong n +if eq get otin i 10 +e1 = i +break +end +end +if ge e1 n +ret otinval 31 +end +s2 = add e1 1 +e2 = n +if gt e2 s2 +if eq get otin sub e2 1 10 +e2 = sub e2 1 +end +end +if le e2 s2 +ret otinval 31 +end +note Goal. +if not otcopy 0 e1 +ret otinval 31 +end +v = ocsetgl e1 +if lt v 0 +put otol 0 0 +otpfr 18 +otpfr 28 +otprs v +otpb 10 +ret 31 +end +for i ulong 6 +put otg i get ocgv i +end +note Report. +if not otcopy s2 sub e2 s2 +ret otinval 31 +end +v = ocvline sub e2 s2 4 +if lt v 0 +put otol 0 0 +otpfr 18 +otpfr 29 +otprs v +otpb 10 +ret 31 +end +oc = get ocids 1 +put otp 0 oc +if eq oc 10 +put otp 1 get ocids 2 +put otp 2 ochexv 3 3 +put otp 3 ochexv 8 3 +put otp 4 ochexv 13 3 +put otp 5 ochexv 18 4 +put otp 6 0 +if eq get ocids 2 7 +put otp 6 ochexv 24 4 +end +else +put otp 7 get ocids 2 +end +note Facts. +fl = otrdfacts +if lt fl 0 +ret otinval 30 +end +if not othdrok ulong fl +ret otinval 30 +end +if not otfsplit ulong fl +ret otinval 30 +end +if not otfrows +ret otinval 30 +end +if not othist +ret otinval 30 +end +nj = ulong 1 +if eq get otg 0 7 +nj = 2 +end +note P operands against G. +if eq oc 10 +same = true +for i ulong 5 +if ne get otp add i 1 get otg i +same = false +end +end +if eq nj 2 +if ne get otp 6 get otg 5 +same = false +end +end +if not same +ret otcontra 32 +end +end +note Every facts row against G. +nr = get otnr 0 +for r ulong nr +j = otrval r 0 +if or lt j 1 gt j nj +ret otcontra 33 +end +sd = get otg 4 +if eq j 2 +sd = get otg 5 +end +same = otrowok r sd +if not same +ret otcontra 32 +end +end +if eq oc 10 +note Success needs the last row of every job to be class ok, exit 0. +for jj ulong nj +r = otlast add jj 1 +if eq r OTRMAX +ret otcontra 33 +end +if ne otrval r 7 1 +ret otcontra 34 +end +end +r1 = otlast 1 +if eq nj 1 +otpfr 0 +otrdims +otpfr 3 +otpdec get otg 4 +otpjob 1 r1 +otpfr 7 +ret 0 +end +r2 = otlast 2 +otpfr 8 +otrdims +otpfr 9 +otpdec get otg 4 +otpfr 10 +otpdec get otg 5 +otpjob 1 r1 +otpjob 2 r2 +otpfr 7 +ret 0 +end +cd = get otp 7 +if eq cd 13 +note Bound: decided before dispatch, so no facts rows and a G dim +note outside 1..256. +if gt nr 0 +ret otcontra 37 +end +adm = true +for i ulong 3 +d = get otg add i 1 +if or lt d 1 gt d 256 +adm = false +end +end +if adm +ret otcontra 37 +end +otpfr 11 +otpdec get otg 1 +otpfr 1 +otpdec get otg 2 +otpfr 1 +otpdec get otg 3 +otpfr 12 +ret 0 +end +if eq nr 0 +ret otcontra 36 +end +rl = sub nr 1 +wantc = ulong 2 +if eq oc 12 +wantc = 3 +end +if ne otrval rl 7 wantc +ret otcontra 34 +end +if ne otrval rl 8 cd +ret otcontra 35 +end +otpfr 13 +otpdec otrval rl 0 +if eq oc 11 +otpfr 14 +else +otpfr 15 +end +otpword cd +otpfr 16 +otpfr add 6 cd +otpfr 7 +ret 0 +end diff --git a/native/omegese45/vocab.om b/native/omegese45/vocab.om new file mode 100644 index 0000000..c0fb82e --- /dev/null +++ b/native/omegese45/vocab.om @@ -0,0 +1,318 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note R45 vocabulary and lossless codec (aien-train #45, contract lane). +note The text ocvtsv is byte-identical to docs/omegese45/vocab.tsv; its sha256 is the +note vocabulary pin (docs/omegese45/CONTRACT.md). Word offsets are parsed from that text, +note so the codec and the T table can never disagree. +note Build order: cat vocab.om msg.om [mjr1.om] <unit with fn main>. All names use the oc prefix. +note Public API (stable, documented in CONTRACT.md): +note ocin uchar 4096 input line bytes, filled by the caller +note ocids ulong 256 ids (encode output / decode and validator input) +note ocipos ulong 256 byte offset in ocin of each id (encode output) +note ocout uchar 4096 decode output text +note ocerr ulong 2 [0] position, [1] reason code of the last error +note fn ocenc n ulong to long ocin[0,n) -> ocids; returns id count or -reason +note fn ocdec n ulong to long ocids[0,n) -> ocout; returns byte count or -reason +note Reason codes: see the const block; ocputrs prints the reason word. +const ocv ulong 41 +const ocmaxi ulong 176 +const ocmaxb ulong 1024 +const ocrempty long 1 +const ocrspace long 2 +const ocrtab long 3 +const ocrcr long 4 +const ocrnasc long 5 +const ocrupper long 6 +const ocrhexc long 7 +const ocrctrl long 8 +const ocrunk long 9 +const ocrlong long 10 +const ocrbadid long 11 +const ocrdigit long 12 +const ocrgram long 13 +const ocrnoend long 14 +const ocrtrail long 15 +const ocrkind long 16 +const ocrnjob long 17 +const ocrjobix long 18 +const ocrdims long 19 +const ocrseed long 20 +text ocvtsv "0\t<pad>\treserved\tcontext padding only; never emitted, never in a message\n1\tgoal\tframe\tprofile word\n2\tact\tframe\tprofile word\n3\tres\tframe\tprofile word, runtime-only (the model never emits it)\n4\trep\tframe\tprofile word\n5\tend\tframe\tOmega keyword `end` (block terminator)\n6\tmm\tkind\tprofile word: one `matmul_u32` job\n7\tpair\tkind\tprofile word: two `matmul_u32` jobs, same dims, seeds in order\n8\tjob\taction\tprofile word: submit one admitted microjob\n9\trefuse\taction\tprofile word: refuse before submission\n10\tok\toutcome\tprofile word\n11\trefused\toutcome\tprofile word\n12\tfail\toutcome\tprofile word\n13\tbound\tcode\tgoal outside the admitted bounds (a dim not in 1..256); decided by the model\n14\treplay\tcode\tworker refusal AN0_REPLAY\n15\tbudget\tcode\tworker refusal: budget/fuel\n16\tworker\tcode\tany other worker refusal (aienet0-run exit 11)\n17\ttransport\tcode\taienet0-run exit 10\n18\treceipt\tcode\taienet0-run exit 12\n19\trecomp\tcode\taienet0-run exit 13\n20\tverdict\tcode\taienet0-run exit 14\n21\tio\tcode\taienet0-run exit 15\n22\tushort\ttype\tOmega type keyword (u16), OMEGESE.md:114\n23\tulong\ttype\tOmega type keyword (u64), OMEGESE.md:114\n24\t0x\tliteral\tOmega hex-literal prefix, OMEGESE.md:691\n25\t0\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n26\t1\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n27\t2\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n28\t3\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n29\t4\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n30\t5\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n31\t6\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n32\t7\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n33\t8\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n34\t9\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n35\ta\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n36\tb\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n37\tc\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n38\td\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n39\te\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n40\tf\tliteral digit\tOmega hex digits (lowercase), OMEGESE.md:691\n" +text ocrtx "empty space tab cr nonasciiupper hexcase ctrl unknown long badid digit grammar noend trailingkind notjob jobindexdims seed " +global ocwo ulong 41 +global ocwl ulong 41 +global ocvok ulong 1 +global ocin uchar 4096 +global ocids ulong 256 +global ocipos ulong 256 +global ocout uchar 4096 +global ocerr ulong 2 +global ocb1 uchar 1 +global ocnb uchar 24 + +note Parse ocvtsv once: row i is "<id>\t<word>\t<class>\t<provenance>\n". +fn ocvinit to void +if eq get ocvok 0 1 +ret +end +p = ulong 0 +for i ulong ocv +while ne get ocvtsv p 9 bound 8 +p = add p 1 +end +p = add p 1 +put ocwo i p +while ne get ocvtsv p 9 bound 16 +p = add p 1 +end +put ocwl i sub p get ocwo i +while ne get ocvtsv p 10 bound 200 +p = add p 1 +end +p = add p 1 +end +put ocvok 0 1 +end + +note Record an error and return -r. +fn ocerrset pos ulong r long to long +put ocerr 0 pos +put ocerr 1 ulong r +ret sub 0 r +end + +fn ocisdig id ulong to bool +ret and ge id 25 le id 40 +end + +note Hex digit value of a lowercase ASCII byte, 16 when it is not one. +fn ochexd b uchar to ulong +if and ge b 48 le b 57 +ret ulong sub b 48 +end +if and ge b 97 le b 102 +ret ulong sub b 87 +end +ret 16 +end + +note ocin[s,s+n) equals the word of id? +fn ocwmatch id ulong s ulong n ulong to bool +if ne n get ocwl id +ret false +end +o = get ocwo id +for j ulong n +if ne get ocin add s j get ocvtsv add o j +ret false +end +end +ret true +end + +note Id of the plain word ocin[s,s+n) among ids 0..23, or 99. +fn oclook s ulong n ulong to ulong +for i ulong 24 +if ocwmatch i s n +ret i +end +end +ret 99 +end + +note Encode one word ocin[s,e) at id index k; return the new count or -reason. +fn ocencw s ulong e ulong k ulong to long +wn = sub e s +hx = false +if ge wn 2 +if and eq get ocin s 48 eq get ocin add s 1 120 +hx = true +end +end +if hx +if ge k ocmaxi +ret ocerrset s ocrlong +end +put ocids k 24 +put ocipos k s +k = add k 1 +for j ulong sub wn 2 +q = add add s 2 j +v = ochexd get ocin q +if eq v 16 +ret ocerrset q ocrunk +end +if ge k ocmaxi +ret ocerrset q ocrlong +end +put ocids k add 25 v +put ocipos k q +k = add k 1 +end +ret long k +end +id = oclook s wn +if eq id 99 +ret ocerrset s ocrunk +end +if ge k ocmaxi +ret ocerrset s ocrlong +end +put ocids k id +put ocipos k s +ret long add k 1 +end + +note Text -> ids. Byte classes are checked first (first offending byte wins), +note then single-space word structure, then words left to right. +fn ocenc n ulong to long +ocvinit +if eq n 0 +ret ocerrset 0 ocrempty +end +if gt n ocmaxb +ret ocerrset ocmaxb ocrlong +end +for i ulong n +b = get ocin i +if eq b 13 +ret ocerrset i ocrcr +end +if eq b 9 +ret ocerrset i ocrtab +end +if gt b 127 +ret ocerrset i ocrnasc +end +if or lt b 32 eq b 127 +ret ocerrset i ocrctrl +end +if and ge b 65 le b 90 +hc = false +if and eq b 88 gt i 0 +if eq get ocin sub i 1 48 +hc = true +end +end +if hc +ret ocerrset i ocrhexc +end +ret ocerrset i ocrupper +end +end +if eq get ocin 0 32 +ret ocerrset 0 ocrspace +end +if eq get ocin sub n 1 32 +ret ocerrset sub n 1 ocrspace +end +for i ulong sub n 1 +if and eq get ocin i 32 eq get ocin add i 1 32 +ret ocerrset add i 1 ocrspace +end +end +k = ulong 0 +s = ulong 0 +for i ulong add n 1 +br = false +if eq i n +br = true +else +if eq get ocin i 32 +br = true +end +end +if br +r = ocencw s i k +if lt r 0 +ret r +end +k = ulong r +s = add i 1 +end +end +ret long k +end + +note Ids -> text in ocout. Errors carry the id index as position. +fn ocdec n ulong to long +ocvinit +if eq n 0 +ret ocerrset 0 ocrempty +end +if gt n ocmaxi +ret ocerrset ocmaxi ocrlong +end +p = ulong 0 +for i ulong n +id = get ocids i +if ge id ocv +ret ocerrset i ocrbadid +end +if ocisdig id +if eq i 0 +ret ocerrset 0 ocrdigit +end +if lt get ocids sub i 1 24 +ret ocerrset i ocrdigit +end +put ocout p get ocvtsv get ocwo id +p = add p 1 +else +if gt i 0 +put ocout p 32 +p = add p 1 +end +o = get ocwo id +for j ulong get ocwl id +put ocout p get ocvtsv add o j +p = add p 1 +end +end +end +ret long p +end + +fn ocputc c uchar to void +put ocb1 0 c +w = write 1 ocb1 0 1 +if ne w 1 +exit 2 +end +end + +fn ocputn n ulong to void +if eq n 0 +ocputc 48 +ret +end +p = ulong 24 +while gt n 0 bound 24 +p = sub p 1 +put ocnb p uchar add 48 rem n 10 +n = div n 10 +end +w = write 1 ocnb p sub 24 p +if ne w long sub 24 p +exit 2 +end +end + +note Print the reason word of code r (1..20). +fn ocputrs r ulong to void +o = mul sub r 1 8 +for j ulong 8 +c = get ocrtx add o j +if ne c 32 +ocputc c +end +end +end + +note Print the surface word of id (digits print as one character). +fn ocputw id ulong to void +ocvinit +o = get ocwo id +for j ulong get ocwl id +ocputc get ocvtsv add o j +end +end diff --git a/tests/omegese45/contract/main.om b/tests/omegese45/contract/main.om new file mode 100644 index 0000000..6cf0dae --- /dev/null +++ b/tests/omegese45/contract/main.om @@ -0,0 +1,361 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note Contract driver (aien-train #45). Build: +note cat native/omegese45/vocab.om native/omegese45/msg.om native/omegese45/mjr1.om \ +note tests/omegese45/contract/main.om | omc > oe45c +note stdin = one mode letter, LF, payload. Modes (see docs/omegese45/CONTRACT.md): +note V <line> VALID <G|A|R|P> | exit 40 INVALID <bytepos> <reason> +note N <kind G|A|R|P|M> LF <decimal ids> MASK <41 x 0|1> LF FINAL <0|1> +note B <G line> LF <job> LF <A line> BIND_OK | 40 INVALID | 41 BIND_MISMATCH <r> | 42 BIND_BOUND +note L <A line> LOWER <m> <k> <n> <seed> | 40 | 41 BIND_MISMATCH notjob +note E <line> IDS <id>... | exit 40 INVALID <bytepos> <reason> +note D <decimal ids> <text line> | exit 40 INVALID <idindex> <reason> +note T the vocab table, byte-identical to vocab.tsv +note J <receipt path> MJR1 <outcome> <attempt> <generation> <dag> <job> <output> +note | exit 43 MJR1_INVALID <pos> <reason> +note Exit 2: usage (bad mode, malformed payload, output failure). +global ocxin uchar 16384 +global ocxn ulong 1 +text ocxva "VALID " +text ocxiv "INVALID " +text ocxmk "MASK " +text ocxfi "FINAL " +text ocxbo "BIND_OK\n" +text ocxbm "BIND_MISMATCH " +text ocxbb "BIND_BOUND\n" +text ocxlo "LOWER" +text ocxid "IDS" +text ocxmj "MJR1 " +text ocxmi "MJR1_INVALID " +text ocxkl "?GARPM" + +note End of the line that starts at s (index of LF or the input length). +fn ocxeol s ulong to ulong +n = get ocxn 0 +e = s +while and lt e n ne get ocxin e 10 bound 20000 +e = add e 1 +end +ret e +end + +note Copy ocxin[a,b) into ocin; return the length (capped at the ocin size). +fn ocxcopy a ulong b ulong to ulong +c = sub b a +if gt c 4096 +c = 4096 +end +for i ulong c +put ocin i get ocxin add a i +end +ret sub b a +end + +note Parse space-separated decimal numbers in ocxin[a,b) into ocids; -1 when malformed. +fn ocxnums a ulong b ulong to long +k = ulong 0 +v = ulong 0 +nd = ulong 0 +for i ulong add sub b a 1 +p = add a i +sep = true +if lt p b +if ne get ocxin p 32 +sep = false +end +end +if sep +if eq nd 0 +if or lt p b gt k 0 +ret -1 +end +else +if ge k 256 +ret -1 +end +put ocids k v +k = add k 1 +v = 0 +nd = 0 +end +else +c = get ocxin p +if or lt c 48 gt c 57 +ret -1 +end +if ge nd 6 +ret -1 +end +v = add mul v 10 ulong sub c 48 +nd = add nd 1 +end +end +ret long k +end + +fn ocxinv r long to void +w = write 1 ocxiv 0 len ocxiv +ocputn get ocerr 0 +ocputc 32 +ocputrs get ocerr 1 +ocputc 10 +end + +fn ocxkind c uchar to ulong +for i ulong 5 +if eq c get ocxkl add i 1 +ret add i 1 +end +end +ret 0 +end + +fn ocxmode_v to int +e = ocxeol 2 +if ne e get ocxn 0 +if ne add e 1 get ocxn 0 +note a second line inside the payload is a control byte +e = get ocxn 0 +end +end +n = ocxcopy 2 e +r = ocvline n 0 +if lt r 0 +ocxinv r +ret 40 +end +w = write 1 ocxva 0 len ocxva +ocputc get ocxkl ulong r +ocputc 10 +ret 0 +end + +fn ocxmode_e to int +e = ocxeol 2 +if ne e get ocxn 0 +if ne add e 1 get ocxn 0 +e = get ocxn 0 +end +end +n = ocxcopy 2 e +r = ocenc n +if lt r 0 +ocxinv r +ret 40 +end +w = write 1 ocxid 0 len ocxid +for i ulong ulong r +ocputc 32 +ocputn get ocids i +end +ocputc 10 +ret 0 +end + +fn ocxmode_d to int +e = ocxeol 2 +k = ocxnums 2 e +if lt k 0 +ret 2 +end +r = ocdec ulong k +if lt r 0 +ocxinv r +ret 40 +end +w = write 1 ocout 0 ulong r +if ne w r +exit 2 +end +ocputc 10 +ret 0 +end + +fn ocxmode_n to int +e1 = ocxeol 2 +if ne e1 3 +ret 2 +end +kd = ocxkind get ocxin 2 +if eq kd 0 +ret 2 +end +e2 = ocxeol add e1 1 +k = ocxnums add e1 1 e2 +if lt k 0 +ret 2 +end +st = ocstart kd +for i ulong ulong k +id = get ocids i +if ge id ocv +ret 2 +end +st = ocstep st id +end +c = ocmask st +w = write 1 ocxmk 0 len ocxmk +for id ulong ocv +ocputc add 48 get ocmk id +end +ocputc 10 +w = write 1 ocxfi 0 len ocxfi +if ocfinal st +ocputc 49 +else +ocputc 48 +end +ocputc 10 +ret 0 +end + +fn ocxmode_b to int +e1 = ocxeol 2 +n = ocxcopy 2 e1 +r = ocsetgl n +if lt r 0 +ocxinv r +ret 40 +end +e2 = ocxeol add e1 1 +k = ocxnums add e1 1 e2 +if ne k 1 +ret 2 +end +job = get ocids 0 +e3 = ocxeol add e2 1 +n = ocxcopy add e2 1 e3 +r = ocbindl n job +if lt r 0 +ocxinv r +ret 40 +end +if eq r 41 +w = write 1 ocxbm 0 len ocxbm +ocputrs get ocerr 1 +ocputc 10 +ret 41 +end +if eq r 42 +w = write 1 ocxbb 0 len ocxbb +ret 42 +end +w = write 1 ocxbo 0 len ocxbo +ret 0 +end + +fn ocxmode_l to int +e = ocxeol 2 +n = ocxcopy 2 e +r = oclowerl n +if lt r 0 +ocxinv r +ret 40 +end +if eq r 41 +w = write 1 ocxbm 0 len ocxbm +ocputrs get ocerr 1 +ocputc 10 +ret 41 +end +w = write 1 ocxlo 0 len ocxlo +for i ulong 4 +ocputc 32 +ocputn get oclv i +end +ocputc 10 +ret 0 +end + +fn ocxmode_t to int +ocvinit +w = write 1 ocvtsv 0 len ocvtsv +if ne w long len ocvtsv +exit 2 +end +ret 0 +end + +fn ocxmode_j to int +e = ocxeol 2 +pl = sub e 2 +if gt pl 4096 +ret 2 +end +for i ulong pl +put ocpath i get ocxin add 2 i +end +r = ocmjrf pl +if lt r 0 +w = write 1 ocxmi 0 len ocxmi +ocputn get ocerr 0 +ocputc 32 +ocmputrs get ocerr 1 +ocputc 10 +ret 43 +end +w = write 1 ocxmj 0 len ocxmj +ocmputo get ocmv 0 +ocputc 32 +ocputn get ocmv 1 +ocputc 32 +ocputn get ocmv 2 +ocputc 32 +ocmhex 8 40 +ocputc 32 +ocmhex 40 56 +ocputc 32 +ocmhex 144 176 +ocputc 10 +ret 0 +end + +fn main to int +t = ulong 0 +fin = false +while and lt t 16384 not fin bound 20000 +r = read 0 ocxin t sub 16384 t +if le r 0 +fin = true +else +t = add t ulong r +end +end +put ocxn 0 t +if lt t 1 +ret 2 +end +if gt t 1 +if ne get ocxin 1 10 +ret 2 +end +end +md = get ocxin 0 +if eq md 84 +ret ocxmode_t +end +if lt t 2 +ret 2 +end +if eq md 86 +ret ocxmode_v +end +if eq md 78 +ret ocxmode_n +end +if eq md 66 +ret ocxmode_b +end +if eq md 76 +ret ocxmode_l +end +if eq md 69 +ret ocxmode_e +end +if eq md 68 +ret ocxmode_d +end +if eq md 74 +ret ocxmode_j +end +ret 2 +end diff --git a/tests/omegese45/translator/cases.tsv b/tests/omegese45/translator/cases.tsv new file mode 100644 index 0000000..3fbd4b9 --- /dev/null +++ b/tests/omegese45/translator/cases.tsv @@ -0,0 +1,18 @@ +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end multiply a 4 by 8 matrix by a 8 by 2 matrix with seed 7 +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end run a matmul of size 4 x 8 x 2 with seed 7 +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end matmul 4x8x2 seed 7 +goal pair ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 ulong 0x0008 end run two matmuls of size 4 x 8 x 2 with seeds 7 and 8 +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end RUN A MATMUL OF SIZE 4 X 8 X 2 WITH SEED 7 +goal mm ushort 0x000 ushort 0x001 ushort 0x001 ulong 0x0001 end matmul 0x1x1 seed 1 +goal mm ushort 0x001 ushort 0x001 ushort 0x001 ulong 0x0001 end matmul 1x1x1 seed 1 +goal mm ushort 0x100 ushort 0x001 ushort 0x001 ulong 0x0001 end matmul 256x1x1 seed 1 +goal mm ushort 0x101 ushort 0x001 ushort 0x001 ulong 0x0001 end matmul 257x1x1 seed 1 +goal mm ushort 0xfff ushort 0x001 ushort 0x001 ulong 0x0001 end matmul 4095x1x1 seed 1 +refuse 21 matmul 4096x1x1 seed 1 +goal mm ushort 0x001 ushort 0x001 ushort 0x001 ulong 0xffff end matmul 1x1x1 seed 65535 +refuse 21 matmul 1x1x1 seed 65536 +refuse 20 tell me a joke +refuse 21 matmul 1x1x1 seed 1e3 +refuse 22 multiply a 4 by 8 matrix by a 9 by 2 matrix with seed 7 +refuse 23 run a matmul of size 4 x 8 x 2 with seeds 7 and 8 +refuse 20 diff --git a/tests/omegese45/translator/heldout-errata.tsv b/tests/omegese45/translator/heldout-errata.tsv new file mode 100644 index 0000000..0ddfa8f --- /dev/null +++ b/tests/omegese45/translator/heldout-errata.tsv @@ -0,0 +1,2 @@ +row original corrected date reason +12 refuse 21 goal mm ushort 0x000 ushort 0x006 ushort 0x008 ulong 0x0003 end 2026-10-29 interface v1.2 section 4: EN_RANGE is only dim > 4095, seed > 65535 or malformed, never dim 0; dim 0 is representable (D 0x000) and the core refuses it with bound. Review45CT finding T3. heldout.tsv (faeb7ad) is not rewritten. diff --git a/tests/omegese45/translator/heldout.tsv b/tests/omegese45/translator/heldout.tsv new file mode 100644 index 0000000..e12e4dd --- /dev/null +++ b/tests/omegese45/translator/heldout.tsv @@ -0,0 +1,45 @@ +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end Please multiply a 4 by 8 matrix by an 8 by 2 matrix with seed 7. +goal mm ushort 0x010 ushort 0x020 ushort 0x008 ulong 0x04d2 end MULTIPLY A 16 BY 32 MATRIX BY A 32 BY 8 MATRIX WITH SEED 1234 +goal mm ushort 0x040 ushort 0x040 ushort 0x040 ulong 0x0000 end run a matmul of size 64 x 64 x 64 with seed 0 +goal mm ushort 0x003 ushort 0x005 ushort 0x007 ulong 0x002a end Run a matmul of size 3x5x7 with seed 42 +goal mm ushort 0x080 ushort 0x100 ushort 0x001 ulong 0xffff end matmul 128x256x1 seed 65535 +goal mm ushort 0x001 ushort 0x001 ushort 0x001 ulong 0x0001 end matmul 1 x 1 x 1 seed 1 +goal mm ushort 0x00a ushort 0x014 ushort 0x01e ulong 0x0063 end matmul 10x20x30 seed 99 +goal mm ushort 0x00c ushort 0x018 ushort 0x006 ulong 0x01f4 end compute a matmul of size 12 x 24 x 6 with seed 500 +goal pair ushort 0x008 ushort 0x004 ushort 0x002 ulong 0x000b ulong 0x000c end Run two matmuls of size 8 x 4 x 2 with seeds 11 and 12. +goal pair ushort 0x12c ushort 0x002 ushort 0x002 ulong 0x0001 ulong 0x0002 end run two matmuls of size 300 x 2 x 2 with seeds 1 and 2 +refuse 22 Multiply a 5 by 6 matrix by a 7 by 8 matrix with seed 3 +refuse 21 multiply a 0 by 6 matrix by a 6 by 8 matrix with seed 3 +refuse 21 matmul 4096x2x2 seed 5 +refuse 21 matmul 2x2x2 seed 70000 +refuse 21 matmul 2x2x2 seed -1 +refuse 21 matmul 2.5x2x2 seed 1 +refuse 20 please add two numbers +refuse 20 what is the weather +refuse 23 run a matmul of size 4 x 4 x 4 with seeds 1 and 2 +refuse 23 run two matmuls of size 4 x 4 x 4 with seed 9 +goal mm ushort 0x009 ushort 0x009 ushort 0x009 ulong 0x0009 end Do a matmul of size 9x9x9 with seed 9 +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end multiply a 4 by 8 matrix with an 8 by 2 matrix using seed 7 +goal mm ushort 0x002 ushort 0x003 ushort 0x004 ulong 0x0005 end matmul 2x3x4 with seed 5 +goal mm ushort 0x002 ushort 0x003 ushort 0x004 ulong 0x0005 end submit a matmul of size 2 x 3 x 4 with seed 5 +goal mm ushort 0x100 ushort 0x100 ushort 0x100 ulong 0xffff end Multiply a 256 by 256 matrix by a 256 by 256 matrix with seed 65535 +goal mm ushort 0x101 ushort 0x001 ushort 0x001 ulong 0x0000 end multiply a 257 by 1 matrix by a 1 by 1 matrix with seed 0 +refuse 20 matmul 4x8x2 +goal mm ushort 0x004 ushort 0x004 ushort 0x004 ulong 0x0003 end multiply two 4 by 4 matrices with seed 3 +goal pair ushort 0x004 ushort 0x004 ushort 0x004 ulong 0x0005 ulong 0x0006 end run 2 matmuls of size 4x4x4 with seeds 5 and 6 +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end matmul 4x8x2 seed 7 please +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end run a matmul of size 4 by 8 by 2 with seed 7 +goal pair ushort 0x010 ushort 0x010 ushort 0x010 ulong 0x0064 ulong 0x00c8 end Two matmuls, 16x16x16, seeds 100 and 200 +goal pair ushort 0x010 ushort 0x010 ushort 0x010 ulong 0x0064 ulong 0x00c8 end matmuls 16x16x16 seeds 100 and 200 +refuse 23 run a matmul of size 4x8x2 with seed 7 and seed 8 +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end matmul 4x8x2 seed 007 +refuse 21 matmul 4x8x2 seed 0x10 +goal mm ushort 0x00c ushort 0x004 ushort 0x00c ulong 0x000c end Multiply a 12 by 4 matrix by a 4 by 12 matrix with seed 12 +refuse 21 matmul 4096x4096x4096 seed 1 +goal pair ushort 0x004 ushort 0x008 ushort 0x002 ulong 0xffff ulong 0x0000 end run two matmuls of size 4 x 8 x 2 with seeds 65535 and 0 +goal pair ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0001 ulong 0x0002 end multiply a 4 by 8 matrix by a 8 by 2 matrix twice with seeds 1 and 2 +refuse 20 run three matmuls of size 2x2x2 with seeds 1, 2 and 3 +refuse 20 multiply a 4 by 8 matrix by a 8 by 2 matrix +refuse 20 matmul 4x8x2 seed 7; matmul 2x2x2 seed 3 +goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end MatMul 4X8X2 Seed 7 +refuse 23 run a matmul of size 4 x 8 x 2 with seed 7 or 8 diff --git a/tests/omegese45/translator/run-translator.sh b/tests/omegese45/translator/run-translator.sh new file mode 100755 index 0000000..a2771ad --- /dev/null +++ b/tests/omegese45/translator/run-translator.sh @@ -0,0 +1,257 @@ +#!/bin/sh +# SPDX-License-Identifier: AGPL-3.0-only +# Translator suite for aien-train #45: builds en2goal, goal2en and rep2en +# from .om with the pinned omc (refuses any other omc), then checks the dev +# cases, the held-out set (raw counts against the committed file, then with +# the dated errata in heldout-errata.tsv), every refusal code, boundaries, +# goal2en/en2goal stability, rep2en per outcome class, contradictions and +# the interface v1.2 facts rules, cost, and negative controls: a k<->n +# en2goal mutant and one rep2en mutant per facts check (each must be caught). +# Loads no model or checkpoint. Shell only builds, runs and compares bytes. +set -u +ROOT=$(cd "$(dirname "$0")/../../.." && pwd) +OMC=${OMC:-/tmp/om-main/seed/out/omc} +PIN=62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b +T=$ROOT/native/omegese45/translate +C=$ROOT/native/omegese45 +D=$ROOT/tests/omegese45/translator +W=${WORK:-$(mktemp -d)} +RUN="taskset -c 10-14 nice -n 19 ionice -c3" +FAIL=0 +fail() { echo "FAIL $*"; FAIL=1; } + +got=$(sha256sum "$OMC" 2>/dev/null | cut -d' ' -f1) +echo "omc sha256 $got" +[ "$got" = "$PIN" ] || { echo "OMC_PIN_MISMATCH want $PIN ($OMC)"; echo OE45_TRANSLATOR_FAIL; exit 1; } + +build() { # name units... + n=$1; shift + cat "$@" > "$W/$n.unit.om" || exit 1 + $RUN "$OMC" < "$W/$n.unit.om" > "$W/$n" 2> "$W/$n.err" || { cat "$W/$n.err"; echo "BUILD_FAIL $n"; exit 1; } + [ "$(od -An -c -N4 "$W/$n" | tr -d ' ')" = '177ELF' ] || { echo "BUILD_FAIL $n not ELF"; exit 1; } + chmod +x "$W/$n" +} +REPU="$T/otio.om $C/vocab.om $C/msg.om $T/otmsg.om" +build en2goal "$T/otio.om" "$T/en2goal.om" "$T/otfrag.om" "$T/main-en2goal.om" +build goal2en $REPU "$T/goal2en.om" "$T/otfrag.om" "$T/main-goal2en.om" +build rep2en $REPU "$T/rep2en.om" "$T/otfrag.om" "$T/main-rep2en.om" +# Mutant: k and n swapped in the emitted G (negative control). +sed -e 's/^kv = get otrd 3$/kv = get otrd 4/' -e 's/^nv = get otrd 4$/nv = get otrd 3/' "$T/en2goal.om" > "$W/en2goal-mut.om" +cmp -s "$T/en2goal.om" "$W/en2goal-mut.om" && { echo "MUTANT_NOT_APPLIED"; exit 1; } +build en2goal-mut "$T/otio.om" "$W/en2goal-mut.om" "$T/otfrag.om" "$T/main-en2goal.om" + +# score BIN FILE -> "exact refused_differently wrong total" +score() { + ex=0; rd=0; wr=0; tot=0 + TAB=$(printf '\t') + while IFS="$TAB" read -r exp req; do + tot=$((tot+1)) + out=$(printf '%s\n' "$req" | "$1"); rc=$? + case $exp in + refuse*) want=${exp#refuse } + if [ "$rc" = "$want" ]; then ex=$((ex+1)); elif [ "$rc" = 0 ]; then wr=$((wr+1)); echo " wrong: [$req] -> $out" >&2; else rd=$((rd+1)); echo " refused-differently: [$req] rc=$rc want=$want" >&2; fi ;; + *) if [ "$rc" = 0 ] && [ "$out" = "$exp" ]; then ex=$((ex+1)); elif [ "$rc" = 0 ]; then wr=$((wr+1)); echo " wrong: [$req] -> $out" >&2; else rd=$((rd+1)); echo " refused-differently: [$req] rc=$rc" >&2; fi ;; + esac + done < "$2" + echo "$ex $rd $wr $tot" +} + +set -- $(score "$W/en2goal" "$D/cases.tsv") +echo "DEV exact=$1 refused_differently=$2 wrong=$3 total=$4" +[ "$1" = "$4" ] || fail "dev cases must all be exact" + +# Held-out. The primary number is raw, against the committed heldout.tsv +# (faeb7ad, never rewritten). heldout-errata.tsv lists dated corrections +# where the interface changed after the file was written; each erratum's +# original must equal the committed expectation. PASS: raw wrong is at most +# the number of errata rows and the corrected file has wrong 0. +set -- $(score "$W/en2goal" "$D/heldout.tsv") +echo "HELDOUT exact=$1 refused_differently=$2 wrong=$3 total=$4 (raw, committed heldout.tsv)" +rawwr=$3 +ner=$(($(wc -l < "$D/heldout-errata.tsv") - 1)) +awk -F'\t' -v OFS='\t' ' + NR == FNR { if (FNR > 1) { want[$1] = $2; fix[$1] = $3 } next } + (FNR in fix) { if ($1 != want[FNR]) bad = 1; $1 = fix[FNR]; n++ } + { print } + END { if (bad) exit 3; print n > "/dev/stderr" }' \ + "$D/heldout-errata.tsv" "$D/heldout.tsv" > "$W/heldout-corrected.tsv" 2> "$W/errata.n" \ + || fail "an erratum's original does not match heldout.tsv" +[ "$(cat "$W/errata.n")" = "$ner" ] || fail "errata applied $(cat "$W/errata.n") of $ner" +tail -n +2 "$D/heldout-errata.tsv" | while IFS=$(printf '\t') read -r row orig corr dt why; do + echo "ERRATUM row=$row original=[$orig] corrected=[$corr] date=$dt reason: $why" +done +set -- $(score "$W/en2goal" "$W/heldout-corrected.tsv" 2>/dev/null) +echo "HELDOUT_CORRECTED exact=$1 refused_differently=$2 wrong=$3 total=$4 (errata=$ner)" +[ "$3" = 0 ] || fail "held-out wrong with errata must be 0" +[ "$rawwr" -le "$ner" ] || fail "raw held-out wrong $rawwr exceeds errata $ner" + +# Over-long input (513 bytes) -> 20. +long=$(printf '%0513d' 0) +printf '%s\n' "$long" | "$W/en2goal" > /dev/null; rc=$? +[ "$rc" = 20 ] && echo "REFUSAL long-input rc=20" || fail "long input rc=$rc" +for c in 20 21 22 23; do grep -q "^refuse $c" "$D/cases.tsv" || fail "no dev case for $c"; done + +# Stability: goal2en of every accepted G re-parses to the same G. +st=0 +for f in "$D/cases.tsv" "$W/heldout-corrected.tsv"; do + cut -f1 "$f" | grep '^goal' | sort -u > "$W/goals" + while read -r g; do + s=$(printf '%s\n' "$g" | "$W/goal2en") || fail "goal2en rc on [$g]" + g2=$(printf '%s\n' "$s" | "$W/en2goal") + [ "$g2" = "$g" ] && st=$((st+1)) || fail "unstable [$g] -> [$s] -> [$g2]" + done < "$W/goals" +done +echo "STABLE count=$st" +out=$(printf 'goal mm ushort 0x04 end\n' | "$W/goal2en"); rc=$? +[ "$rc" = 31 ] && echo "GOAL2EN invalid rc=31 [$out]" || fail "goal2en invalid rc=$rc" +want='Goal for review: one matmul_u32 job multiplying a 4 by 8 matrix by a 8 by 2 matrix with seed 7.' +out=$(printf 'goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end\n' | "$W/goal2en") +[ "$out" = "$want" ] || fail "goal2en template [$out]" + +# rep2en per class, contradictions and facts rules (interface v1.2 section 5). +TAB=$(printf '\t') +H="job${TAB}attempt${TAB}m${TAB}k${TAB}n${TAB}seed${TAB}exit${TAB}class${TAB}code${TAB}dag_id${TAB}mjr1_sha256${TAB}mjr1_outcome${TAB}verifier" +HX="job${TAB}attempt${TAB}m${TAB}k${TAB}n${TAB}seed${TAB}exit${TAB}class${TAB}code${TAB}dag_id${TAB}mjr1_sha256${TAB}mjr1_outcomx${TAB}verifier" +A=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +B=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +V=02$A +V3=03$B +G1='goal mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end' +G2='goal pair ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 ulong 0x0008 end' +GB='goal mm ushort 0x12c ushort 0x002 ushort 0x002 ulong 0x0001 end' +P1='rep ok mm ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 end' +P2='rep ok pair ushort 0x004 ushort 0x008 ushort 0x002 ulong 0x0007 ulong 0x0008 end' +PFT='rep fail transport end' +# row JOB ATTEMPT SEED EXIT CLASS CODE DAG SHA OUTCOME VERIFIER (dims 4 8 2) +row() { printf '%s\t%s\t4\t8\t2\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' "$@"; } +OK1=$(row 1 1 7 0 ok - $A $B 1 $V) +OK1R=$(row 1 2 7 0 ok - $A $B 1 $V) +OK2=$(row 2 1 8 0 ok - $B $A 1 $V3) +TR1=$(row 1 1 7 10 fail transport - - - -) +TR1R=$(row 1 2 7 10 fail transport - - - -) +RP1=$(row 1 1 7 11 refused replay $A - - -) +HDR=$H RB=$W/rep2en MODE=check MISS=0 FIRST= +rep() { # name want_rc G P facts-rows... + name=$1 want=$2 g=$3 p=$4; shift 4 + { [ "$HDR" = NONE ] || echo "$HDR"; for r in "$@"; do echo "$r"; done; } > "$W/f.$name.tsv" + out=$(printf '%s\n%s\n' "$g" "$p" | "$RB" "$W/f.$name.tsv"); rc=$? + LAST=$out + if [ "$MODE" = check ]; then + echo "REP2EN $name rc=$rc $out" + [ "$rc" = "$want" ] || fail "rep2en $name rc=$rc want $want" + elif [ "$rc" != "$want" ]; then + MISS=$((MISS+1)); [ -n "$FIRST" ] || FIRST="$name(rc=$rc,want=$want)" + fi +} +tpl() { # name expected-sentence + [ "$LAST" = "$2" ] && return + if [ "$MODE" = check ]; then fail "$1 template [$LAST]"; else MISS=$((MISS+1)); [ -n "$FIRST" ] || FIRST="$1(template)"; fi +} +repall() { + # English cases (exit 0). + rep ok-mm 0 "$G1" "$P1" "$OK1" + tpl ok-mm "Completed and verified: one matmul_u32 job multiplying a 4 by 8 matrix by a 8 by 2 matrix with seed 7; job 1 dag_id $A mjr1_sha256 $B." + rep ok-pair 0 "$G2" "$P2" "$OK1" "$OK2" + rep retry-ok 0 "$G1" "$P1" "$TR1" "$OK1R" + rep retry-fail 0 "$G1" "$PFT" "$TR1" "$TR1R" + rep bound 0 "$GB" 'rep refused bound end' + rep refused-replay 0 "$G1" 'rep refused replay end' "$RP1" + tpl refused-replay "Not completed: job 1 was refused (code replay): the worker refused a replay of an already executed job." + rep fail-transport 0 "$G1" "$PFT" "$TR1" + rep pair-job2-refused 0 "$G2" 'rep refused budget end' "$OK1" "$(row 2 1 8 11 refused budget - - - -)" + tpl pair-job2-refused "Not completed: job 2 was refused (code budget): the job was refused for budget or fuel." + rep fail-receipt-digest 0 "$G1" 'rep fail verdict end' "$(row 1 1 7 14 fail verdict $A $B - -)" + # Contradictions (exit 30). + rep x-ok-vs-fail 30 "$G1" "$P1" "$TR1" + rep x-operands 30 "$G1" 'rep ok mm ushort 0x004 ushort 0x002 ushort 0x008 ulong 0x0007 end' "$OK1" + rep x-code 30 "$G1" 'rep fail budget end' "$TR1" + rep x-class 30 "$G1" 'rep refused transport end' "$TR1" + rep x-fail-vs-ok 30 "$G1" "$PFT" "$OK1" + rep x-retry-unreported 30 "$G1" "$PFT" "$TR1" "$OK1R" + rep x-pair-missing 30 "$G2" "$P2" "$OK1" + rep x-bound-dispatched 30 "$GB" 'rep refused bound end' "1${TAB}1${TAB}300${TAB}2${TAB}2${TAB}1${TAB}0${TAB}ok${TAB}-${TAB}$A${TAB}$B${TAB}1${TAB}$V" + tpl x-bound-dispatched "G2E_CONTRADICT bound" + rep x-facts-operands 30 "$G1" "$P1" "1${TAB}1${TAB}4${TAB}2${TAB}8${TAB}7${TAB}0${TAB}ok${TAB}-${TAB}$A${TAB}$B${TAB}1${TAB}$V" + rep x-nothing 30 "$G1" "$PFT" + # Invalid inputs (exit 31). + rep bad-report 31 "$G1" 'rep ok end' + rep bad-goal 31 'goal end' "$P1" "$OK1" + rep bad-facts 31 "$G1" "$P1" "$(row 1 1 7 0 ok - - - - -)" + # v1.2 header line. + HDR=NONE; rep i-no-header 31 "$G1" "$P1" "$OK1" + HDR=$HX; rep i-header-wrong 31 "$G1" "$P1" "$OK1"; HDR=$H + # v1.2 ok row: mjr1_outcome 1, verifier 66 lowercase hex starting 02/03 (T1). + rep i-ok-outcome-zzz 31 "$G1" "$P1" "$(row 1 1 7 0 ok - $A $B zzz nonsense)" + rep i-ok-outcome-2 31 "$G1" "$P1" "$(row 1 1 7 0 ok - $A $B 2 $V)" + rep i-ok-verifier-64 31 "$G1" "$P1" "$(row 1 1 7 0 ok - $A $B 1 $A)" + rep i-ok-verifier-04 31 "$G1" "$P1" "$(row 1 1 7 0 ok - $A $B 1 04$A)" + rep i-ok-verifier-upper 31 "$G1" "$P1" "$(row 1 1 7 0 ok - $A $B 1 02$(printf %s "$A" | tr a A))" + rep i-nonok-outcome 31 "$G1" "$PFT" "$(row 1 1 7 10 fail transport - - 3 -)" + rep i-nonok-verifier 31 "$G1" "$PFT" "$(row 1 1 7 10 fail transport - - - $V)" + rep i-nonok-dag 31 "$G1" "$PFT" "$(row 1 1 7 10 fail transport zz - - -)" + # v1.2 exit <-> class/code map (T2). + rep i-exit14-transport 31 "$G1" "$PFT" "$(row 1 1 7 14 fail transport - - - -)" + rep i-exit3-transport 31 "$G1" "$PFT" "$(row 1 1 7 3 fail transport - - - -)" + rep i-exit4-replay 31 "$G1" 'rep refused replay end' "$(row 1 1 7 4 refused replay - - - -)" + rep i-exit10-replay 31 "$G1" 'rep refused replay end' "$(row 1 1 7 10 refused replay - - - -)" + rep i-exit11-receipt 31 "$G1" 'rep fail receipt end' "$(row 1 1 7 11 fail receipt - - - -)" + rep i-refused-transport 31 "$G1" 'rep refused transport end' "$(row 1 1 7 10 refused transport - - - -)" + rep i-fail-replay 31 "$G1" 'rep fail replay end' "$(row 1 1 7 11 fail replay - - - -)" + # v1.2 history (T4). + rep i-ok-then-transport 31 "$G1" "$PFT" "$OK1" "$TR1R" + rep i-ok-then-transport-a1 31 "$G1" "$PFT" "$OK1" "$TR1" + rep i-refused-then-job2 31 "$G2" "$PFT" "$(row 1 1 7 11 refused worker - - - -)" "$(row 2 1 8 10 fail transport - - - -)" + rep i-transport-then-job2 31 "$G2" "$P2" "$TR1" "$OK2" + rep i-job2-first 31 "$G2" "$P2" "$OK2" "$OK1" + rep i-attempt0 31 "$G1" "$P1" "$(row 1 0 7 0 ok - $A $B 1 $V)" + rep i-attempt2-first 31 "$G1" "$P1" "$OK1R" + rep i-attempt-repeat 31 "$G1" "$P1" "$TR1" "$OK1" + rep i-attempt3 31 "$G1" "$P1" "$TR1" "$TR1R" "$(row 1 3 7 0 ok - $A $B 1 $V)" + rep i-retry-after-receipt 31 "$G1" "$P1" "$(row 1 1 7 12 fail receipt - - - -)" "$OK1R" +} +repall + +# Cost on GB10 Spark Grace CPU, cores 10-14, nice 19, ionice idle. +for t in en2goal goal2en rep2en; do + case $t in + en2goal) printf 'run two matmuls of size 4 x 8 x 2 with seeds 7 and 8\n' > "$W/in.$t"; args= ;; + goal2en) printf '%s\n' "$G2" > "$W/in.$t"; args= ;; + rep2en) printf '%s\n%s\n' "$G2" "$P2" > "$W/in.$t"; args=$W/f.ok-pair.tsv ;; + esac + $RUN /usr/bin/time -v "$W/$t" $args < "$W/in.$t" > /dev/null 2> "$W/time.$t" + echo "COST $t wall=$(grep 'Elapsed (wall' "$W/time.$t" | sed 's/.*): //') maxrss_kb=$(grep 'Maximum resident' "$W/time.$t" | sed 's/.*: //') chip=GB10-Spark-Grace-CPU cores=10-14 nice=19" +done + +# Negative control: the k<->n mutant must fail the dev cases. +set -- $(score "$W/en2goal-mut" "$D/cases.tsv" 2>/dev/null) +echo "MUTANT exact=$1 refused_differently=$2 wrong=$3 total=$4" +[ "$3" -gt 0 ] && echo "MUTANT_CAUGHT" || fail "k<->n mutant not caught" + +# Negative controls for rep2en: each facts check is disabled in turn (its +# condition line, which must occur exactly once, becomes `if false`); the +# fixtures above must then give at least one unexpected result. +while IFS='|' read -r mname mline; do + [ -n "$mname" ] || continue + n=$(grep -cxF "$mline" "$T/rep2en.om") + [ "$n" = 1 ] || { fail "mutant $mname line occurs $n times"; continue; } + awk -v L="$mline" '$0 == L { print "if false"; next } { print }' "$T/rep2en.om" > "$W/rep2en-$mname.om" + cmp -s "$T/rep2en.om" "$W/rep2en-$mname.om" && { fail "mutant $mname not applied"; continue; } + build "rep2en-$mname" $REPU "$W/rep2en-$mname.om" "$T/otfrag.om" "$T/main-rep2en.om" + RB=$W/rep2en-$mname MODE=$mname MISS=0 FIRST= + repall + if [ "$MISS" -gt 0 ]; then echo "REPMUTANT $mname missed=$MISS first=$FIRST CAUGHT"; else fail "rep2en mutant $mname not caught"; fi +done <<'EOF' +header|if not othdrok ulong fl +ok-outcome|if not otfone r 11 +ok-verifier|if not otfkey r 12 +nonok-dashes|if not and otfdash r 11 otfdash r 12 +nonok-dag-sha|if not and otfhod r 9 otfhod r 10 +code-class|if ne cl wc +code-exit|if ne ex wx +hist-same-job|if not and eq a 2 pt +hist-next-job|if not and eq j add pj 1 eq a 1 +hist-prev-ok|if and gt pj 0 not pk +EOF + +if [ "$FAIL" = 0 ]; then echo OE45_TRANSLATOR_PASS; exit 0; fi +echo OE45_TRANSLATOR_FAIL; exit 1