Skip to content

Commit

Permalink
Merge pull request #126 from Milkyway-at-home/mendel_auto_diff
Browse files Browse the repository at this point in the history
Mendel auto diff
  • Loading branch information
ericmendelsohn authored May 1, 2022
2 parents fc0a284 + ab484ec commit 7e6500a
Show file tree
Hide file tree
Showing 137 changed files with 1,119,089 additions and 4,096 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ mark_as_advanced(INSTALL_BOINC)
option(DOUBLEPREC
"Build with double precision" ON)

option(AUTODIFF
"Build with automatic differentiation" OFF)
mark_as_advanced(AUTODIFF)

option(AUTODIFF_LOG
"Calculate derivative information in logspace" OFF)
mark_as_advanced(AUTODIFF_LOG)

option(NVIDIA_OPENCL "Using Nvidia OpenCL" OFF)
mark_as_advanced(NVIDIA_OPENCL)

Expand Down
18 changes: 10 additions & 8 deletions cmake_modules/PrintInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ endmacro()

macro(print_build_options)
message(" ----")
message(" Double precision: ${DOUBLEPREC}")
message(" Separation: ${SEPARATION}")
message(" N-Body: ${NBODY}")
message(" OpenCL separation: ${SEPARATION_OPENCL}")
message(" OpenCL nbody: ${NBODY_OPENCL}")
message(" Nbody graphics: ${NBODY_GL}")
message(" Nbody use GL3W: ${USE_GL3W}")
message(" BOINC application: ${BOINC_APPLICATION}")
message(" Double precision: ${DOUBLEPREC}")
message(" Auto differentiation: ${AUTODIFF}")
message(" Logspace Derivatives: ${AUTODIFF_LOG}")
message(" Separation: ${SEPARATION}")
message(" N-Body: ${NBODY}")
message(" OpenCL separation: ${SEPARATION_OPENCL}")
message(" OpenCL nbody: ${NBODY_OPENCL}")
message(" Nbody graphics: ${NBODY_GL}")
message(" Nbody use GL3W: ${USE_GL3W}")
message(" BOINC application: ${BOINC_APPLICATION}")
message(" ----")
endmacro()

Expand Down
104 changes: 104 additions & 0 deletions get_test_likelihoods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
###########################################################
#This code runs the model tests and records their results.#
# Useful for when they need to be updated. #
# Needs get_test_likelihood.sh to work. #
###########################################################

#Import necessary packages
import os
import os.path as pth

#Set Pathways
lua_pth = '~/milkywayathome_client/nbody/tests/RunTestUnits.lua'
tmp_pth = '~/likelitemp.out'
result_pth = '~/test_likelihoods.txt'

#Define lists

model_list = ["model_1","model_2","model_3","model_4","model_5","model_5_bounds_test","model_6","model_7","model_8","model_9","model_ninkovic","model_triaxial","model_newhist1","model_newhist2","model_newhist3","model_LMC","model_bar","model_LMC_bar"]
body_list = ["100","1024","10000"]
seed_list = ["670828913", "886885833", "715144259", "430281807", "543966758"]

#model_list = ["model_1","model_2"]
#body_list = ["100","1024"]
#seed_list = ["670828913", "886885833"]

empty_seed_array = []
empty_body_array = []
likelihoods = []
for s in range(len(seed_list)):
empty_seed_array.append(' ')
for t in range(len(body_list)):
exec("empty_body_array.append("+str(empty_seed_array)+")")
for u in range(len(model_list)):
exec("likelihoods.append("+str(empty_body_array)+")")

#Loop through all tests

for i in range(len(model_list)):
for j in range(len(body_list)):
for k in range(len(seed_list)):
#Change seed in lua file
print("REWRITING LUA FILE................................")
temp = open('~/lua_temp.lua','w+')
lua_file = open(lua_pth,'r')
for line in lua_file:
if (line.startswith('local testSeed =')):
temp.write('local testSeed = testSeeds['+str(k+1)+']\n')
else:
temp.write(line)
lua_file.close()
temp.close()
os.system('rm '+lua_pth)
os.rename('~/lua_temp.lua',lua_pth)

#Run test and get likelihood
print("Running "+model_list[i]+"__"+body_list[j]+"_test: SEED = "+seed_list[k])
check = False
os.system("sh get_test_likelihoods.sh "+model_list[i]+" "+body_list[j])
tmp_file = open(tmp_pth, 'r')
test_num = 0
for line in tmp_file:
if (line.startswith('test ')):
test_num = int(line.replace('test ',''))
prefix = str(test_num)+": "
if (line.startswith(prefix+"<search_likelihood>")):
string = line.replace(prefix+"<search_likelihood>-",'')
like_score = float(string.replace('</search_likelihood>',''))
print("Likelihood = "+str(like_score))
likelihoods[i][j][k] = str(like_score)
check = True
if(not check):
assert False #NO LIKELIHOOD FOUND!
tmp_file.close()
os.system('rm '+tmp_pth)


#Write data
results = open(result_pth,'w+')
for i in range(len(model_list)):
results.write(' ["'+model_list[i]+'"] = {\n')
for j in range(len(body_list)):
results.write(' ["'+body_list[j]+'"] = {\n')
for k in range(len(seed_list)):
if (k+1 == len(seed_list)):
results.write(' ["'+seed_list[k]+'"] = '+str(likelihoods[i][j][k])+'\n')
else:
results.write(' ["'+seed_list[k]+'"] = '+str(likelihoods[i][j][k])+',\n')
if (j+1 == len(body_list)):
results.write(' }\n')
else:
results.write(' },\n\n')
if (i+1 == len(model_list)):
results.write(' }\n')
else:
results.write(' },\n\n')
results.close()








