Result comparison · Data validation · Scoring-code check · open source

consilience: compare measurements and check data, and refuse what can't be read

In one sentence

consilience tells you whether two measurements agree, whether they can be compared at all, which records of a table may be pooled, which rows break your written limits, and whether a scoring function can be cheated before an optimiser runs against it. When it cannot read a number or a unit exactly, it says so instead of guessing.

pip install consilience

Free and open source (MIT; the rule packs and examples CC BY 4.0). Python 3.10 or newer.

Who it's for

  • Researchers comparing results across labs or papers. Two groups report an overpotential in different units, at conditions written differently. Are they the same measurement? Do they agree?
  • Data stewards and people who receive tables of measurements. Before using a dataset, find the rows that exceed their own recorded limits or fall outside physical bounds, and the cells nobody can read reliably.
  • People building automated or AI-assisted analysis who need a check that refuses rather than quietly coerces "1 200" into 200.
  • Anyone pooling potency values (IC50, Ki, Kd, EC50) from ChEMBL or similar sources before averaging, ranking or training on them.
  • Anyone running program search or reinforcement learning against a scoring function (AlphaEvolve, OpenEvolve, ShinkaEvolve, CodeEvolve and similar), who wants to know whether the scorer can be cheated before paying for the search.

The problem it solves

  1. Numbers are often compared that shouldn't be. A value measured at 100 mA/cm² is not comparable with one measured at 10 mA/cm², and a value with no stated temperature cannot be matched with one at 25 °C. Most tools compare the numbers anyway.
  2. Ordinary parsers misread numbers without warning. "1 200" becomes 200, "3,14" becomes 314, "5M" becomes 5 molar, "nan" passes as a value. In a large table nobody notices.
  3. Checks are hard to repeat. A spreadsheet filter leaves no record of exactly which rules were applied to exactly which file.

consilience refuses each of these with a named reason, and every result carries a receipt: a fingerprint (SHA-256 hash) over the inputs, the rules and the result, which consilience verify re-runs.

What you get

consilience compare a.json b.json: one of seven answers.

AnswerWhat it means
agreeThe values match within your tolerance (after unit conversion), allowing for the precision they are written to: 0.777 means 0.7765 to 0.7775 unless you add --exact.
within_floorNot within tolerance, but within the spread you say is normal (or the stated uncertainties). Not evidence of disagreement.
disagreeThe difference is larger than both.
not_comparable(…)A condition differs (and it names which), or the units measure different things.
not_stated(…)A value, unit or condition is missing, so no comparison is made.
undecidable_boundsBoth values are one-sided bounds, such as "< 1e-6" and "< 1e-5", that can both hold: there is no single value to compare. (A value against a bound, "2.3e-7" against "< 1e-6", gets one of the answers above.)
unparseable(…)Something could not be read exactly; the reason is named.

consilience check data.csv --rules rules.yaml: every row that breaks a rule, with the rule, the value, the limit and a row receipt, and every cell it could not read, listed and counted, never skipped. As text, JSON, and an HTML page you can open in a browser.

The answers come from plain, deterministic code. No AI model is involved.

Try it in five minutes

1. Install

pip install consilience

2. Get the examples

consilience examples try
cd try

This writes five example measurements, a small table and its rules, and copies of the three rule packs (electrochemistry, bioactivity, pKa). All of it is made up for trying the tool.

3. Compare two measurements

Measurement A reports 0.320 V ± 4 mV; measurement B reports 331 mV ± 3 mV under the same conditions, written differently ("sulfuric acid" for H2SO4, 500 mmol/L for 0.5 mol/L, 298.15 K for 25 °C).

consilience compare measurement_a.json measurement_b.json --pack electrochemistry

You'll see (hashes shortened here):

verdict:    disagree
a:          0.32 V ± 0.004 V   (as given: 0.32 V ± 4 mV)   [Example lab A, overpotential at 10 mA/cm^2]
b:          0.331 V ± 0.003 V   (as given: 331 mV ± 3 mV)   [Example lab B, overpotential at 10 mA/cm^2]
difference: 0.011 V
tolerance:  0 V   (larger of --abs-tol and --rel-tol x the larger value)
floor:      0.004 V   (largest of --floor and the two uncertainties)
conditions: checked with pack electrochemistry (electrochemistry-v1): electrolyte, current_density, temperature, ir_correction
pack hash:  cbf7aea81b7f…
receipt:    sha256 …

