This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Getting started

vipyr does two things: it calls Viv's checked programs as Python functions, and it loads your own .viv files as Python modules. Below are both, then the tools for feature pipelines.

A first call

Every page writes vp.scf.run(...) for vipyr.scf.run. From a checkout, vp.scf imports directly; on PyPI it is planned as pip install "vipyr[chem]".

import vipyr as vp

# water, unless atoms= and coords= say otherwise
r = vp.scf.run(basis="cc-pvdz")
r.e_tot, r.converged, r.mo_energy   # hartree
r.check()    # the program's own tests on this run

The first call in a process compiles the program to a C library, or loads the one built last time; later calls reuse it. A wrong argument is refused before anything compiles, with the parameter's name in the message.

Your own Viv

A .viv file of your own, kernels.viv:

#| The sum of squares of an array.
def sumsq(x: Arr) -> Num {
    s = 0.0
    for v in x {
        s = s + v * v
    }
    return s
}

vp.load compiles it and returns a module. Each top-level def whose parameters are annotated becomes a Python function that takes NumPy arrays, or a pandas or polars DataFrame whose columns go to the parameters by name. A compile error is a SyntaxError that points into the .viv file.

import numpy as np
import vipyr as vp

k = vp.load("kernels.viv")               # compiled to C once, cached under __pycache__/vipyr/
k.sumsq(np.arange(4.0))                  # 14.0: each annotated top-level def is a Python function

import vipyr.auto                        # or vp.install(): the import hook
import kernels                           # finds kernels.viv beside your .py files
  • %load_ext vipyr in Jupyter adds the %%viv NAME cell magic: a cell of Viv defs becomes the module NAME, and each call is recorded in .viv_runs.jsonl.
  • A package of your own builds its wheel with build-backend = "vipyr.build" and lists its .viv modules under [tool.vipyr] in pyproject.toml.

The language itself is introduced in the Viv tour.

Feature code and models

Three tools for the code between your data and a model, all on your own functions:

import vipyr as vp

# does any feature of fn read a row later than the row it is computed for?
vp.check_point_in_time(fn, df, by="user_id", ts="ts")

# replay serving request by request: equal to the training batch, bit for bit?
vp.check_parity(fn, df, by="user_id", ts="ts")
  • vp.check_point_in_time checks a feature function for future leakage: no output row may depend on an input row with a later timestamp.
  • vp.check_parity checks that serving computes what training computed: it replays the rows one request at a time and compares with the batch result bit for bit.
  • vp.compile.compile_model (or vipyr compile model.pkl -o model.c) writes a fitted scikit-learn pipeline and your custom features as one C99 file, with a self-test that runs on the target machine.

Per-entity features with state, such as sessions, rolling counts and time since the last event, are in vp.features.

Where next