vipr.handlers package

Submodules

vipr.handlers.data_loader module

class vipr.handlers.data_loader.DataLoaderHandler(**kw: Any)

Bases: DataLoaderInterface, Handler

Base handler for data loaders. Specific implementations should override _load_data method.

load_data(**kwargs) DataSet

Loads data from a specified path.

If the handler class has a __vipr_params_model__ (set by @discover_data_loader), unknown keys are stripped from kwargs before forwarding to _load_data. This prevents extra='forbid' validation errors when the config contains keys intended for other handlers.

Parameters:
  • data_path – Optional path to data file

  • **kwargs – Additional parameters for data loading

Returns:

DataSet containing loaded data with x, y, errors, and metadata

vipr.handlers.in_memory_cache module

In-Memory Cache Handler for VIPR

Provides process-persistent caching that survives VIPR app lifecycle within Celery workers. Perfect for streaming scenarios where data needs to be accumulated across multiple task executions.

class vipr.handlers.in_memory_cache.InMemoryCacheHandler(**kw: Any)

Bases: CacheHandler

Simple in-process cache handler that stores Python objects directly in memory.

Key characteristics: - No network or serialization overhead - NOT process-safe (single worker only) - Process-persistent (survives VIPR app lifecycle) - Perfect for Celery worker scenarios

class Meta

Bases: object

label = 'in_memory_cache'
delete(key: str) None

Delete a value from the cache.

Parameters:

key – Cache key to delete

exists(key: str) bool

Check if a key exists in the cache.

Parameters:

key – Cache key to check

Returns:

True if key exists

get(key: str, fallback: Any | None = None) Any

Get a value from the cache.

Parameters:
  • key – Cache key

  • fallback – Value to return if key not found

Returns:

Cached value or fallback

keys(pattern: str | None = None) list

Get all cache keys, optionally filtered by pattern.

Parameters:

pattern – Simple prefix pattern (e.g., “streaming_trends:”)

Returns:

List of matching keys

purge() None

Clear the entire cache.

set(key: str, value: Any, time: int | None = None) None

Set a value in the cache.

Parameters:
  • key – Cache key

  • value – Value to store (any Python object)

  • time – TTL in seconds (ignored in this implementation)

vipr.handlers.loss module

class vipr.handlers.loss.LossHandler(**kw: Any)

Bases: LossInterface, Handler

loss(input, target)

Calculate the loss

Returns:

loss value

vipr.handlers.model_loader module

class vipr.handlers.model_loader.ModelLoaderHandler(**kw: Any)

Bases: ModelLoaderInterface, Handler

load_model(**kwargs)

Loads a model of the given type.

If the handler class has a __vipr_params_model__ (set by @discover_model_loader), unknown keys are stripped from kwargs before forwarding to _load_model. This prevents extra='forbid' validation errors when the config contains keys intended for other handlers.

Parameters:

**kwargs – Additional parameters for model initialization

Returns:

The loaded model

vipr.handlers.network_architecture module

class vipr.handlers.network_architecture.NetworkArchitectureHandler(**kw: Any)

Bases: NetworkArchitectureHandlerInterface, Handler

class Meta

Bases: object

label = 'network_architecture'
get(**kwargs) Module

Defines and returns the network architecture.

Parameters:

**kwargs – Architecture parameters like: - input_shape: Input dimensions - output_shape: Output dimensions - condition_shape: For conditional networks etc.

Returns:

Network architecture

vipr.handlers.optimizer module

class vipr.handlers.optimizer.OptimizerHandler(**kw: Any)

Bases: OptimizerInterface, Handler

get(parameters)

vipr.handlers.postprocessor module

Base class for postprocessor handlers in the VIPR framework.

exception vipr.handlers.postprocessor.PostprocessorError

Bases: VIPRError

Exception raised for postprocessor related errors.

class Meta

Bases: object

label = 'PostprocessorError'
class vipr.handlers.postprocessor.PostprocessorHandler(**kw: Any)

Bases: PostprocessorInterface, Handler

Base postprocessor handler for processing results after predictions.

class Meta

Bases: object

label = 'postprocessor'
abstract postprocess(data: Any, **kwargs) Any

Postprocess the prediction results.

Parameters:
  • data – Input data to postprocess (typically prediction results)

  • **kwargs – Parameters controlling postprocessing behavior

Returns:

Postprocessed results

Return type:

Any

Raises:

PostprocessorError – If postprocessing fails

vipr.handlers.predictor module

class vipr.handlers.predictor.PredictorHandler(**kw: Any)

Bases: PredictorInterface, Handler

Base handler for predictor implementations with unified DataSet interface.

predict(dataset, model: Any, params: dict[str, Any] | None = None) dict[str, Any]

Make predictions using the model with unified DataSet interface.

If the handler class has a __vipr_params_model__ (set by @discover_predictor), unknown keys are stripped from params before forwarding to _predict. This prevents extra='forbid' validation errors when the YAML config contains keys intended for other handlers.

Parameters:
  • dataset – DataSet with batch-first format (batch_size, n_points)

  • model – Model to use for prediction

  • params – Additional parameters for prediction control

Returns:

Dict with prediction results in batch format

vipr.handlers.vipr_log_handler module

Custom VIPR Log Handler that bridges Cement logging with DataCollector and Celery logging.

