sponge.optimizer.Updater
- class sponge.optimizer.Updater(system: Molecule, controller: Union[Controller, List[Controller]] = None, time_step: float = 0.001, velocity: Union[Tensor, ndarray, List[float]] = None, weight_decay: float = 0.0, loss_scale: float = 1.0, **kwargs)[source]
Base class of the MindSPONGE updater, which is a special subclass of the Optimizer in MindSpore. The Updater updates the atomic coordinates of the simulation system. The updating of atomic coordinates requires atomic forces and atomic velocities, where the force is passed from outside and the velocity is the parameter of the Updater itself. And in the case of periodic boundary conditions (PBC), the Updater could also update the size of the PBC box by the virial of the simulation system. The “Updater” controls the values of seven variables during the simulation through a series of Controller: coordinates, velocity, force, energy, kinetics, virial and pbc_box. If more than one Controller is passed in, they will work in sequence.
- Parameters
system (Molecule) – Simulation system.
controller (Union[Controller, List[Controller]]) – Controller or list of controllers to control the seven variables (coordinate, velocity, force, energy, kinetics, virial and pbc_box) of the simulation system. Default:
None
.time_step (float) – Time step. Default:
1e-3
.velocity (Union[Tensor, ndarray, List[float]]) – Array of atomic velocity. The shape of array is (A, D) or (B, A, D), and the data type is float. Default:
None
.weight_decay (float) – An value for the weight decay. Default:
0.0
.loss_scale (float) – A value for the loss scale. Default:
1.0
.kwargs (dict) – other args.
- Inputs:
energy (Tensor) - Energy of the system. Tensor of shape (B, A, D). Data type is float.
force (Tensor) - Force of the system. Tensor of shape (B, A, D). Data type is float.
virial (Tensor) - Virial of the system. Tensor of shape (B, A, D). Data type is float. Default:
None
.
- Outputs:
bool, whether successfully finish the current optimization step and move to next step.
Note
B: Batchsize, i.e. number of walkers in simulation A: Number of atoms. D: Spatial dimension of the simulation system. Usually is 3.
- Supported Platforms:
Ascend
GPU
- property boltzmann: float
Boltzmann constant in current unit.
- Returns
float, Boltzmann constant in current unit.
- decay_and_scale_grad(force: Tensor, virial: Tensor = None)[source]
Do weight decay and gradient scale for force and virial.
- Parameters
force (Tensor) – Tensor of force. Data type is float.
virial (Tensor) – Tensor of virial. Data type is float. Default:
None
.
- Returns
Tensor, Tensor of force after weight decay and gradient scale.
Tensor, Tensor of virial after weight decay and gradient scale. If pbc_box is None, the output virial is the same as input.
- get_dt()[source]
Get the learning rate of current step.
- Returns
float, the learning rate of current step.
- get_kinetics(velocity: Tensor)[source]
Get kinectics.
- Parameters
velocity (Tensor) – Tensor of atom velocities. Data type is float.
- Returns
Tensor, the kinectics of the system.
- get_pressure(kinetics: Tensor, virial: Tensor, pbc_box: Tensor)[source]
Get pressure.
- Parameters
kinetics (Tensor) – Tensor of kinetics. Data type is float.
virial (Tensor) – Tensor of virial. Data type is float.
pbc_box (Tensor) – Tensor of pbc_box. Data type is float.
- Returns
Tensor, the pressure of the system.
- get_temperature(kinetics: Tensor = None)[source]
Get temperature.
- Parameters
kinetics (Tensor) – Tensor of kinetics. Data type is float. Default:
None
.- Returns
Tensor, the temperature of the system.
- next_step(success: bool = True)[source]
Finish the current optimization step and move to next step.
- Parameters
success (bool) – Whether to finish the current optimization step and move to next step. Default:
True
.- Returns
bool, whether successfully finish the current optimization step and move to next step.
- property press_unit_scale: float
Reference value of pressure.
- Returns
float, reference value of pressure.
- set_degrees_of_freedom(dofs: int)[source]
Set degrees of freedom (DOFs)
- Parameters
dofs (int) – Degrees of freedom.
- set_step(step: int = 0)[source]
Set current step of the system.
- Parameters
step (int) – Current step of the system. Default: 0
- update_coordinate(coordinate: Tensor, success: bool = True)[source]
Update the parameters of coordinate
- Parameters
coordinate (Tensor) – Tensor of atomic coordinates. Data type is float.
success (bool) – Whether to update the coordinate. Default:
True
.
- Returns
bool, whether successfully update the coordinate.
- update_kinetics(kinetics: Tensor, success: bool = True)[source]
Update the parameters of kinetics.
- Parameters
kinetics (Tensor) – Tensor of kinetics. Data type is float.
success (bool) – Whether to update the kinetics. Default:
True
.
- Returns
bool, whether successfully update the parameters of kinetics.
- update_pbc_box(pbc_box: Tensor, success: bool = True)[source]
Update the parameters of PBC box.
- Parameters
pbc_box (Tensor) – Tensor of PBC box. Data type is float.
success (bool) – Whether to update the pbc_box. Default:
True
.
- Returns
bool, whether successfully update the parameters of PBC box.
- update_pressure(pressure: Tensor, success: bool = True)[source]
Update the parameters of pressure.
- Parameters
pressure (Tensor) – Tensor of pressure. Data type is float.
success (bool) – Whether to update the pressure. Default:
True
.
- Returns
bool, whether successfully update the parameters of pressure.
- update_temperature(temperature: Tensor, success: bool = True)[source]
Update the parameters of temperature.
- Parameters
temperature (Tensor) – Tensor of temperature. Data type is float.
success (bool) – Whether to update the temperature. Default:
True
.
- Returns
bool, whether successfully update the parameters of temperature.
- update_velocity(velocity: Tensor, success: bool = True)[source]
Update the parameters of velocity.
- Parameters
velocity (Tensor) – Tensor of atomic velocities. Data type is float.
success (bool) – Whether to update the velocities. Default:
True
.
- Returns
bool, whether successfully update the parameters of atomic velocities.