Loading TODO.org +2 −1 Original line number Diff line number Diff line Loading @@ -150,7 +150,8 @@ That went very deep haha. alot of memory allocation stuff *** DONE Make new c function run_binary_with_custom_logging CLOSED: [2019-11-08 Fri 21:19] *** TODO Put in some new tests in the python test api *** TODO Make sure the sharedlibs get written to the correct directory *** DONE Make sure the sharedlibs get written to the correct directory CLOSED: [2019-11-10 Sun 00:21] ** General: *** DONE Get a more reliable way of loading the default values (running a ./tbse echo or something?) CLOSED: [2019-10-29 Tue 17:44] Loading binaryc_python_utils/custom_logging_functions.py +18 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import os import textwrap import subprocess import socket import tempfile # Functions for the automatic logging of stuff def autogen_C_logging_code(logging_dict): Loading Loading @@ -229,3 +230,19 @@ def compile_shared_lib(code, sourcefile_name, outfile_name): if res: print('Output of compilation command:\n{}'.format(res)) def temp_custom_logging_dir(): """ Function to return the path the custom logging library shared object and script will be written to. Makes use of os.makedirs exist_ok which requires python 3.2+ """ tmp_dir = tempfile.gettempdir() path = os.path.join(tmp_dir, 'binary_c_python') # os.makedirs(path, exist_ok=True) return path No newline at end of file custom_logging.cdeleted 100644 → 0 +0 −19 Original line number Diff line number Diff line #pragma push_macro("MAX") #pragma push_macro("MIN") #undef MAX #undef MIN #include "binary_c.h" // add visibility __attribute__ ((visibility ("default"))) to it void binary_c_API_function custom_output_function(struct stardata_t * stardata); void binary_c_API_function custom_output_function(struct stardata_t * stardata) { // struct stardata_t * stardata = (struct stardata_t *)x; Printf("MY_STELLAR_DATA %g %g\n",((double)stardata->model.time),((double)stardata->star[0].mass)); Printf("my_sss2 %g %g\n",((double)stardata->model.time),((double)stardata->star[1].mass));; } #undef MAX #undef MIN #pragma pop_macro("MIN") #pragma pop_macro("MAX") No newline at end of file testing_examples/run_system_with_custom_logging.py 0 → 100644 +0 −0 Empty file added. tests_and_snippets/testing.py→tests_and_snippets/custom_logging_examples.py +11 −6 Original line number Diff line number Diff line import ctypes import tempfile import os from binaryc_python_utils.custom_logging_functions import autogen_C_logging_code, binary_c_log_code, compile_shared_lib from binaryc_python_utils.custom_logging_functions import autogen_C_logging_code, binary_c_log_code, compile_shared_lib, temp_custom_logging_dir import binary_c # generate logging lines Loading @@ -12,20 +14,25 @@ logging_line = autogen_C_logging_code( ) # Generate code around logging lines created_code = binary_c_log_code(logging_line) custom_logging_code = binary_c_log_code(logging_line) # compile_shared_lib(created_code, sourcefile_name='custom_logging.c', outfile_name='libcustom_logging.so') compile_shared_lib(created_code, sourcefile_name=os.path.join(temp_custom_logging_dir(), 'custom_logging.c'), outfile_name=os.path.join(temp_custom_logging_dir(), 'libcustom_logging.so') ) # Loading library dll1 = ctypes.CDLL('libgslcblas.so', mode=ctypes.RTLD_GLOBAL) dll2 = ctypes.CDLL('libgsl.so', mode=ctypes.RTLD_GLOBAL) dll3 = ctypes.CDLL('libbinary_c.so', mode=ctypes.RTLD_GLOBAL) libmean = ctypes.CDLL("libcustom_logging.so", mode=1) # loads the shared library libmean = ctypes.CDLL(os.path.join(temp_custom_logging_dir(), 'libcustom_logging.so'), mode=ctypes.RTLD_GLOBAL) # loads the shared library # Get memory adress of function. mimicking a pointer mem = ctypes.cast(libmean.custom_output_function, ctypes.c_void_p).value # m1 = 15.0 # Msun m2 = 14.0 # Msun separation = 0 # 0 = ignored, use period Loading @@ -38,7 +45,5 @@ argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} output = binary_c.run_binary_custom_logging(argstring, mem) # output = binary_c.run_binary(argstring) # print ("\n\nBinary_c output:\n\n") print (output) Loading
TODO.org +2 −1 Original line number Diff line number Diff line Loading @@ -150,7 +150,8 @@ That went very deep haha. alot of memory allocation stuff *** DONE Make new c function run_binary_with_custom_logging CLOSED: [2019-11-08 Fri 21:19] *** TODO Put in some new tests in the python test api *** TODO Make sure the sharedlibs get written to the correct directory *** DONE Make sure the sharedlibs get written to the correct directory CLOSED: [2019-11-10 Sun 00:21] ** General: *** DONE Get a more reliable way of loading the default values (running a ./tbse echo or something?) CLOSED: [2019-10-29 Tue 17:44] Loading
binaryc_python_utils/custom_logging_functions.py +18 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import os import textwrap import subprocess import socket import tempfile # Functions for the automatic logging of stuff def autogen_C_logging_code(logging_dict): Loading Loading @@ -229,3 +230,19 @@ def compile_shared_lib(code, sourcefile_name, outfile_name): if res: print('Output of compilation command:\n{}'.format(res)) def temp_custom_logging_dir(): """ Function to return the path the custom logging library shared object and script will be written to. Makes use of os.makedirs exist_ok which requires python 3.2+ """ tmp_dir = tempfile.gettempdir() path = os.path.join(tmp_dir, 'binary_c_python') # os.makedirs(path, exist_ok=True) return path No newline at end of file
custom_logging.cdeleted 100644 → 0 +0 −19 Original line number Diff line number Diff line #pragma push_macro("MAX") #pragma push_macro("MIN") #undef MAX #undef MIN #include "binary_c.h" // add visibility __attribute__ ((visibility ("default"))) to it void binary_c_API_function custom_output_function(struct stardata_t * stardata); void binary_c_API_function custom_output_function(struct stardata_t * stardata) { // struct stardata_t * stardata = (struct stardata_t *)x; Printf("MY_STELLAR_DATA %g %g\n",((double)stardata->model.time),((double)stardata->star[0].mass)); Printf("my_sss2 %g %g\n",((double)stardata->model.time),((double)stardata->star[1].mass));; } #undef MAX #undef MIN #pragma pop_macro("MIN") #pragma pop_macro("MAX") No newline at end of file
tests_and_snippets/testing.py→tests_and_snippets/custom_logging_examples.py +11 −6 Original line number Diff line number Diff line import ctypes import tempfile import os from binaryc_python_utils.custom_logging_functions import autogen_C_logging_code, binary_c_log_code, compile_shared_lib from binaryc_python_utils.custom_logging_functions import autogen_C_logging_code, binary_c_log_code, compile_shared_lib, temp_custom_logging_dir import binary_c # generate logging lines Loading @@ -12,20 +14,25 @@ logging_line = autogen_C_logging_code( ) # Generate code around logging lines created_code = binary_c_log_code(logging_line) custom_logging_code = binary_c_log_code(logging_line) # compile_shared_lib(created_code, sourcefile_name='custom_logging.c', outfile_name='libcustom_logging.so') compile_shared_lib(created_code, sourcefile_name=os.path.join(temp_custom_logging_dir(), 'custom_logging.c'), outfile_name=os.path.join(temp_custom_logging_dir(), 'libcustom_logging.so') ) # Loading library dll1 = ctypes.CDLL('libgslcblas.so', mode=ctypes.RTLD_GLOBAL) dll2 = ctypes.CDLL('libgsl.so', mode=ctypes.RTLD_GLOBAL) dll3 = ctypes.CDLL('libbinary_c.so', mode=ctypes.RTLD_GLOBAL) libmean = ctypes.CDLL("libcustom_logging.so", mode=1) # loads the shared library libmean = ctypes.CDLL(os.path.join(temp_custom_logging_dir(), 'libcustom_logging.so'), mode=ctypes.RTLD_GLOBAL) # loads the shared library # Get memory adress of function. mimicking a pointer mem = ctypes.cast(libmean.custom_output_function, ctypes.c_void_p).value # m1 = 15.0 # Msun m2 = 14.0 # Msun separation = 0 # 0 = ignored, use period Loading @@ -38,7 +45,5 @@ argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} output = binary_c.run_binary_custom_logging(argstring, mem) # output = binary_c.run_binary(argstring) # print ("\n\nBinary_c output:\n\n") print (output)