4

How can I get an output from GEKKO on how long it took to solve my model? I know based off of Measure time elapsed in Python that I can get my code to print the total time taken to run my code but I do not know how to isolate the solver time.

from gekko import GEKKO
import time
start = time.time()
m = GEKKO(remote=False)
x = m.Var(value=0)
y = m.Var(value=1)
m.Equations([x + 2*y==0, x**2+y**2==1])
s1 = time.time()
m.solve(disp=True)
e1 = time.time()
print([x.value[0],y.value[0]])
end = time.time()
print('Total Elapsed: ' + str(end-start))
print('Solver Time 1: ' + str(e1-s1))

Solver Time 1 is listed as 0.18468 sec but this is different than the IPOPT reported time of 0.0156 sec. How can I programmatically get the solver reported time?

EXIT: Optimal Solution Found.

 The solution was found.

 The final value of the objective function is  0.

 ---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :  0.0156 sec
John Hedengren
  • 12,068
  • 1
  • 21
  • 25
dmccrea
  • 43
  • 3

1 Answers1

3

You can see the solver reported time with m.options.SOLVETIME such as:

print('Solver Time 2: ', m.options.SOLVETIME)

Solver Time 1 includes the setup and solution transfer. You can speed up the total time by not displaying the solver output with disp=False and solving locally instead of on a remote server with remote=False. A local solve generally reduces the amount of time it takes to send to a server and retrieve a solution but there are fewer solver options with a local solve.

John Hedengren
  • 12,068
  • 1
  • 21
  • 25