# Welcome to disropt¶

**disropt** is a Python package developed within the excellence research program ERC in the project OPT4SMART.
The aim of this package is to provide an easy way to run distributed optimization algorithms that can
be executed by a network of peer copmuting systems.

A comprehensive guide to **disropt** can be found in the Tutorial. Many examples are provided in the Examples section, while the API Documentation can be checked
for more details.
The package is equipped with some commonly used objective functions and constraints which can be directly used.

**disropt** currently supports MPI in order to emulate peer-to-peer communication. However, custom communication protocols can be also implemented.

For example, the following Python code generates an unconstrained, quadratic optimization problem with a 5-dimensional decision variable, which is solved using the so-called Gradient Tracking.

```
import numpy as np
from disropt.agents import Agent
from disropt.algorithms.gradient_tracking import GradientTracking
from disropt.functions import QuadraticForm, Variable
from disropt.utils.graph_constructor import MPIgraph
from disropt.problems import Problem
# generate communication graph (everyone uses the same seed)
comm_graph = MPIgraph('random_binomial', 'metropolis')
agent_id, in_nbrs, out_nbrs, in_weights, _ = comm_graph.get_local_info()
# size of optimization variable
n = 5
# generate quadratic cost function
np.random.seed()
Q = np.random.randn(n, n)
Q = Q.transpose() @ Q
x = Variable(n)
func = QuadraticForm(x - np.random.randn(n, 1), Q)
# create Problem and Agent
agent = Agent(in_nbrs, out_nbrs, in_weights=in_weights)
agent.set_problem(Problem(func))
# run the algorithm
x0 = np.random.rand(n, 1)
algorithm = GradientTracking(agent, x0)
algorithm.run(iterations=1000, stepsize=0.01)
print("Agent {} - solution estimate: {}".format(agent_id, algorithm.get_result().flatten()))
```

This code can be executed over a network with 8 agents by issuing the following command:

```
mpirun -np 8 python example.py
```