scitex 2.16.2__py3-none-any.whl → 2.17.3__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.
Files changed (70) hide show
  1. scitex/_dev/__init__.py +122 -0
  2. scitex/_dev/_config.py +391 -0
  3. scitex/_dev/_dashboard/__init__.py +11 -0
  4. scitex/_dev/_dashboard/_app.py +89 -0
  5. scitex/_dev/_dashboard/_routes.py +169 -0
  6. scitex/_dev/_dashboard/_scripts.py +301 -0
  7. scitex/_dev/_dashboard/_styles.py +205 -0
  8. scitex/_dev/_dashboard/_templates.py +117 -0
  9. scitex/_dev/_dashboard/static/version-dashboard-favicon.svg +12 -0
  10. scitex/_dev/_ecosystem.py +109 -0
  11. scitex/_dev/_github.py +360 -0
  12. scitex/_dev/_mcp/__init__.py +11 -0
  13. scitex/_dev/_mcp/handlers.py +182 -0
  14. scitex/_dev/_ssh.py +332 -0
  15. scitex/_dev/_versions.py +272 -0
  16. scitex/_mcp_resources/_cheatsheet.py +1 -1
  17. scitex/_mcp_resources/_modules.py +1 -1
  18. scitex/_mcp_tools/__init__.py +4 -0
  19. scitex/_mcp_tools/dev.py +186 -0
  20. scitex/_mcp_tools/verify.py +256 -0
  21. scitex/audio/_audio_check.py +84 -41
  22. scitex/cli/capture.py +45 -22
  23. scitex/cli/dev.py +494 -0
  24. scitex/cli/main.py +4 -0
  25. scitex/cli/stats.py +48 -20
  26. scitex/cli/verify.py +473 -0
  27. scitex/dev/plt/__init__.py +1 -1
  28. scitex/dev/plt/mpl/get_dir_ax.py +1 -1
  29. scitex/dev/plt/mpl/get_signatures.py +1 -1
  30. scitex/dev/plt/mpl/get_signatures_details.py +1 -1
  31. scitex/io/_load.py +8 -1
  32. scitex/io/_save.py +12 -0
  33. scitex/plt/__init__.py +16 -6
  34. scitex/session/README.md +2 -2
  35. scitex/session/__init__.py +1 -0
  36. scitex/session/_decorator.py +57 -33
  37. scitex/session/_lifecycle/__init__.py +23 -0
  38. scitex/session/_lifecycle/_close.py +225 -0
  39. scitex/session/_lifecycle/_config.py +112 -0
  40. scitex/session/_lifecycle/_matplotlib.py +83 -0
  41. scitex/session/_lifecycle/_start.py +246 -0
  42. scitex/session/_lifecycle/_utils.py +186 -0
  43. scitex/session/_manager.py +40 -3
  44. scitex/session/template.py +1 -1
  45. scitex/template/__init__.py +18 -1
  46. scitex/template/_templates/plt.py +1 -1
  47. scitex/template/_templates/session.py +1 -1
  48. scitex/template/clone_research_minimal.py +111 -0
  49. scitex/verify/README.md +300 -0
  50. scitex/verify/__init__.py +208 -0
  51. scitex/verify/_chain.py +369 -0
  52. scitex/verify/_db.py +600 -0
  53. scitex/verify/_hash.py +187 -0
  54. scitex/verify/_integration.py +127 -0
  55. scitex/verify/_rerun.py +253 -0
  56. scitex/verify/_tracker.py +330 -0
  57. scitex/verify/_visualize.py +44 -0
  58. scitex/verify/_viz/__init__.py +38 -0
  59. scitex/verify/_viz/_colors.py +84 -0
  60. scitex/verify/_viz/_format.py +302 -0
  61. scitex/verify/_viz/_json.py +192 -0
  62. scitex/verify/_viz/_mermaid.py +440 -0
  63. scitex/verify/_viz/_templates.py +246 -0
  64. scitex/verify/_viz/_utils.py +56 -0
  65. {scitex-2.16.2.dist-info → scitex-2.17.3.dist-info}/METADATA +2 -1
  66. {scitex-2.16.2.dist-info → scitex-2.17.3.dist-info}/RECORD +69 -28
  67. scitex/session/_lifecycle.py +0 -827
  68. {scitex-2.16.2.dist-info → scitex-2.17.3.dist-info}/WHEEL +0 -0
  69. {scitex-2.16.2.dist-info → scitex-2.17.3.dist-info}/entry_points.txt +0 -0
  70. {scitex-2.16.2.dist-info → scitex-2.17.3.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,300 @@
1
+ <!-- ---
2
+ !-- Timestamp: 2026-02-01 08:47:14
3
+ !-- Author: ywatanabe
4
+ !-- File: /home/ywatanabe/proj/scitex-python/src/scitex/verify/README.md
5
+ !-- --- -->
6
+
7
+ # scitex.verify Module
8
+
9
+ Hash-based verification system for reproducible scientific computations.
10
+
11
+ ## Overview
12
+
13
+ The verify module provides cryptographic tracking of scientific pipelines, enabling researchers to:
14
+ - **Detect changes** in input/output files
15
+ - **Trace dependencies** through processing chains
16
+ - **Verify reproducibility** by re-executing scripts
17
+ - **Visualize workflows** as directed acyclic graphs (DAGs)
18
+
19
+ ![Verification DAG](dag.png)
20
+
21
+ *Example DAG showing verification states: ✓ verified (green), ✗ failed (red)*
22
+
23
+ ## Architecture
24
+
25
+ ```
26
+ scitex/verify/
27
+ ├── __init__.py # Public API and convenience functions
28
+ ├── _hash.py # SHA256 hashing utilities
29
+ ├── _db.py # SQLite database for storing hashes
30
+ ├── _tracker.py # Session tracking integration
31
+ ├── _chain.py # Chain verification logic
32
+ ├── _rerun.py # Re-execution verification
33
+ ├── _integration.py # Hooks for stx.io and @stx.session
34
+ ├── _visualize.py # Re-exports from _viz/
35
+ └── _viz/
36
+ ├── _mermaid.py # Mermaid DAG generation
37
+ ├── _json.py # JSON DAG export
38
+ ├── _format.py # Terminal output formatting
39
+ ├── _colors.py # Color constants
40
+ ├── _templates.py # HTML templates
41
+ └── _utils.py # Shared utilities
42
+ ```
43
+
44
+ ## Core Components
45
+
46
+ ### Hash Utilities (`_hash.py`)
47
+
48
+ ```python
49
+ from scitex.verify import hash_file, hash_files, hash_directory
50
+
51
+ # Single file
52
+ h = hash_file("data.csv") # SHA256 hex string
53
+
54
+ # Multiple files
55
+ hashes = hash_files(["a.csv", "b.csv"]) # {path: hash}
56
+
57
+ # Directory (recursive)
58
+ h = hash_directory("output/") # Combined hash of all files
59
+ ```
60
+
61
+ ### Database (`_db.py`)
62
+
63
+ SQLite-based storage for verification records:
64
+
65
+ ```python
66
+ from scitex.verify import get_db
67
+
68
+ db = get_db() # ~/.scitex/verify.db by default
69
+
70
+ # Record a run
71
+ db.record_run(
72
+ session_id="abc123",
73
+ script_path="/path/to/script.py",
74
+ script_hash="sha256...",
75
+ config_hash="sha256...",
76
+ status="success"
77
+ )
78
+
79
+ # Record file hashes
80
+ db.record_file_hash(
81
+ session_id="abc123",
82
+ file_path="/path/to/output.csv",
83
+ file_hash="sha256...",
84
+ role="output" # or "input"
85
+ )
86
+
87
+ # Query runs
88
+ runs = db.list_runs(limit=10, status="success")
89
+ chain = db.get_chain("abc123") # Parent session IDs
90
+ ```
91
+
92
+ ### Session Tracker (`_tracker.py`)
93
+
94
+ Integrates with `@stx.session`:
95
+
96
+ ```python
97
+ from scitex.verify import SessionTracker, start_tracking, stop_tracking
98
+
99
+ # Manual tracking (usually automatic via @stx.session)
100
+ tracker = start_tracking(session_id="abc123")
101
+ tracker.add_input("/path/to/input.csv")
102
+ tracker.add_output("/path/to/output.csv")
103
+ stop_tracking()
104
+ ```
105
+
106
+ ### Chain Verification (`_chain.py`)
107
+
108
+ ```python
109
+ from scitex.verify import verify_file, verify_run, verify_chain
110
+
111
+ # Verify single file
112
+ file_result = verify_file("/path/to/output.csv")
113
+ print(file_result.is_verified) # True if hash matches
114
+
115
+ # Verify session run
116
+ run_result = verify_run("abc123")
117
+ print(run_result.is_verified) # True if all files match
118
+ print(run_result.mismatched_files) # List of changed files
119
+
120
+ # Verify entire chain
121
+ chain_result = verify_chain("/path/to/final_output.csv")
122
+ print(chain_result.is_verified) # True if all runs verified
123
+ print(chain_result.chain_length) # Number of runs in chain
124
+ for run in chain_result.runs:
125
+ print(f"{run.session_id}: {run.status}")
126
+ ```
127
+
128
+ ### Verification Levels
129
+
130
+ ```python
131
+ from scitex.verify import VerificationLevel, VerificationStatus
132
+
133
+ # Levels
134
+ VerificationLevel.CACHE # Fast hash comparison (✓)
135
+ VerificationLevel.RERUN # Re-execution verification (✓✓)
136
+
137
+ # Statuses
138
+ VerificationStatus.VERIFIED
139
+ VerificationStatus.UNVERIFIED
140
+ VerificationStatus.FAILED
141
+ VerificationStatus.UNKNOWN
142
+ ```
143
+
144
+ ### Re-execution Verification (`_rerun.py`)
145
+
146
+ ```python
147
+ from scitex.verify import verify_by_rerun
148
+
149
+ # Re-run script and verify outputs match
150
+ result = verify_by_rerun("/path/to/output.csv")
151
+ print(result.is_verified) # True if re-execution produces same hashes
152
+ print(result.level) # VerificationLevel.RERUN
153
+ ```
154
+
155
+ ## Visualization (`_visualize.py`)
156
+
157
+ ### Terminal Output
158
+
159
+ ```python
160
+ from scitex.verify import format_status, format_chain_verification
161
+
162
+ # Git status-like output
163
+ print(format_status())
164
+
165
+ # Chain visualization
166
+ chain = verify_chain("output.csv")
167
+ print(format_chain_verification(chain))
168
+ ```
169
+
170
+ ### Mermaid DAG
171
+
172
+ ```python
173
+ from scitex.verify import generate_mermaid_dag
174
+
175
+ mermaid = generate_mermaid_dag(target_file="output.csv")
176
+ # Returns:
177
+ # graph TD
178
+ # script_0["✓ 🐍 analyze.py"]:::verified
179
+ # file_0[("✓ 📊 output.csv")]:::file_ok
180
+ # script_0 --> file_0
181
+ # classDef verified fill:#90EE90...
182
+ ```
183
+
184
+ ### HTML/PNG/SVG Export
185
+
186
+ ```python
187
+ from scitex.verify import render_dag
188
+
189
+ # Interactive HTML
190
+ render_dag("dag.html", target_file="output.csv", show_hashes=True)
191
+
192
+ # Static images (requires mmdc)
193
+ render_dag("dag.png", target_file="output.csv")
194
+ render_dag("dag.svg", target_file="output.csv")
195
+
196
+ # Raw formats
197
+ render_dag("dag.mmd", target_file="output.csv") # Mermaid code
198
+ render_dag("dag.json", target_file="output.csv") # Graph structure
199
+ ```
200
+
201
+ ## Integration Hooks (`_integration.py`)
202
+
203
+ Automatically called by `@stx.session` and `stx.io`:
204
+
205
+ ```python
206
+ from scitex.verify import on_session_start, on_session_close, on_io_load, on_io_save
207
+
208
+ # Session lifecycle
209
+ on_session_start(session_id, script_path, config_hash)
210
+ on_session_close(session_id, status="success")
211
+
212
+ # I/O tracking
213
+ on_io_load(file_path) # Records as input
214
+ on_io_save(file_path) # Records as output
215
+ ```
216
+
217
+ ## CLI Commands
218
+
219
+ ```bash
220
+ # List runs
221
+ scitex verify list [--limit N] [--status success|failed]
222
+
223
+ # Check status
224
+ scitex verify status
225
+
226
+ # Verify specific run
227
+ scitex verify run SESSION_ID [--from-scratch]
228
+
229
+ # Trace dependencies
230
+ scitex verify chain FILE_PATH
231
+
232
+ # Database stats
233
+ scitex verify stats
234
+ ```
235
+
236
+ ## MCP Tools
237
+
238
+ Available via MCP protocol:
239
+
240
+ | Tool | Description |
241
+ |------|-------------|
242
+ | `verify_list` | List tracked runs |
243
+ | `verify_run` | Verify specific run |
244
+ | `verify_chain` | Trace dependencies |
245
+ | `verify_status` | Show changed items |
246
+ | `verify_stats` | Database statistics |
247
+ | `verify_mermaid` | Generate Mermaid DAG |
248
+
249
+ ## Database Schema
250
+
251
+ ```sql
252
+ -- Runs table
253
+ CREATE TABLE runs (
254
+ session_id TEXT PRIMARY KEY,
255
+ script_path TEXT,
256
+ script_hash TEXT,
257
+ config_hash TEXT,
258
+ status TEXT,
259
+ started_at TIMESTAMP,
260
+ ended_at TIMESTAMP
261
+ );
262
+
263
+ -- File hashes table
264
+ CREATE TABLE file_hashes (
265
+ id INTEGER PRIMARY KEY,
266
+ session_id TEXT,
267
+ file_path TEXT,
268
+ file_hash TEXT,
269
+ role TEXT, -- 'input' or 'output'
270
+ recorded_at TIMESTAMP,
271
+ FOREIGN KEY (session_id) REFERENCES runs(session_id)
272
+ );
273
+
274
+ -- Verification records table
275
+ CREATE TABLE verifications (
276
+ id INTEGER PRIMARY KEY,
277
+ session_id TEXT,
278
+ level TEXT, -- 'cache' or 'rerun'
279
+ status TEXT, -- 'verified', 'failed'
280
+ verified_at TIMESTAMP,
281
+ FOREIGN KEY (session_id) REFERENCES runs(session_id)
282
+ );
283
+ ```
284
+
285
+ ## Examples
286
+
287
+ See `examples/scitex/verify/` for complete working examples:
288
+
289
+ - `00_run_all.sh` - Run complete pipeline
290
+ - `01-08` - Multi-branch processing pipeline
291
+ - `09_demo_verification.py` - Verification states demo
292
+ - `10_programmatic_verification.py` - API usage examples
293
+
294
+ ## See Also
295
+
296
+ - `examples/scitex/verify/README.md` - Usage examples with DAG visualization
297
+ - `@stx.session` decorator - Automatic session tracking
298
+ - `stx.io` module - File I/O with hash tracking
299
+
300
+ <!-- EOF -->
@@ -0,0 +1,208 @@
1
+ #!/usr/bin/env python3
2
+ # Timestamp: "2026-02-01 (ywatanabe)"
3
+ # File: /home/ywatanabe/proj/scitex-python/src/scitex/verify/__init__.py
4
+ """
5
+ SciTeX Verify Module - Hash-based verification for reproducible science.
6
+
7
+ This module provides tools to track, verify, and visualize the reproducibility
8
+ of scientific computations through cryptographic hashing.
9
+
10
+ Core Concepts
11
+ -------------
12
+ - **Run**: A single execution of a script with tracked inputs/outputs
13
+ - **Hash**: SHA256 fingerprint of files to detect changes
14
+ - **Chain**: Dependency links between runs (parent → child)
15
+ - **Verification**: Comparing stored hashes with current file states
16
+
17
+ Verification Levels
18
+ -------------------
19
+ - **verified-by-cache** (✓): Fast comparison of stored vs current hashes
20
+ - **verified-by-rerun** (✓✓): Full re-execution and comparison (slower, more thorough)
21
+
22
+ Examples
23
+ --------
24
+ >>> import scitex as stx
25
+
26
+ >>> # Automatic tracking via @stx.session + stx.io
27
+ >>> @stx.session
28
+ ... def main():
29
+ ... data = stx.io.load("input.csv") # Auto-tracked as input
30
+ ... result = process(data)
31
+ ... stx.io.save(result, "output.png") # Auto-tracked as output
32
+
33
+ >>> # Manual verification
34
+ >>> stx.verify.status() # Show changed files
35
+ >>> stx.verify.run("session_id") # Verify specific run
36
+ >>> stx.verify.chain("output.png") # Trace back to source
37
+
38
+ CLI Commands
39
+ ------------
40
+ - ``scitex verify list`` - List all runs with verification status
41
+ - ``scitex verify run <id>`` - Verify specific run
42
+ - ``scitex verify chain <file>`` - Trace dependencies back to source
43
+ - ``scitex verify status`` - Show changed items (git status-like)
44
+
45
+ MCP Tools
46
+ ---------
47
+ - ``verify_list`` - List runs
48
+ - ``verify_run`` - Verify specific run
49
+ - ``verify_chain`` - Trace chain
50
+ - ``verify_status`` - Show changes
51
+ """
52
+
53
+ from __future__ import annotations
54
+
55
+ # Chain verification
56
+ from ._chain import (
57
+ ChainVerification,
58
+ FileVerification,
59
+ RunVerification,
60
+ VerificationLevel,
61
+ VerificationStatus,
62
+ get_status,
63
+ verify_chain,
64
+ verify_file,
65
+ verify_run,
66
+ )
67
+
68
+ # Database
69
+ from ._db import (
70
+ VerificationDB,
71
+ get_db,
72
+ )
73
+
74
+ # Hash utilities
75
+ from ._hash import (
76
+ combine_hashes,
77
+ hash_directory,
78
+ hash_file,
79
+ hash_files,
80
+ verify_hash,
81
+ )
82
+
83
+ # Integration hooks
84
+ from ._integration import (
85
+ on_io_load,
86
+ on_io_save,
87
+ on_session_close,
88
+ on_session_start,
89
+ )
90
+
91
+ # Rerun verification (separate module to avoid circular imports)
92
+ from ._rerun import verify_by_rerun, verify_run_from_scratch
93
+
94
+ # Tracker
95
+ from ._tracker import (
96
+ SessionTracker,
97
+ get_tracker,
98
+ set_tracker,
99
+ start_tracking,
100
+ stop_tracking,
101
+ )
102
+
103
+ # Visualization
104
+ from ._visualize import (
105
+ format_chain_verification,
106
+ format_list,
107
+ format_run_detailed,
108
+ format_run_verification,
109
+ format_status,
110
+ generate_html_dag,
111
+ generate_mermaid_dag,
112
+ print_verification_summary,
113
+ render_dag,
114
+ )
115
+
116
+
117
+ # Convenience functions at module level
118
+ def list_runs(limit: int = 100, status: str = None):
119
+ """List tracked runs."""
120
+ db = get_db()
121
+ return db.list_runs(status=status, limit=limit)
122
+
123
+
124
+ def status():
125
+ """Get verification status summary (like git status)."""
126
+ return get_status()
127
+
128
+
129
+ def run(session_id: str, from_scratch: bool = False):
130
+ """Verify a specific run.
131
+
132
+ Parameters
133
+ ----------
134
+ session_id : str
135
+ Session identifier
136
+ from_scratch : bool, optional
137
+ If True, re-execute the script and verify outputs (slow but thorough).
138
+ If False, only compare hashes (fast).
139
+ """
140
+ if from_scratch:
141
+ return verify_run_from_scratch(session_id)
142
+ return verify_run(session_id)
143
+
144
+
145
+ def chain(target: str):
146
+ """Verify the chain for a target file."""
147
+ return verify_chain(target)
148
+
149
+
150
+ def stats():
151
+ """Get database statistics."""
152
+ db = get_db()
153
+ return db.stats()
154
+
155
+
156
+ __all__ = [
157
+ # Hash utilities
158
+ "hash_file",
159
+ "hash_files",
160
+ "hash_directory",
161
+ "combine_hashes",
162
+ "verify_hash",
163
+ # Database
164
+ "VerificationDB",
165
+ "get_db",
166
+ # Tracker
167
+ "SessionTracker",
168
+ "get_tracker",
169
+ "set_tracker",
170
+ "start_tracking",
171
+ "stop_tracking",
172
+ # Chain verification
173
+ "VerificationStatus",
174
+ "VerificationLevel",
175
+ "FileVerification",
176
+ "RunVerification",
177
+ "ChainVerification",
178
+ "verify_file",
179
+ "verify_run",
180
+ "verify_by_rerun",
181
+ "verify_run_from_scratch", # backward compat alias
182
+ "verify_chain",
183
+ "get_status",
184
+ # Visualization
185
+ "format_run_verification",
186
+ "format_run_detailed",
187
+ "format_chain_verification",
188
+ "format_status",
189
+ "format_list",
190
+ "generate_mermaid_dag",
191
+ "generate_html_dag",
192
+ "render_dag",
193
+ "print_verification_summary",
194
+ # Convenience functions
195
+ "list_runs",
196
+ "status",
197
+ "run",
198
+ "chain",
199
+ "stats",
200
+ # Integration hooks
201
+ "on_session_start",
202
+ "on_session_close",
203
+ "on_io_load",
204
+ "on_io_save",
205
+ ]
206
+
207
+
208
+ # EOF