Page 1 of 1
IPOPT output to opensim.log
Posted: Tue May 09, 2023 4:17 pm
by carlosoleto
Hello everyone,
Is there a way to save the IPOPT output (iteration per iteration) to opensim.log?
Best regards.
Re: IPOPT output to opensim.log
Posted: Wed May 10, 2023 5:09 pm
by aafox
Hi Carlos,
There's a useful feature in newer versions of OpenSim (can't remember when it was added) that allows you to specify a file where the output writes to. I often split this up for different analyses steps (e.g. scaling, IK, Moco etc.) - and doing so should write the IPOPT output to file.
In python you would use:
Code: Select all
import opensim as osim
#Remove any existing file logger
osim.Logger.removeFileSink()
#Add a new file to log to
osim.Logger.addFileSink('fileName.log')
Hope that helps.
Aaron
Re: IPOPT output to opensim.log
Posted: Fri May 12, 2023 6:26 am
by carlosoleto
Thanks a lot Aaron.
I tried your code, and it worked, but I'm still without the IPOPT iteration messages in the log.
Here is what I got:
Code: Select all
[2023-05-12 07:20:33.937] [info] Number of threads: 10
[2023-05-12 07:26:03.851] [info] Set log level to Trace.
[2023-05-12 07:26:03.888] [info] ------------------------------------------------------------------------
[2023-05-12 07:26:03.888] [info] Elapsed real time: 331 second(s) (5 minute(s), 31 second(s)).
[2023-05-12 07:26:03.888] [info] Fri May 12 07:26:03 2023
[2023-05-12 07:26:03.888] [warning] MocoCasADiSolver did NOT succeed:
[2023-05-12 07:26:03.888] [warning] User_Requested_Stop
[2023-05-12 07:26:03.888] [info] ========================================================================
So, after setting the number of threads, IPOPT kicks in and starts sending his messages in the console. All the information about the objective goal and so on. That's what I'm missing.
In the end, IPOPT finishes, and I get the answer about convergence succeeding or failing in the log.
Any suggestions?
Best regards.
Re: IPOPT output to opensim.log
Posted: Fri May 12, 2023 10:11 am
by nbianco
Hi Carlos,
This is probably because the Logger controls all the output messages created by OpenSim, but not by the ones created by Matlab. To fix, I think we'd need to somehow pipe the IPOPT output into the output stream that's managed by OpenSim.
Unless...Aaron, have you gotten IPOPT output to save to a file using OpenSim::Logger()?
-Nick
Re: IPOPT output to opensim.log
Posted: Thu May 25, 2023 2:51 pm
by silvestros
Hi Guys,
Carlos you could create a file called ipopt.opt (
https://coin-or.github.io/Ipopt/OPTIONS.html) in the directory you are calling it from and specify a file IPOPT to print to after it is done. I have not done it for this exact problem but have used ipopt.opt file in the past as a work around where I can't get access to IPOPT through the OpenSim API.
Let me know if it works!
Cheers,
Pavlos
Re: IPOPT output to opensim.log
Posted: Thu May 25, 2023 5:02 pm
by aafox
Hi Nick, Pavlos & Carlos,
I just double checked the outputs from some recent simulations we ran, and I have the same sort of output as Carlos - where the iterations are missing. I had assumed that the log was capturing everything in the MATLAB output window. I've checked some of my work in Python as well and it's the same thing in the logs.
Aaron
Re: IPOPT output to opensim.log
Posted: Tue May 30, 2023 11:36 am
by nbianco
Thanks Pavlos!
That seems like the way to go until we figure out a way to get all output always piped to the Matlab console.
-Nick
Re: IPOPT output to opensim.log
Posted: Thu Nov 23, 2023 4:32 am
by deyvidpi
Thanks Pavlos!
Another way to do it is by redirecting everything like so:
But you can't always do that, like if you want to define your log path in the python script. With your method, here is how I go about it:
Create ipopt.opt and add this single line:
python script
Code: Select all
import opensim as osim
osim.Logger.removeFileSink()
osim.Logger.addFileSink('full_log.log')
<your moco code>
with open('full_log.txt', 'a') as opensim_log_f:
with open('last_log.txt', 'r') as ipopt_log_f:
opensim_log_f.write(ipopt_log_f.read())
It save almost everything, but the following lines. Are they the output of CasADi rather that of IPOPT? Would anyone have an idea of how to save them?
Code: Select all
nlp : t_proc (avg) t_wall (avg) n_eval
callback_fun | 1.00ms ( 52.63us) 1.53ms ( 80.44us) 19
nlp_f | 0 ( 0) 277.00us ( 14.58us) 19
nlp_g | 82.00ms ( 4.32ms) 80.71ms ( 4.25ms) 19
nlp_grad_f | 2.00ms (100.00us) 3.65ms (182.64us) 20
nlp_jac_g | 148.00ms ( 7.40ms) 147.23ms ( 7.36ms) 20
total | 271.00ms (271.00ms) 271.68ms (271.68ms) 1
Breakdown of objective (including weights):
goal: 0.402694
Re: IPOPT output to opensim.log
Posted: Thu Nov 23, 2023 10:33 am
by nbianco
Hi David,
Yes, those lines are specific to CasADi/Moco. They should at least get printed to the opensim.log file for now, until we find a way to have everything piped to the same file.
-Nick