3 changes: 3 additions & 0 deletions get_test_likelihoods.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd test_env/

ctest -R $1__$2_test -VV > ~/likelitemp.out
69 changes: 69 additions & 0 deletions make_run_v2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
#/* Copyright (c) 2016 Siddhartha Shelton */

rebuild=true
run=true
run_compare=false
compare_only=false
get_flag_list=false

PathToMilkyWayAtHomeClientFolder='INSERT PATHWAY HERE'

if $rebuild
then
rm -r build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DNBODY_DEV_OPTIONS=ON -DNBODY_GL=OFF -DBOINC_APPLICATION=ON -DSEPARATION=OFF -DDOUBLEPREC=ON -DNBODY_OPENMP=ON -DNBODY_OPENCL=OFF -DAUTODIFF=OFF -DAUTODIFF_LOG=OFF $PathToMilkyWayAtHomeClientFolder/milkywayathome_client/
make -j
fi

cd $PathToMilkyWayAtHomeClientFolder/build/bin

if $run
then
./milkyway_nbody \
-f $PathToMilkyWayAtHomeClientFolder/milkywayathome_client/nbody/sample_workunits/for_developers.lua \
-o $PathToMilkyWayAtHomeClientFolder/test.out \
-z $PathToMilkyWayAtHomeClientFolder/test.hist \
-n 8 -b -w 1 -P -e 54231651\
-i 4.0 1.0 0.2 0.2 12.0 0.2 \

fi

if $run_compare
then
./milkyway_nbody \
-f $PathToMilkyWayAtHomeClientFolder/milkywayathome_client/nbody/sample_workunits/for_developers.lua \
-o $PathToMilkyWayAtHomeClientFolder/output.out \
-z $PathToMilkyWayAtHomeClientFolder/output.hist \
-h $PathToMilkyWayAtHomeClientFolder/test.hist \
-y $PathToMilkyWayAtHomeClientFolder/output.ad \
-n 8 -b -w 1 -P -e 54231651\
-p 4.0 1.0 0.2 0.2 12.0 0.2 \

fi

#SMU = 222,288.47 SOLAR MASSES

#OPTIONS:
#-s -> compare using only emd and cost component
#-S -> use emd, cost, beta dispersion
#-V -> use emd, cost, velocity dispersion
#-D -> use emd, cost, beta dispersion and velocity dispersion
if $compare_only
then
./milkyway_nbody \
-h $PathToMilkyWayAtHomeClientFolder/test.hist \
-S $PathToMilkyWayAtHomeClientFolder/output.hist \

fi


# if you run:

if $get_flag_list
then
./milkyway_nbody --help
# it will show you what all the flags mean
fi
2 changes: 2 additions & 0 deletions milkyway/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ set(mw_lib_headers include/milkyway_config.h.in
include/milkyway_math_double.h
include/milkyway_math_float.h
include/milkyway_math_supplemental.h
include/milkyway_math_autodiff.h
include/milkyway_math_supplemental2.h
include/milkyway_util.h
include/milkyway_alloc.h
include/milkyway_boinc_util.h
Expand Down
2 changes: 2 additions & 0 deletions milkyway/include/milkyway_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#cmakedefine01 BOINC_APPLICATION
#cmakedefine01 DOUBLEPREC
#cmakedefine01 AUTODIFF
#cmakedefine01 AUTODIFF_LOG
#cmakedefine01 MW_ENABLE_DEBUG

#cmakedefine01 HAVE_EXP10
Expand Down
4 changes: 2 additions & 2 deletions milkyway/include/milkyway_lua_marshal.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ int mw_lua_typecheck(lua_State* luaSt, int idx, int expectedType, const char* ty

void handleNamedArgumentTable(lua_State* luaSt, const MWNamedArg* args, int table);

int pushRealArray(lua_State* luaSt, const real* arr, int n);
real* popRealArray(lua_State* luaSt, int* outN);
int pushRealArray(lua_State* luaSt, const real_0* arr, int n);
real_0* popRealArray(lua_State* luaSt, int* outN);

int expectTable(lua_State* luaSt, int idx);

Expand Down
7 changes: 7 additions & 0 deletions milkyway/include/milkyway_lua_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

#include <lua.h>

real* checkReal(lua_State* luaSt, int idx);
real* toReal(lua_State* luaSt, int idx);
real* expectReal(lua_State* luaSt, int idx);
int pushReal(lua_State* luaSt, real realIn);
int getReal(lua_State* luaSt, void* r);
int setReal(lua_State* luaSt, void* r);

void registerMilkywayMath(lua_State* luaSt);

#endif /* _LUA_MILKYWAY_MATH_H_ */
Expand Down
2 changes: 2 additions & 0 deletions milkyway/include/milkyway_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#endif

#include "milkyway_math_supplemental.h"
#include "milkyway_math_autodiff.h"
#include "milkyway_math_supplemental2.h"
#include "milkyway_vectors.h"


Expand Down
Loading

0 comments on commit 7e6500a

Please sign in to comment.