Skip to content

qoolqit.embedding

source package qoolqit.embedding

Classes

source class SpringLayoutEmbedder()

Bases : GraphToGraphEmbedder[SpringLayoutConfig]

A graph to graph embedder using the spring layout algorithm.

Attributes

  • config : ConfigType Returns the config for the embedding algorithm.

  • algorithm : Callable Returns the callable to the embedding algorithm.

  • info : str Prints info about the embedding algorithm.

source class InteractionEmbedder()

Bases : MatrixToGraphEmbedder[InteractionEmbeddingConfig]

A matrix to graph embedder using the interaction embedding algorithm.

Attributes

  • config : ConfigType Returns the config for the embedding algorithm.

  • algorithm : Callable Returns the callable to the embedding algorithm.

  • info : str Prints info about the embedding algorithm.

source dataclass InteractionEmbeddingConfig(method: str = 'Nelder-Mead', maxiter: int = 200000, tol: float = 1e-08)

Bases : EmbeddingConfig

Configuration parameters for the interaction embedding.

source dataclass SpringLayoutConfig(k: float | None = None, iterations: int = 50, threshold: float = 0.0001, seed: int | None = None)

Bases : EmbeddingConfig

Configuration parameters for the spring-layout embedding.

source class BaseEmbedder(algorithm: Callable, config: ConfigType)

Bases : ABC, Generic[InDataType, OutDataType, ConfigType]

Abstract base class for all embedders.

An embedder is a function that maps a InDataType to an OutDataType through an embedding algorithm. Parameters of the embedding algorithm can be customized through the EmbeddingConfig.

Default initializer for all embedders, taking an algorithm and a config.

An algorithm should be a standalone function that takes a piece of data of an InDataType and maps it to an OutDataType. Any extra configuration parameters taken as input by the algorithm function should be defined in the config dataclass, inheriting from EmbeddingConfig.

Parameters

  • algorithm : Callable a callable to the algorithm function.

  • config : ConfigType a config dataclass holding parameter values for the algorithm.

Attributes

  • config : ConfigType Returns the config for the embedding algorithm.

  • algorithm : Callable Returns the callable to the embedding algorithm.

  • info : str Prints info about the embedding algorithm.

Methods

  • validate_input Checks if the given data is compatible with the embedder.

  • validate_output Checks if the resulting output is expected by the embedder.

  • embed Validates the input, runs the embedding algorithm, and validates the output.

source property BaseEmbedder.config: ConfigType

Returns the config for the embedding algorithm.

source property BaseEmbedder.algorithm: Callable

Returns the callable to the embedding algorithm.

source property BaseEmbedder.info: str

Prints info about the embedding algorithm.

source method BaseEmbedder.validate_input(data: InDataType)None

Checks if the given data is compatible with the embedder.

Each embedder should write its own data validator. If the data is not of the supported type or in the specific supported format for that embedder, an error should be raised.

Parameters

  • data : InDataType the data to validate.

Raises

  • TypeError if the data is not of the supported type.

  • SomeError some other error if other constraints are not met.

source method BaseEmbedder.validate_output(result: OutDataType)None

Checks if the resulting output is expected by the embedder.

Each embedder should write its own output validator. If the result is not of the supported type or in the specific supported format for that embedder, an error should be raised.

Parameters

  • result : OutDataType the output to validate.

Raises

  • TypeError if the output is not of the supported type.

  • SomeError some other error if other constraints are not met.

source method BaseEmbedder.embed(data: InDataType)OutDataType

Validates the input, runs the embedding algorithm, and validates the output.

Parameters

  • data : InDataType the data to embed.

source dataclass EmbeddingConfig()

Bases : ABC

Base abstract dataclass for all embedding algorithm configurations.

Subclasses define parameters specific to their algorithms. Each config should define fields that directly translate to arguments in the respective embedding function it configures.

Methods

  • dict Returns the dataclass as a dictionary.

source method EmbeddingConfig.dict()dict

Returns the dataclass as a dictionary.

source class GraphToGraphEmbedder(algorithm: Callable, config: ConfigType)

Bases : BaseEmbedder[DataGraph, DataGraph, ConfigType]

A family of embedders that map a graph to a graph.

Focused on unit-disk graph embedding, where the goal is to find a set of coordinates for a graph that has no coordinates, such that the final unit-disk edges matches the set of edges in the original graph.

A custom algorithm and configuration can be set at initialization.

Default initializer for all embedders, taking an algorithm and a config.

An algorithm should be a standalone function that takes a piece of data of an InDataType and maps it to an OutDataType. Any extra configuration parameters taken as input by the algorithm function should be defined in the config dataclass, inheriting from EmbeddingConfig.

Parameters

  • algorithm : Callable a callable to the algorithm function.

  • config : ConfigType a config dataclass holding parameter values for the algorithm.

Attributes

  • config : ConfigType Returns the config for the embedding algorithm.

  • algorithm : Callable Returns the callable to the embedding algorithm.

  • info : str Prints info about the embedding algorithm.

Methods

source method GraphToGraphEmbedder.validate_input(data: DataGraph)None

Raises

  • TypeError

source method GraphToGraphEmbedder.validate_output(result: DataGraph)None

Raises

  • TypeError

source class MatrixToGraphEmbedder(algorithm: Callable, config: ConfigType)

Bases : BaseEmbedder[np.ndarray, DataGraph, ConfigType]

A family of embedders that map a matrix to a graph.

A custom algorithm and configuration can be set at initialization.

Default initializer for all embedders, taking an algorithm and a config.

An algorithm should be a standalone function that takes a piece of data of an InDataType and maps it to an OutDataType. Any extra configuration parameters taken as input by the algorithm function should be defined in the config dataclass, inheriting from EmbeddingConfig.

Parameters

  • algorithm : Callable a callable to the algorithm function.

  • config : ConfigType a config dataclass holding parameter values for the algorithm.

Attributes

  • config : ConfigType Returns the config for the embedding algorithm.

  • algorithm : Callable Returns the callable to the embedding algorithm.

  • info : str Prints info about the embedding algorithm.

Methods

source method MatrixToGraphEmbedder.validate_input(data: np.ndarray)None

Raises

  • TypeError

  • ValueError

source method MatrixToGraphEmbedder.validate_output(result: DataGraph)None

Raises

  • TypeError