runner¶
Execution layer — load data and adapter, run the Python analysis, invoke the R script.
runner
¶
Execute the Python adapter and the R replication, collecting key statistics.
load_data(path)
¶
Load the analysis dataset from a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Filesystem path to the CSV file, as accepted by :func: |
required |
Returns:
| Type | Description |
|---|---|
|
The dataset as a :class: |
load_adapter(module_path)
¶
Import a Python analysis module from a file path.
The module must define run(df, seed=None) -> dict and may define
prepare(df, seed=None) -> DataFrame. When prepare is declared, cli
runs it once and hands its output to run (and to the Phase-3 consistency
ranges), so the statistics and the checks share one data space; without it,
run receives the raw data as loaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
Filesystem path/str to the Python analysis module; its stem is used to derive the imported module name. |
required |
Returns:
| Type | Description |
|---|---|
|
The imported module object. |
Source code in crossverify/runner.py
call_with_optional_seed(fn, df, seed)
¶
Call fn(df, seed=seed) if it accepts a seed parameter, else fn(df).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable to invoke, typically the adapter's |
required | |
df
|
The :class: |
required | |
seed
|
Random seed forwarded only when |
required |
Returns:
| Type | Description |
|---|---|
|
Whatever |
Source code in crossverify/runner.py
_to_num(v)
¶
Coerce a scalar to float, mapping bool to 1.0/0.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
Value to coerce; |
required |
Returns:
| Type | Description |
|---|---|
|
The value as a |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Source code in crossverify/runner.py
_coerce(mapping)
¶
Coerce every value in a statistics mapping to float with stringified keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
Mapping of statistic name to value; keys are coerced via |
required |
Returns:
| Type | Description |
|---|---|
|
A new dict mapping |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any value is not numeric (non-coercible to |
Source code in crossverify/runner.py
run_python(adapter, df, seed)
¶
Run the adapter's run function and return its coerced statistics.
Invokes adapter.run on a copy of df (forwarding seed when accepted),
then coerces the returned mapping to {str: float} via :func:_coerce.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Imported analysis module that must define
|
required | |
df
|
Input :class: |
required | |
seed
|
Random seed forwarded to |
required |
Returns:
| Type | Description |
|---|---|
|
A dict mapping statistic name to |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If |
TypeError
|
If |
ValueError
|
If a returned statistic is not numeric (propagated from
:func: |
Source code in crossverify/runner.py
_r_child_env(helper_path)
¶
Build a minimal environment for the Rscript child.
Copies only an allowlist from the parent environment so secrets the parent
holds are not exposed to the user-supplied R script, then points
CROSSVERIFY_R at the helper library. The allowlist is :data:_R_ENV_ALLOW
plus any variable whose name starts with R_ or LC_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
helper_path
|
Path to the crossverify R helper library; stringified into the
|
required |
Returns:
| Type | Description |
|---|---|
|
A dict of environment variables for the child process. |
Source code in crossverify/runner.py
r_available()
¶
Report whether the Rscript executable is on the PATH.
Returns:
| Type | Description |
|---|---|
|
|
r_version()
¶
Return the first line of Rscript --version output.
Returns:
| Type | Description |
|---|---|
|
The version string, or |
|
|
or produces no output. |
Source code in crossverify/runner.py
run_r(r_script, data_path, seed, helper_path)
¶
Run the R replication and return (results dict, stdout).
The harness passes three positional arguments to the R script — data path,
output path, seed — and sets CROSSVERIFY_R to the helper library so the
script can source(Sys.getenv("CROSSVERIFY_R")). The R script writes its
statistics as JSON to a temporary output path, which is read back, coerced to
{str: float}, and the temporary file removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_script
|
Path/str to the user-supplied R replication script. |
required | |
data_path
|
Path/str to the dataset, passed to the script as its first argument. |
required | |
seed
|
Random seed passed as the third argument; |
required | |
helper_path
|
Path to the crossverify R helper library, exposed via the
|
required |
Returns:
| Type | Description |
|---|---|
|
A |
|
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the R script exits with a non-zero return code; the message includes the captured stdout and stderr. |
ValueError
|
If a statistic emitted by the script is not numeric (propagated
from :func: |