Initial import
This commit is contained in:
commit
56a50eead3
820 changed files with 192077 additions and 0 deletions
16
extra/borg/scripts/borg_tests.cmake
Normal file
16
extra/borg/scripts/borg_tests.cmake
Normal file
|
@ -0,0 +1,16 @@
|
|||
function(borg_add_vobs_test testnames testbase)
|
||||
set(_vobs_test_cmake ${CMAKE_BINARY_DIR}/CMakeFiles/borg_vobs_test_${testnames}.cmake)
|
||||
set(_base_tmp_vobs_files ${CMAKE_BINARY_DIR}/CMakeFiles/vobs_tests)
|
||||
|
||||
if (NOT EXISTS ${_base_tmp_vobs_files})
|
||||
FILE(MAKE_DIRECTORY ${_base_tmp_vobs_files})
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/extra/borg/scripts/generate_vobs_tests.py
|
||||
${_vobs_test_cmake} ${testbase} ${_base_tmp_vobs_files} RESULT_VARIABLE _generate_result)
|
||||
if (NOT _generate_result EQUAL 0)
|
||||
cmessage(FATAL_ERROR "Could not automatically generate vobs tests.")
|
||||
endif()
|
||||
|
||||
include(${_vobs_test_cmake})
|
||||
endfunction()
|
76
extra/borg/scripts/generate_vobs_tests.py
Normal file
76
extra/borg/scripts/generate_vobs_tests.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
#+
|
||||
# ARES/HADES/BORG Package -- ./extra/borg/scripts/generate_vobs_tests.py
|
||||
# Copyright (C) 2019 Guilhem Lavaux <guilhem.lavaux@iap.fr>
|
||||
#
|
||||
# Additional contributions from:
|
||||
# Guilhem Lavaux <guilhem.lavaux@iap.fr> (2023)
|
||||
#
|
||||
#+
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
output_cmake_file = sys.argv[1]
|
||||
input_config = sys.argv[2]
|
||||
base_dir = sys.argv[3]
|
||||
|
||||
with open(input_config, mode="r") as f:
|
||||
config = {}
|
||||
exec(f.read(), {}, config)
|
||||
config = config['tests']
|
||||
|
||||
tests = config['tests']
|
||||
|
||||
with open(output_cmake_file, "wt") as f:
|
||||
|
||||
for test_name in tests:
|
||||
test = tests[test_name]
|
||||
includes = test['includes']
|
||||
likelihood = test['likelihood']
|
||||
model = test['model']
|
||||
model_args = test.get('model_args', 'comm, box, 0.001');
|
||||
model_code=""
|
||||
|
||||
f.write("""
|
||||
add_executable(test_vobs_%(test_name)s %(base_dir)s/%(test_source)s)
|
||||
target_link_libraries(test_vobs_%(test_name)s test_library_LSS LSS ${LIBS})
|
||||
ares_add_test_targets(test_vobs_%(test_name)s)
|
||||
"""
|
||||
% dict(test_name=test_name, base_dir=base_dir, test_source="test_%s_vobs.cpp" % (test_name,)
|
||||
))
|
||||
|
||||
includes_str = \
|
||||
"\n".join(
|
||||
map(lambda x: "#include \"%s\"" % (x,), includes)
|
||||
)
|
||||
|
||||
|
||||
if 'model' in test:
|
||||
args = test.get('model_args', 'comm, box, 0.001')
|
||||
|
||||
with open(os.path.join(base_dir,"test_%s_vobs.cpp" % (test_name,)), mode="wt") as f2:
|
||||
f2.write("""%(includes)s
|
||||
#include "libLSS/samplers/rgen/hmc/hmc_density_sampler.hpp"
|
||||
#include "libLSS/physics/likelihoods/base.hpp"
|
||||
|
||||
namespace L = LibLSS::Likelihood;
|
||||
using LibLSS::LikelihoodInfo;
|
||||
using LibLSS::HMCDensitySampler;
|
||||
using LibLSS::MarkovState;
|
||||
using LibLSS::BoxModel;
|
||||
|
||||
typedef %(likelihood)s ThisLikelihood;
|
||||
|
||||
|
||||
auto makeModel(MarkovState& state, BoxModel const& box, LikelihoodInfo& info) {
|
||||
auto comm = L::getMPI(info);
|
||||
return std::make_shared<%(model)s>(%(model_args)s);
|
||||
}
|
||||
|
||||
#include "libLSS/tests/generic_borg_vobs_test.cpp"
|
||||
""" % dict(includes=includes_str,likelihood=likelihood,model=model,model_args=model_args))
|
||||
|
||||
# ARES TAG: authors_num = 1
|
||||
# ARES TAG: name(0) = Guilhem Lavaux
|
||||
# ARES TAG: email(0) = guilhem.lavaux@iap.fr
|
||||
# ARES TAG: year(0) = 2019
|
51
extra/borg/scripts/plot_forwards.py
Normal file
51
extra/borg/scripts/plot_forwards.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import h5py as h5
|
||||
import subprocess as sp
|
||||
|
||||
|
||||
models={'lpt':'LPT','old_pm':'PMv1','pm':'PMv2','tcola':'tCOLA'}
|
||||
#models={'lpt':'LPT','pm':'PMv2'}
|
||||
output={}
|
||||
output_v={}
|
||||
Pref=None
|
||||
km=None
|
||||
|
||||
for m,name in models.items():
|
||||
sp.run(f"./libLSS/tests/test_forward_{m}", check=True)
|
||||
with h5.File("dump.h5", mode="r") as ff:
|
||||
output[m] = ff['power'][:]
|
||||
output_v[m] = ff['power_v'][:]
|
||||
Pref = ff['scalars/powerspectrum'][:]
|
||||
km = ff['scalars/k_modes'][:]
|
||||
|
||||
#km = 0.5*(km[1:]+km[:-1])
|
||||
|
||||
fig2 = plt.figure(figsize=(5,5))
|
||||
fig = plt.figure(figsize=(5,6))
|
||||
ax0 = plt.axes([0.1 ,0.2,0.9 ,0.7], rasterized=False)
|
||||
ax1 = plt.axes([0.1 ,0.05,0.9 ,0.15], rasterized=False)
|
||||
ax2_0 = fig2.add_subplot(111)
|
||||
ax0.set_xlim(1e-3,2.2)
|
||||
ax0.set_ylim(1e2,1e5)
|
||||
ax1.set_xlim(1e-3,2.2)
|
||||
ax0.set_xticks([])
|
||||
ax1.set_xlabel('k ($h$ Mpc$^{-1}$)')
|
||||
ax1.set_ylabel('$P(k) / P_{ref}(k)$')
|
||||
ax0.set_ylabel('$P(k)$ ($h^{-3}$ Mpc$^{3}$)')
|
||||
ax2_0.set_ylabel('$P(k)$ (km$^2$ s$^{-2}$ $h^{-3}$ Mpc$^{3}$)')
|
||||
ax2_0.set_xlabel('k ($h$ Mpc$^{-1}$)')
|
||||
ax2_0.set_ylim(1, 1e7)
|
||||
|
||||
|
||||
for m,name in models.items():
|
||||
ax0.loglog(km,output[m],label=name)
|
||||
ax1.semilogx(km, output[m]/Pref,label=name)
|
||||
ax2_0.loglog(km, output_v[m], label=name)
|
||||
|
||||
ax0.loglog(km,Pref)
|
||||
ax0.legend()
|
||||
ax1.set_ylim(0.,1.5)
|
||||
ax1.axhline(1.0,lw=1.0,color='k')
|
||||
ax2_0.legend()
|
||||
fig.savefig("models.pdf",bbox_inches='tight')
|
||||
fig2.savefig("v_models.pdf",bbox_inches='tight')
|
Loading…
Add table
Add a link
Reference in a new issue