Skip to content
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

Raise exception when derivatives are requested from non-differentiable restraint #1020

Open
sethaxen opened this issue Sep 7, 2019 · 0 comments

Comments

@sethaxen
Copy link
Contributor

sethaxen commented Sep 7, 2019

While there are use cases in generic integrative modeling where one might want to use the gradients of a subset of the scoring function, this is dangerous when using MD and gradient-based Markov Chain Monte Carlo techniques. Restraints with non-constant scores that don't accumulate derivatives modify the score/energy without modifying the gradients/forces accordingly; consequently, the moves will in general not be valid.

Here's an example for IMP::isd::CysteineCrossLinkRestraint:

double CysteineCrossLinkRestraint::unprotected_evaluate(
DerivativeAccumulator *accum) const {
double score;
double prob = get_probability();
// check if probability is too low (e.g. equal to zero)
// and assign its value to the smallest double
if (prob <= std::numeric_limits<double>::epsilon()) {
prob = std::numeric_limits<double>::epsilon();
}
score = -log(prob);
if (accum) {
}
return score;
}

A warning when derivatives are requested from such a restraint seems the least disruptive way to go, but perhaps we want to be disruptive here. An alternative would be a special exception macro, something like IMP_NON_DIFFERENTIABLE_EXCEPTION, which the user could disable with something like IMP_CHECK_NON_DIFFERENTIABLE(false).

I can't think of an easy way to raise a warning/exception whenever this happens except to modify the unprotected_evaluate statements for all such restraints. For example, in the above restraint, we would make a modification like:

   if (accum) {
      IMP_NON_DIFFERENTIABLE_EXCEPTION("Derivatives are not computed.");
   } 

This would especially help when the user does not directly interact with the IMP restraint, such as when using PMI. This would also be part of an effort to catalog what is missing from all IMP restraints being fully differentiable. The downside to this approach is that it takes no steps towards ensuring that all derivatives are computed correctly.

Thoughts on this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant