graph2mat.tools.server.server_app

Implements a fastapi server API that accepts requests to predict matrices.

Functions

create_server_app(models[, local])

Creates a flask app to listen to requests and predict matrices.

create_server_app_from_filesystem([...])

Launches a server that serves predictions from trained models stored in checkpoint files.

Classes

Files

ModelSpecification

class graph2mat.tools.server.server_app.Files[source]

Bases: TypedDict

basis: Path | str
ckpt: Path | str
sample_metrics: Path | str
structs: Path | str
class graph2mat.tools.server.server_app.ModelSpecification[source]

Bases: TypedDict

authors: List[str]
data_processor: MatrixDataProcessor
description: str
files: Files
prediction_function: Callable[[BasisMatrixData], Dict[str, ndarray]]
root_dir: Path
test_metrics_summary: str
graph2mat.tools.server.server_app.create_server_app(models: Dict[str, ModelSpecification], local: bool = False) FastAPI[source]

Creates a flask app to listen to requests and predict matrices.

The app is to be ran with uvicorn. For example:

>>> import uvicorn
>>> models = {}
>>> app = server_app(models)
>>> uvicorn.run(app, host="localhost", port=56000)
Parameters:
  • models (Dict[str, ModelSpecification]) – A dictionary with the models to be used. The keys are the names of the models, and the values are dictionaries with everything that we need/know about the model.

  • local (bool, optional) – If True, the server allows the user to ask for changes in the local file system.

graph2mat.tools.server.server_app.create_server_app_from_filesystem(model_files: Dict[str, str] = {}, local: bool = False, cpu: bool = True)[source]

Launches a server that serves predictions from trained models stored in checkpoint files.

This function just builds the dictionary of models from the ckpt files and then calls server_app.

Parameters:
  • ckpt_files (Sequence[str]) – List of checkpoint files to load.

  • local (bool, optional) – If True, the server allows the user to ask for changes in the local file system.

  • cpu (bool, optional) – Load parameters in the CPU regardless of whether they were in the GPU, by default True.