# Obtaining solver timings from Pyomo

I would like to seek some advice on the following:

I am currently using Pyomo to generate my MILP model in Pyomo and solve it using Gurobi, respectively.

As the solution process is iterative, I would like to enquire on how to obtain the following timings for each iteration:

1. the time to build the Pyomo model
2. the time to translate the Pyomo model into the format used by the solver
3. the time spent inside the solver, i.e., the solution time
4. the time spent loading the solver solution back into Pyomo.

Thank you!

For timing within the gurobi solver, maybe you can call <optimizer>.solve() method with report_timing=True, as described in pyomo's documentation at https://pyomo.readthedocs.io/en/stable/library_reference/solvers/gurobi_persistent.html

I haven't used Gurobi before. If gurboipy logs the starting and ending time of the optimization, then you can manually time the start and end of your whole program. That would give you 4 and 1 + 2.

I think importing python library is slow. You can exclude the time for importing libraries.

I don't know how to split 1 and 2 at the moment.

• Thanks, but this is jus echoing the output to the screen, besides I am not using the 'gurobi_persistent' for the solver factory. I am just using 'gurobi' for the solver factory
– Mike
Jun 29 at 8:06
• capture stdout and extract the timing. Jun 29 at 12:44
• groups.google.com/g/pyomo-forum/c/ajoPqgmJ0rQ?pli=1 Jun 29 at 13:59
• Thanks, but I am not sure if it is of any help, as I would like to log it down programmatically into dictionary with with keys being that of each iteration number.
– Mike
Jun 29 at 16:31