Skip to content

Commit

Permalink
Merge pull request #10 from seshasaibehara/DiffClex
Browse files Browse the repository at this point in the history
Gradients of correlations
  • Loading branch information
bpuchala authored Oct 28, 2023
2 parents cbce626 + 3e1f36e commit fb70028
Show file tree
Hide file tree
Showing 16 changed files with 4,847 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to `libcasm-clexulator` will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0a4] - 2023-10-26

### Added

- Added gradients of correlations functionality in C++, Python functions
- Added FADBAD library to support compiling of Clexulators capable of calculating gradients

## [2.0a3] - 2023-10-25

### Fixed
Expand Down
50 changes: 27 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,48 +78,52 @@ ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# create libcasm_clexulator
set(
libcasm_clexulator_HEADERS
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ConfigDoFValues.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/Correlations.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/BasicClexParamPack.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/SparseCoefficients.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/NeighborList.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/LocalClusterExpansion.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ConfigDoFValuesTools.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ImpactTable.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ConfigDoFValuesTools_impl.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ClusterExpansion.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/OrderParameter.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/DoFSpace.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/DoFSpaceAxisInfo.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/Clexulator.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/SparseCoefficients.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ConfigDoFValues.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/LocalCorrelations.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ConfigDoFValuesTools_impl.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ImpactTable.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/Correlations.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/BaseClexulator.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/DoFSpace.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/LocalClusterExpansion.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/version.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/Clexulator.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ConfigDoFValuesTools.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/DoFSpaceAxisInfo.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/ClexParamPack.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/BasicClexParamPack.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/BaseClexulator.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/DiffClexParamPack.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/OrderParameter.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/external/fadbad/fadbad.h
${PROJECT_SOURCE_DIR}/include/casm/clexulator/external/fadbad/badiff.h
${PROJECT_SOURCE_DIR}/include/casm/clexulator/external/fadbad/tadiff.h
${PROJECT_SOURCE_DIR}/include/casm/clexulator/external/fadbad/fadiff.h
${PROJECT_SOURCE_DIR}/include/casm/clexulator/io/json/ConfigDoFValues_json_io.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/io/json/SparseCoefficients_json_io.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/io/json/Clexulator_json_io.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/io/json/DoFSpace_json_io.hh
${PROJECT_SOURCE_DIR}/include/casm/clexulator/io/json/ConfigDoFValues_json_io.hh
)
set(
libcasm_clexulator_SOURCES
${PROJECT_SOURCE_DIR}/src/casm/clexulator/LocalCorrelations.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/ImpactTable.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/Correlations.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/ClusterExpansion.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/LocalClusterExpansion.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/OrderParameter.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/DoFSpace.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/DoFSpaceAxisInfo.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/ClusterExpansion.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/Clexulator.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/LocalClusterExpansion.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/NeighborList.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/BaseClexulator.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/NeighborList.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/ImpactTable.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/DoFSpace.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/LocalCorrelations.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/Correlations.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/version.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/io/json/SparseCoefficients_json_io.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/io/json/ConfigDoFValues_json_io.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/io/json/DoFSpace_json_io.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/io/json/Clexulator_json_io.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/io/json/ConfigDoFValues_json_io.cc
${PROJECT_SOURCE_DIR}/src/casm/clexulator/io/json/SparseCoefficients_json_io.cc
)
add_library(casm_clexulator SHARED ${libcasm_clexulator_SOURCES})
target_include_directories(casm_clexulator
Expand Down
12 changes: 12 additions & 0 deletions include/casm/clexulator/Correlations.hh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ class Correlations {
DoFKey const &key, Eigen::VectorXd const &new_value,
Eigen::VectorXd const &reference_extensive_correlations);

// --- Gradients of correlations
/// \brief Calculates and returns gradients of correlations with respect
/// to DoF corresponding to key
/// Returns a M x N matrix, where M represents the number of correlations,
/// and N represents the dimensions of the degrees of freedom corresponding to
/// key. For example, if key is Hstrain, N will be 6. If key is disp, and
/// there are 3 sites in the configuration, N will be 9 (x, y, z displacements
/// for each site). Each row of the matrix corresponds to gradients of all M
/// correlations with respect to one of the dimensions of degrees of freedom
/// corresponding to key
Eigen::MatrixXd const grad_correlations(DoFKey const &key);

private:
/// Holds all correlation indices
std::vector<unsigned int> m_correlation_indices;
Expand Down
4 changes: 2 additions & 2 deletions include/casm/clexulator/DiffClexParamPack.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "casm/casm_io/enum/json_io.hh"
#include "casm/casm_io/enum/stream_io.hh"
#include "casm/clexulator/ClexParamPack.hh"
#include "casm/external/fadbad/badiff.h"
#include "casm/external/fadbad/fadiff.h"
#include "casm/clexulator/external/fadbad/badiff.h"
#include "casm/clexulator/external/fadbad/fadiff.h"
#include "casm/global/definitions.hh"

namespace CASM {
Expand Down
28 changes: 28 additions & 0 deletions include/casm/clexulator/external/fadbad/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright (C) 1996-2006 Ole Stauning ([email protected])
All rights reserved.

This code is provided "as is", without any warranty of any kind,
either expressed or implied, including but not limited to, any implied
warranty of merchantibility or fitness for any purpose. In no event
will any party who distributed the code be liable for damages or for
any claim(s) by any other party, including but not limited to, any
lost profits, lost monies, lost data or data rendered inaccurate,
losses sustained by third parties, or any other special, incidental or
consequential damages arising out of the use or inability to use the
program, even if the possibility of such damages has been advised
against. The entire risk as to the quality, the performance, and the
fitness of the program for any particular purpose lies with the party
using the code.

This code, and any derivative of this code, may not be used in a
commercial package without the prior explicit written permission of
the authors. Verbatim copies of this code may be made and distributed
in any medium, provided that this copyright notice is not removed or
altered in any way. No fees may be charged for distribution of the
codes, other than a fee to cover the cost of the media and a
reasonable handling fee.

***************************************************************
ANY USE OF THIS CODE CONSTITUTES ACCEPTANCE OF THE TERMS OF THE
COPYRIGHT NOTICE
***************************************************************
76 changes: 76 additions & 0 deletions include/casm/clexulator/external/fadbad/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

FADBAD++ Templates for Automatic Differentiation
================================================

FADBAD++ defines C++ templates for performing automatic differentiation
of functions implemented as C/C++ programs. Three types of automatic
differentiation has been implemented. The forward and the backward methods
are implemented to compute first order derivatives and the Taylor expansion
method is implemented to compute Taylor series expansion.
All templates are flexible in the way that the arithmetic used in as
template-arguments can be chosen by the user. This way differentiation of
programs, based on any arithmetic such as: double, interval, multiprecision
etc. is possible. This flexibility also makes it possible to perform automatic
differentiation on a program which itself uses automatic differentiation.
All three methods can be mixed in an application and the user can obtain
derivatives using the most optimal combination of methods for the application.

APPLICATIONS:

* Forward automatic differentiation on a function f : R^n->R^n, evaluated
in interval arithmetics, using the BIAS/PROFIL package, to obtain function
values and derivatives. Used with the interval Newton method to obtain
guarenteed enlosures of all solutions to the nonlinear equation f(x)=0.

* Forward-Backward automatic differentiation on a function f : R^n->R,
evaluated in interval arithmetics, using the BIAS/PROFIL package and the
backward method to obtain first order derivatives (the gradient) and the
forward method to differentiate the first order derivatives to obtain the
second order derivatives (the Hessian). Used with the interval Krawczyk
method to perform global optimization obtaining a guarenteed enclosure of
the global minimum.

* Numerical integration of a function f : RxR^n->R, using a
three-point-two-derivative formula. The Backward method has been used to
differentiate the Numerical integration program obtaining the n partial
derivatives of the integral with respect to the n parameters in the
function.

* Taylor expansion of the solution to an ordinary differential equation,
used to solve initial value problems. The Forward method has been used to
differentiate the initial value problem solver to obtain the solution of
the variational problem.

* Taylor expansion of the solution to an ordinary differential equation
using interval arithmetics and using the Forward method to obtain
derivatives of the Taylor coefficients with respect to the point of
expansion, which are the values of the Taylor coefficients for the
solution of the variational problem. Used in a method which solves initial
value problems with guaranteed enclosures.

LICENSING:

FADBAD++ is distributed under the dual licensing business model similer to the
model used by MySQL, Trolltech and Sleepycat. In return for the advantages you
realize from using FADBAD++ in your application, we require that you do one of
the following:

* Either: Contribute to the continued development of the product by
purchasing commercial licenses from the authors. This option secures you
the right to distribute your application under the license terms of your
choice.

* Or: Contribute to the Open Source community by placing your application
under an Open Source license (e.g. the GPL). This option secures all users
the rights to obtain the application's full source code, modify it, and
redistribute it.

Contact the authors if you want to obtain a commercial licence or if you are
unsure about what license to use <[email protected]>.

More information about automatic differentiation in general and source code
for FADBAD++ with documentation can be obtained from the FADBAD++ homepage:

http://www.fadbad.com


Loading

0 comments on commit fb70028

Please sign in to comment.