Repository navigation
Trial mode, move, and lifecycle methods - #147
Conversation
Incremental operations (get_cvi, remove, merge, split, and the new move) take a keyword-only commit argument. With commit=False they return the score the operation would produce and leave the object unchanged; get_cvi and move also accept a 1-D array of candidate labels and return one score per label. Unseen labels create a new cluster; undefined scores are NaN. Additions are split into a pure plan step and an apply step. The object keeps its most recent trial's computed state, so a following committed call with the same operation and arguments applies it without recomputing. Structural trials stage on a copy that the commit adopts. move(sample, old_label, new_label) commits exactly the state of remove followed by get_cvi, atomically; moving to the same label is a no-op. Also adds reset(), clone(), n_clusters, n_samples, labels, is_better(), and trial/move capability flags (False for CONN and JAX). The trial memo is excluded from pickles. Version bumped to 0.8.0.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #147 +/- ##
===========================================
+ Coverage 95.31% 96.34% +1.03%
===========================================
Files 21 22 +1
Lines 2584 3313 +729
===========================================
+ Hits 2463 3192 +729
Misses 121 121 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
GitHub's ubuntu-latest image no longer provides Python 3.9, so setup failed and fail-fast cancelled every other version.
Covers clone for subclasses and older pickles, invalid trial inputs, warnings from undefined batch trials, rejection of stale plans, and the _trial helper functions.
The version bump will land in a separate PR.
Restore each index's _param_inc exactly as on develop, so committing get_cvi and uncached move calls keep their previous numerics and speed. The plan/apply path is now used only by trials and by commits that reuse a matching trial. Tests compare the two paths to a tight tolerance and check that plain commits never call the planner.
AP6YC
left a comment
There was a problem hiding this comment.
Overall good, but things are starting to get bloated. Next PRs are going to consolidate functionality since both functionality and documentation is getting duplicated.
There was a problem hiding this comment.
Yeah, I'll add another PR to update the CI matrix since 3.9 is EOL now.
There was a problem hiding this comment.
This works for me as a separate section in the guide. Another PR might be useful to consolidate and simplify a lot of this ever expanding guide, but this works okay for now.
There was a problem hiding this comment.
Base is getting bloated. Compactness compute is getting duplicated here, and more private methods are making cvi decently large in memory. I'll accept this, but there's got to be a better way to start structuring a lot of the machinery for base so that it isn't so bloated and confusing, either through OOP refactoring or identifying where functionality is duplicated and consolidating.
There was a problem hiding this comment.
Yes, I even opened an issue about this. I wanted to add the new feature prior to making major removals. Next set is to remove all the duplicate code.
There was a problem hiding this comment.
I'm assuming pure helpers meaning pure functions here, which is good for trialing, so I'm good for this additional module.
There was a problem hiding this comment.
I appreciate the add here for readme, but the readme is getting way too bloated; I'm gonna start enforcing cutback and human writing/reading of the readme, saving details for the docs. Accepting here mainly to start another PR to cut back and consolidate with the docs. LLMs are currently trained to eagerly self document in the README, but I'm using READMEs for humans since my eyes glaze over when reading other verbose READMEs for other tools, and I don't want that for us.
There was a problem hiding this comment.
Agreed. I'll make a pass on the readme as well to ensure it isn't too verbose
Adds the cvi pieces artlib's unified
CVIARTwrapper needs.Trial mode (
commitkeyword)get_cvi,remove,merge,split, and the newmovetake a keyword-onlycommit: bool = True.commit=False, the call returns the score the operation would produce and leaves the object unchanged.commit=False,get_cvi(sample, labels)andmove(sample, old, labels)accept a 1-D array of candidate labels and return one score per label. Committing still requires a scalar label, so batchget_cvistays unambiguous._param_inc, unchanged fromdevelop, so existing users see the same numbers and speed. This means the add math exists twice per index for now; tests keep the two paths in agreement, and Unify the plain-commit and trial add paths #148 tracks unifying them.move(sample, old_label, new_label, *, commit=True)removefollowed byget_cvi.switch_label.Lifecycle, accessors, capabilities
reset()clears the data and keeps the configuration and backend. Batchget_cviworks again afterwards.clone()returns a fresh, unfitted object with the same constructor configuration.n_clusters,n_samples,labels.is_better(new, old, tol=0.0)followsinfo.optimality, accepts ties, and treats NaN as acceptance.CVICapabilitiesgainstrialandmove. Both are True for NumPy and Numba, and False for CONN and JAX, which raiseNotImplementedError.Cost
get_cvi(no trial) is within 1–2 µs ofdevelop(CH: 13.1 → 14.7 µs at K=40, d=8). That remainder is the check for a saved trial.Tests
tests/test_trial.pycovers every index except CONN, on both NumPy and Numba:moveequalsremoveplusget_cvi;import cvidoes not import artlib.The full suite passes locally (1807 passed, 149 skipped). JAX is not installed locally, so its tests were skipped.
CI
The Python 3.9 job now runs on
ubuntu-22.04, becauseubuntu-latestno longer provides Python 3.9.