
Product
Introducing Data Exports
Export Socket alert data to your own cloud storage in JSON, CSV, or Parquet, with flexible snapshot or incremental delivery.
nnodely
Advanced tools
Model-structured neural network framework for the modeling and control of physical systems
Modeling, control, and estimation of physical systems are central to many engineering disciplines. While data-driven methods like neural networks offer powerful tools, they often struggle to incorporate prior domain knowledge, limiting their interpretability, generalizability, and safety.
To bridge this gap, we present nnodely (where "nn" can be read as "m," forming Modely) — a framework that facilitates the creation and deployment of Model-Structured Neural Networks (MS-NNs).
MS-NNs combine the learning capabilities of neural networks with structural priors grounded in physics, control, and estimation theory, enabling:
In short:
nnodely is not a replacement for a general purpose deep learning frameworks — it is a structured layer on top of them, purpose-built for physical systems.
📖 Documentation • 🔬 Case Studies • 🚀 Other Applications
You can install nnodely from PyPI via:
pip install nnodely
Alternatively, you can build it from source by first cloning the repository and installing the requirements and the nnodely library:
git clone https://github.com/tonegas/nnodely.git
cd nnodely
pip install -r requirements.txt
pip install .
To check if nnodely is installed correctly try running the following script.
from nnodely import Input, Output, nnodely, Parameter
x = Input("x")
l = x.last()
o = (Parameter('A')*l.sw([-2,-1])+Parameter('B')*l).closedLoop(x)
f = Output("fib",o)
model = nnodely()
model.addModel("Fibonacci",f)
model.addMinimize("target", l.sw([-2,-1])+l, f)
model.neuralizeModel(1)
model.loadData("data",{ "x" : list(range(100)) } )
model.trainModel(prediction_samples = 2, lr = 0.5, num_of_epochs = 500)
model.exportPythonModel(models = "Fibonacci")
print(model({ "x" : [1] },prediction_samples = 20,num_of_samples = 20))
In the example, the neural network is trained to mimic the Fibonacci series. Finally, a native pytorch network is exported in a file.
nnodely/ # root directory
├── nnodely/ # source code
│ ├── basic/ # core low-level classes
│ ├── exporter/ # model export utilities
│ ├── layers/ # supported layers
│ ├── operators/ # core operators
│ ├── support/ # utility functions
│ └── visualizer/ # visualization tools
├── case-studies/ # main case studies
├── docs/ # documentation
├── tests/ # unit and integration tests
├── imgs/ # images used in the documentation
└── mplplots/ # utilities for MatPlotLib
This folder contains all the nnodely library files with relative references.
The nnodely main class defined in nnodely.py, it contains all the main properties of the nnodely object and it derives from five main operators, cointained in the folder operators/:
addModel, neuralizeModel, addConnection, addClosedLoop etc..dataLoad.trainModel.saveModel, loadModel, exportONNX etc..resultsAnalysis.Network defined in network.py, that contains the shared support functions for all the operators.The folder basic/ contains the main classes for the low level functionalities:
The other folders are:
exporter/ that contains the classes for the export functions.support/ for the support functions.visualizer/ that contains all the classes related to the visualization.layers/ folder.The layers/ folder contains all the layers that can be used in the MSNN.
In particular, the model structured NN is defined by Inputs, Outputs and Parameters:
The main basic layers without parameters are:
The main basic layers with parameters are:
W*x+b operated on the space dimension (third dimension).
This operation is presented in [1].In the case studies folder you can find the main case studies cited in the paper. Each case study is a jupyter notebook that explains the main functionalities of the library.
This folder contains all files used to automatically generate the documentation.
This folder contains the unit tests of the library. Each file tests a specific functionality.
This folder contains the utilities for Matplotlib.
This folder contains the images used in the documentation.
To contribute to the nnodely framework, you can:
We welcome contributions and collaborations.
This project is released under the license License: MIT.
[1] Mauro Da Lio, Daniele Bortoluzzi, Gastone Pietro Rosati Papini. (2019). Modelling longitudinal vehicle dynamics with neural networks. Vehicle System Dynamics. https://doi.org/10.1080/00423114.2019.1638947 (look the [code])
[2] Alice Plebe, Mauro Da Lio, Daniele Bortoluzzi. (2019). On Reliable Neural Network Sensorimotor Control in Autonomous Vehicles. IEEE Transaction on Intelligent Transportation System. https://doi.org/10.1109/TITS.2019.2896375
[3] Mauro Da Lio, Riccardo Donà, Gastone Pietro Rosati Papini, Francesco Biral, Henrik Svensson. (2020). A Mental Simulation Approach for Learning Neural-Network Predictive Control (in Self-Driving Cars). IEEE Access. https://doi.org/10.1109/ACCESS.2020.3032780 (look the [code])
[4] Edoardo Pagot, Mattia Piccinini, Enrico Bertolazzi, Francesco Biral. (2023). Fast Planning and Tracking of Complex Autonomous Parking Maneuvers With Optimal Control and Pseudo-Neural Networks. IEEE Access. https://doi.org/10.1109/ACCESS.2023.3330431 (look the [code])
[5] Mattia Piccinini, Sebastiano Taddei, Matteo Larcher, Mattia Piazza, Francesco Biral. (2023). A Physics-Driven Artificial Agent for Online Time-Optimal Vehicle Motion Planning and Control. IEEE Access. https://doi.org/10.1109/ACCESS.2023.3274836 (look [code basic] and [code extended])
[6] Hector Perez-Villeda, Justus Piater, Matteo Saveriano. (2023). Learning and extrapolation of robotic skills using task-parameterized equation learner networks. Robotics and Autonomous Systems. https://doi.org/10.1016/j.robot.2022.104309 (look the [code])
[7] M. Raissi. P. Perdikaris b, G.E. Karniadakis a. (2019). Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations Journal of Computational Physics. https://doi.org/10.1016/j.jcp.2018.10.045 (look the [example Burger's equation])
[8] Wojciech Marian Czarnecki, Simon Osindero, Max Jaderberg, Grzegorz Świrszcz, Razvan Pascanu. (2017). Sobolev Training for Neural Networks. arXiv. https://doi.org/10.48550/arXiv.1706.04859 (look the [code])
[9] Mattia Piccinini, Matteo Zumerle, Johannes Betz, Gastone Pietro Rosati Papini. (2025). A Road Friction-Aware Anti-Lock Braking System Based on Model-Structured Neural Networks. IEEE Open Journal of Intelligent Transportation Systems. https://doi.org/10.1109/OJITS.2025.3563347 (look at the [code])
[10] Mauro Da Lio, Mattia Piccinini, Francesco Biral. (2023). Robust and Sample-Efficient Estimation of Vehicle Lateral Velocity Using Neural Networks With Explainable Structure Informed by Kinematic Principles. IEEE Transactions on Intelligent Transportation Systems. https://doi.org/10.1109/TITS.2023.3303776
TODO: Possiamo aggiungere DOI di repo con zenodo e mettere la citazione di quello guida -->
FAQs
Model-structured neural network framework for the modeling and control of physical systems
We found that nnodely demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Export Socket alert data to your own cloud storage in JSON, CSV, or Parquet, with flexible snapshot or incremental delivery.

Research
/Security News
Bitwarden CLI 2026.4.0 was compromised in the Checkmarx supply chain campaign after attackers abused a GitHub Action in Bitwarden’s CI/CD pipeline.

Research
/Security News
Docker and Socket have uncovered malicious Checkmarx KICS images and suspicious code extension releases in a broader supply chain compromise.