Skip to content

Pytorch-based framework for solving parametric constrained optimization problems, physics-informed system identification, and parametric model predictive control.

License

Notifications You must be signed in to change notification settings

tombax7/neuromancer

 
 

Repository files navigation

NeuroMANCER v1.2

Neural Modules with Adaptive Nonlinear Constraints and Efficient Regularizations.

Authors: Aaron Tuor, Jan Drgona, Mia Skomski, Stefan Dernbach, James Koch, Zhao Chen, Christian Møldrup Legaard, Draguna Vrabie

Documentation

The documentation for the library can be found online and in the pdf form.

# Neuromancer syntax example for differentiable parametric programming
import neuromancer as nm

# primal solution map to be trained
func = nm.blocks.MLP(insize=2, outsize=2, hsizes=[80] * 4)
sol_map = nm.maps.Map(func,
        input_keys=["a", "p"],
        output_keys=["x"],
        name='primal_map')

# problem primal variables
x = nm.constraints.variable("x")[:, [0]]
y = nm.constraints.variable("x")[:, [1]]

# sampled problem parameters
p = nm.constraints.variable('p')
a = nm.constraints.variable('a')

# nonlinear objective function
f = (1-x)**2 + a*(y-x**2)**2
obj = f.minimize(weight=1., name='obj')

# constraints
con_1 = 100*(x >= y)
con_2 = 100*((p/2)**2 <= x**2+y**2)
con_3 = 100*(x**2+y**2 <= p**2)

# create constrained optimization loss
objectives = [obj]
constraints = [con_1, con_2, con_3]
loss = nm.loss.PenaltyLoss(objectives, constraints)
# construct constrained optimization problem
components = [sol_map]
problem = nm.problem.Problem(components, loss)

UML diagram UML diagram of NeuroMANCER classes.

Installation

First clone the neuromancer, slim, and psl libraries.

user@machine:~$ git clone -b master https://github.com/pnnl/neuromancer.git --single-branch
user@machine:~$ git clone -b master https://github.com/pnnl/psl.git --single-branch
user@machine:~$ git clone -b master https://github.com/pnnl/slim.git --single-branch

Install dependencies

Ubuntu

$ conda env create -f env.yml
$ conda activate neuromancer
(neuromancer) $ conda install tqdm
(neuromancer) $ conda install pytorch-scatter -c pyg
(neuromancer) $ conda install -c anaconda sphinx
(neuromancer) $ conda install -c conda-forge sphinx_rtd_theme

Windows

$ conda env create -f windows_env.yml
$ conda activate neuromancer
(neuromancer) $ conda install tqdm
(neuromancer) $ conda install pytorch-scatter -c pyg
(neuromancer) $ conda install -c anaconda sphinx
(neuromancer) $ conda install -c conda-forge sphinx_rtd_theme
(neuromancer) $ conda install -c defaults intel-openmp -f

Other operating system

$ conda create -n neuromancer python=3.10.4
$ conda activate neuromancer
(neuromancer) $ conda config --add channels conda-forge
(neuromancer) $ conda install pytorch cudatoolkit=10.2 -c pytorch
(neuromancer) $ conda install scipy numpy matplotlib scikit-learn pandas dill mlflow pydot=1.4.2 pyts numba networkx
(neuromancer) $ conda install networkx plum-dispatch 
(neuromancer) $ conda install -c anaconda pytest hypothesis
(neuromancer) $ conda install tqdm
(neuromancer) $ conda install pytorch-scatter -c pyg
(neuromancer) $ conda install -c anaconda sphinx
(neuromancer) $ conda install -c conda-forge sphinx_rtd_theme

Install neuromancer ecosystem

(neuromancer) $ cd psl; python setup.py develop
(neuromancer) $ cd ../slim; python setup.py develop
(neuromancer) $ cd ../neuromancer; python setup.py develop

Examples

For detailed examples of NeuroMANCER usage for control, system identification, and parametric programming as well as tutorials for basic usage, see the scripts in the examples folder.

The parametric programming examples have additional package dependencies for benchmarking against traditional constrained optimization solvers, e.g., cvxpy (these should also have been installed using env.yml)

(neuromancer) user@machine:~$ conda install cvxpy cvxopt seaborn
(neuromancer) user@machine:~$ pip install casadi 

For developers

All test code is developed using pytest and hypothesis. Please refer to the test folder and create unit tests for any new modules introduced to the library.

Publications

Cite as

@article{Neuromancer2022,
  title={{NeuroMANCER: Neural Modules with Adaptive Nonlinear Constraints and Efficient Regularizations}},
  author={Tuor, Aaron and Drgona, Jan and Skomski, Mia and Koch, James and Chen, Zhao and Dernbach, Stefan and Legaard, Christian Møldrup and Vrabie, Draguna},
  Url= {https://github.com/pnnl/neuromancer}, 
  year={2022}
}

About

Pytorch-based framework for solving parametric constrained optimization problems, physics-informed system identification, and parametric model predictive control.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%