deduplicate-lib 0.1.2__tar.gz → 1.0.0__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.
- deduplicate_lib-1.0.0/.gitignore +10 -0
- deduplicate_lib-1.0.0/CHANGELOG.md +274 -0
- {deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info → deduplicate_lib-1.0.0}/PKG-INFO +46 -28
- {deduplicate_lib-0.1.2 → deduplicate_lib-1.0.0}/README.md +21 -7
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_curves.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_bimodal.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_linear.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_probe_steps.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_trimodal.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_uniform.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_unimodal.png +0 -0
- deduplicate_lib-1.0.0/docs/api/algorithms.rst +51 -0
- deduplicate_lib-1.0.0/docs/api/core.rst +37 -0
- deduplicate_lib-1.0.0/docs/api/index.rst +8 -0
- deduplicate_lib-1.0.0/docs/api/tolerance.rst +184 -0
- deduplicate_lib-1.0.0/docs/conf.py +22 -0
- deduplicate_lib-1.0.0/docs/index.rst +15 -0
- deduplicate_lib-1.0.0/docs/large_datasets.rst +186 -0
- deduplicate_lib-1.0.0/docs/quickstart.rst +70 -0
- deduplicate_lib-1.0.0/docs/requirements.txt +3 -0
- deduplicate_lib-1.0.0/docs/scripts/ntpp_window_study.py +414 -0
- deduplicate_lib-1.0.0/examples/multi_hashing_demo.ipynb +349 -0
- deduplicate_lib-1.0.0/examples/multi_hashing_demo_output.ipynb +679 -0
- deduplicate_lib-1.0.0/pyproject.toml +190 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/__init__.py +6 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/core/duplicate_detection_algorithm.py +530 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/core/hash_index.py +316 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-1.0.0}/src/deduplicate_lib/core/plugin_registry.py +1 -2
- deduplicate_lib-1.0.0/src/deduplicate_lib/core/resources.py +140 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/core/tolerance_calculator.py +230 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/core/vector_store.py +405 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/plugins/duplicate_detection_algorithms/distance_matrix.py +151 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +775 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +323 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +130 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/version.py +24 -0
- deduplicate_lib-1.0.0/tests/__init__.py +0 -0
- deduplicate_lib-1.0.0/tests/conftest.py +72 -0
- deduplicate_lib-1.0.0/tests/integration/test_example_notebook.py +79 -0
- deduplicate_lib-1.0.0/tests/integration/test_tol_find_and_deduplicate.py +102 -0
- deduplicate_lib-1.0.0/tests/unit/core/.coverage +0 -0
- deduplicate_lib-1.0.0/tests/unit/core/__init__.py +0 -0
- deduplicate_lib-1.0.0/tests/unit/core/test_duplicate_detection_algorithm.py +457 -0
- deduplicate_lib-1.0.0/tests/unit/core/test_registry.py +50 -0
- deduplicate_lib-1.0.0/tests/unit/core/test_resources.py +141 -0
- deduplicate_lib-1.0.0/tests/unit/core/test_tolerance_calculator.py +157 -0
- deduplicate_lib-1.0.0/tests/unit/core/test_vector_store.py +325 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/__init__.py +0 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/__init__.py +0 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/conftest.py +9 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/reference_multi_hashing.py +46 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/test_distance_matrix.py +229 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/test_hash_index.py +516 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/test_multi_hashing.py +515 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/test_out_of_core.py +364 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/test_tuning_copy.py +145 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/__init__.py +0 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/plateau_detection.png +0 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/plateau_detection_DistanceMatrix.png +0 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/plateau_detection_MultiHashing.png +0 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/test_natural_tolerance_plateau_probe.py +323 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/test_out_of_core_tuning.py +104 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/test_perturbed_dataset_reclustering.py +165 -0
- deduplicate_lib-0.1.2/PKG-INFO +0 -165
- deduplicate_lib-0.1.2/pyproject.toml +0 -50
- deduplicate_lib-0.1.2/setup.cfg +0 -4
- deduplicate_lib-0.1.2/src/deduplicate_lib/__init__.py +0 -1
- deduplicate_lib-0.1.2/src/deduplicate_lib/core/duplicate_detection_algorithm.py +0 -329
- deduplicate_lib-0.1.2/src/deduplicate_lib/core/tolerance_calculator.py +0 -156
- deduplicate_lib-0.1.2/src/deduplicate_lib/plugins/duplicate_detection_algorithms/distance_matrix.py +0 -77
- deduplicate_lib-0.1.2/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +0 -279
- deduplicate_lib-0.1.2/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +0 -231
- deduplicate_lib-0.1.2/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +0 -94
- deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info/SOURCES.txt +0 -20
- deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info/dependency_links.txt +0 -1
- deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info/requires.txt +0 -19
- deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info/top_level.txt +0 -1
- {deduplicate_lib-0.1.2 → deduplicate_lib-1.0.0}/LICENSE +0 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-1.0.0}/src/deduplicate_lib/core/__init__.py +0 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-1.0.0}/src/deduplicate_lib/plugins/__init__.py +0 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-1.0.0}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/__init__.py +0 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-1.0.0}/src/deduplicate_lib/plugins/tolerance_calculators/__init__.py +0 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-11-17
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- `MultiHashing` was rewritten around flat `uint64` hash tables: per perturbation, a
|
|
9
|
+
sorted array of the dataset's distinct hashes (`sorted_hashes`), plus a per-vector
|
|
10
|
+
count of the perturbations in which it is the earliest vector of its hash bucket
|
|
11
|
+
(`unique_counts`). `get_dataset_unique_structures()` is now O(P·n log n) instead of
|
|
12
|
+
O(P·n²) and uses a fraction of the memory, which is the first step towards
|
|
13
|
+
out-of-core deduplication of very large datasets. Results are unchanged: the unique
|
|
14
|
+
masks, `duplicate_check()` and `get_uniqueness_score()` are tested against the old
|
|
15
|
+
implementation.
|
|
16
|
+
- Hashes come from a new numba kernel, `fast_quantise_and_hash`, instead of Python's
|
|
17
|
+
`hash()`, so they are the same in every process (Python salts `hash()` per process)
|
|
18
|
+
and can be persisted.
|
|
19
|
+
- Progress output of the tolerance calculators goes through `logging`
|
|
20
|
+
(`deduplicate_lib.*` loggers) instead of `print`; leftover debug prints were removed.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- `DuplicateDetectionAlgorithm.get_unique_vector_mask()` returns the boolean mask of
|
|
24
|
+
unique vectors. `get_unique_vector_indices()` still returns integer indices.
|
|
25
|
+
- Out-of-core datasets: pass `dataset=` (a `.npy`/`.h5`/`.hdf5` path or a
|
|
26
|
+
`VectorStore`) instead of `dataset_array=`, and `MultiHashing` reads the vectors in
|
|
27
|
+
chunks instead of loading them. New `deduplicate_lib.core.vector_store` module:
|
|
28
|
+
`InMemoryStore`, `NpyStore` (memory-mapped), `HDF5Store` (appendable),
|
|
29
|
+
`CallableStore` (adapter for databases and other sources), `open_store()`.
|
|
30
|
+
- `memory_limit` (bytes, `"8GB"`, or `"auto"` = half the available memory) sizes the
|
|
31
|
+
row chunks and perturbation batches. `MultiHashing` keeps the per-perturbation hash
|
|
32
|
+
tables only if they fit in a quarter of it; otherwise it keeps just the unique
|
|
33
|
+
counts, and `duplicate_check()`, `get_uniqueness_score()` and appends raise
|
|
34
|
+
`MemoryError`.
|
|
35
|
+
- `n_threads`: `fast_quantise_and_hash` is now parallel (numba `prange`).
|
|
36
|
+
- `progress=True` shows tqdm progress bars.
|
|
37
|
+
- `deduplicate(out=...)` streams the unique vectors to a `.npy`/HDF5 file and returns
|
|
38
|
+
it as a store. Out-of-core datasets write `<input>_unique.<ext>` by default; for
|
|
39
|
+
in-memory datasets `deduplicate()` still returns an array.
|
|
40
|
+
- `MultiHashing(index_dir=...)` keeps the hash tables on disk (memory-mapped), so
|
|
41
|
+
`duplicate_check()` and appends work at any dataset size. The index is reused when
|
|
42
|
+
the dataset and hashing parameters match (`IndexMismatchError` names what differs),
|
|
43
|
+
resumes an interrupted build (it commits after every perturbation batch), and
|
|
44
|
+
recovers vectors appended to an HDF5 dataset without a `flush()`. Commits are
|
|
45
|
+
atomic (`metadata.json` names the current generation-numbered files) and fsynced;
|
|
46
|
+
see `deduplicate_lib.core.hash_index`.
|
|
47
|
+
- `MultiHashing.add_vectors()` appends many vectors at once (same result as appending
|
|
48
|
+
one at a time) and `MultiHashing.flush()` saves appended vectors to the index.
|
|
49
|
+
- `VectorStore.iter_chunks()` takes an optional row range.
|
|
50
|
+
- Optional extras `hdf5` (h5py) and `progress` (tqdm).
|
|
51
|
+
- Docs: a "Large datasets" page.
|
|
52
|
+
|
|
53
|
+
### Changed (DistanceMatrix)
|
|
54
|
+
- `DistanceMatrix` refuses out-of-core datasets (`ValueError`) and raises
|
|
55
|
+
`MemoryError` when its `max_vector_array_size`² matrix would exceed `memory_limit`,
|
|
56
|
+
pointing to `MultiHashing`. Pass a larger `memory_limit` to override.
|
|
57
|
+
|
|
58
|
+
### Changed (tolerance calculators, breaking)
|
|
59
|
+
- Both tolerance calculators tune on a sample of the dataset read through
|
|
60
|
+
`dda.store`, so they work on out-of-core datasets, and run every search on a
|
|
61
|
+
separate in-memory copy of the DDA (`DuplicateDetectionAlgorithm.tuning_copy()`):
|
|
62
|
+
the DDA passed in (its dataset, store, `index_dir` and hash tables) is no longer
|
|
63
|
+
modified. New arguments `sample_size` (rows tuned on), `sampling` (`"blocks"`,
|
|
64
|
+
`"random"`, `"head"`), `block_rows` and `seed`; all arguments after the DDA are
|
|
65
|
+
keyword-only.
|
|
66
|
+
- `PerturbedDatasetReclustering` builds its noisy copies from the sample (default
|
|
67
|
+
`perturbations_per_vector=5`, `sample_size=500`, `sampling="random"`); the default
|
|
68
|
+
target is the number of sampled vectors. An invalid
|
|
69
|
+
`target_unique_vectors_threshold` raises in `__init__`.
|
|
70
|
+
- `NaturalTolerancePlateauProbe` sweeps log-spaced tolerances from below the
|
|
71
|
+
"all different" to above the "all same" tolerance (it used a linear sweep between
|
|
72
|
+
10%/90%-unique bounds, which missed fine clustering scales), detects plateaus
|
|
73
|
+
against log tolerance, merges neighbouring plateaus with the same count, and returns
|
|
74
|
+
a plateau's geometric midpoint. New `find_natural_plateaus()` returns every plateau
|
|
75
|
+
as a `Plateau` (start/end/midpoint tolerance, unique count, steps, `trivial`);
|
|
76
|
+
`calculate_tolerance(condition=...)` takes `"longest"` (default), `"tightest"` or
|
|
77
|
+
`"loosest"` and never picks the trivial all-unique/all-same plateaus. Default
|
|
78
|
+
`sampling="blocks"`. The gradient window (`datapoints_to_calculate_gradient`) now
|
|
79
|
+
defaults to 10% of `probe_steps` (it was 3 steps), chosen from a study across
|
|
80
|
+
synthetic datasets, sizes, dimensions and both DDAs; see "Choosing the gradient
|
|
81
|
+
window" in the docs and `docs/scripts/ntpp_window_study.py`. Fixes plateau detection mis-pairing starts and ends when the
|
|
82
|
+
sweep begins inside a plateau.
|
|
83
|
+
- `memory_limit="auto"` uses `MemAvailable` on Linux; it used the free physical
|
|
84
|
+
pages, which leave out reclaimable page cache and were often a small fraction of
|
|
85
|
+
the usable memory.
|
|
86
|
+
|
|
87
|
+
### Added (tolerance calculators)
|
|
88
|
+
- `VectorStore.sample_blocks()` and `deduplicate_lib.core.tolerance_calculator.draw_sample()`.
|
|
89
|
+
|
|
90
|
+
### Fixed
|
|
91
|
+
- `deduplicate()` recomputes the unique mask first; it returned rows chosen by a stale
|
|
92
|
+
mask after a `tolerance` change or a same-size `set_dataset_array()`.
|
|
93
|
+
- `MultiHashing` keeps a user-supplied `pertrubation_array`; it was replaced by one
|
|
94
|
+
generated from `seed` on the first build. A seed-generated array is regenerated when
|
|
95
|
+
`seed` changes, and assigning a new array triggers a rebuild.
|
|
96
|
+
- `deduplicate(out=...)` refuses to write over its own input file.
|
|
97
|
+
- `DistanceMatrix.set_dataset_store()` with an on-disk dataset raises before dropping the
|
|
98
|
+
current data, leaving the DDA usable.
|
|
99
|
+
- `DistanceMatrix` only refuses (`MemoryError`) a distance matrix larger than an
|
|
100
|
+
explicit `memory_limit`; with the default `"auto"` (which depends on the memory free
|
|
101
|
+
at that moment) it warns (`ResourceWarning`).
|
|
102
|
+
- `MultiHashing.add_vectors()` keeps `vector_count` in step with the hash tables if it
|
|
103
|
+
fails part-way, and hashes rows left in an out-of-core store by such a failure before
|
|
104
|
+
appending more.
|
|
105
|
+
- `VectorStore.take()`/`sample()` read only the requested rows (memory-mapped fancy
|
|
106
|
+
indexing for `.npy`, one point selection for HDF5) instead of a 65536-row chunk per row.
|
|
107
|
+
- The hash index fingerprints every indexed row (sha256 per block of 2^20 rows,
|
|
108
|
+
extended incrementally as the index grows) instead of the first and last 1024 rows,
|
|
109
|
+
so an index is no longer reused after rows in the middle of the dataset change.
|
|
110
|
+
Opening an index reads the indexed rows once. Index format version 2.
|
|
111
|
+
|
|
112
|
+
### Known issues
|
|
113
|
+
- Peak memory while building hash tables can exceed `memory_limit` by roughly
|
|
114
|
+
1.2-1.5x (`np.unique`'s working copies are not budgeted).
|
|
115
|
+
- Many small `MultiHashing.add_vectors()` calls in `index_dir` mode slow down with the
|
|
116
|
+
number of pending (unflushed) hashes; call `flush()` periodically or add in larger
|
|
117
|
+
batches.
|
|
118
|
+
|
|
119
|
+
### Removed (breaking)
|
|
120
|
+
- `ToleranceCalculator(tolerance_dataset_array=...)`, `temp_attr`,
|
|
121
|
+
`create_perturbed_dataset()`, `_ensure_perturbed_dataset()`, and the
|
|
122
|
+
`perturbations_per_vector`/`perturbation_scale` arguments of the base class and
|
|
123
|
+
`NaturalTolerancePlateauProbe`; `NaturalTolerancePlateauProbe(probe_buffer_fraction=...)`
|
|
124
|
+
and its `"minimum"`/`"maximum"` conditions (use `"tightest"`/`"loosest"`).
|
|
125
|
+
- `MultiHashing.hash_dict` and its helpers (`initialize_hash_vector_dictionary`,
|
|
126
|
+
`compute_hash_vector_dictionary`, `add_input_vector_hashes_to_dictionary`,
|
|
127
|
+
`warn_if_vector_dict_mismatch`) and `fast_round_and_perturb`. Use
|
|
128
|
+
`sorted_hashes`/`unique_counts`, `initialize_hash_tables()`, `compute_hash_tables()`
|
|
129
|
+
and `add_input_vector_hashes()` instead. `create_hash_vector()` now returns `uint64`
|
|
130
|
+
hashes, whose values differ from the old ones.
|
|
131
|
+
|
|
132
|
+
## [0.1.3] - 2026-10-12
|
|
133
|
+
|
|
134
|
+
### Changed
|
|
135
|
+
- Packaging moved to uv + hatchling: dev/test dependencies are now PEP 735 dependency
|
|
136
|
+
groups (`uv sync` installs them) instead of the `dev` extra, `uv.lock` pins the
|
|
137
|
+
development environment, and CI installs with `uv sync --locked` and tests on
|
|
138
|
+
Python 3.10–3.12.
|
|
139
|
+
- Minimum Python version raised from 3.8 to 3.10 (current numba releases already
|
|
140
|
+
require it).
|
|
141
|
+
- The version now comes from git tags via hatch-vcs instead of a hand-edited
|
|
142
|
+
`__version__` (which had drifted: the `0.1.2` tag still said `0.1.1`).
|
|
143
|
+
`deduplicate_lib.__version__` still works. New tags use the `vMAJOR.MINOR.PATCH` form.
|
|
144
|
+
- Ruff now enforces the same rule set as ALomancy (isort, bugbear, pyupgrade,
|
|
145
|
+
comprehensions, unused arguments, simplify, ruff-specific). Code was updated to
|
|
146
|
+
match: sorted imports, builtin generics, `stacklevel=2` on all warnings, so they
|
|
147
|
+
point at the caller instead of inside the library.
|
|
148
|
+
- `DuplicateDetectionAlgorithm.pre_dda_processing()` (and the `MultiHashing`
|
|
149
|
+
override) no longer accept unused `*args, **kwargs`.
|
|
150
|
+
|
|
151
|
+
### Fixed
|
|
152
|
+
- `DistanceMatrix.get_dataset_unique_structures()` now keeps exactly one vector from
|
|
153
|
+
each group of near-duplicates: in dataset order, a vector is unique unless it is within
|
|
154
|
+
`tolerance` of a vector already kept. Before, a vector counted as unique only if
|
|
155
|
+
nothing at all was within `tolerance` (row 0 excepted), so every group that didn't
|
|
156
|
+
contain row 0 was flagged in full and `deduplicate()` dropped it entirely. This matches
|
|
157
|
+
`MultiHashing`, which already keeps the first vector of each group.
|
|
158
|
+
|
|
159
|
+
### Behaviour change
|
|
160
|
+
- Unique counts from `DistanceMatrix` are higher wherever near-duplicate groups exist,
|
|
161
|
+
so the tolerances that `NaturalTolerancePlateauProbe` and
|
|
162
|
+
`PerturbedDatasetReclustering` find with it shift. In the integration tests,
|
|
163
|
+
0.168 → 0.181 (reclustering) and 0.141 → 0.153 (plateau probe). At the old values,
|
|
164
|
+
one point plus a 30-vector cluster deduplicated to the point alone; at the new
|
|
165
|
+
values, to the point plus one cluster member.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## [0.1.2] - 2026-09-23
|
|
170
|
+
|
|
171
|
+
### Fixed
|
|
172
|
+
- `NaturalTolerancePlateauProbe`: fixed selection of the minimum/maximum plateau.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## [0.1.1] - 2026-09-23
|
|
177
|
+
|
|
178
|
+
### Added
|
|
179
|
+
- `NaturalTolerancePlateauProbe` can select the minimum or maximum plateau.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## [0.1.0] - 2026-06-14
|
|
184
|
+
|
|
185
|
+
### Fixed
|
|
186
|
+
- `MultiHashing.duplicate_check()` / `get_uniqueness_score()` no longer return stale results
|
|
187
|
+
when `tolerance`, `seed`, or `perturbations` change after the hash dictionary was first
|
|
188
|
+
built — `pre_dda_processing()` now detects these changes and forces a rebuild.
|
|
189
|
+
- `DistanceMatrix.duplicate_check()` no longer triggers an unnecessary full O(N²)
|
|
190
|
+
distance-matrix rebuild (and large preallocation) on a clean dataset; it now only ensures
|
|
191
|
+
the dataset array is preinitialized.
|
|
192
|
+
- `set_dataset_array()` is now a no-op (no reallocation, no `_dirty` invalidation) when the
|
|
193
|
+
incoming array is identical to the data already loaded, avoiding redundant rebuilds when
|
|
194
|
+
tolerance calculators temporarily swap datasets and restore the original.
|
|
195
|
+
- Removed a redundant double-computation of the hash vector dictionary in
|
|
196
|
+
`MultiHashing.get_dataset_unique_structures()`.
|
|
197
|
+
- `DistanceMatrix._rebuild_auxiliary_structures()` no longer redundantly reinitializes the
|
|
198
|
+
distance matrix before recomputing it.
|
|
199
|
+
|
|
200
|
+
### Changed
|
|
201
|
+
- Dropped the unused `input_dataset_array` parameter from `pre_dda_processing()`.
|
|
202
|
+
- Extracted `MultiHashing._perturbation_array_stale()` to share the perturbation-array
|
|
203
|
+
staleness check between `pre_dda_processing()` and `_rebuild_auxiliary_structures()`.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## [0.0.5] - 2026-04-23
|
|
208
|
+
|
|
209
|
+
### Changed
|
|
210
|
+
- Reinstated dictionary-based storage in multi-hashing implementation (`b3f3fad`).
|
|
211
|
+
- Verified full test and coverage status for the dictionary reversion (`b3f3fad`).
|
|
212
|
+
- Finalized release/build readiness updates (`ff9ee21`, `02614ed`).
|
|
213
|
+
|
|
214
|
+
### Merged
|
|
215
|
+
- PR #9: Reinstate dictionaries for MH (`aa9aff4`).
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## [0.0.4] - 2026-04-22
|
|
220
|
+
|
|
221
|
+
### Added
|
|
222
|
+
- Pre-initialisation logic for dataset handling (`60736ff`).
|
|
223
|
+
|
|
224
|
+
### Changed
|
|
225
|
+
- Coverage/test completeness improvements (`74658d4`).
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## [0.0.3] - 2026-04-16
|
|
230
|
+
|
|
231
|
+
### Added
|
|
232
|
+
- Tight and loose options to PDR (`eca4ab0`).
|
|
233
|
+
- `get_uniqueness_score` support in multi-hash flow (`671ddac`).
|
|
234
|
+
|
|
235
|
+
### Changed
|
|
236
|
+
- Acceptance threshold moved to sigma-based threshold (`62d80e6`).
|
|
237
|
+
- Round-then-perturb bug fix and hash-array/input reset fixes (`671ddac`).
|
|
238
|
+
- Test updates and cleanup (`4d72241`, `47f1271`).
|
|
239
|
+
- Version update for v0.0.3 (`ab12fde`).
|
|
240
|
+
|
|
241
|
+
### Merged
|
|
242
|
+
- PR #5: Release v0.0.3 (`97d2102`).
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## [0.0.2] - 2026-03-30
|
|
247
|
+
|
|
248
|
+
### Added
|
|
249
|
+
- Example usage and deduplicate function introduced (`7ee94df`).
|
|
250
|
+
- Additional tests (`85e666a`).
|
|
251
|
+
- SciPy dependency (`9c1cfc4`).
|
|
252
|
+
|
|
253
|
+
### Changed
|
|
254
|
+
- Release prep for v0.0.2 (`2239439`).
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## [0.0.1] - 2026-03-26
|
|
259
|
+
|
|
260
|
+
### Added
|
|
261
|
+
- Initial CI and test setup (`b0b5477`, `bb03869`).
|
|
262
|
+
- Numba acceleration for DDAs (`cf10a8e`, `fa93d56`).
|
|
263
|
+
- Codecov integration and badge (`033d99f`, `e13a1ba`).
|
|
264
|
+
- License and core tolerance calculator tests (`3edf959`).
|
|
265
|
+
|
|
266
|
+
### Changed
|
|
267
|
+
- README and packaging updates (`851b609`, `8108a50`).
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## [0.0.0] - 2026-03-17
|
|
272
|
+
|
|
273
|
+
### Added
|
|
274
|
+
- Initial project commit (`03a02d8`).
|
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: deduplicate_lib
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Deduplication of numpy vector arrays, with automatic tolerance tuning.
|
|
5
|
+
Project-URL: Homepage, https://github.com/julianholland/deduplicate
|
|
6
|
+
Project-URL: Repository, https://github.com/julianholland/deduplicate
|
|
5
7
|
Author-email: Julian Holland <holland@fhi.mpg.de>
|
|
6
|
-
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
+
License: MIT
|
|
8
9
|
License-File: LICENSE
|
|
9
|
-
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering
|
|
18
|
+
Requires-Python: >=3.10
|
|
10
19
|
Requires-Dist: numba
|
|
20
|
+
Requires-Dist: numpy
|
|
11
21
|
Requires-Dist: scipy
|
|
12
|
-
Provides-Extra: dev
|
|
13
|
-
Requires-Dist: pytest; extra == "dev"
|
|
14
|
-
Requires-Dist: pytest-mock; extra == "dev"
|
|
15
|
-
Requires-Dist: coverage; extra == "dev"
|
|
16
|
-
Requires-Dist: ruff; extra == "dev"
|
|
17
|
-
Requires-Dist: nbconvert; extra == "dev"
|
|
18
|
-
Requires-Dist: nbclient; extra == "dev"
|
|
19
|
-
Requires-Dist: notebook; extra == "dev"
|
|
20
|
-
Requires-Dist: ipykernel; extra == "dev"
|
|
21
|
-
Requires-Dist: matplotlib; extra == "dev"
|
|
22
22
|
Provides-Extra: docs
|
|
23
|
-
Requires-Dist:
|
|
24
|
-
Requires-Dist:
|
|
25
|
-
Requires-Dist: sphinx
|
|
26
|
-
|
|
23
|
+
Requires-Dist: furo; extra == 'docs'
|
|
24
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == 'docs'
|
|
25
|
+
Requires-Dist: sphinx>=7; extra == 'docs'
|
|
26
|
+
Provides-Extra: hdf5
|
|
27
|
+
Requires-Dist: h5py; extra == 'hdf5'
|
|
28
|
+
Provides-Extra: progress
|
|
29
|
+
Requires-Dist: tqdm; extra == 'progress'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
27
31
|
|
|
28
32
|
<div align="center">
|
|
29
33
|
<h1><code>deduplicate_lib</code></h1>
|
|
@@ -34,7 +38,7 @@ Dynamic: license-file
|
|
|
34
38
|
[](https://github.com/julianholland/deduplicate)
|
|
35
39
|
[](https://codecov.io/gh/julianholland/deduplicate)
|
|
36
40
|
[](https://badge.fury.io/py/deduplicate_lib)
|
|
37
|
-
[](https://www.python.org/downloads/)
|
|
38
42
|
[](https://opensource.org/licenses/MIT)
|
|
39
43
|
[](https://github.com/julianholland/deduplicate/actions/workflows/ci.yml)
|
|
40
44
|
[](https://github.com/astral-sh/ruff)
|
|
@@ -76,11 +80,25 @@ dda.input_vector = np.array([1.0, 2.0])
|
|
|
76
80
|
print(dda.duplicate_check()) # True
|
|
77
81
|
```
|
|
78
82
|
|
|
83
|
+
### Large datasets
|
|
84
|
+
|
|
85
|
+
Datasets too large for memory can be deduplicated straight from disk (`.npy`, HDF5, or any
|
|
86
|
+
source via `CallableStore`), in chunks sized by `memory_limit`:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
dda = MultiHashing(dataset="descriptors.npy", tolerance=0.05, memory_limit="8GB", n_threads=8)
|
|
90
|
+
dda.get_dataset_unique_structures()
|
|
91
|
+
mask = dda.get_unique_vector_mask() # boolean mask over the dataset
|
|
92
|
+
dda.deduplicate() # writes descriptors_unique.npy
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Optional extras: `pip install deduplicate_lib[hdf5,progress]`.
|
|
96
|
+
|
|
79
97
|
See the **[full documentation](https://deduplicate-lib.readthedocs.io)** for API reference, tolerance tuning, and more examples.
|
|
80
98
|
|
|
81
99
|
### Dependencies
|
|
82
100
|
|
|
83
|
-
- Python 3.
|
|
101
|
+
- Python 3.10+
|
|
84
102
|
- `numpy`
|
|
85
103
|
- `numba`
|
|
86
104
|
- `scipy`
|
|
@@ -96,15 +114,15 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
|
|
|
96
114
|
git clone https://github.com/julianholland/deduplicate.git
|
|
97
115
|
cd deduplicate
|
|
98
116
|
|
|
99
|
-
#
|
|
100
|
-
|
|
117
|
+
# Create a virtual environment with the package and dev dependencies (needs uv)
|
|
118
|
+
uv sync
|
|
101
119
|
|
|
102
120
|
# Run tests
|
|
103
|
-
pytest
|
|
121
|
+
uv run pytest
|
|
104
122
|
|
|
105
123
|
# Run linting
|
|
106
|
-
ruff check .
|
|
107
|
-
ruff format .
|
|
124
|
+
uv run ruff check .
|
|
125
|
+
uv run ruff format .
|
|
108
126
|
```
|
|
109
127
|
|
|
110
128
|
### Running Tests
|
|
@@ -162,4 +180,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
162
180
|
- [x] Speedup slow tasks with Numba
|
|
163
181
|
- [x] Set up Read the Docs
|
|
164
182
|
- [x] Create general deduplicate function
|
|
165
|
-
- [x] Speed up NTPP
|
|
183
|
+
- [x] Speed up NTPP
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://github.com/julianholland/deduplicate)
|
|
8
8
|
[](https://codecov.io/gh/julianholland/deduplicate)
|
|
9
9
|
[](https://badge.fury.io/py/deduplicate_lib)
|
|
10
|
-
[](https://www.python.org/downloads/)
|
|
11
11
|
[](https://opensource.org/licenses/MIT)
|
|
12
12
|
[](https://github.com/julianholland/deduplicate/actions/workflows/ci.yml)
|
|
13
13
|
[](https://github.com/astral-sh/ruff)
|
|
@@ -49,11 +49,25 @@ dda.input_vector = np.array([1.0, 2.0])
|
|
|
49
49
|
print(dda.duplicate_check()) # True
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
### Large datasets
|
|
53
|
+
|
|
54
|
+
Datasets too large for memory can be deduplicated straight from disk (`.npy`, HDF5, or any
|
|
55
|
+
source via `CallableStore`), in chunks sized by `memory_limit`:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
dda = MultiHashing(dataset="descriptors.npy", tolerance=0.05, memory_limit="8GB", n_threads=8)
|
|
59
|
+
dda.get_dataset_unique_structures()
|
|
60
|
+
mask = dda.get_unique_vector_mask() # boolean mask over the dataset
|
|
61
|
+
dda.deduplicate() # writes descriptors_unique.npy
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Optional extras: `pip install deduplicate_lib[hdf5,progress]`.
|
|
65
|
+
|
|
52
66
|
See the **[full documentation](https://deduplicate-lib.readthedocs.io)** for API reference, tolerance tuning, and more examples.
|
|
53
67
|
|
|
54
68
|
### Dependencies
|
|
55
69
|
|
|
56
|
-
- Python 3.
|
|
70
|
+
- Python 3.10+
|
|
57
71
|
- `numpy`
|
|
58
72
|
- `numba`
|
|
59
73
|
- `scipy`
|
|
@@ -69,15 +83,15 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
|
|
|
69
83
|
git clone https://github.com/julianholland/deduplicate.git
|
|
70
84
|
cd deduplicate
|
|
71
85
|
|
|
72
|
-
#
|
|
73
|
-
|
|
86
|
+
# Create a virtual environment with the package and dev dependencies (needs uv)
|
|
87
|
+
uv sync
|
|
74
88
|
|
|
75
89
|
# Run tests
|
|
76
|
-
pytest
|
|
90
|
+
uv run pytest
|
|
77
91
|
|
|
78
92
|
# Run linting
|
|
79
|
-
ruff check .
|
|
80
|
-
ruff format .
|
|
93
|
+
uv run ruff check .
|
|
94
|
+
uv run ruff format .
|
|
81
95
|
```
|
|
82
96
|
|
|
83
97
|
### Running Tests
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Duplicate Detection Algorithms
|
|
2
|
+
==============================
|
|
3
|
+
|
|
4
|
+
Two algorithms are provided. Choose based on dataset size and whether exact
|
|
5
|
+
results are required.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
DistanceMatrix
|
|
9
|
+
--------------
|
|
10
|
+
|
|
11
|
+
Exact algorithm. Builds the full N×N pairwise distance matrix. Vectors are
|
|
12
|
+
taken in dataset order, and a vector is a duplicate only if it is within
|
|
13
|
+
``tolerance`` of a vector already kept, so each group of near-duplicates keeps
|
|
14
|
+
exactly one vector (its earliest). O(N²)
|
|
15
|
+
time and space; a good choice for datasets up to ~5 000 vectors. Supports all
|
|
16
|
+
four distance metrics: ``"euclidean"``, ``"manhattan"``, ``"cosine"``, and
|
|
17
|
+
``"hamming"``.
|
|
18
|
+
|
|
19
|
+
.. autoclass:: deduplicate_lib.plugins.duplicate_detection_algorithms.distance_matrix.DistanceMatrix
|
|
20
|
+
:members:
|
|
21
|
+
:show-inheritance:
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
MultiHashing
|
|
25
|
+
------------
|
|
26
|
+
|
|
27
|
+
Approximate algorithm. O(N · perturbations) time; scales well to large
|
|
28
|
+
datasets. Restricted to ``"hamming"`` distance. Accuracy is controlled by
|
|
29
|
+
``perturbations`` (more is better) and ``sigma_accepatnce_threshold`` (higher
|
|
30
|
+
reduces false positives but requires more perturbations to be reliable).
|
|
31
|
+
|
|
32
|
+
.. autoclass:: deduplicate_lib.plugins.duplicate_detection_algorithms.multi_hashing.MultiHashing
|
|
33
|
+
:members:
|
|
34
|
+
:show-inheritance:
|
|
35
|
+
|
|
36
|
+
.. note::
|
|
37
|
+
|
|
38
|
+
``sigma_accepatnce_threshold`` selects the acceptance band used to declare
|
|
39
|
+
a hash-collision a duplicate:
|
|
40
|
+
|
|
41
|
+
============================== ================
|
|
42
|
+
``sigma_accepatnce_threshold`` Acceptance band
|
|
43
|
+
============================== ================
|
|
44
|
+
1 (default) 68.3%
|
|
45
|
+
2 95.4%
|
|
46
|
+
3 99.7%
|
|
47
|
+
4 99.99%
|
|
48
|
+
============================== ================
|
|
49
|
+
|
|
50
|
+
Higher values reduce false positives but require more perturbations to be
|
|
51
|
+
statistically reliable.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Core API
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
The typical DDA lifecycle is: construct the DDA (optionally passing
|
|
5
|
+
``dataset_array`` or calling ``set_dataset_array()`` afterwards) → set
|
|
6
|
+
``input_vector`` → call ``duplicate_check()`` or
|
|
7
|
+
``add_input_vector_to_dda()`` for streaming ingestion → call
|
|
8
|
+
``deduplicate()`` to retrieve the full set of unique vectors.
|
|
9
|
+
|
|
10
|
+
.. autoclass:: deduplicate_lib.core.duplicate_detection_algorithm.DuplicateDetectionAlgorithm
|
|
11
|
+
:members: deduplicate, duplicate_check, add_input_vector_to_dda, set_dataset_array, set_dataset_store, store, is_out_of_core, get_dataset_unique_structures, get_unique_vector_mask, get_unique_vector_indices, tuning_copy
|
|
12
|
+
:show-inheritance:
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
Vector stores
|
|
16
|
+
-------------
|
|
17
|
+
|
|
18
|
+
Where a dataset's vectors live. Pass a path or a store as ``dataset`` to use an
|
|
19
|
+
out-of-core dataset; see :doc:`../large_datasets`.
|
|
20
|
+
|
|
21
|
+
.. automodule:: deduplicate_lib.core.vector_store
|
|
22
|
+
:members: VectorStore, InMemoryStore, NpyStore, HDF5Store, CallableStore, open_store
|
|
23
|
+
:show-inheritance:
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Hash index
|
|
27
|
+
----------
|
|
28
|
+
|
|
29
|
+
.. automodule:: deduplicate_lib.core.hash_index
|
|
30
|
+
:members: HashIndex, IndexMismatchError
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Resources
|
|
34
|
+
---------
|
|
35
|
+
|
|
36
|
+
.. automodule:: deduplicate_lib.core.resources
|
|
37
|
+
:members: parse_memory_limit, chunk_rows, perturbation_batch
|