Core of runs (core package)¶
CoreRun¶
Class is responsible for run of one optimization of GADMA.
-
class
gadma.core.core_run.
CoreRun
(index, shared_dict, settings)¶ Bases:
object
Class of main run in GADMA. Has a
run()
method to start launch. Runs creates new directory named by its index in the output directory then all log, code and pictures will be saved there. AIC and CLAIC is calculated here.- Parameters
index (int) – Index of the run. Like id.
shared_dict (
gadma.cor.shared_dict.SharedDictForCoreRun
) – Dictionary to save results in callbacks. Will be saved with key equal to index. Is used for multiprocessing cooperation.settings (
gadma.cli.settings_storage.SettingsStorage
) – Settings of the run. Information to form output directory and so on will be taken from settings.
-
EVAL_FILENAME
= 'eval_file'¶
-
REPORT_FILENAME
= 'GADMA_GA.log'¶
-
SAVE_FILENAME
= 'save_file'¶
-
base_callback
(x, y)¶ Base callback:
Updates values of best solution in
shared_dict
.If new best values are received then draws and generates code to the output_dir of this run.
- Parameters
x – Vector of values for model parameters.
y – Value of log-likelihood for this values.
-
callback
(x, y)¶ Main callback for optimizers to get. It is combination of three callbacks:
- Parameters
x – Vector of values for model parameters.
y – Value of log-likelihood for this values.
-
code_iter_callback
(x, y)¶ Generates code of best model on current iteration to the code directory. Code directory is located in the output directory of this run. Generation happens every
self.settings.print_models_code_every_n_iteration
iteration.- Parameters
x – Vector of values for model parameters.
y – Value of log-likelihood for this values.
-
property
data
¶ Returns current data.
-
draw_iter_callback
(x, y)¶ Draws best model on current iteration in the pictures directory. Pictures directory is located in the output directory of this run. Drawing happens every
self.settings.draw_models_every_n_iteration
iteration.- Parameters
x – Vector of values for model parameters.
y – Value of log-likelihood for this values.
-
draw_model_in_output_dir
(x, y, best_by='log-likelihood', final=True)¶ Draws picture of demographic model with x as parameters to the output directory of run.
- Parameters
x – Vector of values for model parameters.
y – Value of log-likelihood for this values.
best_by – By what function (log-likelihood, AIC, CLAIC) this colution is best.
final – If True then solution is final and it will be saved by final name.
-
get_run_options
()¶ Returns iterator of run options, each element has four options:
File to restore optimization from. If None then no resume.
Structure of the demographic model for the run.
Bool points_only - if True then resumed run uses old points as initial points only and optimization is run from the beginning.
Function of x transformation - for case when restored vectors should be transformed somehow before they will be used in the optimization.
-
get_save_file
()¶ Returns filename to save optimization run. If demographic model does not have structure then returns self.save_file else adds suffix about structure at the end of self.save_file.
-
intermediate_callback
(x, y)¶ Almost final callback that is called after each global + local optimization.
Saves AIC and CLAIC values in the
shared_dict
if needed. If new best by AIC or CLAIC vector then code and picture are generated.- Parameters
x – Vector of values for model parameters.
y – Value of log-likelihood for this values.
-
property
model
¶ Returns current demographic model.
-
run
(initial_kwargs={})¶ Main method of the class to run optimization. Runs
run_without_increase()
orrun_with_increase()
according to settings.
-
run_with_increase
(initial_kwargs={})¶ Run launch with increase of the demographic model structure. Structure of the model will be increased up to final structure. Then the final solution will be returned. Runs
run_without_increase()
andincrease_structure()
in the loop.- Parameters
initial_kwargs – Initial kwargs for optimization.
-
run_without_increase
(initial_kwargs={})¶ Run one launch without any increase of demographic model structure. Runs one global+local optimization for the current model.
- Parameters
initial_kwargs – Initial kwargs for optimization.
Core¶
-
gadma.core.core.
job
(index, shared_dict, settings)¶ Function of one parallel run of GADMA. Creates
gadma.core.core_run.CoreRun
object and call itsrun()
method.- Parameters
index (int) – Index of the run.
shared_dict (
gadma.core.shared_dict.SharedDictForCoreRun
) – Shared dict between all runs.settings (
gadma.cli.settings_storage.SettingsStorage
) – Settings of the run.
-
gadma.core.core.
main
()¶ Main function that is called from command line. Creates parallel runs of GADMA and holds base pool of processes. Prints progress periodically for each run, saves plots and pictures of best model and generates code.
Functions for drawing and code generation in main function of core¶
-
gadma.core.draw_and_generate_code.
draw_plots_to_file
(x, engine, settings, filename, fig_title)¶ Draws plots of data (SFS) and model from
engine
with parametersx
.- Parameters
x (list or dict) – Values of the parameters in model.
engine (
gadma.engines.engine.Engine
) – Engine with specified model and data.filename (str) – File name to save picture.
fig_title (str) – Title of the schematic model plot.
- Note
print warnings if schematic model plot was not drawn.
-
gadma.core.draw_and_generate_code.
generate_code_to_file
(x, engine, settings, filename)¶ Generates code of demographic model to file. Settings are required to get
engine
arguments inevaluation()
function.- Parameters
x (list or dict) – Values of the parameters in model.
engine (
gadma.engines.engine.Engine
) – Engine with specified model and data.settings (
gadma.cli.settings_storage.SettingsStorage
) – Settings of the run.filename (str) – File name to save picture.
-
gadma.core.draw_and_generate_code.
print_runs_summary
(start_time, shared_dict, settings)¶ Prints best demographic model by logLL among all processes.
- Parameters
start_time (float) – Time when equation was started.
shared_dict (
gadma.core.shared_dict.SharedDict
) – Dictionary to share information between processes.settings (
gadma.cli.settings_storage.SettingsStorage
) – Settings of run.