Objective_function.cpu_objective_function module¶
Description¶
This module defines the ParaMol.Objective_function.cpu_objective_function.CPUObjectiveFunction class used by ParaMol to perform parallel evaluation of the objective function using CPUs.
-
class
ParaMol.Objective_function.cpu_objective_function.CPUObjectiveFunction¶ Bases:
objectParaMol’s wrapper for the CPU parallel callback function.
- Variables
X (list) – List containing conformations data.
calculate_energies (bool) – Flag that controls whether or not the energies will be calculated.
calculate_energies – Flag that controls whether or not the forces will be calculated.
n_atoms (int) – Number of atoms of the system-
Notes
Unix implementation of multiprocessing uses forks. This will not work under Windows. When running under Unix, all workers may share the same object, due to how fork works (i.e., the child processes have separate memory but it’s copy-on-write, so it may be shared as long as nobody modifies it). In copy-on-write the fundamental idea is that if multiple callers ask for resources which are initially indistinguishable, you can give them pointers to the same resource. This function can be maintained until a caller tries to modify its “copy” of the resource, at which point a true private copy is created to prevent the changes becoming visible to everyone else. All of this happens transparently to the callers. The primary advantage is that if a caller never makes any modifications, no private copy need ever be created.
-
f_callback_function(context, system_id, worker_id)¶ Method that may be used as a callback function for the parallel computation of the objective function using CPUs.
- Parameters
context (
ParaMol.Objective_function.pickable_swig.PickalableContext) – Pickalable OpenMM context.system_id (int) – Index of the OpenMM system copy.
worker_id (int) – Index of the parallel worker.
- Returns
emm_data, fmm_data (np.array(batch_size), np.array(batch_size, n_atoms, 3)) – Arrays containing MM energies and forces.
-
static
init_worker()¶ Method that is the constructor for the Pool of workers. It Contains a global dictionary with variables shared between threads.
- Returns
None