API
scitex-session — @session decorator + lifecycle management (standalone).
- scitex_session.start(sys=None, plt=None, file=None, sdir=None, sdir_suffix=None, args=None, os=None, random=None, np=None, torch=None, seed=42, agg=False, fig_size_mm=(160, 100), fig_scale=1.0, dpi_display=100, dpi_save=300, fontsize='small', autolayout=False, show_execution_flow=False, hide_top_right_spines=True, alpha=0.9, line_width=1.0, clear_logs=False, verbose=True)[source]
Initialize experiment session with reproducibility settings.
- Parameters:
sys (module, optional) – Python sys module for I/O redirection
plt (module, optional) – Matplotlib pyplot module for plotting configuration
file (str, optional) – Script file path. If None, automatically detected
sdir (Union[str, Path], optional) – Save directory path
sdir_suffix (str, optional) – Suffix to append to save directory
args (object, optional) – Command line arguments or configuration object
seed (int, default=42) – Random seed for reproducibility
agg (bool, default=False) – Whether to use matplotlib Agg backend
verbose (bool, default=True) – Whether to print detailed information
- Returns:
(CONFIGS, stdout, stderr, plt, COLORS, rng)
- Return type:
- scitex_session.close(CONFIG, message=':)', notify=False, verbose=True, exit_status=None)[source]
Close experiment session and finalize logging.
- Parameters:
CONFIG (DotDict) – Configuration dictionary from start()
message (str, default=':)') – Completion message
notify (bool, default=False) – Whether to send notification
verbose (bool, default=True) – Whether to print verbose output
exit_status (int, optional) – Exit status code (0=success, 1=error, None=finished)
- scitex_session.running2finished(CONFIG, exit_status=None, remove_src_dir=True, max_wait=60)[source]
Move session from RUNNING to FINISHED directory.
- Parameters:
- Returns:
Updated configuration with new SDIR
- Return type:
- scitex_session.session(func=None, *, verbose=False, agg=True, notify=False, sdir_suffix=None, **session_kwargs)[source]
Decorator to wrap function in scitex session.
Automatically handles: - CLI argument parsing from function signature - Session initialization (logging, output directories) - Execution - Cleanup - Error handling
This decorator is designed for script entry points. The decorated function should be called without arguments from if __name__ == ‘__main__’: to trigger CLI parsing and session management.
- Parameters:
func (
Callable) – Function to wrap (set automatically by decorator)verbose (
bool) – Enable verbose loggingagg (
bool) – Use matplotlib Agg backendnotify (
bool) – Send notification on completionsdir_suffix (
str) – Suffix for output directory name**session_kwargs – Additional session configuration parameters
- Return type:
Example
@stx.session def analyze(data_path: str, threshold: float = 0.5):
‘’’Analyze data file.’’’ data = stx.io.load(data_path) result = process(data, threshold) stx.io.save(result, “output.csv”) return 0
- if __name__ == ‘__main__’:
analyze() # No arguments = CLI mode with session management
# CLI: python script.py –data-path data.csv –threshold 0.7
- Example with options:
@stx.session(verbose=True, notify=True) def train_model(model_name: str, epochs: int = 10):
‘’’Train ML model.’’’ # These are automatically available as globals: # - CONFIG: Session configuration dict # - plt: Matplotlib pyplot (configured for session) # - COLORS: Custom Colors # - rngg: RandomStateManager (fixes seeds, creates named generators) logger.info(f”Session ID: {CONFIG[‘ID’]}”) logger.info(f”Output directory: {CONFIG[‘SDIR_RUN’]}”) # … training code … return 0
- if __name__ == ‘__main__’:
train_model()
Notes
Function name can be anything (not just ‘main’)
Calling with arguments bypasses session management: analyze(‘/path’, 0.5)
Only one session-managed function per script
Do NOT call multiple @session decorated functions from one script
Do NOT nest session-decorated function calls without arguments
- Injected Global Variables:
When called without arguments (CLI mode), these are injected into globals: - CONFIG (dict): Session configuration with ID, SDIR, paths, etc. - plt (module): matplotlib.pyplot configured with session settings - COLORS (CustomColors): Custom Colors for consistent plotting - rngg (RandomStateManager): Manages reproducibility by fixing global seeds
and creating named generators via rngg(“name”)
- scitex_session.run(func, parse_args=None, **session_kwargs)[source]
Run function with session management.
Alternative to decorator for more explicit control.
- Parameters:
- Return type:
Example
- def main(args):
# Your code return 0
- if __name__ == ‘__main__’:
stx.session.run(main)
- class scitex_session.SessionManager[source]
Manages experiment sessions with tracking and lifecycle management.
- get_active_sessions()[source]
Get all active sessions.
- Returns:
Dictionary of active session information
- Return type:
Dict[str, Any]