scihist 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
scihist/__init__.py ADDED
@@ -0,0 +1,68 @@
1
+ """SciHist: Lineage-tracked batch execution for scientific data pipelines.
2
+
3
+ This package adds lineage tracking on top of scidb. It provides the same
4
+ for_each() interface as scidb, but automatically wraps functions in
5
+ LineageFcn for provenance recording.
6
+
7
+ Example:
8
+ from scihist import for_each, Fixed, configure_database
9
+ from scilineage import lineage_fcn
10
+
11
+ configure_database("experiment.duckdb", ["subject", "session"])
12
+
13
+ @lineage_fcn
14
+ def process_data(raw, calibration):
15
+ return raw * calibration
16
+
17
+ for_each(
18
+ process_data,
19
+ inputs={"raw": RawData, "calibration": Fixed(Calibration, session="baseline")},
20
+ outputs=[ProcessedData],
21
+ subject=[1, 2, 3],
22
+ session=["A", "B", "C"],
23
+ )
24
+ """
25
+
26
+ from .foreach import for_each, save
27
+ from .database import configure_database, find_by_lineage
28
+ from .state import check_combo_state, check_node_state, check_multiple_nodes_state
29
+
30
+ # Re-export DB wrappers from scidb
31
+ from scidb import Fixed, Merge, ColumnSelection, ForEachConfig
32
+
33
+ # Re-export scifor helpers
34
+ from scifor import Col, set_schema, get_schema, PathInput
35
+
36
+ # Re-export scilineage system
37
+ from scilineage import lineage_fcn, LineageFcn, LineageFcnResult, LineageFcnInvocation
38
+
39
+ __version__ = "0.1.0"
40
+
41
+ __all__ = [
42
+ # Core batch execution
43
+ "for_each",
44
+ "save",
45
+ # Configuration
46
+ "configure_database",
47
+ # Lineage query
48
+ "find_by_lineage",
49
+ # Node staleness
50
+ "check_combo_state",
51
+ "check_node_state",
52
+ "check_multiple_nodes_state",
53
+ # DB wrappers
54
+ "Fixed",
55
+ "Merge",
56
+ "ColumnSelection",
57
+ "ForEachConfig",
58
+ "PathInput",
59
+ # Schema helpers
60
+ "Col",
61
+ "set_schema",
62
+ "get_schema",
63
+ # Lineage system
64
+ "lineage_fcn",
65
+ "LineageFcn",
66
+ "LineageFcnResult",
67
+ "LineageFcnInvocation",
68
+ ]
scihist/database.py ADDED
@@ -0,0 +1,51 @@
1
+ """SciHist database configuration — wraps scidb.configure_database with cache backend registration."""
2
+
3
+ from typing import Any
4
+
5
+
6
+ def configure_database(
7
+ db_path: str,
8
+ schema_keys: list[str] | None = None,
9
+ **kwargs,
10
+ ) -> Any:
11
+ """Configure the active database and register it as the lineage cache backend.
12
+
13
+ This is the scihist wrapper around scidb.configure_database(). In addition
14
+ to opening the DuckDB-backed database, it registers the database as the
15
+ cache backend so that lineage-tracked computations can look up previously
16
+ computed results.
17
+
18
+ Args:
19
+ db_path: Path to the DuckDB database file.
20
+ schema_keys: List of metadata keys that form the dataset schema.
21
+ **kwargs: Additional keyword arguments forwarded to scidb.configure_database().
22
+
23
+ Returns:
24
+ The configured DatabaseManager instance.
25
+ """
26
+ from scidb import configure_database as _scidb_configure
27
+ from scilineage import configure_backend
28
+
29
+ db = _scidb_configure(db_path, schema_keys, **kwargs)
30
+ configure_backend(db)
31
+ return db
32
+
33
+
34
+ def find_by_lineage(invocation) -> list | None:
35
+ """Find output values by computation lineage.
36
+
37
+ Given a LineageFcnInvocation (function + inputs), finds any previously
38
+ computed outputs that match by querying the _lineage table via the active
39
+ database.
40
+
41
+ Args:
42
+ invocation: The LineageFcnInvocation computation to look up.
43
+
44
+ Returns:
45
+ List of output values if found, None otherwise.
46
+ """
47
+ from scidb.database import get_database
48
+
49
+ db = get_database()
50
+ lineage_hash = invocation.compute_lineage_hash()
51
+ return db.find_by_lineage_hash(lineage_hash)