interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tests / physics0 / learner / pd0_truth_main.c

53 lines · 3209 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* TEST-ONLY truth process for the learner harness (substrate side: links the
18 * generators). Runs as a separate process so no learner or harness object ever
19 * links pd0_gen.c. Text protocol on stdin/stdout:
20 * rel -> the true relation (PDLAW1 delta form) and S*
21 * ep <n_obs> <reset..> <n> <ch val>* -> noise-free trajectory of n steps (or "oob")
22 * Usage: pd0-truth <level|null> <seed> */
23#include "physics0/pd0_gen.h"
24#include "physics0/pd0_relation.h"
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28
29int main(int argc, char **argv)
30{
31 if (argc < 3) return 2;
32 int level = strcmp(argv[1], "null") == 0 ? PD0_LEVEL_NULL : atoi(argv[1]);
33 pd0_gen g; pd0_desc d; if (pd0_gen_init(&g, level, strtoull(argv[2], NULL, 0)) != 0 || pd0_gen_desc(level, &d) != 0) return 2;
34 pd0_rng dummy_noise, dummy_null; pd0_stream(&dummy_noise, 1, "x"); pd0_stream(&dummy_null, 1, "y");
35 char line[4096];
36 while (fgets(line, sizeof line, stdin)) {
37 if (!strncmp(line, "rel", 3)) {
38 pd0_relation r; memset(&r, 0, sizeof r); pd0_gen_true_relation(&g, d.dt_micro, &r);
39 printf("rel %u %u %u %u %d %d\n", r.n_vars, r.n_latent, r.n_channels, r.n_eq, pd0_relation_size(&r), pd0_gen_true_size(level));
40 for (int e = 0; e < r.n_eq; e++) for (int t = 0; t < r.eq[e].n_terms; t++) { printf("term %u %lld", r.eq[e].target, (long long)r.eq[e].t[t].coef); for (int i = 0; i < r.n_vars; i++) printf(" %u", r.eq[e].t[t].ex[i]); for (int c = 0; c < r.n_channels; c++) printf(" %u", r.eq[e].t[t].ex[PD0_MAX_VARS + c]); printf("\n"); }
41 printf("end\n"); fflush(stdout);
42 } else if (!strncmp(line, "ep ", 3)) {
43 char *p = line + 3; int no = (int)strtol(p, &p, 10); int64_t s[PD0_MAX_OBS] = { 0 }, h = 0, ns[PD0_MAX_OBS], nh, obs[PD0_MAX_OBS];
44 for (int j = 0; j < no; j++) s[j] = strtoll(p, &p, 10);
45 int n = (int)strtol(p, &p, 10); printf("traj %d\n", n);
46 for (int st = 0; st < n; st++) { int ch = (int)strtol(p, &p, 10); int64_t v = strtoll(p, &p, 10); int64_t u[PD0_MAX_CH] = { 0 }; if (ch >= 0 && ch < PD0_MAX_CH) u[ch] = v;
47 if (pd0_gen_step(&g, s, h, u, d.dt_micro, ns, &nh, obs, &dummy_noise, &dummy_null)) { printf("oob\n"); break; }
48 memcpy(s, ns, sizeof s); h = nh; for (int j = 0; j < no; j++) printf("%s%lld", j ? " " : "", (long long)s[j]); printf("\n"); }
49 printf("end\n"); fflush(stdout);
50 } else if (!strncmp(line, "quit", 4)) break;
51 }
52 return 0;
53}