Runtime Library#
prophys-runtime evaluates exported surrogates without Python. It is a
small shared library with a C interface that runs the same network
interpreter and tree kernels as the Python package, so an exported
surrogate gives the same bits in a control system, a simulator plug in or an
edge device as in prophys.
Exporting#
A model package of format 1.2 carries every surrogate of the model
(SurrogateExport). to_bytes() writes
the binary blob the runtime loads. Networks with compiled physics layers
export as one program, so the physics runs in the runtime too. A physics
layer that did not compile stops the export with NN112 and its reason.
pkg = compiled.export()
exp = pkg.surrogate("power")
open("power.prsb", "wb").write(exp.to_bytes())
exp.verify() # recompute the parity checksum in Python
Each export records its probe inputs and an FNV 1a checksum of the outputs at those inputs. The runtime recomputes it on demand, which proves that the deployed binary reproduces the exported surrogate exactly.
C interface#
typedef struct Surrogate Surrogate;
Surrogate *prophys_runtime_load(const uint8_t *blob, size_t len);
void prophys_runtime_free(Surrogate *s);
size_t prophys_runtime_inputs(const Surrogate *s);
size_t prophys_runtime_outputs(const Surrogate *s);
size_t prophys_runtime_members(const Surrogate *s);
/* out has members * rows * outputs doubles */
int prophys_runtime_eval(const Surrogate *s, const double *x, size_t rows, double *out);
int prophys_runtime_verify(const Surrogate *s); /* 1 reproduced, 0 not, -1 error */
size_t prophys_runtime_last_error(char *buf, size_t len);
The runtime is supplied as a prebuilt shared library with this C header for
the target platform; contact RhineQC GmbH (see Imprint / Impressum) for the
build matching your system. The same free tier as the Python package
applies, and a valid license in PROPHYS_LICENSE unlocks larger
surrogates.
Blob format#
All numbers are little endian. The header holds the magic PRSB, the
format version, the kind (1 network, 2 trees), the number of members, the
description length, the parameters per member, the inputs, the outputs and
the link (1 logistic). The network program or tree spec follows as doubles,
then the parameters of every member, the number of probe rows, the probe
inputs and the sixteen character checksum.