Is CMAES optimizer working well?

Simbody is useful for internal coordinate and coarse grained molecule modeling, large scale mechanical models like skeletons, and anything else that can be modeled as bodies interconnected by joints, acted upon by forces, and restricted by constraints.
User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Is CMAES optimizer working well?

Post by Jiang Ping » Tue Aug 04, 2015 3:43 pm

hi all,

I am using CMAES optimizer to optimize my objective function.
If I didnt run it by multithread, it would work well, but get stuck after several steps when I enable multithread option.
Anyone has meet the similar problem?

thanks in advance,
jiang

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Is CMAES optimizer working well?

Post by Christopher Dembia » Tue Aug 04, 2015 4:31 pm

Hey Jiang:

We have some test case that tests the multithreaded use of CMAES. Have you tried running the Simbody tests? If so, doest CMAESTest pass?

What do you mean by "gets stuck"? The code hangs? Is there any possibility that you're doing something in your objective function that is not threadsafe? Does it reliably get stuck? After how many iterations? You can try to get more information about what's happening by setting the diagnostics level of the optimizer:

Code: Select all

Optimizer opt = SimTK::Optimizer(sys, SimTK::CMAES);
opt.setDiagnosticsLevel(3);
The diagnostics levels are documented here in the CMAES section of the class description: https://simtk.org/api_docs/simbody/late ... mizer.html

User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Re: Is CMAES optimizer working well?

Post by Jiang Ping » Tue Aug 04, 2015 6:05 pm

hi,

Thanks for the rapid reply. I have run several times and the code hanged after 20-50 iterations(Each time is different).
I used a mutable variable to record the optimization steps. To keep thread safe, I created mutex to avoid modifying it by different threads. now I declared them in global scope. Maybe this was problematic.

Thanks for your help.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Is CMAES optimizer working well?

Post by Christopher Dembia » Tue Aug 04, 2015 7:33 pm

Jiang:

Does the code still hang if you *don't* use that mutable variable?

User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Re: Is CMAES optimizer working well?

Post by Jiang Ping » Wed Aug 05, 2015 10:12 am

hi,

Thanks again for your reply.
I deleted all mutable variables but the code still hang. I tried to locate where it get stuck and found it continued doing some update of Delay Measure data.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Is CMAES optimizer working well?

Post by Christopher Dembia » Wed Aug 05, 2015 10:25 am

Jiang:

I'm not sure how you're using the Delay Measure or what you're doing in your objective function but perhaps you should use a lock on the state object? Are you using the same state object on multiple threads? We are currently working on a change to Simbody that makes locking the state more convenient; this change should be in the next release of Simbody (https://github.com/simbody/simbody/pull/414/files).

User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Re: Is CMAES optimizer working well?

Post by Jiang Ping » Wed Aug 05, 2015 10:51 pm

hi,

The state is not shared by threads. I created state object in the objective function.
I used valgrind to check memory leak. Attachment is the log. I found there will be a little memory leak after calling setProporties() of a model component, and after creating a new thread by parallel executor. I am continue checking now.

Thanks for your help,
Jiang
Attachments
Jlog.txt
memory check log
(361.48 KiB) Downloaded 66 times

User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Re: Is CMAES optimizer working well?

Post by Jiang Ping » Thu Aug 06, 2015 12:07 am

Update the progress. I deleted Object::registerType( Delp1990Muscle_Deprecated() );.
Now only 5 memory leak remains.

best regards,
jiang
Attachments
Jlog2.log
(7.93 KiB) Downloaded 59 times

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Is CMAES optimizer working well?

Post by Christopher Dembia » Thu Aug 06, 2015 4:33 pm

Jiang:

Thanks for running valgrind. We have some github issues related to memory leaks (https://github.com/opensim-org/opensim-core/issues/170). We would like to get rid of the memory leak you mention, but unfortunately the fix you suggest won't work for us since we still use that Delp1990Muscle_Deprecated class.

If you have fixes to the leaks, we would appreciate your contribution to the OpenSim source code :).

I don't understand how the leaks relate to your CMAES issues, though. Could you be more specific about "it continued doing some update of Delay Measure data."? Do you know exactly which variables are causing the issue?

Even if you are using a different state on each thread, are you using the same System (or OpenSim Model, since it seems like you're using OpenSim) on each thread? What if you also make a copy of the model on each thread?

I see that the SimTK::Measure uses a Measure_Delay_Buffer underneath, and I was thinking that perhaps the data in this class is not thread-safe, but this buffer object is stored in the state, so I don't think that's the issue.

User avatar
Jiang Ping
Posts: 132
Joined: Sun Aug 26, 2012 4:09 am

Re: Is CMAES optimizer working well?

Post by Jiang Ping » Fri Aug 07, 2015 11:40 pm

Memory leak in Coordinate::_lockFunction (a ModifiableConstant)
https://github.com/opensim-org/opensim-core/issues/127

This leak does not result from the _lockFunction. it occurs because you called Model::setup() twice.
The first time was called by Model(string filename), the second time was called by Model::buildSystem()
The memory for second call was released by SimTK, but the memory for first call is still there.
We need to release it. After calling Model(string filename);
I will try to fix it

And this is the last memory leak I need to fix.

best regards,
jiang

POST REPLY