utils – Utilities
Utility modules for DifferentialLab.
- exception utils.DifferentialLabError[source]
Bases:
ExceptionBase exception for all DifferentialLab errors.
Catch this to handle any application-defined error.
- exception utils.EquationParseError[source]
Bases:
DifferentialLabErrorRaised when an ODE/difference/PDE expression cannot be parsed or evaluated.
- exception utils.SolverFailedError[source]
Bases:
DifferentialLabErrorRaised when the numerical solver fails to converge or encounters an error.
- exception utils.ValidationError[source]
Bases:
DifferentialLabErrorRaised when user input fails validation (domain, ICs, parameters, etc.).
- utils.build_eval_namespace(params)[source]
Build the safe evaluation namespace combining SAFE_MATH and user params.
- utils.export_csv_to_path(x, y, filepath, *, y_grid=None)[source]
Export solution data to CSV at the given path.
- Parameters:
- Return type:
- Returns:
The path that was written.
- utils.export_json_to_path(statistics, metadata, filepath)[source]
Export statistics and metadata to JSON at the given path.
- utils.normalize_params(parameters)[source]
Return a mutable copy of parameters, or an empty dict if
None.
- utils.normalize_unicode_escapes(text)[source]
Replace
\uXXXXescape sequences with their Unicode characters.Allows users to enter expressions like
\u03C9**2 * y[0]and have them treated equivalently toω**2 * y[0].
- utils.safe_eval(compiled, namespace)[source]
Evaluate a compiled expression in a sandboxed namespace.
- utils.validate_exclusive_args(arg_a, arg_b, name_a, name_b)[source]
Ensure exactly one of two mutually exclusive arguments is provided.
- utils.validate_expression_ast(expression, context='expression')[source]
Check that the expression contains only allowed AST nodes.
- Parameters:
- Raises:
EquationParseError – If the expression contains disallowed constructs.
- Return type:
- utils.perform_git_pull()[source]
Perform git pull in the project root.
Before pulling, stashes any local changes in input/ and output/ to prevent them from being overwritten. After the pull completes, the stashed changes are restored. Files in .env and other .gitignore entries are automatically protected by git.
- utils.record_check_done()[source]
Record that an update check was performed (touch the file).
Updates the modification time of
.last_update_checkso the next check is deferred by UPDATE_CHECK_INTERVAL_DAYS.- Return type:
- utils.should_run_check()[source]
Return True if we should run the update check (once per week).
- Return type:
- Returns:
True if enough time has passed since last check, or no previous check.
utils.exceptions
Custom exception hierarchy for DifferentialLab.
All application-specific exceptions inherit from DifferentialLabError,
enabling broad except DifferentialLabError handling when desired.
- exception utils.exceptions.DifferentialLabError[source]
Bases:
ExceptionBase exception for all DifferentialLab errors.
Catch this to handle any application-defined error.
- exception utils.exceptions.ValidationError[source]
Bases:
DifferentialLabErrorRaised when user input fails validation (domain, ICs, parameters, etc.).
- exception utils.exceptions.EquationParseError[source]
Bases:
DifferentialLabErrorRaised when an ODE/difference/PDE expression cannot be parsed or evaluated.
- exception utils.exceptions.SolverFailedError[source]
Bases:
DifferentialLabErrorRaised when the numerical solver fails to converge or encounters an error.
utils.export
Export utilities for CSV, JSON, and plot files.
- utils.export.export_csv_to_path(x, y, filepath, *, y_grid=None)[source]
Export solution data to CSV at the given path.
- Parameters:
- Return type:
- Returns:
The path that was written.
utils.logger
Application logging setup.
Configures a hierarchical logger under the differential_lab namespace.
Log level, file output, and console output are controlled via environment
variables (LOG_LEVEL, LOG_FILE, LOG_CONSOLE).
utils.update_checker
Update checker for DifferentialLab.
Checks weekly if a newer version is available in the repository. If so, shows a dialog (when enabled via env) and can perform git pull without overwriting user data (input/, output/, .env, etc.).
- utils.update_checker.should_run_check()[source]
Return True if we should run the update check (once per week).
- Return type:
- Returns:
True if enough time has passed since last check, or no previous check.
- utils.update_checker.record_check_done()[source]
Record that an update check was performed (touch the file).
Updates the modification time of
.last_update_checkso the next check is deferred by UPDATE_CHECK_INTERVAL_DAYS.- Return type:
- utils.update_checker.is_update_available(current_version)[source]
Check if a newer version is available.
- utils.update_checker.perform_git_pull()[source]
Perform git pull in the project root.
Before pulling, stashes any local changes in input/ and output/ to prevent them from being overwritten. After the pull completes, the stashed changes are restored. Files in .env and other .gitignore entries are automatically protected by git.