biopb.tensor.client¶
biopb.tensor.client ¶
Python client for TensorFlight server.
This module provides a lazy numpy-like array interface using dask.array for accessing tensors stored in a Flight server.
Features: - Lazy chunk loading via dask.array - LRU caching via cachey - Numpy-compatible slicing and operations
ResolveCancelled ¶
Bases: Exception
Raised by :meth:TensorFlightClient.resolve when its should_cancel
callback asks it to stop.
The client stops consuming the resolve stream and unwinds; the server's
recall daemon thread runs to completion and caches its result, so a later
:meth:resolve coalesces onto the finished work rather than re-downloading.
TensorFlightClient ¶
TensorFlightClient(
location: str = "grpc://localhost:8815",
cache_bytes: int = 1000000000,
token: Optional[str] = None,
)
Client for accessing tensors from a TensorFlightServer.
This client provides lazy, cached access to multi-dimensional arrays stored in a Flight server, with support for multifield acquisitions where tensors within a source have different shapes.
Usage
client = TensorFlightClient('grpc://localhost:8815')
List data sources (each may contain multiple tensors)¶
sources = client.list_sources()
Get source-level metadata¶
metadata = client.get_source_metadata('my-source')
Access a tensor by its globally-unique array_id (identity policy):¶
'source_id/field' for a multi-tensor source, or 'source_id' for a¶
single-tensor one. See proto/biopb/tensor/descriptor.proto.¶
arr = client.get_tensor('my-source/tensor-0') # Returns dask.array data = arr[0:100, 0:100].compute() # Load slice
Note
The dask arrays returned by get_tensor() are picklable and work with dask.distributed: each worker fetches chunks over its own connection, so you can scatter an array across a cluster and compute on it.
Initialize the Flight client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
str
|
Flight server location |
'grpc://localhost:8815'
|
cache_bytes
|
int
|
Maximum bytes for chunk cache (default 1GB) |
1000000000
|
token
|
Optional[str]
|
Bearer token for server authentication. |
None
|
Source code in src/main/python/biopb/tensor/client.py
list_sources ¶
List available data sources.
Returns:
| Type | Description |
|---|---|
Dict[str, DataSourceDescriptor]
|
Dictionary mapping source_id to DataSourceDescriptor. |
Dict[str, DataSourceDescriptor]
|
Each DataSourceDescriptor.tensors contains TensorDescriptor info |
Dict[str, DataSourceDescriptor]
|
with shape/dtype for all tensors in that source. |
Note
Results may be truncated if server has max_list_flights_results configured. Check schema metadata for truncation info (truncated=True indicates more sources exist on server than were returned).
Source code in src/main/python/biopb/tensor/client.py
query_sources ¶
Execute SQL query against server's source metadata database.
The server-side metadata database is mandatory (biopb/biopb#225), so any standard tensor-server supports this. Only an embedded server explicitly constructed without a metadata database rejects the query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql
|
str
|
SQL query (e.g., "SELECT source_id, source_type FROM sources WHERE dtype='uint16'") |
required |
format
|
str
|
Shape of the returned result:
|
'arrow'
|
Returns:
| Type | Description |
|---|---|
Any
|
The query result in the requested |
Any
|
returns an empty object of that same type. For |
Any
|
|
Any
|
columns such as |
Any
|
dtype, and nullable integer columns may widen to float). For |
Any
|
|
Any
|
normalized to |
Any
|
would otherwise produce, so |
Any
|
expected. |
Note
The server reports truncation via schema metadata
(total_sources / returned_sources). Those keys survive only
on the "arrow" result; for every format truncation is also
surfaced via a logged INFO line.
Raises:
| Type | Description |
|---|---|
ValueError
|
If format is not one of the supported values. (SQL validation -- forbidden keywords / disallowed tables -- happens server-side and surfaces as a Flight error, below, not a client-side ValueError.) |
ImportError
|
If |
FlightServerError
|
If the server has no metadata database enabled, or rejects the query (e.g. forbidden keywords / disallowed tables). |
Example
client = TensorFlightClient('grpc://localhost:8815') table = client.query_sources("SELECT source_id FROM sources WHERE source_type='ome-zarr'") table.to_pandas() # or pass format="pandas" to get a DataFrame
Source code in src/main/python/biopb/tensor/client.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
get_source_metadata ¶
Get source-level OME/vendor metadata as a dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id
|
str
|
Source identifier |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The source's metadata dict (the format-specific OME/vendor metadata), |
dict
|
or an empty dict if the source carries none. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the source is unknown, or unresolved (cloud /
synced-folder) -- call :meth: |
Source code in src/main/python/biopb/tensor/client.py
get_physical_scale ¶
get_physical_scale(
array_id: Optional[str] = None,
tensor_id: Optional[str] = None,
*,
source_id: Optional[str] = None
) -> Optional[Tuple[List[float], List[str]]]
Per-dimension physical pixel size + unit for a tensor.
Returns (scale, unit): two lists aligned with the tensor's
dim_labels (source axis order), or None when no physical sizes
are known (an older server, or a format that carries none).
physical_scale/physical_unit are TensorDescriptor fields the
server fills on every GetFlightInfo (issue #31), so this reads the
descriptor a prior :meth:get_tensor already cached -- no extra RPC when
it is cached, and it never requests the opt-in metadata_json field on
that same descriptor. (Contrast :meth:get_source_metadata, which forces
with_metadata to ship the whole OME tree; do not dig physical sizes
out of that -- this is the compact projection meant for display scale.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array_id
|
Optional[str]
|
Globally-unique tensor id (identity policy) -- e.g.
|
None
|
tensor_id
|
Optional[str]
|
DEPRECATED. The legacy |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Tuple[List[float], List[str]]]
|
|
Source code in src/main/python/biopb/tensor/client.py
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 | |
get_descriptor ¶
Fetch one tensor's TensorDescriptor by its globally-unique array_id.
A tensor is identified by its array_id alone (see the tensor identity
policy at the top of proto/biopb/tensor/descriptor.proto), so this
takes that one identifier rather than a (source_id, tensor_id) pair.
Works even when the source is beyond the (truncatable) list_sources()
cap, and the result is cached. Passing a bare source_id (single-tensor
source, or to anchor on a multi-tensor source's default/first tensor) is
accepted. To enumerate ALL tensors/scenes of a source, use
list_sources()[source_id].tensors -- NOT this method.
This is a cheap probe -- it does NOT resolve. On an unresolved (cloud /
synced-folder) source it raises an error pointing at :meth:resolve,
never triggering a download. Call :meth:resolve first to read such a
source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array_id
|
str
|
Globally-unique tensor id, e.g. |
required |
Returns:
| Type | Description |
|---|---|
TensorDescriptor
|
The |
Source code in src/main/python/biopb/tensor/client.py
resolve ¶
resolve(
source_id: str,
*,
on_progress: Optional[
Callable[[ResolveProgress], None]
] = None,
should_cancel: Optional[Callable[[], bool]] = None
) -> DataSourceDescriptor
Resolve an unresolved source and return its full DataSourceDescriptor.
.. note:: Experimental. Cloud / remote source support (unresolved sources,
resolve, and :meth:warm) is experimental and its behavior may change.
An unresolved source is catalogued by URL only -- its shape/dtype/field
list are unknown until first access (it lists with data_resident False
and an empty list_sources()[source_id].tensors). The canonical case is
a cloud / synced-folder ("Files-On-Demand") source.
Resolving asks the server to hydrate it. For a dehydrated placeholder this
downloads the whole file -- a recall that can take minutes, consume
local disk, and fail when offline -- then reads its real shape, dtype, and
field list. This is the heavyweight, consenting operation that catalog
browsing (:meth:list_sources / :meth:query_sources) deliberately
avoids; call it only when you intend to read the data. After it returns,
:meth:get_tensor and friends work normally.
Idempotent: resolving an already-resolved source just re-fetches it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id
|
str
|
The source to resolve (e.g. |
required |
on_progress
|
Optional[Callable[[ResolveProgress], None]]
|
Optional callback invoked with a |
None
|
should_cancel
|
Optional[Callable[[], bool]]
|
Optional predicate polled on each heartbeat; when it
returns True the client stops consuming the stream and raises
:class: |
None
|
Returns:
| Type | Description |
|---|---|
DataSourceDescriptor
|
The full |
DataSourceDescriptor
|
-- the complete field set in one call, regardless of catalog size. |
Raises:
| Type | Description |
|---|---|
ResolveCancelled
|
if |
Source code in src/main/python/biopb/tensor/client.py
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 | |
warm ¶
warm(
source_id: str,
*,
on_progress: Optional[
Callable[[WarmProgress], None]
] = None,
should_cancel: Optional[Callable[[], bool]] = None
) -> WarmProgress
Hydrate-ahead: recall a resolved source's member files on the server.
.. note:: Experimental. Cloud / remote source support (:meth:resolve and
this hydrate-ahead path) is experimental and its behavior may change.
:meth:resolve populates a source's metadata but, for a multi-file
cloud source (zarr / ome-zarr / ndtiff / tiff-sequence / micromanager),
leaves the bulk pixel data dehydrated -- each member file then recalls
one-at-a-time, slowly, the first time a read touches it (the viewer
scrubbing planes is the worst case). warm opts into pulling them all
resident up front so later reads never stall.
The recall happens entirely server-side (the server walks the source
directory and reads each file to force the sync engine's recall); no
pixels cross the wire, only progress. It is idempotent -- already-resident
files are cheap local reads -- so a warm re-run after a cancel simply
finishes the remainder. Only meaningful for multi-file sources; a
single-file source returns immediately (resolve already recalled it).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id
|
str
|
The (already-resolved) source to warm. |
required |
on_progress
|
Optional[Callable[[WarmProgress], None]]
|
Optional callback invoked with a |
None
|
should_cancel
|
Optional[Callable[[], bool]]
|
Optional predicate polled per message; when it returns
True the client closes the stream -- which the server observes and
stops the recall promptly -- and this raises
:class: |
None
|
Returns:
| Type | Description |
|---|---|
WarmProgress
|
The terminal |
WarmProgress
|
|
WarmProgress
|
|
Raises:
| Type | Description |
|---|---|
ResolveCancelled
|
if |
RuntimeError
|
if the server predates the |
Source code in src/main/python/biopb/tensor/client.py
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 | |
add_source ¶
add_source(
url: str,
*,
source_type: str = "",
dim_labels: Optional[List[str]] = None,
on_progress: Optional[
Callable[[AddSourceProgress], None]
] = None,
should_cancel: Optional[Callable[[], bool]] = None
) -> AddSourceResult
Register a local path on the SERVER as a served source at runtime.
This is the wire entrypoint behind the tensor-browser's drag-drop: it hands the server a filesystem path (or directory) that it interprets on its own filesystem, and the server routes it through the same claim -> adapter -> catalog pipeline the directory watcher uses. A dropped directory that is not itself a dataset is walked recursively and may register several sources, so the action streams progress and a final tally rather than returning a single descriptor.
The path must exist on the server. Because a dropped directory's walk has no known size up front, there is no percentage -- progress is a running count of sources registered so far.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Absolute path (or directory) on the server's filesystem. |
required |
source_type
|
str
|
Explicit adapter type (e.g. |
''
|
dim_labels
|
Optional[List[str]]
|
Optional dimension labels for the registered tensor(s). |
None
|
on_progress
|
Optional[Callable[[AddSourceProgress], None]]
|
Optional callback invoked with an |
None
|
should_cancel
|
Optional[Callable[[], bool]]
|
Optional predicate polled per message; when it returns True the client closes the stream, which the server observes and stops discovery -- sources already registered stay registered. |
None
|
Returns:
| Type | Description |
|---|---|
AddSourceResult
|
The terminal |
AddSourceResult
|
|
AddSourceResult
|
A directory dropped above the large-scan threshold comes back as a |
AddSourceResult
|
|
Raises:
| Type | Description |
|---|---|
FlightServerError
|
whole-request failure (path not found / unreadable on the server, or the server declines the request). |
RuntimeError
|
the server predates the |
Source code in src/main/python/biopb/tensor/client.py
1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 | |
remove_source ¶
Deregister a drag-dropped source branch on the SERVER at runtime.
The narrow counterpart to :meth:add_source: it removes ONLY
drag-dropped sources, which the server identifies by the dnd://
origin scheme on their catalog source_url. root_url is such a
branch root (a dnd://... value); every source at or under it is
removed as a unit. A non-dnd:// root_url is refused by the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_url
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
RemoveSourceResult
|
A |
RemoveSourceResult
|
( |
Raises:
| Type | Description |
|---|---|
FlightServerError
|
the server refused the request (e.g. a
non- |
RuntimeError
|
the server predates the |
Source code in src/main/python/biopb/tensor/client.py
get_source ¶
DEPRECATED -- use :meth:get_descriptor (one tensor) or
:meth:list_sources (all tensors of a source) instead.
This method is inconsistent with the tensor identity policy
(proto/biopb/tensor/descriptor.proto): it splits a tensor's identity
into a (source_id, tensor_id) pair, whereas a tensor is identified by
its globally-unique array_id alone. It is also misnamed -- despite
returning a DataSourceDescriptor, it is a single-tensor probe: the
returned .tensors holds ONLY the resolved tensor (or the source's
default/first tensor when tensor_id is None), never the full scene
list. For a multi-scene source, get_source(id).tensors is length-1
and scenes 2..N are NOT enumerated here. Use
list_sources()[id].tensors for the complete enumeration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id
|
str
|
Data source identifier. |
required |
tensor_id
|
Optional[str]
|
Optional tensor to anchor the lookup; None -> the source's default (first) tensor. |
None
|
Returns:
| Type | Description |
|---|---|
DataSourceDescriptor
|
DataSourceDescriptor wrapping the single resolved TensorDescriptor. |
Source code in src/main/python/biopb/tensor/client.py
get_tensor ¶
get_tensor(
array_id: Optional[str] = None,
tensor_id: Optional[str] = None,
slice_hint: Optional[Tuple[slice, ...]] = None,
scale_hint: Optional[Sequence[int]] = None,
reduction_method: Optional[str] = None,
*,
source_id: Optional[str] = None
) -> da.Array
Get a lazy dask array for a tensor, addressed by its array_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array_id
|
Optional[str]
|
Globally-unique tensor id (identity policy) -- e.g.
|
None
|
tensor_id
|
Optional[str]
|
DEPRECATED. The legacy |
None
|
slice_hint
|
Optional[Tuple[slice, ...]]
|
Optional slice tuple to filter chunks |
None
|
scale_hint
|
Optional[Sequence[int]]
|
Optional per-dimension integer downsampling factors |
None
|
reduction_method
|
Optional[str]
|
Optional dynamic reduction method for scaled reads |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
dask.array with lazy chunk loading |
Raises:
| Type | Description |
|---|---|
ValueError
|
If source not found, tensor not found, or a bare multi-tensor source id is given without a within-source field |
Source code in src/main/python/biopb/tensor/client.py
2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 | |
get_tensor_pb ¶
get_tensor_pb(
array_id: Optional[str] = None,
tensor_id: Optional[str] = None,
slice_hint: Optional[Tuple[slice, ...]] = None,
scale_hint: Optional[Sequence[int]] = None,
reduction_method: Optional[str] = None,
*,
source_id: Optional[str] = None
) -> SerializedTensor
Get a SerializedTensor protobuf for cross-process transfer.
Returns a protobuf containing connection info and chunk tickets for lazy reconstruction. The protobuf can be serialized to bytes and broadcast to worker processes, where each worker can call tensor_from_pb() to reconstruct a lazy dask array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array_id
|
Optional[str]
|
Globally-unique tensor id (identity policy) -- e.g.
|
None
|
tensor_id
|
Optional[str]
|
DEPRECATED. The legacy |
None
|
slice_hint
|
Optional[Tuple[slice, ...]]
|
Optional slice tuple to filter chunks |
None
|
scale_hint
|
Optional[Sequence[int]]
|
Optional per-dimension integer downsampling factors |
None
|
reduction_method
|
Optional[str]
|
Optional dynamic reduction method for scaled reads |
None
|
Returns:
| Type | Description |
|---|---|
SerializedTensor
|
SerializedTensor protobuf object |
Source code in src/main/python/biopb/tensor/client.py
2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 | |
tensor_from_pb
staticmethod
¶
Reconstruct a lazy dask array from SerializedTensor protobuf.
Creates a dask array that fetches chunks from the Flight server independently. Each worker process maintains its own connection pool and LRU cache keyed by (location, auth_token).
If endpoints field is empty, calls GetFlightInfo on the server to rebuild the endpoint list.
If debug_pickled_array is populated, unpickles directly (bypasses server).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb
|
SerializedTensor
|
SerializedTensor protobuf object |
required |
cache_bytes
|
int
|
Maximum bytes for chunk cache (default 1GB). Only effective for the first tensor created in a process for a given (location, auth_token) pair. |
1000000000
|
Returns:
| Type | Description |
|---|---|
Array
|
dask.array with lazy chunk loading |
Source code in src/main/python/biopb/tensor/client.py
2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 | |
upload_array ¶
upload_array(
arr: Array,
source_name: str,
chunk_shape: Optional[Sequence[int]] = None,
dim_labels: Optional[Sequence[str]] = None,
ome_metadata: Optional[dict] = None,
) -> str
Upload dask array to server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Array
|
Dask array to upload |
required |
source_name
|
str
|
Source identifier format: - "cache:my-name" → cache-backed (ephemeral) - "cache:" → cache-backed with server-generated name - "ome_zarr:my-name" → zarr-backed (persistent) - "ome_zarr:" → zarr-backed with server-generated name |
required |
chunk_shape
|
Optional[Sequence[int]]
|
Override chunk shape. If None, uses arr.chunksize with automatic rechunking if chunks are non-uniform. |
None
|
dim_labels
|
Optional[Sequence[str]]
|
Optional dimension labels |
None
|
ome_metadata
|
Optional[dict]
|
Optional OME metadata dict |
None
|
Returns:
| Type | Description |
|---|---|
str
|
source_id of created source (e.g., "cache_abc123" or "ome_zarr_def456") |
Source code in src/main/python/biopb/tensor/client.py
2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 | |
upload_zarr ¶
upload_zarr(
zarr_path: str,
source_name: str,
chunk_shape: Optional[Sequence[int]] = None,
dim_labels: Optional[Sequence[str]] = None,
ome_metadata: Optional[dict] = None,
) -> str
Upload local zarr to server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zarr_path
|
str
|
Path to local zarr directory |
required |
source_name
|
str
|
Source identifier format: - "cache:my-name" → cache-backed (ephemeral) - "cache:" → cache-backed with server-generated name - "ome_zarr:my-name" → zarr-backed (persistent) - "ome_zarr:" → zarr-backed with server-generated name |
required |
chunk_shape
|
Optional[Sequence[int]]
|
Override chunk shape. If None, uses zarr's chunk shape. |
None
|
dim_labels
|
Optional[Sequence[str]]
|
Optional dimension labels (read from zarr if not provided) |
None
|
ome_metadata
|
Optional[dict]
|
Optional OME metadata (read from zarr if not provided) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
source_id of created source (e.g., "cache_abc123" or "ome_zarr_def456") |
Source code in src/main/python/biopb/tensor/client.py
create_source ¶
create_source(
source_name: str,
shape: Sequence[int],
dtype: str,
chunk_shape: Sequence[int],
dim_labels: Optional[Sequence[str]] = None,
ome_metadata: Optional[dict] = None,
) -> str
Create source on server (internal).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_name
|
str
|
"cache:name" → cache-backed; "ome_zarr:name" → zarr-backed "cache:" or "ome_zarr:" → server-generated name |
required |
shape
|
Sequence[int]
|
Array shape |
required |
dtype
|
str
|
Data type string (numpy format) |
required |
chunk_shape
|
Sequence[int]
|
Chunk size per dimension |
required |
dim_labels
|
Optional[Sequence[str]]
|
Optional dimension labels |
None
|
ome_metadata
|
Optional[dict]
|
Optional OME metadata dict |
None
|
Returns:
| Type | Description |
|---|---|
str
|
source_id assigned by server |
Source code in src/main/python/biopb/tensor/client.py
upload_chunk ¶
Upload single chunk (internal).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id
|
str
|
Source identifier |
required |
bounds
|
ChunkBounds
|
Chunk start/stop coordinates |
required |
data
|
ndarray
|
Numpy array with chunk data |
required |
Source code in src/main/python/biopb/tensor/client.py
close ¶
health_check ¶
Check server health status via Flight action.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with health status information: |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
FlightError
|
If server is unreachable or action fails |
Source code in src/main/python/biopb/tensor/client.py
cache_stats ¶
Fetch server-side cache statistics via Flight action.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary of CacheStats fields: total_entries, total_bytes, |
Dict[str, Any]
|
max_entries, max_bytes, hits, misses, evictions, pending_waits, |
Dict[str, Any]
|
ref_held_evictions_skipped, oversized_skips, and (file backend) |
Dict[str, Any]
|
per-pool stats under "pool_stats". |
Raises:
| Type | Description |
|---|---|
FlightError
|
If server is unreachable or action fails |
Source code in src/main/python/biopb/tensor/client.py
get_upload_status ¶
Get upload status for a writable source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id
|
str
|
Source identifier returned by create_source() |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with source_id, state, expected_chunks, and uploaded_chunks. |
Source code in src/main/python/biopb/tensor/client.py
get_upload_status_pb ¶
Get upload status for a registration-first SerializedTensor handle.
This helper is intended for cache-backed handles returned before upload completion, where tensor_descriptor.array_id is the source identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pb
|
SerializedTensor
|
SerializedTensor handle returned by a registration-first flow. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with source_id, state, expected_chunks, and uploaded_chunks. |
Source code in src/main/python/biopb/tensor/client.py
wait_for_upload_ready ¶
wait_for_upload_ready(
source_id: str,
timeout_seconds: float = 60.0,
poll_interval_seconds: float = 0.5,
) -> Dict[str, Any]
Poll upload status until the source reports READY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id
|
str
|
Source identifier returned by create_source(). |
required |
timeout_seconds
|
float
|
Maximum time to wait before timing out. |
60.0
|
poll_interval_seconds
|
float
|
Delay between status checks. |
0.5
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Final upload status dictionary when READY. |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the upload does not reach READY within the timeout. |
RuntimeError
|
If the upload reports FAILED. |
Source code in src/main/python/biopb/tensor/client.py
wait_for_upload_ready_pb ¶
wait_for_upload_ready_pb(
pb: SerializedTensor,
timeout_seconds: float = 60.0,
poll_interval_seconds: float = 0.5,
) -> Dict[str, Any]
Poll upload status until a registration-first SerializedTensor is READY.
Source code in src/main/python/biopb/tensor/client.py
cache_info ¶
Return cache statistics from the pooled cache for this connection.
Returns:
| Type | Description |
|---|---|
Dict
|
Dictionary with cache size and item count |
Source code in src/main/python/biopb/tensor/client.py
cache_clear ¶
Clear the pooled cache for this connection namespace.
Source code in src/main/python/biopb/tensor/client.py
configure_cache ¶
Pin this process's chunk-cache budget for a connection, authoritatively.
Sets the per-process chunk cache to cache_bytes and keeps it there: every
later fetch honors this budget regardless of the cache_bytes it requests.
Idempotent. Call it once per worker process (e.g. from a dask worker-init
plugin) to fix the budget deterministically across a dynamically-sized
cluster.
A localhost server (the default) or cache_bytes <= 0 pins the cache OFF;
later fetches then skip caching rather than recreating one of their own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
str
|
Flight server location string |
required |
token
|
Optional[str]
|
Bearer token (or None for no auth) |
required |
cache_bytes
|
int
|
Requested per-process cache size in bytes |
required |
Returns:
| Type | Description |
|---|---|
int
|
The effective (resolved) cache size that was pinned, in bytes. |
Source code in src/main/python/biopb/tensor/client.py
make_debug_serialized_tensor ¶
Create a SerializedTensor with debug_pickled_array for testing.
Eagerly computes the array and pickles it, bypassing Flight server. Preserves original chunk structure for testing chunk-related behavior. Populates inferable tensor_descriptor fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Array
|
Dask array to serialize |
required |
array_id
|
str
|
Optional array identifier |
'debug'
|
Returns:
| Type | Description |
|---|---|
SerializedTensor
|
SerializedTensor with debug_pickled_array populated |