A modular PyTorch framework for developing physics-informed neural network surrogate models for chemical process modeling, simulation, and process systems engineering.
Project description
pinnse is a modular PyTorch framework for the development of physics-informed neural-network (PINN) surrogate models for chemical process modelling, simulation, and process systems engineering. The package separates process-specific ingredients—such as operating bounds, governing equations, input-output formulations, and residual definitions—from reusable learning infrastructure for data handling, normalization, neural-network construction, training, validation, testing, and visualization.
The repository currently includes representative examples for nonideal flash separation, isothermal plug-flow reactors under multiple surrogate formulations, inverse PINNs for parameter estimation, and a nonisothermal plug-flow reactor with coupled mass and energy balances.
At its core, pinnse follows a simple idea: define the process physics once, expose it through residual functions, and train a differentiable surrogate against both labelled data and physical constraints. The resulting models remain data-efficient, physically informed, and suitable for downstream use in simulation, design analysis, and optimization-oriented workflows.
Contents
- Why pinnse?
- Installation
- Quick start
- Framework workflow
- Core package
- Example case studies
- Repository structure
- Extending pinnse
- Outputs
- License
Why pinnse?
First-principles models in chemical engineering are often nonlinear, tightly coupled, and costly to solve repeatedly. Conventional surrogate models can reduce this cost, but purely data-driven surrogates may violate conservation laws, equilibrium constraints, or boundary conditions. pinnse addresses this limitation by combining labelled simulator or solver data with residual losses derived from the governing equations.
The framework is designed for process systems engineering settings in which a single unit operation may admit multiple surrogate formulations. For example, a plug-flow reactor may be represented in terms of effluent flowrates, reaction extents, or conversions. In pinnse, such formulation-specific choices are localized within each example, while the common infrastructure for data preparation, normalization, model training, and analysis is reused across cases.
Installation
Clone the repository and install the package in editable mode:
git clone <repository-url>
cd pinnse
python -m pip install -e .
A clean environment is recommended:
conda create -n pinnse python=3.11 -y
conda activate pinnse
python -m pip install -e .
The core package depends on:
numpyscipytorchpandastqdm
The example workflows and plotting utilities also use:
python -m pip install matplotlib scikit-learn openpyxl
For flash-data generation through Aspen Plus, the following are additionally required:
python -m pip install pywin32
Note Training from the supplied
.xlsxdatasets does not require Aspen Plus. Aspen is only needed when regenerating flash datasets or running Aspen-based workflows.
Quick start
The isothermal PFR examples are the most direct entry point because they do not depend on Aspen Plus.
cd examples/isopfr/efm
python main.py
python check.py
A standard run performs the following steps:
- loads
I_S_data.xlsxandD_S_data.xlsx, - normalizes the input and output spaces,
- constructs supervised, physics-collocation, and boundary-collocation loaders,
- builds a PINN surrogate model,
- trains against data and residual losses,
- stores the best checkpoint in
logs/, and - evaluates the trained model through
check.py.
The nonisothermal PFR example follows the same pattern:
cd examples/nonisopfr
python main.py
python check.py
Flash examples can be trained from the supplied datasets:
cd examples/flash/case1
python main.py
Framework workflow
pinnse implements a composite PINN objective of the form
\mathcal{L}_{\mathrm{total}}
= \mathcal{L}_{\mathrm{data}}
+ \lambda_P\,\mathcal{L}_{\mathrm{physics}}
+ \lambda_B\,\mathcal{L}_{\mathrm{boundary}},
where the data loss fits labelled samples, the physics loss penalizes residual violations at collocation points, and the boundary loss enforces boundary or initial conditions.
The figure above summarizes the workflow implemented in the repository:
| Stage | Purpose | Typical file |
|---|---|---|
| Framework initialization | Defines the process variables, operating bounds, model formulation, network architecture, dataset sizes, optimizer, scheduler, and loss weights. | main.py |
| Data generation and sampling | Generates labelled data from Aspen Plus, SciPy-based solvers, or process models, and prepares the sampled input-output space. | data_gen.py |
| Data loading | Splits the labelled data and constructs supervised, physics-collocation, and boundary-collocation data loaders. | pinnse/data.py |
| PINN architecture | Defines the differentiable neural-network surrogate. | pinnse/PINNs.py |
| Physics residual formulation | Encodes the governing equations in residual form and evaluates them on collocation batches. | phys_res.py |
| Training, validation, and testing | Optimizes the surrogate, monitors validation performance, checkpoints the best model, and records loss histories. | pinnse/train.py |
| Post-processing and analysis | Evaluates trained models, denormalizes outputs, computes errors, and generates figures. | check.py, pinnse/utils.py, pinnse/plots.py |
Core package
The reusable framework is implemented in the pinnse/ package.
pinnse/PINNs.py
This module defines the neural-network architectures used as PINN surrogates.
| Class | Role |
|---|---|
ANN |
Standard fully connected feedforward network with Xavier-uniform weight initialization and zero biases. |
SANN |
Feedforward network with a Softplus output layer, useful when outputs must remain non-negative. |
BranchedANN |
Shared-trunk architecture with multiple output heads for structured multi-output regression. |
Fourier_ANN |
Feedforward architecture with Fourier feature embedding, useful for strongly varying or oscillatory mappings. |
Minimal example:
import torch.nn as nn
from pinnse import ANN
layer_size = [dim_in] + [64] * 6 + [dim_out]
model = ANN(layer_size=layer_size, activation=nn.Tanh)
pinnse/data.py
This module provides DataModule, which converts normalized pandas.DataFrame objects into PyTorch data loaders.
Key capabilities include:
- supervised train/validation/test splits through
labeled_data_loader(), - physics-collocation sampling through
phys_colloc_loader(), - boundary-collocation sampling through
bnd_colloc_loader(), - data-loader inspection and export utilities.
Notably, phys_colloc_loader() samples the interior input space using Latin hypercube sampling, while composition variables with prefixes such as Z_, X_, or Y_ are sampled with Dirichlet distributions so that the resulting composition groups remain physically meaningful.
pinnse/train.py
This module implements the Training class, which couples supervised data loss with optional physics and boundary residual losses.
Its functionality includes:
- epoch-wise training with
adam_step(), - optional second-stage optimization with
lbfgs_step(), - validation and testing through
validate_test(), - checkpointing of the best model,
- storage of training and validation loss histories,
- gradient-norm tracking for data, physics, and boundary losses,
- optional adaptive updating of loss weights.
pinnse/utils.py
This module provides common utilities for normalization, denormalization, result export, and post-training analysis.
| Class | Role |
|---|---|
Normalization |
Applies min-max, centred scaling, max-absolute, mean normalization, and z-score transformations. Includes routines specialized for PFR formulations. |
Denormalization |
Maps normalized model predictions back to dimensional variables. |
Analyze |
Loads trained models, evaluates predictions, and computes error metrics. |
Save |
Writes histories or results to Excel or CSV. |
pinnse/plots.py
This module defines the Plotter class for visualizing model-development history. It includes methods to plot:
- individual loss histories,
- full training and validation loss traces,
- physics and boundary weight evolution,
- gradient histories,
- inverse-parameter trajectories, and
- a combined summary view through
plot_everything().
pinnse/__init__.py
The package exports the main public API:
from pinnse import (
ANN, SANN, BranchedANN, Fourier_ANN,
DataModule, Training, Plotter,
Normalization, Denormalization, Save, Analyze,
)
Example case studies
The repository includes example workflows in examples/.
| Example | Description |
|---|---|
examples/flash/case1 |
PINN workflow for a flash-separation formulation using supplied labelled data. |
examples/flash/case2 |
Alternative flash formulation with its own residual and training script. |
examples/isopfr/efm |
Isothermal PFR using an effluent-flow formulation. |
examples/isopfr/erm |
Isothermal PFR using an extent-of-reaction formulation. |
examples/isopfr/efm.inverse |
Inverse PINN workflow for parameter estimation in the isothermal PFR setting. |
examples/nonisopfr |
Nonisothermal PFR with coupled mass and energy balances. |
A typical example directory contains:
main.py: model setup and training script,phys_res.py: physics and boundary residual definitions,data_gen.py: dataset generation script,check.py: post-training evaluation and comparison,I_S_data.xlsx,D_S_data.xlsx: labelled input and output datasets,pfr_model.py: process model helper functions where applicable,run.sh: convenience shell script.
Repository structure
pinnse/
├── docs/
│ ├── framework_overview.png
│ └── pinnse_logo.png
├── examples/
│ ├── flash/
│ │ ├── Aspen Simulations/
│ │ ├── case1/
│ │ └── case2/
│ ├── isopfr/
│ │ ├── efm/
│ │ ├── erm/
│ │ ├── efm.inverse/
│ │ └── cm/
│ └── nonisopfr/
├── pinnse/
│ ├── __init__.py
│ ├── PINNs.py
│ ├── data.py
│ ├── train.py
│ ├── utils.py
│ └── plots.py
├── pyproject.toml
├── README.md
└── LICENSE
Extending pinnse
To apply pinnse to a new process system, the typical workflow is:
- define the process inputs (
I_S) and outputs (D_S), - generate or collect labelled datasets,
- write a
phys_res.pyfile that evaluates the governing-equation residuals, - define any required boundary residuals,
- construct a
main.pyscript that configures the architecture, data loaders, optimizer, scheduler, and loss weights, - train the model using
Training, and - evaluate the resulting surrogate through a
check.pyscript.
This design allows the process-specific physics to remain local to the new case while the rest of the pipeline is inherited directly from the package.
Outputs
A typical training run generates:
- a best-model checkpoint,
- training and validation loss histories,
- optional weight and gradient histories,
- prediction-versus-reference comparison results,
- figures summarizing the model performance.
The exact output files are controlled by the example scripts and their logging conventions.
License
This project is released under the MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pinnse-0.0.4.tar.gz.
File metadata
- Download URL: pinnse-0.0.4.tar.gz
- Upload date:
- Size: 28.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
291ff8c743da08b7a0cfa821aef8e2a8c26c5c4423bc1c8221e4f365ae831b28
|
|
| MD5 |
ba8d8c655ed99987849986a01299191a
|
|
| BLAKE2b-256 |
9950966f808868ba1d1066aa759f6484a15ec8bbb04ef5fd732773789ebff3d5
|
File details
Details for the file pinnse-0.0.4-py3-none-any.whl.
File metadata
- Download URL: pinnse-0.0.4-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1629cb5763c5b035b413e725c1a6775eb792b0bd435689fc39c9632558146b41
|
|
| MD5 |
e791e6f3fc4d2906e6b3757fb10455bb
|
|
| BLAKE2b-256 |
b3400922ea224afed31d2d9126dfb58197f60032499f7da4af56e6b10bd90947
|