qbiocode.apps.quvine.baselines.registry module#

Method Registry for Baseline Methods

This module provides a centralized registry for managing and executing all baseline embedding methods. It eliminates code duplication and provides consistent error handling, timing, and logging across all methods.

Summary#

Classes:

MethodMetadata

Metadata for a registered baseline method.

MethodRegistry

Central registry for managing baseline embedding methods.

MethodResult

Result from executing a method.

Reference#

class MethodMetadata(name, config_builder, executor, requires_q_targets=False, requires_graph=True, category='baseline', description='')[source]#

Bases: object

Metadata for a registered baseline method.

Variables:
  • name – Unique identifier for the method

  • config_builder – Function that builds config from OmegaConf

  • executor – Function that executes the method

  • requires_q_targets – Whether method needs quantum targets

  • requires_graph – Whether method needs graph data

  • category – Method category (baseline, quantum, fusion)

  • description – Human-readable description

name: str#
config_builder: Callable#
executor: Callable#
requires_q_targets: bool = False#
requires_graph: bool = True#
category: str = 'baseline'#
description: str = ''#
class MethodResult(name, embedding=None, execution_time=0.0, success=True, error=None, exception=None, metadata=None)[source]#

Bases: object

Result from executing a method.

Variables:
  • name – Method name

  • embedding – Resulting embedding matrix

  • execution_time – Time taken in seconds

  • success – Whether execution succeeded

  • error – Error message if failed

  • exception – The exception that caused the failure, so callers can chain (raise ... from result.exception) instead of losing the traceback to a log line

  • metadata – Additional metadata

name: str#
embedding: Optional[ndarray] = None#
execution_time: float = 0.0#
success: bool = True#
error: Optional[str] = None#
exception: Optional[BaseException] = None#
metadata: Optional[Dict[str, Any]] = None#
class MethodRegistry(cfg, base_seed, verbose=False)[source]#

Bases: object

Central registry for managing baseline embedding methods.

This class provides: - Method registration and discovery - Consistent execution with timing - Error handling and logging - Result storage and retrieval

Example

>>> registry = MethodRegistry(cfg, base_seed)
>>> registry.register(method_metadata)
>>> results = registry.run_all(graph_data, q_targets, store)
__init__(cfg, base_seed, verbose=False)[source]#

Initialize the method registry.

Parameters:
  • cfg – OmegaConf configuration object

  • base_seed (int) – Base random seed for reproducibility

  • verbose (bool) – Whether to print verbose output

register(metadata)[source]#

Register a method with the registry.

Parameters:

metadata (MethodMetadata) – Method metadata including name, config builder, and executor

Raises:

ValueError – If method name already registered

Return type:

None

register_multiple(metadata_list)[source]#

Register multiple methods at once.

Parameters:

metadata_list (List[MethodMetadata]) – List of method metadata objects

Return type:

None

is_enabled(method_name)[source]#

Check if a method is enabled in the configuration.

Parameters:

method_name (str) – Name of the method

Return type:

bool

Returns:

True if method is enabled, False otherwise

run_method(method_name, graph_data, q_targets=None, **kwargs)[source]#

Execute a single method.

Parameters:
  • method_name (str) – Name of the method to execute

  • graph_data – NetworkX graph

  • q_targets (Optional[List]) – Quantum targets (if required)

  • **kwargs – Additional arguments passed to executor

Return type:

MethodResult

Returns:

MethodResult with embedding and execution info

run_all(graph_data, q_targets=None, store=None, method_filter=None)[source]#

Execute all registered and enabled methods.

Parameters:
  • graph_data – NetworkX graph

  • q_targets (Optional[List]) – Quantum targets (optional)

  • store – EmbeddingStore to add results to (optional)

  • method_filter (Optional[Callable[[str], bool]]) – Optional function to filter which methods to run

Return type:

List[MethodResult]

Returns:

List of MethodResult objects

run_category(category, graph_data, q_targets=None, store=None)[source]#

Execute all methods in a specific category.

Parameters:
  • category (str) – Category name (e.g., ‘baseline’, ‘quantum’)

  • graph_data – NetworkX graph

  • q_targets (Optional[List]) – Quantum targets (optional)

  • store – EmbeddingStore to add results to (optional)

Return type:

List[MethodResult]

Returns:

List of MethodResult objects

get_results(successful_only=False)[source]#

Get all execution results.

Parameters:

successful_only (bool) – If True, return only successful results

Return type:

List[MethodResult]

Returns:

List of MethodResult objects

get_result(method_name)[source]#

Get result for a specific method.

Parameters:

method_name (str) – Name of the method

Return type:

Optional[MethodResult]

Returns:

MethodResult if found, None otherwise

list_methods(category=None)[source]#

List all registered methods.

Parameters:

category (Optional[str]) – Optional category filter

Return type:

List[str]

Returns:

List of method names

get_metadata(method_name)[source]#

Get metadata for a method.

Parameters:

method_name (str) – Name of the method

Return type:

Optional[MethodMetadata]

Returns:

MethodMetadata if found, None otherwise

clear_results()[source]#

Clear all stored results.

Return type:

None