# Solvers performance comparison¶

One of the goals of `lamberthub`

is to provide different performance comparison
tools for new authors addressing the Lambert’s problem. At the moment, the
following utilities are available:

**Iterations performance plotter:**generates a contour map showing the number of iterations for a particular combination of the transfer angle and the non-dimensional time of flight.**Time required per iteration:**shows a contour map in which the time per iteration is shown against the transfer angle and the non-dimensional time. It also computes the required average time.

In this page, all these tools are presented together with the results output by them.

## Iterations contour maps¶

A first performance comparison between the current implemented solvers can be
performed via the `IterationsPlotter`

class. This class provides all the
necessary methods to output a figure showing the relation between the transfer
angle, the non-dimensional time of flight and the number of iterations.

The following code shows how to create a collection of these figures for a given
set of solvers. Taking advantage of the `ALL_SOLVERS`

macro provided by
`lamberthub`

, it is possible to build a graphical representation for all the
algoritms currently available.

```
import matplotlib.pyplot as plt
from lamberthub import ALL_SOLVERS
from lamberthub.plotting import IterationsPlotter
def plot_iterations_performance(SOLVERS_LIST):
""" Plots iterations performance for each one of the solvers from given set """
for solver in SOLVERS_LIST:
fig, ax = plt.subplots()
iter_plotter = IterationsPlotter(ax=ax, fig=fig)
iter_plotter.plot_performance(solver, maxiter=10)
plt.show()
plot_iterations_performance(ALL_SOLVERS)
```

```
/home/docs/checkouts/readthedocs.org/user_builds/lamberthub/envs/latest/lib/python3.8/site-packages/lamberthub/plotting/iterations.py:82: MatplotlibDeprecationWarning: Passing parameters norm and vmin/vmax simultaneously is deprecated since 3.3 and will become an error two minor releases later. Please pass vmin/vmax directly to the norm when creating it.
self.collection = self.ax.pcolor(
/home/docs/checkouts/readthedocs.org/user_builds/lamberthub/envs/latest/lib/python3.8/site-packages/lamberthub/plotting/iterations.py:92: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. This has been deprecated since 3.3 and in 3.6, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = mpl.cm.get_cmap("sunshine_9lev").copy()
self.collection.cmap.set_under("black")
```

```
/home/docs/checkouts/readthedocs.org/user_builds/lamberthub/envs/latest/lib/python3.8/site-packages/lamberthub/universal_solvers/arora.py:137: RuntimeWarning: invalid value encountered in sqrt
tof20 = S * np.sqrt(1 - 20 * tau) * (tau + 0.04940968903 * (1 - 20 * tau))
/home/docs/checkouts/readthedocs.org/user_builds/lamberthub/envs/latest/lib/python3.8/site-packages/lamberthub/universal_solvers/arora.py:138: RuntimeWarning: invalid value encountered in sqrt
tof100 = S * np.sqrt(1 - 100 * tau) * (tau + 0.00999209404 * (1 - 100 * tau))
```

## Time required per iteration¶

The number of iterations does not provide a full insight of the problem, as an algorithm with low iterations number might require a lot of time per iteration it finds a solution. Therefore, a plotter in which the time per iteration is shown against a combination of transfer angle and non-dimensional time of flight is required.

Note

Notice this performance tool is directly linked to machine specifications, the number of processes being run in it, the current implementation and the number of samples.

The following code snippet runs the time performance plotter for all the
available solvers. Results might vary in your local machine as these ones are
executed with a low number of samples in order to avoid `RuntimeErrors`

in the
server computer which builds the documentation.

```
import matplotlib.pyplot as plt
from lamberthub import ALL_SOLVERS
from lamberthub.plotting import TPIPlotter
def plot_time_performance(SOLVERS_LIST):
""" Plots the contour maps and a bar chart for a given set of solvers """
# Plots iterations performance for each one of the solvers from given set
for solver in SOLVERS_LIST:
fig_ctime, ax_ctime = plt.subplots()
iter_plotter = TPIPlotter(ax=ax_ctime, fig=fig_ctime)
iter_plotter.plot_performance(solver, N_samples=5)
plt.show()
plot_time_performance(ALL_SOLVERS)
```

```
/home/docs/checkouts/readthedocs.org/user_builds/lamberthub/envs/latest/lib/python3.8/site-packages/lamberthub/plotting/time.py:96: MatplotlibDeprecationWarning: Passing parameters norm and vmin/vmax simultaneously is deprecated since 3.3 and will become an error two minor releases later. Please pass vmin/vmax directly to the norm when creating it.
self.collection = self.ax.pcolor(
/home/docs/checkouts/readthedocs.org/user_builds/lamberthub/envs/latest/lib/python3.8/site-packages/lamberthub/plotting/time.py:106: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. This has been deprecated since 3.3 and in 3.6, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = mpl.cm.get_cmap("sunshine_9lev").copy()
self.collection.cmap.set_under("black")
```

## Total time required¶

```
import matplotlib.pyplot as plt
from lamberthub import ALL_SOLVERS
from lamberthub.plotting import TTCPlotter
def plot_time_performance(SOLVERS_LIST):
""" Plots the contour maps and a bar chart for a given set of solvers """
# Plots iterations performance for each one of the solvers from given set
for solver in SOLVERS_LIST:
fig_ctime, ax_ctime = plt.subplots()
iter_plotter = TTCPlotter(ax=ax_ctime, fig=fig_ctime)
iter_plotter.plot_performance(solver, N_samples=5)
plt.show()
plot_time_performance(ALL_SOLVERS)
```

```
/home/docs/checkouts/readthedocs.org/user_builds/lamberthub/envs/latest/lib/python3.8/site-packages/lamberthub/plotting/time.py:204: MatplotlibDeprecationWarning: Passing parameters norm and vmin/vmax simultaneously is deprecated since 3.3 and will become an error two minor releases later. Please pass vmin/vmax directly to the norm when creating it.
self.collection = self.ax.pcolor(
/home/docs/checkouts/readthedocs.org/user_builds/lamberthub/envs/latest/lib/python3.8/site-packages/lamberthub/plotting/time.py:214: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. This has been deprecated since 3.3 and in 3.6, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = mpl.cm.get_cmap("sunshine_9lev").copy()
self.collection.cmap.set_under("black")
```