How mbelotti-nuk/pk-neuralnet works
1. What this repo is
- PK-neuralnet is a Python package and command-line toolchain for a domain-specific neural network workflow: build a dataset, train a model, run predictions, and export a trained model into NACARTE/SpaceClaim-compatible form.
- The package code lives under pknn/, with a small companion reader package under nacarte/.
2. Top-level workflow
- The architecture is a linear pipeline: raw input files and resource tables are converted into a structured database, that database feeds training, the trained model is used for prediction, and a separate export path serializes the model for NACARTE.
- The same YAML configuration style is used to drive each command, so configuration is a major boundary between user intent and implementation.
3. CLI entry points
- The README exposes four user-facing commands: databasepknn, trainpknn, predictpknn, and savepknn.
- These map to the main application stages and are the primary integration surface for users and automation scripts.
4. Database creation subsystem
- pknn/build_database.py and pknn/inp_process/ handle ingestion of raw inputs.
- binaryreader.py and database.py suggest the data is parsed from binary/domain-specific formats into an internal tabular or file-backed database.
- The examples include raw data folders, a generated database/ folder, and resource files such as massAttCoeff.xml and conversion tables, so this stage is responsible for domain preprocessing and feature assembly.
5. Training subsystem
- pknn/train.py is the training entry point.
- pknn/net/ contains the model and training machinery: pk_nn.py for the neural network, train_functions.py for optimization/training logic, datamanager.py for batching/data loading, and pytorchtools.py for training utilities such as checkpointing or early stopping.
- Artifacts produced here include PyTorch model files (.pt), checkpoints, and a saved scaler object (Scaler.pickle), which indicates training persists both the network and preprocessing state.
6. Prediction subsystem
- pknn/predict.py is the inference entry point.
- Prediction reuses the trained model and the stored preprocessing artifacts, so the inference path depends on the same data normalization and model definition used during training.
- The example layout includes a dedicated prediction_example/ config and a model_example/ directory, reinforcing that prediction is a separate operational mode rather than part of training.
7. Export subsystem
- pknn/export/ and pknn/exportmodel.py implement serialization to NACARTE-facing formats.
- exportsd.py and importsd.py imply bidirectional translation between the package’s model representation and SpaceClaim/NACARTE artifacts.
- This is the main integration boundary with external CAD/engineering tooling.
8. NACARTE integration boundary
- The nacarte/ package, especially out_reader.py, appears to read NACARTE outputs back into Python.
- This suggests the repo supports not only exporting a model to NACARTE but also consuming downstream results for validation or post-processing.
9. Shared utilities and presentation
- pknn/functionalities/ contains cross-cutting helpers: config.py for configuration handling and graphics.py for plotting/visualization.
- These are not core ML components, but they support the user experience around configuration, inspection, and result presentation.
10. Data and artifact formats
- The project is heavily file-based: YAML configs, binary/raw inputs, generated database directories, text metadata files, XML resources, .pt model/checkpoint files, and pickle-based scaler state.
- That means the architecture is centered on explicit on-disk artifacts rather than a long-running service or database server.
11. Documentation and examples as architecture references
- The docs/ and make_docs/ trees are extensive and include generated API docs plus example walkthroughs for database creation, training, prediction, and export.
- The examples/ directory provides end-to-end sample inputs and outputs, which is useful for understanding the intended flow and module boundaries.
12. Testing boundary
- tests/test_reader.py and tests/testfiles/ indicate at least the input-reading layer is unit-tested.
- This aligns with the repo’s highest-risk boundary: parsing domain-specific files into a reliable internal dataset.
Main entry points: train.py Train · predict.py Inference · config.py Config · binaryreader.py Binary reader
Components 17
CLI pipeline
User-facing commands that drive the main workflow.
- Build DB · Database creation command that ingests raw inputs and resources.
pknn/build_database.py - Train · Training command for fitting the neural network.
pknn/train.py - Predict · Inference command for running predictions from a saved model.
pknn/predict.py - Save model · Export command that packages a trained model for NACARTE use.
pknn/exportmodel.py
Data prep
Builds the structured database from raw domain files and resources.
- Binary reader · Parses domain-specific raw/binary inputs into internal records.
pknn/inp_process/binaryreader.py - Database · Internal database assembly and file-backed dataset structure.
pknn/inp_process/database.py
Training
Model definition, batching, optimization, and training artifacts.
- Data manager · Training data assembly, batching, and scaling hooks.
pknn/net/datamanager.py - NN model · Core neural network architecture.
pknn/net/pk_nn.py - Train logic · Training loop, loss handling, and optimization behavior.
pknn/net/train_functions.py - Torch utils · Checkpointing and other training support utilities.
pknn/net/pytorchtools.py
Prediction
Inference path that reuses trained model and preprocessing state.
- Inference · Prediction execution that loads the trained network and scaler.
pknn/predict.py
Export
Serialization into NACARTE / SpaceClaim-facing artifacts.
NACARTE boundary
Reader for downstream NACARTE outputs and round-trip validation.
- Out reader · Reads downstream NACARTE outputs for validation or post-processing.
nacarte/out_reader.py
Shared support
Cross-cutting configuration, visualization, and test coverage.
- Config · YAML configuration handling used by all major commands.
pknn/functionalities/config.py - Graphics · Plotting and result presentation helpers.
pknn/functionalities/graphics.py - Reader test · Unit coverage for the parsing boundary.
tests/test_reader.py
Connections 20
- Build DB → Config: loads · Database generation is driven by YAML configuration.
- Build DB → Binary reader: uses · Entry point invokes raw input parsing.
- Binary reader → Database: writes · Parsed inputs are assembled into the internal database.
- Database → Train: feeds · Generated database becomes training input.
- Train → Config: loads · Training uses the same configuration boundary.
- Train → Data manager: uses · Training prepares batches and scaled inputs.
- Data manager → NN model: feeds · Managed data drives the neural network.
- Train → Train logic: runs · Optimization loop and training control.
- Train logic → NN model: optimizes · Training logic updates the model.
- Train logic → Torch utils: uses · Checkpointing / early-stop utilities support training.
- Train → Inference: produces · Training artifacts are consumed by prediction.
- Inference → Config: loads · Prediction is also configuration-driven.
- Inference → NN model: loads · Inference reuses the trained model definition.
- Inference → Data manager: reuses · Prediction depends on the same preprocessing state.
- Save model → Config: loads · Export is configured through the shared YAML style.
- Save model → Export SD: serializes · Model export hands off to NACARTE serialization.
- Export SD → Import SD: round-trip · Export/import modules represent the external format boundary.
- Import SD → Out reader: consumed by · NACARTE outputs can be read back into Python.
- Inference → Graphics: reports · Prediction results can be visualized.
- Binary reader → Reader test: covered by · Parsing boundary is unit-tested.