Helper functions for GP

flare.gp_algebra.efs_energy_vector(name, efs_energy_kernel, x, hyps, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

Returns covariances between the local eneregy, force components, and partial stresses of a test environment and the total energy labels in the training set.

flare.gp_algebra.efs_force_vector(name, efs_force_kernel, x, hyps, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

Returns covariances between the local eneregy, force components, and partial stresses of a test environment and the force labels in the training set.

flare.gp_algebra.energy_energy_vector(name, kernel, x, hyps, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

Get a vector of covariances between the local energy of a test environment and the total energy labels in the training set.

flare.gp_algebra.energy_energy_vector_unit(name, s, e, x, kernel, hyps, cutoffs=None, hyps_mask=None, d_1=None)

Gets part of the energy/energy vector.

flare.gp_algebra.energy_force_vector(name, kernel, x, hyps, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

Get the vector of covariances between the local energy of a test environment and the force labels in the training set.

flare.gp_algebra.energy_force_vector_unit(name, s, e, x, kernel, hyps, cutoffs=None, hyps_mask=None, d_1=None)

Gets part of the energy/force vector.

flare.gp_algebra.force_energy_vector(name, kernel, x, d_1, hyps, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

Get a vector of covariances between a force component of a test environment and the total energy labels in the training set.

flare.gp_algebra.force_energy_vector_unit(name, s, e, x, kernel, hyps, cutoffs, hyps_mask, d_1)

Gets part of the force/energy vector.

flare.gp_algebra.force_force_vector(name, kernel, x, d_1, hyps, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

Get a vector of covariances between a force component of a test environment and the force labels in the training set.

flare.gp_algebra.force_force_vector_unit(name, s, e, x, kernel, hyps, cutoffs, hyps_mask, d_1)

Gets part of the force/force vector.

flare.gp_algebra.get_distance_mat_pack(hyps: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53befb4390>, name: str, s1: int, e1: int, s2: int, e2: int, same: bool, kernel, cutoffs, hyps_mask)

Compute covariance matrix element between set1 and set2 :param hyps: list of hyper-parameters :param name: name of the gp instance. :param same: whether the row and column are the same :param kernel: function object of the kernel :param cutoffs: The cutoff values used for the atomic environments :type cutoffs: list of 2 float numbers :param hyps_mask: dictionary used for multi-group hyperparmeters :return: covariance matrix

flare.gp_algebra.get_force_block(hyps: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53befb4d50>, name: str, kernel, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

parallel version of get_ky_mat :param hyps: list of hyper-parameters :param name: name of the gp instance. :param kernel: function object of the kernel :param cutoffs: The cutoff values used for the atomic environments :type cutoffs: list of 2 float numbers :param hyps_mask: dictionary used for multi-group hyperparmeters

Returns:covariance matrix
flare.gp_algebra.get_force_block_pack(hyps: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53befb4410>, name: str, s1: int, e1: int, s2: int, e2: int, same: bool, kernel, cutoffs, hyps_mask)

Compute covariance matrix element between set1 and set2 :param hyps: list of hyper-parameters :param name: name of the gp instance. :param same: whether the row and column are the same :param kernel: function object of the kernel :param cutoffs: The cutoff values used for the atomic environments :type cutoffs: list of 2 float numbers :param hyps_mask: dictionary used for multi-group hyperparmeters

Returns:covariance matrix
flare.gp_algebra.get_ky_and_hyp(hyps: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53bef6a690>, name, kernel_grad, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

parallel version of get_ky_and_hyp

Parameters:
  • hyps – list of hyper-parameters
  • name – name of the gp instance.
  • kernel_grad – function object of the kernel gradient
  • cutoffs (list of 2 float numbers) – The cutoff values used for the atomic environments
  • hyps_mask – dictionary used for multi-group hyperparmeters
  • n_cpus – number of cpus to use.
  • n_sample – the size of block for matrix to compute
Returns:

hyp_mat, ky_mat

flare.gp_algebra.get_ky_and_hyp_pack(name, s1, e1, s2, e2, same: bool, hyps: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53bef6a650>, kernel_grad, cutoffs=None, hyps_mask=None)

computes a block of ky matrix and its derivative to hyper-parameter If the cpu set up is None, it uses as much as posible cpus

Parameters:
  • hyps – list of hyper-parameters
  • name – name of the gp instance.
  • kernel_grad – function object of the kernel gradient
  • cutoffs (list of 2 float numbers) – The cutoff values used for the atomic environments
  • hyps_mask – dictionary used for multi-group hyperparmeters
Returns:

hyp_mat, ky_mat

flare.gp_algebra.get_like_from_mats(ky_mat, l_mat, alpha, name)

compute the likelihood from the covariance matrix

Parameters:ky_mat – the covariance matrix
Returns:float, likelihood
flare.gp_algebra.get_like_grad_from_mats(ky_mat, hyp_mat, name)

compute the gradient of likelihood to hyper-parameters from covariance matrix and its gradient

Parameters:
  • ky_mat (np.array) – covariance matrix
  • hyp_mat (np.array) – dky/d(hyper parameter) matrix
  • name – name of the gp instance.
Returns:

float, list. the likelihood and its gradients

flare.gp_algebra.get_neg_like(hyps: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53bef6a6d0>, name: str, force_kernel, logger_name=None, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

compute the log likelihood and its gradients :param hyps: list of hyper-parameters :type hyps: np.ndarray :param name: name of the gp instance. :param kernel_grad: function object of the kernel gradient :param output: Output object for dumping every hyper-parameter

sets computed
Parameters:
  • cutoffs (list of 2 float numbers) – The cutoff values used for the atomic environments
  • hyps_mask – dictionary used for multi-group hyperparmeters
  • n_cpus – number of cpus to use.
  • n_sample – the size of block for matrix to compute
Returns:

float, np.array

flare.gp_algebra.get_neg_like_grad(hyps: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53bef6a710>, name: str, kernel_grad, logger_name: str = None, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

compute the log likelihood and its gradients

Parameters:
  • hyps (np.ndarray) – list of hyper-parameters
  • name – name of the gp instance.
  • kernel_grad – function object of the kernel gradient
  • logger_name (str) – name of logger object for dumping every hyper-parameter sets computed
  • cutoffs (list of 2 float numbers) – The cutoff values used for the atomic environments
  • hyps_mask – dictionary used for multi-group hyperparmeters
  • n_cpus – number of cpus to use.
  • n_sample – the size of block for matrix to compute
Returns:

float, np.array

flare.gp_algebra.kernel_distance_mat(hyps: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53befb43d0>, name: str, kernel, cutoffs=None, hyps_mask=None, n_cpus=1, n_sample=100)

parallel version of get_ky_mat :param hyps: list of hyper-parameters :param name: name of the gp instance. :param kernel: function object of the kernel :param cutoffs: The cutoff values used for the atomic environments :type cutoffs: list of 2 float numbers :param hyps_mask: dictionary used for multi-group hyperparmeters :return: covariance matrix

flare.gp_algebra.obtain_noise_len(hyps, hyps_mask)

obtain the noise parameter from hyps and mask

flare.gp_algebra.partition_force_energy_block(n_sample: int, size1: int, size2: int, n_cpus: int)

Special partition method for the force/energy block. Because the number of environments in a structure can vary, we only split up the environment list, which has length size1.

Note that two sizes need to be specified: the size of the envionment list and the size of the structure list.

Parameters:
  • n_sample (int) – Number of environments per processor.
  • size1 (int) – Size of the environment list.
  • size2 (int) – Size of the structure list.
  • n_cpus (int) – Number of cpus.
flare.gp_algebra.partition_matrix(n_sample, size, n_cpus)

partition the training data for matrix calculation the number of blocks are close to n_cpus since mp.Process does not allow to change the thread number

flare.gp_algebra.partition_matrix_custom(n_sample: int, start1, end1, start2, end2, n_cpus)

Partition a specified portion of a matrix.

flare.gp_algebra.partition_vector(n_sample, size, n_cpus)

partition the training data for vector calculation the number of blocks are the same as n_cpus since mp.Process does not allow to change the thread number

flare.gp_algebra.queue_wrapper(result_queue, wid, func, args)

wrapper function for multiprocessing queue