This repository implements Polymer Chemistry Informed Neural Networks (PCINNs) for methyl methacrylate (MMA) free-radical polymerization prediction. The method combines data-driven training with kinetic-model guidance via Jacobian matching.
Paper: Ballard, N. Polymer Chemistry Informed Neural Networks. Polym. Chem., 2024. DOI: 10.1039/D4PY00995A
Upstream repository: https://github.com/PolymatGIQ/PCINN
Primary implementation: MMA_PCINN.ipynb
The original script MMA_PCINN.py is kept for reference only.
python -m venv .venv
source .venv/Scripts/activate # Windows Git Bash
pip install torch==2.10.0 numpy==2.4.2 pandas==2.2.3 matplotlib==3.10.8 openpyxl==3.1.5 "ipykernel>=6.29,<7"Open MMA_PCINN.ipynb in Jupyter/VS Code and run cells.
The notebook contains two workflows:
- Single-fold training/export workflow (quick path)
- Uses
TestReactionto hold out one reaction (default:TestReaction = 8). - Trains three models: Baseline NN, PCINN, Soft-Anchor PCINN.
- Plots loss curves and exports model artifacts.
- Full leave-one-experiment-out multi-seed CV (long-running, optional)
- Runs all 8 folds and multiple seeds (
N_SEEDS = 5by default). - Default run count:
3 models × 8 folds × 5 seeds = 120training runs. - Produces table-style aggregate metrics and fold-level PCINN vs SA-PCINN comparisons.
MMA_PCINN.ipynb currently has 30 cells (13 markdown, 17 code):
- Dependencies and pinned install cell.
- Imports/environment setup (including optional unsafe KMP gate, off by default).
- Reproducibility and device setup (
SEED=42,DEVICEauto-select). - Model definitions:
NNmodelandDomainModel. - Data preprocessing and scaler/domain model loading.
- Jacobian sampling range configuration.
- Single-fold split configuration via
TestReaction. - Baseline NN training (paper-original cell preserved as commented reference + improved executable cell).
- PCINN training (paper-original cell preserved as commented reference + improved executable cell).
- Soft-Anchor PCINN training.
- Single-fold loss/curve comparison summary.
- Full 8-fold multi-seed cross-validation section.
- Model export with smoke-test reload verification.
- Baseline NN: data-only MSE.
- PCINN:
L_data + L_jac(Jacobian matching to pretrained theory model). - Soft-Anchor PCINN:
L_data + L_jac + λ_anchor * L_anchor, where:
using the same sampled points used for Jacobian matching.
Quick path:
- Restart kernel and run through the single-fold sections.
- Confirm all three model sections execute and render loss curves.
- Confirm
NNpred,EBNNpred, andSApredeach have shape(N, 6). - Confirm export files are written to
exports/and smoke-test reload passes (max_diff < 1e-6).
Optional full CV:
- Run the multi-seed CV cell and confirm aggregate tables/plots are produced.
- Expect substantially longer runtime than the single-fold workflow.
This repository is licensed under CC BY-NC 4.0. See License.md.