Skip to content
Snippets Groups Projects
Commit 45c89d5d authored by David Hendriks's avatar David Hendriks
Browse files

working on implementing the monte carlo generator

parent 68e82a11
No related branches found
No related tags found
No related merge requests found
...@@ -93,20 +93,20 @@ class monte_carlo_sampling: ...@@ -93,20 +93,20 @@ class monte_carlo_sampling:
self._add_code( self._add_code(
# Write some info in the function # Write some info in the function
"# Grid code generated on {}\n".format(datetime.datetime.now().isoformat()), "# Grid code generated on {}\n".format(datetime.datetime.now().isoformat()),
"# This function generates the systems that will be evolved with binary_c\n\n" "# This function generates the systems that will be evolved with binary_c\n\n",
# Set some values in the generated code: # Set some values in the generated code:
"# Set initial values\n", "# Set initial values\n",
"_total_starcount = 0\n", "_total_starcount = 0\n",
"parameter_dict = {}\n", "parameter_dict = {}\n\n",
) )
######### #########
# Set up the loop and yield calls # Set up the loop and yield calls
self._add_code( self._add_code(
# Comment # Comment
"# Start of the while loop" "# Start of the while loop\n",
# while loop # while loop
"while True:" "while True:\n",
) )
# Increase indent_depth # Increase indent_depth
...@@ -116,18 +116,18 @@ class monte_carlo_sampling: ...@@ -116,18 +116,18 @@ class monte_carlo_sampling:
# Fill the while loop with a dummy sytem of a fixed mass # Fill the while loop with a dummy sytem of a fixed mass
self._add_code( self._add_code(
# Sample the variables # Sample the variables
"# Add M_1 variable\n" "# Add M_1 variable\n",
# while loop # while loop
"parameter_dict['M_1'] = 1\n\n" "parameter_dict['M_1'] = 1\n\n",
) )
######### #########
# Handle system yield # Handle system yield
self._add_code( self._add_code(
# Comment # Comment
"# Yield the system dict\n" "# Yield the system dict\n",
# while loop # while loop
"yield(parameter_dict)\n" "yield(parameter_dict)\n",
) )
################################################################################# #################################################################################
...@@ -166,7 +166,7 @@ class monte_carlo_sampling: ...@@ -166,7 +166,7 @@ class monte_carlo_sampling:
) as file: ) as file:
file.write(self.code_string) file.write(self.code_string)
raise NotImplementedError("This functionality is not available yet") # raise NotImplementedError("This functionality is not available yet")
def _monte_carlo_sampling_load_generator(self): def _monte_carlo_sampling_load_generator(self):
""" """
...@@ -176,7 +176,7 @@ class monte_carlo_sampling: ...@@ -176,7 +176,7 @@ class monte_carlo_sampling:
# Code to load the # Code to load the
self.verbose_print( self.verbose_print(
message="Load monte-carlo generator function from {file}".format( message="Load monte-carlo generator function from {file}".format(
file=self.grid_options["_monte_carlo_generator_filename"] file=self.grid_options["_monte_carlo_sampling_generator_filename"]
), ),
verbosity=self.grid_options["verbosity"], verbosity=self.grid_options["verbosity"],
minimal_verbosity=1, minimal_verbosity=1,
...@@ -184,11 +184,11 @@ class monte_carlo_sampling: ...@@ -184,11 +184,11 @@ class monte_carlo_sampling:
spec = importlib.util.spec_from_file_location( spec = importlib.util.spec_from_file_location(
"binary_c_python_monte_carlo_sampling_generator", "binary_c_python_monte_carlo_sampling_generator",
os.path.join(self.grid_options["monte_carlo_sampling_generator_filename"]), os.path.join(self.grid_options["_monte_carlo_sampling_generator_filename"]),
) )
monte_carlo_sampling_generator_file = importlib.util.module_from_spec(spec) monte_carlo_sampling_generator_file = importlib.util.module_from_spec(spec)
spec.loader.exec_module(monte_carlo_sampling_generator_file) spec.loader.exec_module(monte_carlo_sampling_generator_file)
generator = monte_carlo_sampling_generator_file.grid_code generator = monte_carlo_sampling_generator_file.monte_carlo_generator
self.grid_options["_monte_carlo_sampling_generator"] = generator self.grid_options["_monte_carlo_sampling_generator"] = generator
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment