cleverly.validation.RefutationCheckpoint#

class cleverly.validation.RefutationCheckpoint(directory: str | PathLike[str])[source]#

Keep each finished draw of the long refutation tests as a file in a directory.

Pass it as refute(..., checkpoint=RefutationCheckpoint(directory)). Each finished draw of dummy_outcome, simulated_outcome, plasmode, bootstrap_stability and bootstrap_measurement_error is written as one JSON file, under a temporary name and then renamed, so a call stopped mid-write never reads a partial file. Run the same call again with the same directory and it loads the stored draws, refits only the missing ones, and returns the report an uninterrupted call returns. The placebo, noise and subset tests are not stored.

The directory records the request on first use: the estimator’s class and settings, the data’s fingerprint, the resolved seed and repeat seeds, every estimate and standard error of the fit, the estimand, each stored test’s draw count, process or declaration, bands, rule and resampling, and the versions of cleverly, NumPy, SciPy and scikit-learn. A call whose request differs in any part refuses, naming the part. Two development commits can share one cleverly version, so give each commit its own directory. An unseeded fit draws its seed at the first call; the directory records it, and a resume passes it back as random_state=. A directory that holds no draw yet takes a new request. A facade call whose answer is already cached returns it without reading the draws. Run one call per directory at a time: the request file is not locked.

Parameters:
directorystr or os.PathLike

Where the files go. It is created when missing.

Methods#

RefutationCheckpoint.child(name: str, *, record: bool = True) → RefutationCheckpoint[source]#

The checkpoint of one candidate of a variable-importance run.

Parameters:
namestr

The candidate’s name. Its directory is named by a digest of it, so a name holding / or .. stays inside this directory.

recordbool

Whether to record the name in this directory. The preview of planned refits passes False and writes nothing.

Returns:
RefutationCheckpoint

A checkpoint in a subdirectory of this one.

Raises:
CapabilityError

If two names map to one subdirectory.

RefutationCheckpoint.load(test: str, replicate: int) → EmpiricalRefitRecord | ReplicationFailure | None[source]#

Return the stored draw replicate of test, or None when there is none.

Parameters:
teststr

The test.

replicateint

The draw’s index.

Returns:
EmpiricalRefitRecord, ReplicationFailure or None

The stored draw, or None.

RefutationCheckpoint.save(test: str, replicate: int, outcome: Any) → None[source]#

Store draw replicate of test.

Parameters:
teststr

The test.

replicateint

The draw’s index.

outcomeEmpiricalRefitRecord or ReplicationFailure

What the draw returned.

Attributes#

RefutationCheckpoint.directory: str | PathLike[str]#