Skip to content

sdu-cfei/modest-py

Repository files navigation

FMI-compliant Model Estimation in Python

modestpy
unit_test_status

Description

ModestPy facilitates parameter estimation in models compliant with Functional Mock-up Interface.

Features:

  • combination of global and local search methods (genetic algorithm, pattern search, truncated Newton method, L-BFGS-B, sequential least squares),
  • suitable also for non-continuous and non-differentiable models,
  • scalable to multiple cores (genetic algorithm from modestga),
  • Python 3.

Due to time constraints, ModestPy is no longer actively developed. The last system known to work well was Ubuntu 18.04. Unit tests in GitHub Actions are run on Ubuntu 18.04 and Python 3.6/3.7. It does not mean it will not work on other systems, but it is not guaranteed. Use Docker (as described below) if you want to run ModestPy on a tested platform.

Installation with pip (recommended)

It is now possible to install ModestPy with a single command:

pip install modestpy

Alternatively:

pip install https://github.com/sdu-cfei/modest-py/archive/master.zip

Installation with conda

Conda is installation is less frequently tested, but should work:

conda config --add channels conda-forge
conda install modestpy

Docker

Due to time constraints, Modestpy is no longer actively developed. The last system known to work well was Ubuntu 18.04. If you encounter any issues with running ModestPy on your system (e.g. some libs missing), try using Docker.

I prepared a Dockerfile and some initial make commands:

  • make build - build an image with ModestPy, based on Ubuntu 18.04 (tag = modestpy)
  • make run - run the container (name = modestpy_container)
  • make test - run unit tests in the running container and print output to terminal
  • make bash - run Bash in the running container

Most likely you will like to modify Dockerfile and Makefile to your needs, e.g. by adding bind volumes with your FMUs.

Test your installation

The unit tests will work only if you installed ModestPy with conda or cloned the project from GitHub. To run tests:

>>> from modestpy.test import run
>>> run.tests()

or

cd <project_directory>
python ./bin/test.py

Usage

Users are supposed to call only the high level API included in modestpy.Estimation. The API is fully discussed in the docs. You can also check out this simple example. The basic usage is as follows:

from modestpy import Estimation

if __name__ == "__main__":
    session = Estimation(workdir, fmu_path, inp, known, est, ideal)
    estimates = session.estimate()
    err, res = session.validate()

More control is possible via optional arguments, as discussed in the documentation.

The if __name__ == "__main__": wrapper is needed on Windows, because modestpy relies on multiprocessing. You can find more explanation on why this is needed here.

modestpy automatically saves results in the working directory including csv files with estimates and some useful plots, e.g.:

  1. Error evolution in combined GA+PS estimation (dots represent switch from GA to PS): Error-evolution
  2. Visualization of GA evolution: GA-evolution
  3. Scatter matrix plot for interdependencies between parameters: Intedependencies

Cite

To cite ModestPy, please use:

K. Arendt, M. Jradi, M. Wetter, C.T. Veje, ModestPy: An Open-Source Python Tool for Parameter Estimation in Functional Mock-up Units, Proceedings of the American Modelica Conference 2018, Cambridge, MA, USA, October 9-10, 2018.

The preprint version of the conference paper presenting ModestPy is available here. The paper was based on v.0.0.8.

License

Copyright (c) 2017-2019, University of Southern Denmark. All rights reserved.

This code is licensed under BSD 2-clause license. See LICENSE file in the project root for license terms.