hoops_ai.ml.EXPERIMENTAL

class hoops_ai.ml.EXPERIMENTAL.CustomFlowModel(encode_cad_data_fn=None, encode_label_data_fn=None, convert_encoded_data_to_graph_fn=None, load_model_input_from_files_fn=None, collate_function_fn=None, retrieve_model_fn=None, model_name_fn=None, get_citation_info_fn=None, predict_and_postprocess_fn=None, metrics_fn=None)

Bases: FlowModel

Child class with default ‘dummy’ implementations of the abstract methods. Users can pass in custom callables (strategies) to override each method’s behavior.

Parameters:
collate_function(batch)

Return a collated batch for this model.

Return type:

Any

convert_encoded_data_to_graph(storage, graph, filename)

Converts encoded data from storage into a graph representation, which serves as input for the ML model. use graph.save_graph(filename) to save the graph in a file

Parameters:
Return type:

Dict[str, Any]

encode_cad_data(cad_file, cad_access, storage)

Opens the CAD file and encodes its data into a format suitable for machine learning. Stores the encoded data using the provided storage handler. return the tuple [face_count, edge_count]

Parameters:
Return type:

Tuple[int, int]

encode_label_data(label_storage, storage)

Uses the LabelStorage object to retrieve the labeling information for a given input Stores the label data for the specific machine learning Task

return the str key when the label data is found in the storage object and the size of the label data

Parameters:
Return type:

Tuple[str, int]

get_citation_info()

Provides citation details for the model, including author, paper, publication year, and open-source references.

Return type:

Dict[str, Any]

load_model_input_from_files(graph_file, data_id, label_file=None)

Loads the graph created in method convert_encoded_data_to_graph from a file. the return of this method is exactly the input as expected by the machine learning model the label_file is optional. If not given, the method should return a valid object.

This method will be called multiple times by the DatasetLoader. This method will be called with label_file == None for doing inference

Parameters:
  • graph_file (str)

  • data_id (int)

  • label_file (str)

Return type:

Any

metrics()

Publish/push the ml metrics after traiing the model

Return type:

MetricStorage

model_name()

Provides the name of the model.

Return type:

str

predict_and_postprocess(batch)

Post-processes and formats the raw model output into a structured prediction.

Return type:

Any

retrieve_model(check_point=None)

Retrieves the PyTorch Lightning model used in this flow.

Parameters:

check_point (str)

Return type:

pytorch_lightning.LightningModule

class hoops_ai.ml.EXPERIMENTAL.FlowInference(cad_loader, flowmodel, log_file='training_errors.log')

Bases: object

Parameters:
  • cad_loader (CADLoader)

  • flowmodel (FlowModel)

  • log_file (str)

load_from_checkpoint(checkpoint_path)

Loads a model from a checkpoint.

Parameters:

checkpoint_path (str) – Path to the model checkpoint file

predict_and_postprocess(batch)

Makes predictions using the loaded model.

Parameters:

batch (Dict[str, torch.Tensor]) – Preprocessed input batch.

Returns:

Predicted class indices.

Return type:

np.ndarray

preprocess(file_path)

Preprocesses the input file to prepare it for the model.

Parameters:

file_path (str) – Path to the input bin dgl file.

Returns:

Preprocessed batch ready for prediction.

Return type:

Dict[str, torch.Tensor]

class hoops_ai.ml.EXPERIMENTAL.FlowTrainer(flowmodel=None, datasetLoader=None, batch_size=64, num_workers=0, experiment_name='UNKNOWN_Experiment', accelerator='cpu', devices='auto', gradient_clip_val=1.0, max_epochs=100, learning_rate=0.002, result_dir=None, **trainer_kwargs)

Bases: object

Parameters:
metrics_storage()

Return the location of the metrics

Return type:

str

purify(num_processes=1, chunks_per_process=1)

Purify the datasets in parallel (if num_processes > 1) or in a single process. This method executes a forward/backward pass on a batch of size 1 to check for numerical errors (e.g., NaNs or crashes) and logs a JSON file for each processed chunk.

Parameters:
  • num_processes (int)

  • chunks_per_process (int)

test(trained_model_path)

Tests the model using the specified checkpoint.

Parameters:

trained_model_path (str)

train()

Trains the model and returns the path to the best checkpoint.

Return type:

str

class hoops_ai.ml.EXPERIMENTAL.GraphClassification(num_classes=10, result_dir=None, log_file='cnn_graph_training_errors.log', generate_stream_cache_for_visu=False)

Bases: FlowModel

GraphClassification is a user-friendly wrapper around the UVNet model. It provides default hyperparameters and an interface for users to interact without directly accessing the UVnet class.

Parameters:
  • num_classes (int, optional) – Number of classes for classification. Default: 10

  • log_file (str, optional) – Path to the log file. Default: ‘training_errors.log’

  • result_dir (str)

  • generate_stream_cache_for_visu (bool)

collate_function(batch)

Return a collate function for this model.

Return type:

Any

convert_encoded_data_to_graph(storage, graph_handler, filename)

Converts encoded data from storage into a graph representation, which serves as input for the ML model.

Parameters:
Return type:

Dict[str, Any]

encode_cad_data(cad_file, cad_loader, storage)

Opens the CAD file and encodes its data into a format suitable for machine learning. Stores the encoded data using the provided storage handler.

Parameters:
Return type:

Tuple[int, int]

encode_label_data(label_storage, storage)

Uses the LabelStorage object to retrieve the labeling information for a given input Stores the label data for the specific machine learning Task

return the str key when the label data is found in the storage object and the size of the label data

Parameters:
Return type:

Tuple[str, int]

get_citation_info()

Provides citation details for the UV-Net model, including authors, paper title, publication year, model architecture, original applications, and a link to the open-source GitHub repository.