The units were converted and the conditions matched, so the values could be compared; they differ by 11 mV, more than either uncertainty. If you know labs normally spread by, say, 13 mV on this measurement, add --floor "13 mV" and the answer becomes within_floor.

Now try the others:

consilience compare measurement_a.json measurement_c.json --pack electrochemistry   # not_comparable(current_density)
consilience compare measurement_a.json measurement_d.json --pack electrochemistry   # not_stated(temperature)
consilience compare measurement_a.json measurement_e.json --pack electrochemistry   # unparseable(b.value: ambiguous_separator)

Measurement C was taken at a different current density, D does not state its temperature, and E writes its value as "0,32" (a decimal comma or a thousands separator?). Each refusal names its reason, and the pack rule behind it.

4. Check a table

consilience check readings.csv --rules readings_rules.yaml --html report.html

You'll see:

violations:  5
  line 7    S-004  R1  reading 2.71 V > limit_v 2.5 V + margin 0.02 V   row receipt f6ebb38ff21a
  line 10   S-007  R2  temperature_c -280 degC < min -273.15 degC   row receipt bda89ad69f3a
  line 14   S-011  R1  reading 850 mV > limit_v 800 mV + margin 20 mV   row receipt 511d51f9d275
  line 18   S-015  R3  humidity_pct 104 percent > max 100 percent   row receipt be633f7a4560
  line 21   S-018  R3  humidity_pct -3 percent < min 0 percent   row receipt 3a7f9477333a
could not read: 2 cells (not checked; nothing was guessed)
  line 12   S-009  limit_v "n/a": not_a_number (needed by R1)
  line 16   S-013  temperature_c "21,5": ambiguous_separator (needed by R2)

(after a header with the file's and the rules' fingerprints). Open report.html in a browser for the same report as a page.

5. Exit codes, for scripts

compare: 0 agree or within_floor, 1 disagree, 2 not_comparable, not_stated or undecidable_bounds, 3 unparseable. check: 0 clean, 1 violations, 3 some cells could not be read. 64 for a usage error (missing file, unknown field). Add --receipt FILE to save a receipt, and consilience verify FILE re-runs it and confirms the hash.

6. From Python

from consilience import compare, check

r = compare("measurement_a.json", "measurement_b.json", pack="electrochemistry")
print(r.verdict)                       # disagree

c = check("readings.csv", "readings_rules.yaml")
print(c.summary["violations"])         # 5

7. Pool a whole table (compare-table)

Converting units does not make two values comparable. A potency measured in a cell-based assay and one measured on a purified protein should not be averaged, and a value written as "> 500 nM" is a bound, not a number. compare-table groups the records, forms classes of records whose conditions match, compares every pair, and marks each record pool_valid or names why not. A small made-up table, potency.csv:

mol,tgt,value,relation,unit,standard_type,assay_type
M1,T1,40,=,nM,IC50,B
M1,T1,0.052,=,uM,IC50,B
M1,T1,35,=,nM,IC50,F
M1,T1,500,>,nM,IC50,B
M2,T1,12,=,nM,Ki,B
M2,T1,900,=,nM,Ki,B
consilience compare-table potency.csv --key mol,tgt --pack bioactivity

You'll see:

Consilience pooling check (pack bioactivity-v1): 6 records, 2 groups (mol + tgt).
- 1 records are bounds (">", "<"): kept as bounds, never averaged.
- 1 groups contain records that must not be pooled together (more than one condition class).
  Pairs refused, by first reason: not_comparable(assay_type) 3.
- Pairs inside a class: 1 agree within 0.3 log units, 1 only within 1.0 log units, 2 disagree, 0 are two bounds that can both hold.
- 1 records are pool_valid (poolable with the others of their condition class).
- Not checked (column absent from the table): BA3, BA4, BA5, BA6, BA7, BA8, BA9, BA10, BA11, BR1, BR2.
receipt: sha256 7ba3e8dd8a50905f6c6ffdd625915c954016739d9213f4d06ed49fe7ddaf8f39

The cell-based value (F) is not pooled with the purified-protein ones (B), the bound is kept as a bound, and the two Ki values for M2 disagree by more than an order of magnitude. The last line lists the pack's rules that could not run because this small table lacks those columns: nothing is assumed about them. With real ChEMBL exports add --map chembl, and --out DIR saves the per-record table, the classes and the receipt. Exit code 1 means a class disagrees inside. The pka pack works the same way for measured pKa values. Full guide: compare-table.md.

