-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interface re-design: state and Lux model (#22)
Co-authored-by: Christoph Ortner <[email protected]> Co-authored-by: Teemu Järvinen <[email protected]>
- Loading branch information
1 parent
758dd4a
commit f15dd7f
Showing
14 changed files
with
868 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Index | ||
|
||
```@index | ||
``` | ||
|
||
```@autodocs | ||
Modules = [AtomsCalculators, AtomsCalculators.AtomsCalculatorsTesting, AtomsCalculators.Testing] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Previous Version of Interface Docs | ||
|
||
There are two alternative ways to call the interface: using functions `potential_energy`, `forces` and [virial](https://en.wikipedia.org/wiki/Virial_stress), or using `calculate` | ||
function together with `Energy`, `Forces` and `Virial`. | ||
|
||
Individual calls are implemented by dispatching `AtomsCalculators` functions | ||
|
||
- `AtomsCalculators.potential_energy` for potential energy calculation | ||
- `AtomsCalculators.forces` for allocating force calculation and/or... | ||
- `AtomsCalculators.forces!` for non-allocating force calculation | ||
- `AtomsCalculators.virial` for [virial](https://en.wikipedia.org/wiki/Virial_stress) calculation | ||
|
||
The `calculate` interface is implemented by dispatching to | ||
|
||
- `AtomsCalculators.calculate` using `AtomsCalculators.Energy()` as the first argument for energy calculation | ||
- `AtomsCalculators.calculate` using `AtomsCalculators.Forces()` as the first argument for forces calculaton | ||
- `AtomsCalculators.calculate` using `AtomsCalculators.Virial()` as the first argument for virial calculation | ||
|
||
You do not need to implement all of these by yourself. There is macro that will help implement the other calls. | ||
|
||
Each of the individual calls have two common inputs: `AtomsBase.AbstractSystem` compatible structure and a `calculator` that incudes details of the calculation method. Calculate interface has additionally the type of calculation as the first input. You can tune calculation by passing keyword arguments, which can be ignored, but they need to be present in the function definition. | ||
|
||
## High-level vs Low-level Interface | ||
|
||
The philosophy behing AtomsCalculators.jl is to provide high-level calls with default | ||
parameters through `potential_energy`, `forces`, `forces!` and `virial` and low-level calls | ||
with user-specifiable parameters through `calculate`. | ||
|
||
The low-level `calculate` interface follows the [Lux](https://lux.csail.mit.edu/stable/) model for parameters and state. This means that calculators are **immutable** structs that are passed | ||
to the `calculate` function together with `parameters` and `state`. All calculations then return | ||
an output and a state. | ||
|
||
When implementing a new calculator, two paths can be chosen: | ||
|
||
1. **Providing a full low level implementation** | ||
In this setup, one implements `calculate` for the various type of | ||
calculations to be supported, with full handling of parameters and state. **On top of that**, | ||
one should provide sensible **defaults** for calls with parameters and state set to `nothing`. | ||
These will be used to generate the high-level calls. | ||
2. **Only implementing high-level calls** | ||
In this case, one only implements the high-level `potential_energy`, `forces` and `virial` | ||
(or some of them). Appropriate low-level implementation for `calculate` is then automatically | ||
generated by using and returning dummy state and parameters set to `nothing`. | ||
|
||
Note that when using the high-level approach, fixed parameters are allowed to be bundled inside the calculator. | ||
|
||
### Method Signatures | ||
|
||
`potential_energy`, `forces`, `forces!` and `virial`: | ||
|
||
- First input is `AtomsBase.AbstractSystem` compatible structure | ||
- Second input is `calculator` structure | ||
- Method has to accept keyword arguments (they can be ignored) | ||
- Non-allocating force call `force!` has an AbstractVector as the first input, to which the evaluated force values are stored (look for more details below) | ||
|
||
`calculate`: | ||
|
||
- First input is either `Energy()`, `Forces()` or `Virial()` | ||
- Second is `AtomsBase.AbstractSystem` compatible structure | ||
- Third is `calculator` structure | ||
- Fourth is `parameters` | ||
- Fifth is `state` | ||
- Method has to accept keyword arguments (they can be ignored) | ||
|
||
## Output | ||
|
||
Outputs for the functions need to have following properties | ||
|
||
- Energy is a subtype of `Number` that has a unit with dimensions of energy (mass * length^2 / time^2) | ||
- Force output is a subtype of `AbstractVector` with element type also a subtype of AbstractVector (length 3 in 3D) and unit with dimensions of force (mass * length / time^2). With additional property that it can be reinterpret as a matrix | ||
- Virial is a square matrix (3x3 in 3D) that has units of force times length or energy | ||
- Calculate methods return a [NamedTuple](https://docs.julialang.org/en/v1/base/base/#Core.NamedTuple) that uses keys `:energy`, `:forces` and `:virial` to identify the results, which have the types defined above, and additionally returns the updated `:state`. | ||
|
Oops, something went wrong.