Returns:

A formatted citation string.

Return type:

str

load_model_input_from_files(graph_file, data_id, label_file=None)

Loads a single graph from a file to be used as input for the machine learning model.

Parameters:
  • graph_file (str)

  • data_id (int)

  • label_file (str)

Return type:

Any

metrics()

Publish/push the ml metrics after traiing the model

Return type:

MetricStorage

model_name()
Return type:

str

predict_and_postprocess(batch)

Post-processes and formats the raw model output into a structured prediction. Returns a numpy array with top 3 predictions and their probability percentages as integers.

Returns:

Array with shape (batch_size, 2, 3), where: - First dimension: batch items - Second dimension [0]: class indices (int) - Second dimension [1]: probability percentages (int)

Return type:

numpy.ndarray

retrieve_model(check_point=None)

Retrieves the PyTorch Lightning model used in this flow.

Parameters:

check_point (str)

Return type:

pytorch_lightning.LightningModule

class hoops_ai.ml.EXPERIMENTAL.GraphNodeClassification(num_classes=25, n_layers_encode=8, dim_node=256, d_model=512, n_heads=32, dropout=0.3, attention_dropout=0.3, act_dropout=0.3, learning_rate=0.002, optimizer_betas=(0.99, 0.999), scheduler_factor=0.5, scheduler_patience=5, scheduler_threshold=0.0001, scheduler_min_lr=1e-06, scheduler_cooldown=2, max_warmup_steps=5000, log_file='training_errors.log', result_dir=None, generate_stream_cache_for_visu=False, **kwargs)

Bases: FlowModel

GraphNodeClassification is a user-friendly wrapper around the BrepSeg model. It provides default hyperparameters and an interface for users to interact without directly accessing the BrepSeg class.

Parameters:
  • num_classes (int, optional) – Number of classes for classification. Default: 10

  • n_layers_encode (int, optional) – Number of encoding layers in the BrepEncoder. Default: 6

  • dim_node (int, optional) – Dimension of node embeddings. Default: 256

  • d_model (int, optional) – Dimension of the model in BrepEncoder. Default: 512

  • n_heads (int, optional) – Number of attention heads in BrepEncoder. Default: 8

  • dropout (float, optional) – Dropout rate for the classifier. Default: 0.3

  • attention_dropout (float, optional) – Dropout rate for attention layers. Default: 0.1

  • act_dropout (float, optional) – Dropout rate for activation layers. Default: 0.1

  • learning_rate (float, optional) – Initial learning rate for the optimizer. Default: 0.002

  • optimizer_betas (Tuple[float, float], optional) – Betas for the AdamW optimizer. Default: (0.99, 0.999)

  • scheduler_factor (float, optional) – Factor for ReduceLROnPlateau scheduler. Default: 0.5

  • scheduler_patience (int, optional) – Patience for ReduceLROnPlateau scheduler. Default: 5

  • scheduler_threshold (float, optional) – Threshold for ReduceLROnPlateau scheduler. Default: 1e-4

  • scheduler_min_lr (float, optional) – Minimum learning rate for scheduler. Default: 1e-6

  • scheduler_cooldown (int, optional) – Cooldown period for scheduler. Default: 2

  • max_warmup_steps (int, optional) – Number of warmup steps for learning rate scaling. Default: 5000

  • log_file (str, optional) – Path to the log file. Default: ‘training_errors.log’

  • **kwargs (Any) – Additional keyword arguments for BrepSeg.

  • CONSTRUCTOR!!!!! (" LUIS CHECKS DEFAULT PARAMETERS EITHER THIS ONE OF THE ONE IN THE)

  • parameters (# Model) – default_model_params = { “num_classes”: 25, “n_layers_encode”: 8, “dim_node”: 256, “d_model”: 512, “n_heads”: 32, “dropout”: 0.3, “attention_dropout”: 0.3, “act_dropout”: 0.3,

  • }

  • result_dir (str)

  • generate_stream_cache_for_visu (bool)

  • **kwargs

collate_function(batch)

Return a collate function for this model.

Return type:

Any

convert_encoded_data_to_graph(storage, graph_handler, filename)

Converts encoded data from storage into a graph representation, which serves as input for the ML model.

Parameters:
Return type:

Dict[str, Any]

encode_cad_data(cad_file, cad_loader, storage)

Opens the CAD file and encodes its data into a format suitable for machine learning. Stores the encoded data using the provided storage handler.

Parameters:
Return type:

Tuple[int, int]

encode_label_data(label_storage, storage)

Uses the LabelStorage object to retrieve the labeling information for a given input Stores the label data for the specific machine learning Task

return the str key when the label data is found in the storage object and the size of the label data

Parameters:
Return type:

Tuple[str, int]

get_citation_info()

Provides citation details for the BrepMFR model, including author, paper title, publication year, model architecture, original applications, and a link to the open-source GitHub repository.

Returns:

A formatted citation string.

Return type:

str

load_model_input_from_files(graph_file, data_id, label_file=None)

Loads a single graph from a file to be used as input for the machine learning model.

Parameters:
  • graph_file (str)

  • data_id (int)

  • label_file (str)

Return type:

Any

metrics()

Publish/push the ml metrics after training the model

Return type:

MetricStorage

model_name()
Return type:

str

predict_and_postprocess(batch)

Post-processes and formats the raw model output into a structured prediction. Returns the predictions and their associated probabilities.

Return type:

Any

retrieve_model(check_point=None)

Retrieves the PyTorch Lightning model used in this flow.

Parameters:

check_point (str)

Return type:

pytorch_lightning.LightningModule

Modules

flexible_flow_model

flow_inference

flow_model

flow_model_graph_classification

flow_model_graphnode_classification

flow_trainer