-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove infinite loop in linear polymer #3491
Conversation
Cap the number of retries for monomer placement to `max_tries`, as explained in the function documentation.
The `linear_polymer_positions()` function already has a retry mechanism with a default value of max_tries=1000. Running the test 10000 times with a random Mersenne Twister seed resulted in no failure. A single run required 3 retries in one test function, all the other runs placed a polymer on the first try in every tests. 6 runs took 1 min instead of 250 ms to execute.
Codecov Report
@@ Coverage Diff @@
## python #3491 +/- ##
=======================================
+ Coverage 87% 87% +<1%
=======================================
Files 536 536
Lines 24400 24254 -146
=======================================
- Hits 21250 21132 -118
+ Misses 3150 3122 -28
Continue to review full report at Codecov.
|
@@ -186,6 +187,11 @@ draw_polymer_positions(PartCfg &partCfg, int const n_polymers, | |||
} else if (not positions[p].empty()) { | |||
/* Go back one position and try again */ | |||
positions[p].pop_back(); | |||
rejections++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain why this is needed? Couldn't you just increase attempts_poly
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, when the first one has fixed position. But there has to be a more elegant solution than this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this while loop doesn't increment attempts_poly
, therefore in high density systems, you can get stuck in an infinite cycle of deleting the previous bead and adding a new one at the same position
Description of changes:
draw_polymer_positions()
(regression from Fix polymer generation #3484)polymer_linear.py
test that used to hide a bug in the previous implementation ofdraw_polymer_positions()