This handler extends the standard Cement LoggingLogHandler to automatically forward all log messages to: 1. DataCollector for frontend visualization 2. Celery task logger for terminal debugging (when running in Celery context) 3. Internal buffer for logs that occur before DataCollector is available

class vipr.handlers.vipr_log_handler.VIPRLogHandler(*args, **kwargs)

Bases: LoggingLogHandler

Custom log handler that forwards log messages to DataCollector.

This handler maintains all standard Cement logging functionality while also collecting log entries for frontend display. Includes internal buffer for logs that occur before DataCollector is available.

class Meta

Bases: Meta

Handler meta-data.

console_format = '%(asctime)s - %(levelname)s - %(namespace)s - %(message)s'

Console log format with ISO 8601 timestamp

debug_format = '%(asctime)s - %(levelname)s - %(namespace)s - %(message)s'

Debug log format with ISO 8601 timestamp

file_format = '%(asctime)s - %(levelname)s - %(namespace)s - %(message)s'

File log format with ISO 8601 timestamp

forward_to_celery = True

Whether to forward logs to Celery task logger (configurable)

forward_to_datacollector = True

Whether to forward logs to DataCollector (configurable)

include_namespace = True

Include namespace in DataCollector log messages

label: str = 'vipr_logging'

The string identifier of this handler.

max_buffer_size = 1000

Maximum buffer size to prevent memory issues

critical(msg: str, namespace: str | None = None, **kw: Any) None

Log to the CRITICAL facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

debug(msg: str, namespace: str | None = None, **kw: Any) None

Log to the DEBUG facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

error(msg: str, namespace: str | None = None, **kw: Any) None

Log to the ERROR facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

fatal(msg: str, namespace: str | None = None, **kw: Any) None

Log to the FATAL (deprecated, maps to CRITICAL) facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

info(msg: str, namespace: str | None = None, **kw: Any) None

Log to the INFO facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

warning(msg: str, namespace: str | None = None, **kw: Any) None

Log to the WARNING facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

vipr.handlers.vipr_log_handler2 module

Custom VIPR Log Handler that bridges Cement logging with DataCollector and Celery logging.

This handler extends the standard Cement LoggingLogHandler to automatically forward all log messages to: 1. DataCollector for frontend visualization 2. Celery task logger for terminal debugging (when running in Celery context) 3. Internal buffer for logs that occur before DataCollector is available

class vipr.handlers.vipr_log_handler2.VIPRLogHandler(*args, **kwargs)

Bases: LoggingLogHandler

Custom log handler that forwards log messages to DataCollector.

This handler maintains all standard Cement logging functionality while also collecting log entries for frontend display. Includes internal buffer for logs that occur before DataCollector is available.

class Meta

Bases: Meta

Handler meta-data.

console_format = '%(asctime)s - %(levelname)s - %(namespace)s - %(message)s'

Console log format with ISO 8601 timestamp

debug_format = '%(asctime)s - %(levelname)s - %(namespace)s - %(message)s'

Debug log format with ISO 8601 timestamp

file_format = '%(asctime)s - %(levelname)s - %(namespace)s - %(message)s'

File log format with ISO 8601 timestamp

forward_to_celery = True

Whether to forward logs to Celery task logger (configurable)

forward_to_datacollector = True

Whether to forward logs to DataCollector (configurable)

include_namespace = True

Include namespace in DataCollector log messages

label: str = 'vipr_logging'

The string identifier of this handler.

max_buffer_size = 1000

Maximum buffer size to prevent memory issues

critical(msg: str, namespace: str | None = None, **kw: Any) None

Log to the CRITICAL facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

debug(msg: str, namespace: str | None = None, **kw: Any) None

Log to the DEBUG facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

error(msg: str, namespace: str | None = None, **kw: Any) None

Log to the ERROR facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

fatal(msg: str, namespace: str | None = None, **kw: Any) None

Log to the FATAL (deprecated, maps to CRITICAL) facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

info(msg: str, namespace: str | None = None, **kw: Any) None

Log to the INFO facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

warning(msg: str, namespace: str | None = None, **kw: Any) None

Log to the WARNING facility and forward to buffer and Celery.

Parameters:
  • msg – The message to log

  • namespace – A log prefix, generally the module __name__

  • **kw – Additional keyword arguments

vipr.handlers.vipr_plugin_handler module

VIPR Plugin Handler

Custom plugin handler that extends Cement’s plugin system to properly handle entry point plugins alongside internal plugins.

This handler ensures that plugins registered via Python entry points (like vipr-reflectometry) are not processed by Cement’s internal plugin loader, preventing ModuleNotFoundError when users set “enabled: true” in config.

class vipr.handlers.vipr_plugin_handler.VIPRPluginHandler

Bases: CementPluginHandler

Custom plugin handler for VIPR that handles both internal and entry point plugins.

After parsing plugin configuration, this handler removes entry point plugin names from Cement’s enabled list to prevent Cement from trying to load them as internal plugins (which would fail with ModuleNotFoundError).

Entry point plugins are loaded separately via discover_and_load_plugins() in the main VIPR.setup() method.

class Meta

Bases: object

Handler meta-data.

label = 'vipr_plugin'

Module contents