[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[IMP-dev] More small patches



- Modify MaxChangeScoreState to use the list macros.


- Clean up various attempts at automatically picking parameters in the nonbonded lists. For now just have them be user setable.

Also, I don't think that functions which are not part of the API should be given doxygen comments.
Index: kernel/include/IMP/score_states/MaxChangeScoreState.h
===================================================================
--- kernel/include/IMP/score_states/MaxChangeScoreState.h	(revision 560)
+++ kernel/include/IMP/score_states/MaxChangeScoreState.h	(working copy)
@@ -27,9 +27,7 @@
 {
   FloatKeys keys_;
   FloatKeys origkeys_;
-  Particles ps_;
   float max_change_;
-  virtual void do_before_evaluate();
 public:
   //! Track the changes with the specified keys.
   MaxChangeScoreState(const FloatKeys &keys,
@@ -37,6 +35,8 @@
 
   virtual ~MaxChangeScoreState(){}
 
+  IMP_SCORE_STATE(internal::kernel_version_info);
+
   //! Measure differences from the current value.
   void reset();
 
Index: kernel/src/score_states/MaxChangeScoreState.cpp
===================================================================
--- kernel/src/score_states/MaxChangeScoreState.cpp	(revision 560)
+++ kernel/src/score_states/MaxChangeScoreState.cpp	(working copy)
@@ -74,4 +74,8 @@
   max_change_=0;
 }
 
+void MaxChangeScoreState::show(std::ostream &out) const {
+  out << "MaxChangeScoreState" << std::endl;
+}
+
 } // namespace IMP
Index: kernel/include/IMP/score_states/NonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/NonbondedListScoreState.h	(revision 560)
+++ kernel/include/IMP/score_states/NonbondedListScoreState.h	(working copy)
@@ -42,15 +42,19 @@
   /** How much to add to the size of particles to allow particles to move
       without rebuilding the list */
   Float slack_;
-  //! An estimate of what the slack should be next time the list is recomputed
-  Float next_slack_;
-  int num_steps_;
   bool nbl_is_valid_;
   int number_of_rebuilds_;
   int number_of_updates_;
+  int number_of_overflows_;
+  //! The maximum allowable size for the NBL
+  /** An exception will be thrown if the list exceeds this size.
+   */
+  unsigned int max_nbl_size_;
   typedef std::vector<std::pair<Particle*, Particle*> > NBL;
   NBL nbl_;
 
+  struct NBLTooLargeException{};
+
 protected:
 
   Float get_slack() const {return slack_;}
@@ -93,7 +97,11 @@
     if (!are_bonded(a,b)) {
       IMP_LOG(VERBOSE, "Found pair " << a->get_index() 
         << " " << b->get_index() << std::endl);
-      nbl_.push_back(std::make_pair(a, b));
+      if (nbl_.size() <  max_nbl_size_) {
+        nbl_.push_back(std::make_pair(a, b));
+      } else {
+        throw NBLTooLargeException();
+      }
     } else {
       IMP_LOG(VERBOSE, "Pair " << a->get_index()
               << " and " << b->get_index() << " rejected on bond" 
@@ -184,6 +192,29 @@
   FloatKey get_radius_key() const {return rk_;}
   void set_radius_key(FloatKey rk) {rk_=rk;} 
 
+  //! Set the maximum allowable size for the NBL
+  /** The NBL will keep reducing the slack and trying to
+      rebuild until it can make the list smaller than this.
+   */
+  void set_max_size(unsigned int mx) {
+    max_nbl_size_= mx;
+  }
+
+
+  //! Set the slack used when generating the NBL
+  /** The slack allows the the NBL to non be rebuilt every step
+      making the process more efficient. However, too large
+      a value can result in the NBL being excessively large.
+
+      A good guideline is that it should be the maximum amount
+      a particle coordinate would change in 20 steps or so.
+   */
+  void set_slack(float slack) {
+    IMP_check(slack>= 0, "Slack must be nonnegative",
+              ValueException("Negative slack"));
+    slack_=slack;
+  }
+
   IMP_CONTAINER(BondedListScoreState, bonded_list,
                 BondedListIndex);
 
Index: kernel/src/score_states/NonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/NonbondedListScoreState.cpp	(revision 560)
+++ kernel/src/score_states/NonbondedListScoreState.cpp	(working copy)
@@ -37,11 +37,11 @@
                                         cutoff_(cut),
                                         nbl_is_valid_(false)
 {
-  slack_=20;
-  next_slack_=slack_;
-  num_steps_=1;
+  slack_=cutoff_;
   number_of_updates_=1;
   number_of_rebuilds_=0;
+  number_of_overflows_=0;
+  max_nbl_size_= std::numeric_limits<unsigned int>::max();
 }
 
 
@@ -55,7 +55,9 @@
 {
   out << "Nonbonded list averaged " 
       << static_cast<Float>(number_of_updates_)
-      / number_of_rebuilds_ << " steps between rebuilds" << std::endl;
+      / number_of_rebuilds_ << " steps between rebuilds"
+      << " and overflowed " <<  number_of_overflows_ 
+      << " times" << std::endl;
 }
 
 
@@ -96,47 +98,25 @@
     (*bli)->before_evaluate(ScoreState::get_before_evaluate_iteration());
   }
 
-  if (nbl_is_valid_) {
-    /*std::cout << "Rate is " << rate << " target is " << target_steps
-              << " so slack is " << target_slack << " mc " << mc
-              << " nbl " << nbl_.size() << " cost " 
-              << rebuild_cost << std::endl;*/
-    if (mc > slack_) {
-      /*    Float rate= std::pow(static_cast<Float>(nbl_.size()),
-            .333f)/ num_steps_;
-            Float target_steps= .6*std::pow(rebuild_cost, .25f)
-            *std::pow(rate, -.75f);
-            Float target_slack= (target_steps+1)*mc/num_steps_;
-            next_slack_= target_slack*.5 + .5*next_slack_;
-      */
-
-      /*std::cout << "Killing nbl because " << mc << " 
-        << slack_ << " " << next_slack_ 
-        << " " << num_steps_ << std::endl;*/
-      if (num_steps_ < 50) {
-        //slack_= next_slack_;
-      }
-      num_steps_=1;
-      //next_slack_= std::max(2.0*mc, 2.0*slack_);
-      set_nbl_is_valid(false);
-      ++number_of_rebuilds_;
-      slack_=next_slack_;
-    /*} else if (num_steps_ > 100) {
-      //next_slack_=slack_/2.0;
-      slack_=next_slack_;
-      num_steps_=1;
-      set_nbl_is_valid(false);
-      ++number_of_rebuilds_;*/
-    } else {
-      ++num_steps_;
-      //next_slack_= next_slack_*.98;
-    }
-  }
-
   bool rebuilt=false;
   if (!get_nbl_is_valid()) {
-    rebuild_nbl();
-    rebuilt=true;
+    unsigned int rebuild_attempts=0;
+    do {
+      try {
+        ++rebuild_attempts;
+        ++number_of_rebuilds_;
+        rebuild_nbl();
+        rebuilt=true;
+      } catch (NBLTooLargeException &) {
+        slack_= slack_/2.0;
+        ++number_of_overflows_;
+        if (number_of_rebuilds_==100) {
+          IMP_WARN("Can't rebuild NBL with given max NBL size of "
+                   << max_nbl_size_ << std::endl);
+          throw ValueException("Bad NBL max size");
+        }
+      }
+    } while (!rebuilt);
   } else {
     nbl_.erase(std::remove_if(nbl_.begin(), nbl_.end(), 
                               internal::HasInactive()),