Skip to content

Cache

Cache helpers from annnet.core._Matrix.

Use G.cache for graph-owned cache helpers. Direct imports from underscore modules follow the internal API policy.

annnet.core._Matrix.CacheManager

Derived sparse-matrix cache (CSR/CSC/adjacency), keyed on the structural clock.

Keys on _structure_version (see _derive.bump_structure), never on _version: that is a history counter which does not advance on removes.

Attributes

csr property
csr

Return the CSR (Compressed Sparse Row) matrix.

Returns:

Type Description
csr_matrix
Notes

Built and cached on first access.

csc property
csc

Return the CSC (Compressed Sparse Column) matrix.

Returns:

Type Description
csc_matrix
Notes

Built and cached on first access.

adjacency property
adjacency

Return the adjacency matrix computed from incidence.

Returns:

Type Description
sparray
Notes

For incidence matrix B, adjacency is computed as A = B @ B.T. Boundary (half) edges — exchange/demand reactions flagged with the is_boundary edge attribute, which carry a single real endpoint and no partner — are dropped from B first, so they contribute neither spurious inter-metabolite links nor self-loop-like diagonal terms.

Functions

has_csr
has_csr()

Check whether a valid CSR cache exists.

Returns:

Type Description
bool
has_csc
has_csc()

Check whether a valid CSC cache exists.

Returns:

Type Description
bool
has_adjacency
has_adjacency()

Check whether a valid adjacency cache exists.

Returns:

Type Description
bool
get_csr
get_csr()

Return the cached CSR matrix.

Returns:

Type Description
csr_matrix
get_csc
get_csc()

Return the cached CSC matrix.

Returns:

Type Description
csc_matrix
get_adjacency
get_adjacency()

Return the cached adjacency matrix.

Returns:

Type Description
sparray
invalidate
invalidate(formats=None)

Invalidate cached formats.

Parameters:

Name Type Description Default
formats list[str]

Formats to invalidate ('csr', 'csc', 'adjacency'). If None, invalidate all.

None

Returns:

Type Description
None
build
build(formats=None)

Pre-build specified formats (eager caching).

Parameters:

Name Type Description Default
formats list[str]

Formats to build ('csr', 'csc', 'adjacency'). If None, build all.

None

Returns:

Type Description
None
clear
clear()

Clear all caches.

Returns:

Type Description
None
info
info()

Get cache status and memory usage.

Returns:

Type Description
dict

Status and size information for each cached format.