splitwitness 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- splitwitness-0.2.2/CONTRIBUTING.md +7 -0
- splitwitness-0.2.2/DESIGN.md +48 -0
- splitwitness-0.2.2/EVIDENCE.md +47 -0
- splitwitness-0.2.2/LICENSE +21 -0
- splitwitness-0.2.2/MANIFEST.in +3 -0
- splitwitness-0.2.2/MEMBERSHIPS.md +115 -0
- splitwitness-0.2.2/PKG-INFO +254 -0
- splitwitness-0.2.2/README.md +239 -0
- splitwitness-0.2.2/examples/clean-links.csv +3 -0
- splitwitness-0.2.2/examples/links.csv +4 -0
- splitwitness-0.2.2/examples/memberships.csv +8 -0
- splitwitness-0.2.2/examples/records.csv +6 -0
- splitwitness-0.2.2/pyproject.toml +30 -0
- splitwitness-0.2.2/setup.cfg +4 -0
- splitwitness-0.2.2/src/splitwitness/__init__.py +7 -0
- splitwitness-0.2.2/src/splitwitness/__main__.py +51 -0
- splitwitness-0.2.2/src/splitwitness/core.py +227 -0
- splitwitness-0.2.2/src/splitwitness/memberships.py +172 -0
- splitwitness-0.2.2/src/splitwitness.egg-info/PKG-INFO +254 -0
- splitwitness-0.2.2/src/splitwitness.egg-info/SOURCES.txt +26 -0
- splitwitness-0.2.2/src/splitwitness.egg-info/dependency_links.txt +1 -0
- splitwitness-0.2.2/src/splitwitness.egg-info/entry_points.txt +2 -0
- splitwitness-0.2.2/src/splitwitness.egg-info/top_level.txt +1 -0
- splitwitness-0.2.2/tests/test_audit.py +587 -0
- splitwitness-0.2.2/tests/test_capped_paths.py +104 -0
- splitwitness-0.2.2/tests/test_counts_only.py +170 -0
- splitwitness-0.2.2/tests/test_membership_index.py +155 -0
- splitwitness-0.2.2/tests/test_memberships.py +522 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Please open an issue before adding new input formats, policies or dependencies.
|
|
4
|
+
Bug fixes should include a failing regression and pass the tests and Ruff checks
|
|
5
|
+
listed in README.md. Keep default reports free of record identifiers; document
|
|
6
|
+
any new disclosure or acceptance boundary. Do not include real private datasets
|
|
7
|
+
or identifiers in issues, tests or example reports. Contributions use MIT.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Design boundaries
|
|
2
|
+
|
|
3
|
+
1. Read each file up to max_bytes + 1, fail if oversized, decode strict UTF-8,
|
|
4
|
+
reject NUL, parse exact CSV headers and field/row acceptance limits. Hash the
|
|
5
|
+
same raw bytes used for parsing. No second read and no trusting a file stat.
|
|
6
|
+
2. Validate all unique assignments and every link before reporting anything.
|
|
7
|
+
Reject exact/reversed duplicate (endpoint pair, relation) constraints.
|
|
8
|
+
3. Use union-by-size and iterative path compression to form connected components.
|
|
9
|
+
Store both adjacency directions for witness extraction. Relation strings do
|
|
10
|
+
not choose behavior. Self-links add no union but remain input links.
|
|
11
|
+
4. Iterate record IDs in sorted order. Each component's member list is therefore
|
|
12
|
+
sorted independently of union-find roots or input order. Count each member
|
|
13
|
+
once. A component violates the policy iff its set of split labels has size >1.
|
|
14
|
+
5. Count cross-split member pairs by (n*n - sum(split_size*split_size)) // 2.
|
|
15
|
+
Never enumerate the quadratic number of pairs. Counts are Python integers.
|
|
16
|
+
6. Sort violating components by minimum ID. For each requested example, BFS from
|
|
17
|
+
minimum ID to smallest differently assigned ID, sorting neighbors by
|
|
18
|
+
(neighbor ID, relation). A predecessor is assigned only on first discovery.
|
|
19
|
+
This selects a deterministic shortest endpoint-to-endpoint path. If it exceeds
|
|
20
|
+
the report cap, omit the whole path while retaining hop count and endpoints.
|
|
21
|
+
7. Construct the full report and serialize it before writing stdout. No invalid
|
|
22
|
+
input yields a partial success report. An output write itself can still fail
|
|
23
|
+
partially. No report is a certificate of underlying relationship truth.
|
|
24
|
+
|
|
25
|
+
Graph structure is O(V+E) memory in addition to input parsing and component lists.
|
|
26
|
+
Union/find has near-linear amortized work. Sorting records costs O(V log V);
|
|
27
|
+
neighbor sorting across sampled components is bounded by O(sum deg(v) log deg(v))
|
|
28
|
+
there; BFS work is O(V+E) over the sampled disjoint components. Witness arrays
|
|
29
|
+
may be as long as a component before the output cap is applied. These statements
|
|
30
|
+
are algorithm descriptions, not measured memory/time guarantees. Duplicate
|
|
31
|
+
relation labels on different pairs are fine. Multiple relations on one pair count
|
|
32
|
+
as multiple edges. The report distinguishes direct edges from connected member
|
|
33
|
+
pairs so redundant evidence cannot inflate the affected-record count.
|
|
34
|
+
|
|
35
|
+
All split labels are symmetric. There are no implicit allowed crossings,
|
|
36
|
+
relation exclusions, confidence thresholds, group inference, split generation,
|
|
37
|
+
automatic data movement, fuzzy matching or payload scans. Real evaluation design
|
|
38
|
+
and false/omitted edges remain the caller's responsibility. No claims about
|
|
39
|
+
statistical independence or score impact follow from this graph calculation.
|
|
40
|
+
|
|
41
|
+
## Opt-in membership mode
|
|
42
|
+
|
|
43
|
+
See MEMBERSHIPS.md. It uses an incidence representation keyed by exact namespace/
|
|
44
|
+
group tuples; each membership participates in union-find and witness traversal.
|
|
45
|
+
BFS expands groups once, so a shared group is a single hop between any members
|
|
46
|
+
without materializing all its pairs. Every record needs coverage. It returns its
|
|
47
|
+
own explicit mode and count fields; the original link-mode implementation and
|
|
48
|
+
report remain unchanged. CLI chooses the auditor only by the explicit flag.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Motivation and existing work
|
|
2
|
+
|
|
3
|
+
Sources read November 13, 2026. These are motivation and alternatives, not
|
|
4
|
+
endorsements of this tool or evidence of its adoption.
|
|
5
|
+
|
|
6
|
+
- **scikit-learn, cross-validation guide:** "GroupKFold is a variation of K-fold
|
|
7
|
+
which ensures that the same group is not represented in both testing and
|
|
8
|
+
training sets." This motivates co-location constraints. GroupKFold constructs
|
|
9
|
+
folds given groups; splitwitness audits fixed assignments given explicit links.
|
|
10
|
+
https://scikit-learn.org/stable/modules/cross_validation.html
|
|
11
|
+
- **Yoel Zeldes, The Story of a Bad Train-Test Split, December 16, 2018:**
|
|
12
|
+
"making sure each connected component resides in its entirety either in train
|
|
13
|
+
or test set." The article describes interacting title/thumbnail relationships
|
|
14
|
+
and discusses how splitting components can itself bias a sample. Connected
|
|
15
|
+
components are established practice, not an algorithm invented here.
|
|
16
|
+
https://towardsdatascience.com/the-story-of-a-bad-train-test-split-3343fcc33d2c/
|
|
17
|
+
- **Vector Agentic Skills, Duplicates and Entity Leakage:** "Pairs -> connected
|
|
18
|
+
components (union-find) -> one group id per component -> grouped split."
|
|
19
|
+
This is an existing workflow recipe. splitwitness does not detect the pairs.
|
|
20
|
+
https://agenticskills.vector-ai-lab.com/skills/train-test-split-auditor/duplicates-and-entity-leakage/
|
|
21
|
+
- **leakaudit reference manual:** `find_duplicate_groups` propagates hash-based
|
|
22
|
+
matches transitively, and `dhash_audit` reports cross-split image groups. This
|
|
23
|
+
already covers image-oriented connected-component auditing. Use it when those
|
|
24
|
+
perceptual-hash inputs and R workflow fit.
|
|
25
|
+
https://anakincodex.r-universe.dev/leakaudit/doc/manual.html
|
|
26
|
+
- **spaCR leakage-audit documentation:** "the same path or crop identity never
|
|
27
|
+
crosses a boundary" and "byte-identical crops are detected by streaming SHA-256
|
|
28
|
+
even if renamed" are among its checks. It also has augmentation, group and CV
|
|
29
|
+
coverage checks. That is broader, domain-aware auditing of image datasets;
|
|
30
|
+
splitwitness reads no payloads and makes none of those detection claims.
|
|
31
|
+
https://einarolafsson.github.io/spacr/leakage_audit.html
|
|
32
|
+
- **trustcv data-leakage guide:** "Some leaks happen before trustcv receives the
|
|
33
|
+
data; no check can see those". It documents group, duplicate, temporal and other
|
|
34
|
+
checks. splitwitness is deliberately narrower: a framework-independent graph
|
|
35
|
+
constraint receipt, not a replacement for model/evaluation validation.
|
|
36
|
+
https://ki-smile.github.io/trustcv/guides/data-leakage.html
|
|
37
|
+
|
|
38
|
+
## The small gap this implementation targets
|
|
39
|
+
|
|
40
|
+
Two strict CSV manifests are enough to audit arbitrary caller-declared
|
|
41
|
+
co-location links across an existing assignment. Reports separate direct
|
|
42
|
+
crossing links from the full affected transitive family, avoid quadratic pair
|
|
43
|
+
enumeration, and optionally show deterministic shortest evidence paths with
|
|
44
|
+
bounded report size. No ML framework, image decoder, embeddings, database or
|
|
45
|
+
payload column is required. This is a packaging and evidence-policy choice, not
|
|
46
|
+
a claim that other tools cannot do the same graph calculation or that this tool
|
|
47
|
+
has demonstrated real-world demand. Synthetic tests do not establish that.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anish Pentyala
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Audit declared group memberships
|
|
2
|
+
|
|
3
|
+
Sometimes the input is a patient/session/export inventory rather than a list of
|
|
4
|
+
pairs. Use the opt-in membership mode to avoid creating a clique of every pair
|
|
5
|
+
in a group. This is part of splitwitness, not a separate detection algorithm.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
splitwitness examples/records.csv examples/memberships.csv --memberships --examples 1
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Records keep the exact `id,split` format. The second CSV has the exact header:
|
|
12
|
+
|
|
13
|
+
```csv
|
|
14
|
+
record_id,namespace,group_id
|
|
15
|
+
photo-001,patient,patient-A
|
|
16
|
+
photo-002,patient,patient-A
|
|
17
|
+
photo-002,export,export-B
|
|
18
|
+
photo-003,export,export-B
|
|
19
|
+
photo-003,session,session-C
|
|
20
|
+
photo-004,session,session-C
|
|
21
|
+
unrelated-005,singleton,unrelated-005
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
A record may have multiple memberships. A group is the exact tuple
|
|
25
|
+
`(namespace, group_id)`: patient `123` does not connect to session `123` unless
|
|
26
|
+
some record explicitly belongs to both. A record belonging to two groups connects
|
|
27
|
+
their families transitively. Group values are neither payloads nor verified real
|
|
28
|
+
identities. False group values and false joins are the caller's responsibility.
|
|
29
|
+
|
|
30
|
+
Every assigned record **must** have at least one membership, including records
|
|
31
|
+
that otherwise have no related examples. Use a deliberate singleton group for
|
|
32
|
+
those records; don't invent a common "unknown" group. Header-only membership
|
|
33
|
+
input, missing coverage, unknown record IDs, duplicate membership triples and
|
|
34
|
+
empty fields all fail with exit 2 and no JSON. All fields use the same exact
|
|
35
|
+
string/CSV validation as link mode. Empty strings do not mean "missing". There
|
|
36
|
+
is no implicit per-record singleton, null inference or silently dropped row.
|
|
37
|
+
A complete singleton inventory can still be a false assertion by its caller.
|
|
38
|
+
|
|
39
|
+
## Different report, same narrow promise
|
|
40
|
+
|
|
41
|
+
Membership mode has `mode: "memberships"`, schema_version1 and policy
|
|
42
|
+
`all_declared_groups_must_stay_within_one_split`. Do not treat its counts as link
|
|
43
|
+
mode counts. `memberships` counts accepted input rows; `groups` counts namespaced
|
|
44
|
+
identities; `cross_split_groups` counts groups whose members themselves span
|
|
45
|
+
splits. `components`, `violating_components`, `affected_records`, per-split counts
|
|
46
|
+
and unordered `cross_split_record_pairs` describe the full connected families.
|
|
47
|
+
A family can cross partitions even when some of its individual groups do not.
|
|
48
|
+
`singleton_components` counts one-record components, not one-member groups.
|
|
49
|
+
There is no generated-edge count or direct-link count because no edges are input.
|
|
50
|
+
Multiple shared groups cannot count an affected record or member pair twice.
|
|
51
|
+
|
|
52
|
+
Examples retain the same component/endpoint selection: smallest component record
|
|
53
|
+
ID to smallest differently assigned record ID. In this mode a hop means two
|
|
54
|
+
records share a group. A witness is shortest in number of these group-sharing
|
|
55
|
+
hops, as if every group were a clique, **not** a shortest path through an arbitrary
|
|
56
|
+
star expansion. A breadth-first traversal expands a group's memberships once;
|
|
57
|
+
it never builds the quadratic set of all pairwise links. Groups at a visited
|
|
58
|
+
record are considered in `(namespace, group_id)` Unicode lexical order; members
|
|
59
|
+
of each group in record-ID order. First discovery sets the predecessor. This is
|
|
60
|
+
a deterministic tie-break, not a promise to choose the lexicographically smallest
|
|
61
|
+
record-only path. It may differ from link mode's neighbor/relation ordering.
|
|
62
|
+
|
|
63
|
+
Each witness edge has left_id, right_id, namespace and group_id. This explicitly
|
|
64
|
+
shows why the two endpoints were connected. The values are caller assertions,
|
|
65
|
+
not an authenticated identity or data-provenance proof. If the witness exceeds
|
|
66
|
+
`--max-witness-edges`, its entire path is omitted, with exact hops/endpoints and
|
|
67
|
+
`path_omitted: true`. The cap is inclusive. The exact predecessor-chain distance is counted first;
|
|
68
|
+
edge dictionaries are built only if the complete path fits the cap. The BFS
|
|
69
|
+
queue, predecessor map and inventory graph still take memory. Retained paths
|
|
70
|
+
are walked a second time. This is not a traversal, hard RAM or speed guarantee.
|
|
71
|
+
|
|
72
|
+
## Limits, cost and disclosure
|
|
73
|
+
|
|
74
|
+
The existing `--max-links` option caps **membership rows** when `--memberships`
|
|
75
|
+
is selected. Other byte/record/field/split caps and 0/1/2 exit meanings are unchanged.
|
|
76
|
+
The existing positional `links` argument is the membership CSV only when this
|
|
77
|
+
flag is present. There is no format auto-detection. Normal `audit`/CLI link mode
|
|
78
|
+
and its report schema/default settings are unchanged.
|
|
79
|
+
|
|
80
|
+
All inventory strings and associations are in memory, without temporary files or
|
|
81
|
+
network calls. With `examples=0`, only the group-to-record incidence index and
|
|
82
|
+
a temporary covered-record set are built; the reverse record-to-group index is
|
|
83
|
+
reserved for witness requests. Duplicate memberships are still rejected against
|
|
84
|
+
the group index, and every record must still be covered. Any positive example
|
|
85
|
+
request retains both indexes, even when no violation is found or the path cap is
|
|
86
|
+
zero. This avoids one redundant index for counts-only audits, not all incidence
|
|
87
|
+
storage. Group membership, union-find and component state still take memory.
|
|
88
|
+
Actual allocation and runtime depend on inventory shape; this is not a general
|
|
89
|
+
speedup or hard memory guarantee. Storage is O(records + groups + memberships + input bytes), not
|
|
90
|
+
O(sum group_size squared). Group/member sorting and selected-component witness
|
|
91
|
+
searches add work. A group's members are expanded once per witness. A large
|
|
92
|
+
connected family may still take substantial memory/time, and acceptance caps are
|
|
93
|
+
not a hard bound on either. Witness arrays exist before the output cap applies.
|
|
94
|
+
No general runtime or RAM promise is made.
|
|
95
|
+
|
|
96
|
+
Default examples remain zero: group values/namespace labels do not appear in
|
|
97
|
+
report counts or per-split summaries. Opting into examples exposes record IDs,
|
|
98
|
+
namespace labels **and group IDs**. Even without examples, split labels, counts
|
|
99
|
+
and exact input SHA-256 digests can be sensitive. The receipts bind the exact CSV
|
|
100
|
+
bytes parsed; they do not establish relationship truth, inventory completeness,
|
|
101
|
+
or a simultaneous immutable snapshot of both input paths. No secure memory
|
|
102
|
+
clearing. No identity inference, data movement, automatic repair or independence
|
|
103
|
+
certificate. OS kills and output write failures have the same limitations as
|
|
104
|
+
link mode.
|
|
105
|
+
|
|
106
|
+
## Library
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from splitwitness import audit_memberships
|
|
110
|
+
report = audit_memberships("records.csv", "memberships.csv", examples=1)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The same `Limits`, `AuditError`, examples and max_witness_edges options apply.
|
|
114
|
+
The caller chooses suitable namespaces/groups and must not confuse syntactically
|
|
115
|
+
complete coverage with a truthful or exhaustive relationship inventory.
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: splitwitness
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Offline transitive split-constraint audits with bounded witness paths
|
|
5
|
+
Author: Anish Pentyala
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/anishpentyala/splitwitness
|
|
8
|
+
Project-URL: Repository, https://github.com/anishpentyala/splitwitness
|
|
9
|
+
Project-URL: Issues, https://github.com/anishpentyala/splitwitness/issues
|
|
10
|
+
Keywords: machine-learning,data-leakage,csv,data-validation
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# splitwitness
|
|
17
|
+
|
|
18
|
+
[](https://github.com/anishpentyala/splitwitness/actions)
|
|
19
|
+
|
|
20
|
+
Audit an existing train/validation/test assignment against explicit links that
|
|
21
|
+
must stay in one partition. Get exact component counts and optional short,
|
|
22
|
+
reproducible evidence paths. Runs offline, with Python's standard library.
|
|
23
|
+
|
|
24
|
+
## Quickstart
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
python -m pip install "git+https://github.com/anishpentyala/splitwitness.git"
|
|
28
|
+
cat > records.csv <<'CSV'
|
|
29
|
+
id,split
|
|
30
|
+
a,train
|
|
31
|
+
b,train
|
|
32
|
+
c,test
|
|
33
|
+
CSV
|
|
34
|
+
cat > links.csv <<'CSV'
|
|
35
|
+
left_id,right_id,relation
|
|
36
|
+
a,b,same-person
|
|
37
|
+
b,c,duplicate-export
|
|
38
|
+
CSV
|
|
39
|
+
splitwitness records.csv links.csv --examples 1
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This exits 1: all three records belong to one component spanning train and test.
|
|
43
|
+
Only one link crosses directly, but two unordered cross-split record pairs are
|
|
44
|
+
connected. Checking the grouping columns independently would miss the transitive
|
|
45
|
+
relationship. The report checks only the links you supplied, not identity,
|
|
46
|
+
statistical independence or all possible leakage.
|
|
47
|
+
|
|
48
|
+
A PyPI release is being prepared. Until its package page is linked here, use the
|
|
49
|
+
source-install command above.
|
|
50
|
+
|
|
51
|
+
A duplicate export can connect two patient groups even when the patient IDs do
|
|
52
|
+
not overlap. Checking each grouping column separately misses the full affected
|
|
53
|
+
family. splitwitness follows all supplied links transitively, reports the whole
|
|
54
|
+
connected component and counts each affected record once.
|
|
55
|
+
|
|
56
|
+
This is a constraint checker, not an identity detector or an independence test.
|
|
57
|
+
The caller decides which relationships should prohibit crossing a split. A clean
|
|
58
|
+
report only says those **declared** links stayed within partitions. It says
|
|
59
|
+
nothing about missing links, false identity claims, model quality, statistical
|
|
60
|
+
independence, temporal leakage, feature leakage or contamination from pretraining.
|
|
61
|
+
|
|
62
|
+
## Install and run
|
|
63
|
+
|
|
64
|
+
Python 3.9 or newer. From a copy of this source tree:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
python -m pip install .
|
|
68
|
+
splitwitness examples/records.csv examples/links.csv --examples 2
|
|
69
|
+
# exits 1: a complete report found a violated constraint
|
|
70
|
+
splitwitness examples/records.csv examples/clean-links.csv
|
|
71
|
+
# exits 0: all supplied constraints satisfied
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The first example has five records in two connected components. Four records
|
|
75
|
+
belong to a component spanning train and test. Only one input link crosses the
|
|
76
|
+
boundary, but all four records are affected. There are four unordered cross-split
|
|
77
|
+
record pairs in that component. The fifth record is isolated and not affected.
|
|
78
|
+
The example witness goes from photo-001 to photo-003 in two hops, through
|
|
79
|
+
same-patient and duplicate-export links.
|
|
80
|
+
|
|
81
|
+
## Group inventories
|
|
82
|
+
|
|
83
|
+
Opt-in `--memberships` accepts complete namespaced group inventories instead of
|
|
84
|
+
explicit link pairs, without expanding each group into a quadratic clique.
|
|
85
|
+
See [MEMBERSHIPS.md](MEMBERSHIPS.md) for its separate counts, shortest group-hop
|
|
86
|
+
witnesses and additional disclosure of group IDs in opt-in examples. Link mode
|
|
87
|
+
and its report stay unchanged.
|
|
88
|
+
|
|
89
|
+
## Manifests
|
|
90
|
+
|
|
91
|
+
`records.csv`, with this exact ordered header:
|
|
92
|
+
|
|
93
|
+
```csv
|
|
94
|
+
id,split
|
|
95
|
+
photo-001,train
|
|
96
|
+
photo-002,train
|
|
97
|
+
photo-003,test
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`links.csv`, with this exact ordered header:
|
|
101
|
+
|
|
102
|
+
```csv
|
|
103
|
+
left_id,right_id,relation
|
|
104
|
+
photo-001,photo-002,same-patient
|
|
105
|
+
photo-002,photo-003,duplicate-export
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- Every record has exactly one assignment. Empty record manifests and duplicate
|
|
109
|
+
IDs are errors, including repeated IDs with the same split.
|
|
110
|
+
- Every endpoint must exist in records. Unknown endpoints fail the entire audit.
|
|
111
|
+
- Links are undirected co-location constraints. Every relation participates.
|
|
112
|
+
Labels are descriptive, not trusted provenance, confidence scores or filters.
|
|
113
|
+
A low-confidence match should be reviewed before including it.
|
|
114
|
+
- Reverse duplicates with the same relation are errors. Different relations on
|
|
115
|
+
the same pair are allowed and counted as separate input links, not extra
|
|
116
|
+
record pairs. Self-links are allowed, redundant constraints.
|
|
117
|
+
- Header-only links are valid: all records are isolated. This does not verify
|
|
118
|
+
that the caller supplied a complete relationship inventory.
|
|
119
|
+
- IDs, splits and relations are exact nonempty strings. No trimming, numeric
|
|
120
|
+
conversion, case folding, whitespace collapse or Unicode normalization occurs.
|
|
121
|
+
`01`, `1`, ` a` and `a` are distinct. Even whitespace-only fields are strings.
|
|
122
|
+
- UTF-8, comma-separated CSV with Python `csv.reader(strict=True)` semantics.
|
|
123
|
+
Quoted commas, quotes and newlines work. NUL, BOM-prefixed headers, blank data
|
|
124
|
+
records, wrong headers, ragged records and invalid UTF-8 fail. This is not a
|
|
125
|
+
promise to implement every RFC interpretation; Python accepts bare quotes in
|
|
126
|
+
some unquoted fields. The process's native CSV field cap is an additional
|
|
127
|
+
parser bound and is not changed by this library.
|
|
128
|
+
|
|
129
|
+
## Report and exit codes
|
|
130
|
+
|
|
131
|
+
The CLI writes one complete JSON report to stdout after both manifests pass
|
|
132
|
+
validation. It never edits inputs, repairs splits, trains models, downloads data
|
|
133
|
+
or executes relation labels.
|
|
134
|
+
|
|
135
|
+
- `0`: complete audit, constraints satisfied.
|
|
136
|
+
- `1`: complete audit, at least one connected component spans splits.
|
|
137
|
+
- `2`: audit incomplete, invalid invocation/input/resource cap, or broken output
|
|
138
|
+
pipe. Validation failures emit a diagnostic on stderr and **no JSON**.
|
|
139
|
+
|
|
140
|
+
`counts` includes records, accepted links, connected components, isolated records
|
|
141
|
+
(no incident link, so a self-linked record is not isolated), violating components,
|
|
142
|
+
affected records, direct crossing links, and unordered cross-split record pairs
|
|
143
|
+
within components. All counts cover the full validated inputs, not a sample.
|
|
144
|
+
`cross_split_record_pairs` counts connected pairs in different splits, whether or
|
|
145
|
+
not they share a direct link. It is a constraint exposure count, not a measure of
|
|
146
|
+
leakage probability or model-score inflation. `splits` gives total and affected
|
|
147
|
+
records for each exact split label. No train/test semantics are assumed.
|
|
148
|
+
|
|
149
|
+
Examples default to zero. `--examples N` selects the first N violating components
|
|
150
|
+
by their smallest record ID (Python Unicode code-point ordering). An example has
|
|
151
|
+
that ID, component size, split counts, and one witness. The witness starts at the
|
|
152
|
+
smallest component ID and ends at the smallest ID in a different split. It is a
|
|
153
|
+
shortest path **between those chosen endpoints**, not the closest cross-split
|
|
154
|
+
pair. Breadth-first search visits neighbor-ID/relation pairs in sorted order to
|
|
155
|
+
break ties. Input order, edge orientation and union-find root choice do not change
|
|
156
|
+
semantic results.
|
|
157
|
+
|
|
158
|
+
`--max-witness-edges N` defaults to 20. A longer path is omitted entirely, with
|
|
159
|
+
`path: null`, `path_omitted: true` and its exact hop count. It is not presented as
|
|
160
|
+
a clipped proof. This bounds report evidence size, not traversal cost. The predecessor chain is
|
|
161
|
+
counted before edge dictionaries are built; an omitted path does not allocate
|
|
162
|
+
those dictionaries. Breadth-first search still retains its queue and predecessor
|
|
163
|
+
map, and graph storage remains in memory. A retained path is walked a second time
|
|
164
|
+
to build its evidence. This is not a hard RAM bound or a general speed claim.
|
|
165
|
+
Increasing examples or the path limit can expose more identifiers and make
|
|
166
|
+
reports large.
|
|
167
|
+
|
|
168
|
+
`inputs` contains SHA-256 and byte counts of the exact bytes parsed from each
|
|
169
|
+
file, including headers/newlines. Permuting equivalent CSV changes the receipts,
|
|
170
|
+
not the semantic counts or witness selection. Digests are not signatures and do
|
|
171
|
+
not authenticate provenance, completeness or an immutable simultaneous snapshot
|
|
172
|
+
of both files. Each input is read once, sequentially.
|
|
173
|
+
|
|
174
|
+
## Limits and privacy
|
|
175
|
+
|
|
176
|
+
Acceptance caps are configurable with `--max-bytes` (per file, default 16 MiB),
|
|
177
|
+
`--max-records` (100,000), `--max-links` (500,000), `--max-field-chars` (1,024 per
|
|
178
|
+
field) and `--max-splits` (100). Positive integers only; examples and witness-edge
|
|
179
|
+
caps also allow zero. Caps fail closed; nothing is silently clipped or skipped.
|
|
180
|
+
An empty links file still needs the header. A single populated split is accepted.
|
|
181
|
+
|
|
182
|
+
The graph, CSV bytes and parsed strings live in process memory. This is not a
|
|
183
|
+
streaming/disk-backed implementation and caps are **not** hard RAM or runtime
|
|
184
|
+
bounds. Memory use is O(input bytes + records + links); retained graph adjacency
|
|
185
|
+
includes both orientations. Sorting and witness searches add work. Each sampled
|
|
186
|
+
component is searched separately. Membership mode has its own incidence-graph
|
|
187
|
+
costs described in MEMBERSHIPS.md. Avoid untrusted device/FIFO paths or files that
|
|
188
|
+
may block indefinitely. There is no timeout or sandbox for filesystem reads.
|
|
189
|
+
|
|
190
|
+
No network calls, telemetry, persistent cache or scratch database. No payload
|
|
191
|
+
columns are accepted. Still, identifiers, split labels and relationships can be
|
|
192
|
+
sensitive. Default reports include split labels, counts and input digests;
|
|
193
|
+
opt-in examples include record IDs and relation labels. Library exceptions and
|
|
194
|
+
CLI diagnostics identify input roles and record numbers, not field values or
|
|
195
|
+
paths. Python tracebacks from misuse are not a private reporting channel. Do not
|
|
196
|
+
share reports without checking them. There is no secure memory erasure guarantee.
|
|
197
|
+
|
|
198
|
+
One erroneous edge can connect large unrelated families. The report proves only
|
|
199
|
+
reachability under the declared undirected constraints, not real-world identity.
|
|
200
|
+
Do not automatically repair data or move evaluation rows based on this output.
|
|
201
|
+
|
|
202
|
+
## Python API
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from splitwitness import AuditError, Limits, audit
|
|
206
|
+
|
|
207
|
+
try:
|
|
208
|
+
report = audit("records.csv", "links.csv", examples=2,
|
|
209
|
+
max_witness_edges=10,
|
|
210
|
+
limits=Limits(max_records=50_000))
|
|
211
|
+
except AuditError as error:
|
|
212
|
+
print(error) # incomplete, not a clean audit
|
|
213
|
+
else:
|
|
214
|
+
assert report["passed"], report["counts"]
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`audit` returns a JSON-ready dictionary or raises `AuditError` for invalid
|
|
218
|
+
manifests/options or ordinary filesystem/parser failures. It expects filesystem
|
|
219
|
+
paths. Programming errors, interruptions and process memory exhaustion may still
|
|
220
|
+
raise their normal exceptions. The CLI catches memory exhaustion before JSON
|
|
221
|
+
serialization completes; an OS kill cannot be caught. Output I/O failures are not
|
|
222
|
+
an atomic-output guarantee: a consumer can receive a partial write if the pipe or
|
|
223
|
+
filesystem fails while stdout is being written.
|
|
224
|
+
|
|
225
|
+
## Development
|
|
226
|
+
|
|
227
|
+
```sh
|
|
228
|
+
python -m unittest discover -s tests -v # after install, or PYTHONPATH=src
|
|
229
|
+
ruff check src tests
|
|
230
|
+
ruff format --check src tests
|
|
231
|
+
python -m build
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Tests include a separate set-expansion graph oracle and shuffled/orientation-
|
|
235
|
+
reversed inputs. See [DESIGN.md](DESIGN.md) for algorithms and [EVIDENCE.md](EVIDENCE.md)
|
|
236
|
+
for motivation and existing alternatives. This project does not claim a new graph
|
|
237
|
+
algorithm or unique leakage detection. Source install only; no registry release
|
|
238
|
+
or outside adoption is implied.
|
|
239
|
+
|
|
240
|
+
## Counts-only link storage (0.2.1)
|
|
241
|
+
|
|
242
|
+
In explicit-link mode, the default `examples=0` audit does not retain the
|
|
243
|
+
bidirectional adjacency entries used only for witness paths. A set of incident
|
|
244
|
+
record IDs still distinguishes a self-linked record from an isolated record.
|
|
245
|
+
All links still take part in duplicate/endpoint validation, union-find grouping,
|
|
246
|
+
crossing-link counts, transitive violations and pair counts. This does not skip
|
|
247
|
+
constraint checks or return a partial audit.
|
|
248
|
+
|
|
249
|
+
Requesting any examples retains witness adjacency as before, even when the
|
|
250
|
+
path-output cap is zero. Membership-mode storage is unchanged. Parsed CSV rows,
|
|
251
|
+
undirected-link duplicate detection, component members and other report state
|
|
252
|
+
still consume memory; this is not streaming input or a hard RAM/time bound.
|
|
253
|
+
Actual memory and time depend on graph shape and requested evidence, so no
|
|
254
|
+
portable reduction or speedup is promised.
|