8. Check a scoring function before an optimiser runs (stress)

Program search and reinforcement learning exploit any loophole in a scoring function: an accepted NaN, a number the candidate reports about itself, a score that changes under a harmless transformation. stress reads a short contract describing what a valid answer is, attacks the scorer, and keeps any counterexample. Install the extra:

pip install "consilience[stress]"

A toy scorer, scorer.py, that checks the range of four numbers in [0, 1] but lets NaN slip through:

import numpy as np

def score(x):
    x = np.asarray(x, dtype=float)
    if (x < 0).any() or (x > 1).any():     # range checked, but NaN slips through
        raise ValueError("out of range")
    return float(np.nansum(x)) + 0.5 * float(np.isnan(x).sum())

A valid reference answer, python -c "import numpy as np; np.savez('ref.npz', x=[0.5]*4)", and contract.yaml beside them, written from the problem (not from the scorer):

kind: evaluator-contract
name: toy/sum_in_unit_box
contract_author: human
harness: {kind: function, evaluator: scorer.py, entry: score}
fields:
  - {name: x, type: real_array, shape: [4], role: construction}
validity:
  - {rule: finite, field: x}
  - {rule: range, field: x, min: "0", max: "1"}
score:
  direction: maximize
  record: {value: "4.0", source: "toy: the maximum is 4"}
reference: {file: ref.npz}
consilience stress contract.yaml --out receipts

You'll see:

consilience stress: toy/sum_in_unit_box
BLOCK: 3 finding(s) with a counterexample you can re-run.
margin m = 0.05 (from record_resolution); reference score 2; record 4.0
  BLOCK C1 accepts_gross_invalid [finite]: attack=x:nonfinite[0]=nan, score=2
  BLOCK C1 accepts_gross_invalid [finite]: attack=x:nonfinite[2]=nan, score=2
  BLOCK C1 accepts_gross_invalid [finite]: attack=x:nonfinite[3]=nan, score=2
  C3 naive search: 8 restarts, 0% ended invalid (best invalid None, best valid 3.94687)
  limits: naive search; not a security sandbox; findings concern the hashed scoring code only

The scorer accepted a NaN at a score as good as a valid answer, and the candidate is saved under receipts/candidates/. consilience verify receipts/receipt.json re-scores it and re-checks the inequality behind each BLOCK. Exit codes: 0 PASS (no counterexample within the budget; not a proof), 1 BLOCK, 2 ABSTAIN with a named reason. Full guide, including when not to use it: stress.md.

Writing rules

Rules live in a plain YAML file. Each rule has an id, a sentence in plain English, and a precise limit. A table check:

  - id: R1
    kind: limit
    column: reading
    limit_column: limit_v
    must_be: at_most
    margin: 0.02 V
    plain_english: A reading must not exceed its own recorded limit by more than 0.02 V.

There are two kinds of table rule: limit (a value against a limit recorded in the same row) and bound (a value against fixed physical bounds, such as "not below 0 K"). A pack for compare says which measurement conditions must match and which spellings mean the same thing. A misspelt key in a rule file is refused, never ignored. Full format: RULES.md.

What it can't do (read before relying on it)

  • It does not read prose. It does not find numbers or conditions in papers, reports or AI output. You give it structured files (JSON for measurements, CSV for tables).
  • It only checks the conditions you give it. If a condition that matters is missing from both files and no pack names it, nothing will notice.
  • The electrochemistry pack covers one field, and only four conditions (electrolyte, current density, temperature, iR correction). For any other field you write a pack; without one, every condition must match exactly, spelling included.
  • The example data is made up. It shows how the tool works. It describes no real lab, instrument or experiment, and the 13 mV floor is an example number.
  • It does not know whether your rules are right. A check reports rows that break the rules you wrote, nothing more.
  • The pooling check needs the condition columns. A rule whose column is absent is listed as not checked; it is never assumed to pass. The bioactivity pack does not check ATP or substrate concentration (mostly free text in ChEMBL).
  • The scoring-code check finds common loopholes, not deep ones. It catches invalid input, trusted self-reports, missing type checks and integer invariance. A PASS means no counterexample was found within the budget, not that the scorer is safe. It is not a security sandbox: run it only on code you would run anyway.
  • There is no hosted service. It runs on your computer and sends nothing anywhere.

Links

← All capabilitieslab-gate: check an experiment plan before it runs →