Skip to content

Add UDLF-CSR backend (CPRR and LHRR with sparse engines) - #12

Merged
GRLeticio merged 3 commits into
devfrom
feature/csr
Oct 14, 2026
Merged

GRLeticio merged 3 commits into
devfrom
feature/csr

Conversation

@GRLeticio

Copy link
Copy Markdown
Collaborator

Summary

Adds support for UDLF-CSR, a rewrite of UDLF that runs CPRR and LHRR
with several engines (dense, sparse, MKL, BLAS, Eigen) to scale to large datasets. It uses the same API and
returns the same Result as UDLF, so switching between them is one line:

from pyUDLF import UDLF

udlf = UDLF()                                                 # UDLF 1.70
csr = UDLF(bin_path="path/to/UDLF-CSR/Source/bin/udlf", backend="csr", threads=1)

a = udlf.run("CPRR", ranked_lists=rks, params={"l": 400, "k": 20}, classes=labels)
b = csr.run("CPRR", ranked_lists=rks, params={"l": 400, "k": 20}, classes=labels,
            engine="sparse")                                  # dense | sparse | mkl | blas | eigen
a.map_after, b.map_after, b.warnings, b.raw_metrics

What pyUDLF handles

UDLF-CSR behaves differently from UDLF in several ways (checked in its sources, commit b391800, and by running
it). pyUDLF takes care of them:

  • writes every config variable (missing ones are left uninitialized by UDLF-CSR);
  • detects errors from its output (it always exits with code 0);
  • runs it in a temporary directory with the output/ folder it writes to, and sends its N×N matrix to
    /dev/null unless output="matrix";
  • writes the classes file in the order of the lists (UDLF-CSR reads classes by line order);
  • parses its log (percentages, two EFFECTIVENESS blocks);
  • detects the binary type, so a UDLF binary used with backend="csr" (or the opposite) gives a clear error.

Measures are computed by pyUDLF with the UDLF definitions, so UDLF and UDLF-CSR results are directly comparable.
UDLF-CSR's own measures are kept in Result.raw_metrics (its recall is averaged per query, not per class).

New options

  • UDLF(backend="csr"), run(..., engine=...); UDLF-CSR names such as "CPRR_SPARSE" are also accepted.
  • UDLF(threads=...) sets OMP_NUM_THREADS.
  • Result.warnings: problems found in the results.
  • scripts/build_csr.sh builds UDLF-CSR pinned to commit b391800: the dense and sparse engines by default,
    all engines with --full (needs MKL, GraphBLAS, Eigen)

GRLeticio and others added 3 commits October 14, 2026 12:23
    csr = UDLF(bin_path=..., backend="csr", threads=1)
    res = csr.run("CPRR", ranked_lists=rks, params={"l": 1000}, classes=labels,
                  engine="sparse")

- runs CPRR and LHRR of UDLF-CSR with engine="dense" | "sparse" | "mkl" |
  "blas" | "eigen" (or the UDLF-CSR names, e.g. "CPRR_SPARSE") and returns
  the same Result as UDLF
- handles how UDLF-CSR differs from UDLF (checked in its sources and by
  running it): every config variable is written (missing ones are left
  uninitialized), errors are read from its output (it always exits with
  0), it runs in a directory with the output/ folder it writes to, its
  N x N matrix goes to /dev/null unless output="matrix", the classes file
  is written in the order of the lists (it reads classes by line order),
  and its log (percentages, two EFFECTIVENESS blocks) is parsed
- measures are computed by pyUDLF with the UDLF definitions, so UDLF and
  UDLF-CSR results are comparable; UDLF-CSR's own are in raw_metrics
- Result.warnings: repeated elements in the ranked lists (sparse engines),
  and runs repeated after UDLF-CSR's intermittent "Failed to open backing
  file" startup error (dangling pointer in VirtualArray::create)
- UDLF(threads=...) sets OMP_NUM_THREADS: the dense engines are not
  deterministic with several threads
- the binary type is detected, so a UDLF binary used as UDLF-CSR (or the
  opposite) is reported instead of failing later
- scripts/build_csr.sh builds UDLF-CSR pinned to commit b391800 (dense and
  sparse engines, or all with --full); CI builds it and runs the tests
- tests/test_csr.py compares each engine with UDLF-CSR run directly
  (PYUDLF_CSR_ENGINES selects the engines to test); README and CHANGELOG
  document the backend and the UDLF-CSR issues found

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The sparse engines rewrite only the first min(scored elements, L)
positions of each ranked list (CprrSparse/LHRRSparse updateRankedLists;
same pattern in LHRRMKL and CprrEigen). When a query has fewer scored
elements than L, the remaining positions keep the previous ranking and
repeat elements already placed. Verified: with L = 100 on the synthetic
data, repetitions go from every list (k = 5) to none (k = 30).

The warning now says why it happens and how to avoid it (larger k or
smaller l); the CHANGELOG records the cause for the UDLF-CSR authors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- One CI job failed once on the push of feature/csr (Linux, Python 3.12,
  "Run tests"), then passed with the same code on the pull request; 40
  local runs of the suite had no failure. The only known intermittent
  cause is UDLF-CSR's startup error ("Failed to open backing file",
  dangling pointer in VirtualArray::create), measured at 1-5% of the runs
  of every engine. The test suite runs UDLF-CSR about 60 times, so 3
  attempts were not always enough. The run (which fails before any
  computation) is now repeated up to 5 times, in pyUDLF and in the test
  helper, through csr.RUN_ATTEMPTS.
- CI installs pytest-github-actions-annotate-failures, so a failing test
  shows up as an annotation (on the pull request and in the API) instead
  of only in the job log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GRLeticio
GRLeticio merged commit 51e1d39 into dev Oct 14, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant