Is CMAES optimizer working well?
- Jiang Ping
- Posts: 132
- Joined: Sun Aug 26, 2012 4:09 am
Is CMAES optimizer working well?
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
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
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Is CMAES optimizer working well?
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:
The diagnostics levels are documented here in the CMAES section of the class description: https://simtk.org/api_docs/simbody/late ... mizer.html
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);
- Jiang Ping
- Posts: 132
- Joined: Sun Aug 26, 2012 4:09 am
Re: Is CMAES optimizer working well?
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.
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.
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Is CMAES optimizer working well?
Jiang:
Does the code still hang if you *don't* use that mutable variable?
Does the code still hang if you *don't* use that mutable variable?
- Jiang Ping
- Posts: 132
- Joined: Sun Aug 26, 2012 4:09 am
Re: Is CMAES optimizer working well?
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.
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.
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Is CMAES optimizer working well?
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).
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).
- Jiang Ping
- Posts: 132
- Joined: Sun Aug 26, 2012 4:09 am
Re: Is CMAES optimizer working well?
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
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 79 times
- Jiang Ping
- Posts: 132
- Joined: Sun Aug 26, 2012 4:09 am
Re: Is CMAES optimizer working well?
Update the progress. I deleted Object::registerType( Delp1990Muscle_Deprecated() );.
Now only 5 memory leak remains.
best regards,
jiang
Now only 5 memory leak remains.
best regards,
jiang
- Attachments
-
- Jlog2.log
- (7.93 KiB) Downloaded 68 times
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Is CMAES optimizer working well?
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.
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
![Smile :)](./images/smilies/icon_e_smile.gif)
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.
- Jiang Ping
- Posts: 132
- Joined: Sun Aug 26, 2012 4:09 am
Re: Is CMAES optimizer working well?
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
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