-
Notifications
You must be signed in to change notification settings - Fork 93
Fix memory scaling calculation for non-periodic boundary conditions #412
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
Changes from all commits
f65c434
0585acf
5cc3069
b3e4d83
4249ee6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -363,7 +363,15 @@ def calculate_memory_scaler( | |
| if memory_scales_with == "n_atoms": | ||
| return state.n_atoms | ||
| if memory_scales_with == "n_atoms_x_density": | ||
| volume = torch.abs(torch.linalg.det(state.cell[0])) / 1000 | ||
| if all(state.pbc): | ||
| volume = torch.abs(torch.linalg.det(state.cell[0])) / 1000 | ||
| else: | ||
| bbox = state.positions.max(dim=0).values - state.positions.min(dim=0).values | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would using this as the general case fail? for example if we had a 2d system or surface with a lot of vacuum the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Neither is perfect in those cases but I agree a bounding box is better than cell. I am happy to make it the general case. Does a clamp value of 2 A make sense to you? Needed for flat molecules like benzene (though benzene isn't actually flat).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clamp is harder to reason about because there are some systems say metallic lithium where the unit cell is ~1A.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the limiting case is something flat anthracene in a vacuum. If you have two molecules far enough apart then this heuristic would fail. n_atoms*density is just to say it scales as the number of nearest neighbors? why not call a nl algorithm to estimate and go based on that?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's right but I am not quite intuiting how that would resolve the 2D vs 3D tradeoff. What would that look like in practice, call the neighbor list with a 5-6 A cutoff and then calculate A couple drawbacks:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should probably use a bounding box algorithm to start (it's very fast&simple logic). If we do want to do something more complicated (using neighborlists), we'd either have to calculate it twice or refactor a bit of code to get it to work well (since I think we determine the batches before we calculate the neighbors). If we do want to support neighborlist-based memory scaling, we'd probably make a new
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, I'll just do BB and add 2 A in every non-periodic direction to account for 2D systems and slabs |
||
| # add 2 A in non-periodic directions to account for 2D systems and slabs | ||
| for i, periodic in enumerate(state.pbc): | ||
| if not periodic: | ||
| bbox[i] += 2.0 | ||
| volume = bbox.prod() / 1000 # convert A^3 to nm^3 | ||
| number_density = state.n_atoms / volume.item() | ||
| return state.n_atoms * number_density | ||
| raise ValueError( | ||
|
|
||
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.
ik it's not added in this PR, but this 1000 feels like a magic number to me. we should at minimum have a comment explaining it - or make it configurable at most.
Uh oh!
There was an error while loading. Please reload this page.
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.
ill add a comment, once I remember what the 1000 is for... I think it's an A^3 -> nm^3 conversion