Model Iterator

Classes for the iteration of models. The parameter space page contains classes related to parameter search algorithms.

API

Classes:

ModelInnerIterator([config, par_generator, ...])

Class to run all models in a single iteration.

ModelIterator([config, model_kwargs, ...])

Iterator for models

SplitModelIterator([do_orblib, do_weights])

Class to run all models in a single iteration.

class model_iterator.ModelInnerIterator(config=None, par_generator=None, do_dummy_run=False, dummy_chi2_function=None)

Class to run all models in a single iteration.

Uses pathos.multiprocessing.Pool to execute the models

Parameters:
configa dyn.config_reader.Configuration object
par_generatora dyn.parameter_space.ParameterGenerator child object
do_dummy_runBool

whether this is a dummy run - if so, dummy_chi2_function is executed instead of the model (for testing!)

dummy_chi2_functionfunction

a function of model parameters to be executed instead of the real model

Methods:

assign_model_directories([rows_orblib, rows_ml])

Assigns model directories in all_models.table.

create_and_run_model(data_input)

Main method to create and run a model

delete_staging_files(rows)

Deletes staging files.

is_new_orblib(row_idx)

Checks whether the orbit library characterized by the parameters in row number row_idx exists in earlier rows of self.all_models.table.

run_iteration()

run one iteration step

write_output_to_all_models_table(rows_to_do, ...)

Parameters:

assign_model_directories(rows_orblib=[], rows_ml=[])

Assigns model directories in all_models.table.

Models indexed by rows_orblib: The model directories follow the pattern orblib_xxx_yyy/mlzz.zz/ where xxx is the iteration number, yyy a consecutive number of that iteration’s orbit library, and zz.zz is the value of the models’ ml parameter in the format given in its sformat attribute.

Models indexed by rows_ml: These models re-use an existing orbit library. Hence, their directory strings re-use an existing orblib_xxx_yyy part and get augmented with the appropriate /mlzz.zz/.

Parameters:
rows_orbliblist, optional

Indices of models with new orbit libraries. The default is None.

rows_mllist, optional

Indices of models with existing orbit libraries. The default is None.

Returns:
None.
Raises:
ValueError

If the orbit library of a model in rows_ml cannot be found in all_models.table.

create_and_run_model(data_input)

Main method to create and run a model

Parameters:
data_inputtuple of length 2 or 4

len(input)==2: (i, row) where i is the index of a model in this iteration, and row is the row index of the all_models table for this model Both the orblib and the weights will be computed. len(input==4): (i, row, get_orblib, get_weights) where i and row are as above, get_orblib==True if the orblib needs to be computed get_weights==True if the weights need to be computed

Returns:
tuple

all the output for this model, bundled up in a tuple

delete_staging_files(rows)

Deletes staging files.

Parameters:
rowsiterable of ints

The all_models table rows indicating models whose staging files are to be deleted.

Returns:
n_filesint

Number of staging files deleted.

is_new_orblib(row_idx)

Checks whether the orbit library characterized by the parameters in row number row_idx exists in earlier rows of self.all_models.table.

Parameters:
row_idxint

Row index of the model entry to be checked.

Returns:
is_newbool

True if no earlier row contains the orbit library, False otherwise.

run_iteration()

run one iteration step

Executes one iteration step: run all models in self.all_models.table for which all_done == False. The model runs (1) build the orbit library and (2) execute weight_solver. The models are run in parallel threads as defined in the ncpus parameter in the configuration file. In case multiple models comprise the same (new) orbit library it is ensured that they are calculated only once, avoiding conflicting threads.

Returns:
dict

ParameterGenerator.status.

write_output_to_all_models_table(rows_to_do, output)
Parameters:
rows_to_dolist of ints

which rows of all models table to fill with output

outputlist

output returned by Pool.map

Returns:
Fills output into the all_models table
class model_iterator.ModelIterator(config=None, model_kwargs={}, do_dummy_run=None, dummy_chi2_function=None, plots=True)

Iterator for models

Creating this ModelIterator object will (i) generate parameters sets, (ii) run models for those parameters, (iii) check stopping criteria, and iterate this procedure till a stopping criterion is met. This is implemented by creating a ModelInnerIterator object whose run_iteration method is called a number of times.

Parameters:
configa dyn.config_reader.Configuration object
model_kwargsdict

other kewyord argument required for this model

do_dummy_runBool

whether this is a dummy run - if so, dummy_chi2_funciton is executed instead of the model (for testing!)

dummy_chi2_functionfunction

a function of model parameters to be executed instead of the real model

plotsbool

whether or not to make plots

Methods:

get_plots()

Returns the latest iteration's plots as figure objects.

get_plots()

Returns the latest iteration’s plots as figure objects.

Returns:
tuple of matplotlib.pyplot.figure:

matplotlib.pyplot.figure: chi2 vs. model id plot matplotlib.pyplot.figure: chisquare plot (matplotlib.pyplot.figure, str): kinematic maps of best model so far, kinematics name

class model_iterator.SplitModelIterator(do_orblib=True, do_weights=True, **kwargs)

Class to run all models in a single iteration.

First calculates the orbit libraries and then runs weight solving. Both orbit integration and weight solving can be switched on and off. Uses pathos.multiprocessing.Pool to execute the models. Orbit integration uses a pool of ncpus parallel processes, weight solving uses ncpus_weights from the Configuration object.

Parameters:
do_orblibBool

If True, calculate orbit libraries for models with orblib_done==False.

do_weightsBool

If True, run weight solving for models with weights_done == False. Orblibs will be read from disk or computed if not existing.

configa dyn.config_reader.Configuration object
par_generatora dyn.parameter_space.ParameterGenerator child object
do_dummy_runBool

whether this is a dummy run - if so, dummy_chi2_funciton is executed instead of the model (for testing!)

dummy_chi2_functionfunction

a function of model parameters to be executed instead of the real model

Methods:

run_iteration()

Execute one iteration step

run_iteration()

Execute one iteration step

Calls the parameter generator and (a) calculates all new orbit libraries and consecutively (b) does the weight solving. (a) and (b) are run in their respective parallel pools as defined by the ncpus and ncpus_weights parameters, respectively.

Returns:
dict

ParameterGenerator.status.

Inheritance Diagram

Inheritance diagram of model_iterator