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

ContextCache retrieves same context with two consecutive calls. #252

Merged
merged 1 commit into from
Jul 12, 2017

Conversation

andrrizzi
Copy link
Contributor

This fixes a problem where in some cases ContextCache.get_context(state, integrator=None) would pick two different Contexts after two consecutive calls with the same state. The advantage of having always the same context is that the user doesn't necessarily have to set positions and save some time.

Copy link
Contributor

@Lnaden Lnaden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes themselves look good, I just noticed something else which is bugging me though. I may just not be familiar enough with the cache though.

# Multiple matches, prefer the non-default Integrator.
# Always pick the least recently used to make two consective
# calls retrieving the same integrator.
for context_id in reversed(matching_context_ids):
if context_id[1] != self._default_integrator_id():
context = self._lru[context_id]
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat related to the problem, but actually older

Although you make this "prefer" the non default integrator, won't this never select the default integrator? Since you reject every integrator id matching default, I don't see where the default selection actually comes in. Wouldn't you need a line before the for loop starts to select the default integrator and replace it in the loop if the if condition is met?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion, the default integrator should actually be selected only if it's the only available option in the elif just above it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so let me run through the list of conditions to make sure its all handled I don't miss anything:

  1. No context: pick the default (main if)
  2. One context (could be the default), pick the one (elif)
  3. Multiple contexts, may be default, try to pick the non-default (else)

Is there ever going to be a case where multiple contexts are picked and they are all the default integrator? I know that each context/integrator pair is unique, but the default can just be cloned and fed into multiple contexts. I don't know if by this point the default is paired up and can't be used again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly.

but the default can just be cloned and fed into multiple contexts

If it happens, it means that the thermodynamic states of the multiple contexts are incompatible, so only one will end up in matching_context_ids.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so long as its accounted for. Switching to approve

@andrrizzi andrrizzi merged commit 9e29979 into master Jul 12, 2017
@andrrizzi andrrizzi deleted the deterministic-cache branch July 12, 2017 16:39
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

Successfully merging this pull request may close these issues.

2 participants