Skip to content

Experiments

An experiment declaration turns a run into a closed term with a content identity. This page states what the identity covers, how a run is cached under it, when data is refused, how provenance is recorded, and what a reference check compares. The surface is in Experiments.

Resolution

An experiment of module \(M\) is resolved against the module graph rooted at \(M\), loaded with the experiment's link clauses as fillings of the package's holes, so the program it runs is the linked program. Resolution fixes:

  1. the entry \(e\), the flat-program name of the program clause's declaration, read in \(M\)'s scope like any reference;
  2. when the experiment has handle clauses \(h_1, \ldots, h_k\) (outermost first), the computation \(E.\mathsf{entry}\) with the entry's parameters, whose body is \(\mathsf{handle}\ h_1 \ldots \mathsf{handle}\ h_k\ \mathsf{in}\ e(x_1, \ldots, x_n)\); its result type is the outermost handler's output type and its row is the entry's row without the handled instances, with the rows the handlers' clauses perform. The kernel checks it like any computation, so a handler that does not handle its instance's interface is refused. The experiment then runs \(E.\mathsf{entry}\) in place of \(e\);
  3. the assignment \(\sigma\), mapping each name of a data, fix, or sweep clause to its value. Every name is a parameter of the entry or, for a program run, one of its sample sites; a computation needs a value for every parameter. A name given twice is refused;
  4. the method \(m\) and its options \(o\), every option the experiment omits taking its declared default;
  5. the seed \(s\).

A module with typed holes is refused before anything runs, and so is a program that needs a hole no link fills.

Points and their hashes

The sweeps \(x_1 \in V_1, \ldots, x_r \in V_r\) define the finite index type \(V_1 \times \cdots \times V_r\), and the experiment is the family of runs indexed by it. Each point \(p = (v_1, \ldots, v_r)\) extends the assignment with \(x_i \mapsto v_i\). Its point hash is

\[ h(p) = \mathsf{H}\bigl(\mathsf{kind}, \mathsf{hash}(e), \{(x, \mathsf{pin}(x))\}, \{(x, \sigma_p(x))\}, m, o, s\bigr) \]

where \(\mathsf{hash}(e)\) is the content hash of the entry, \(\mathsf{pin}(x)\) the pinned digest of a data file, and each set is serialized sorted by name. For a fit, \(\mathsf{hash}(e)\) also covers the program's interpretation bindings and the digest of its program source (the statement digests of the root and of every module it imports, with the hole fillings), which the fitted model is compiled from. The experiment's hash is the digest of its points' hashes in index order.

Two consequences follow. First, the hash is invariant under everything that does not change what a run computes: renaming the experiment, the entry, or any declaration (content hashes are alpha-invariant), reordering clauses, comments, formatting, and writing a default option out. Second, any change to what a run computes changes the hash: an edit to the entry or to anything it calls, a different filling of a hole, a different handler, a different data file, a fixed or swept value, the method or an option, or the seed. Since the data enter through their pins, the hash is computed without reading the data.

Data integrity

A data file is read and its BLAKE3 digest compared with its pin on every run, whether or not the run's record is stored. A mismatch is an error, as a mismatched integrity check on an import is in Dhall: the experiment's hash describes the pinned content, and a run on other content would be a run of another experiment.

Caching by constructive trace

A point's record is stored in the project's artifact store under the key \(\mathsf{H}(h(p), \mathsf{engine})\), where \(\mathsf{engine}\) is the engine identity. Running the point again with an unchanged hash reads the record and computes nothing: the record is the point's constructive trace, the value stored under a key that determines it, as in a build system with content-addressed outputs. A point whose hash changed runs again, and the others of the same experiment are read. The computation itself goes through the fit cache, so a run or fit computed for another experiment with the same inputs is reused.

A record holds the experiment's inputs (the entry's name and content hash, the data pins, the values, the method and options, the seed, the links, the handlers, and every source file of the program with its digest and its Software Heritage identifier) and its outputs: a run's value and trace, or a fit's posterior draws with each site's mean, standard deviation, \(\hat R\), and effective sample sizes.

Provenance

A record is stated in the W3C PROV data model, serialized as PROV-JSON. Each run is one bundle named by its point hash, in which

  • the run is an activity with its start and end times;
  • the program, its source files, its data files, and its configuration are entities that the run used, each with its content hash;
  • the result is an entity the run generated, derived from the program and the data, and attributed to the quivers engine, a software agent associated with the run.

A source file carries its Software Heritage identifier swh:1:cnt:<sha1_git>, the intrinsic identifier of its content, under which the archive serves the file once it is archived.

An experiment's runs are packaged as a Workflow Run RO-Crate. The module declaring the experiment is the crate's main computational workflow, whose formal parameters are the names the experiment gives values to; each run is a CreateAction whose instrument is the workflow, whose objects are the data files and values it used, and whose results are its record and its PROV account; and the crate conforms to the Process Run Crate, Workflow Run Crate, and Workflow RO-Crate profiles.

Reference checks

A reference file stores, for each point by its swept values, a run's value or each site's posterior mean \(\bar\theta^{\mathrm{ref}}\) and standard deviation \(s^{\mathrm{ref}}\), as posteriordb stores reference posteriors. With the pinned tolerances \(\tau_{\mathrm{mean}}\) and \(\tau_{\mathrm{sd}}\), a fit passes at a site when, elementwise,

\[ \lvert \bar\theta - \bar\theta^{\mathrm{ref}} \rvert \le \tau_{\mathrm{mean}}\, s^{\mathrm{ref}} \qquad\text{and}\qquad \lvert s - s^{\mathrm{ref}} \rvert \le \tau_{\mathrm{sd}}\, s^{\mathrm{ref}}, \]

and a run passes when its value lies within \(\tau_{\mathrm{value}}\) of the reference's (a value that is not a number must be equal). Each compared statistic needs a pinned tolerance, and the reference file is pinned like a data file, so a check never compares against a reference other than the one the experiment names.

References