Skip to main content

Crate polydat

Crate polydat 

Source
Expand description

§polydat (formerly nbrs-variates)

Deterministic variate generation kernel (GK) for workload testing.

Transforms named u64 coordinate tuples into typed output variates via a compiled DAG of composable function nodes. The same coordinate always produces the same outputs — deterministic, reproducible, and parallelizable with zero shared mutable state.

§Quick Start

§From DSL source

The simplest way to build a kernel is from Polydat DSL source:

use polydat::dsl::compile_polydat;

let mut kernel = compile_polydat(r#"
    input cycle: u64
    hashed := hash(cycle)
    user_id := mod(hashed, 1000000)
"#).unwrap();

kernel.set_inputs(&[42]);
let user_id = kernel.pull("user_id").as_u64();
assert!(user_id < 1_000_000);

§From the assembler API

For programmatic construction:

use polydat::compile::assembly::{PolydatAssembler, WireRef};
use polydat::library::hash::Hash;
use polydat::library::arithmetic::Mod;

let mut asm = PolydatAssembler::new(vec!["cycle".into()]);
asm.add_node("hashed", Box::new(Hash::new()), vec![WireRef::input("cycle")]);
asm.add_node("user_id", Box::new(Mod::new(1_000_000)), vec![WireRef::node("hashed")]);
asm.add_output("user_id", WireRef::node("user_id"));

let mut kernel = asm.compile().unwrap();
kernel.set_inputs(&[42]);
assert!(kernel.pull("user_id").as_u64() < 1_000_000);

§Architecture

coordinates (u64 tuple)
    │
    ▼
┌─────────────────────────┐
│  PolydatProgram (immutable)  │  Shared via Arc across threads
│  - nodes: Vec<PolydatNode>   │
│  - wiring: Vec<Vec<..>> │
│  - output_map           │
└──────────┬──────────────┘
           │
    ┌──────┴──────┐
    │  PolydatState    │  One per thread — no locks
    │  - buffers  │
    │  - coords   │
    └──────┬──────┘
           │
           ▼
    pull("user_id") → Value::U64(527897)

§Compilation Levels

The kernel supports four compilation levels:

  • Phase 1 (default): Pull-through interpreter. ~70ns/node.
  • Phase 2: Compiled u64 closures. ~4.5ns/node.
  • Hybrid: Per-node optimal (JIT where supported, closures elsewhere).
  • Phase 3: Cranelift JIT native code. ~0.2ns/node. Requires the jit feature (enabled by default).

§Features

  • jit (default): Cranelift JIT compilation for Phase 3. Disable with default-features = false for a lighter build.
  • vectordata: Vector dataset access nodes for ML/AI workloads.

§Modules

Re-exports§

pub use derive_support::Const;
pub use compile::cone::default_jit_mode;
pub use compile::cone::set_default_jit_mode;
pub use compile::cone::JitMode;
pub use kernel::set_panic_reporting_downstream;
pub use resource::RESOURCE_ACCESSOR;
pub use resource::ResourceAccessor;
pub use resource::resource_lookup;
pub use library::support::audit;
pub use inventory;
pub use half;

Modules§

ast
Core types for Polydat nodes: values, ports, metadata, and the evaluation trait.
binder
Typed-binding contracts between adapters and the polydat runtime.
compile
Kernel compilation: assembled DAG → fast executable kernel.
derive_support
Trait surface that the #[polydat_node] proc-macro (polydat-derive) calls into for boxing / unboxing wire values.
dsl
Polydat DSL: lexer, parser, and AST for .polydat kernel definition files.
iteration
Iteration & coordinate algebra.
kernel
Polydat runtime kernel: compiled DAG with pull-through evaluation.
library
Standard Polydat function-node library + sampling primitives + library-internal support.
resource
Dependency-inverted resource-accessor bridge (SRD-104, Phase 0).
viz
DAG visualization for Polydat Kernels.

Macros§

register_nodes
Register a node module’s signatures and builder with the Polydat runtime.

Attribute Macros§

polydat_node
#[polydat_node] — derive a polydat node from a typed Rust function signature.