Iterative Base Class
Warning
This class is not designed for standalone use. Instead, it should be inherited by other classes.
- class pydmqmc.methods.Iterative(system, parallel=False)
Bases:
MethodBase class for iterative calculations.
- Parameters:
- systemSystem object
The predefined System to run the model with.
- parallelbool, default False
Whether to use MPI to parallelize the calculation.
Attributes
Whether the current process is the designated reporter.
Whether this method is set up to run in parallel.
Whether the current processor is the root if running in parallel.
Rank of the current processor if running in parallel.
Number of processors if running in parallel.
Whether or not the calculation has been run.
List of dictionaries with report values.
Dictionary of fulfilled requirements for each report value.
The list of values to be reported throughout the calculation.
The System object to which this method is applied.
Methods
do_report(itr_var_name, itr_var_value[, quiet])Store information about the current iteration in self.report.
parse_method([method])Parse the supplied string to return the corresponding function.
reset_rng([rng_seed])Create a new psuedo-random number generator with the given seed.
run()Ensure calculations are only run once.
save_data(report_basename[, index_quant, ...])Save the iteration report to file.
setup(report_values)Create structures for periodically reporting calculation state.
- do_report(itr_var_name, itr_var_value, quiet=False)
Store information about the current iteration in self.report.
The iteration variable (that is, the variable being monotonically changed as the iteration progresses) must be supplied to provide context about the data being stored.
Only one process (the root, if in parallel) will actually execute this function.
- Parameters:
- itr_var_namestr
Name of the iteration variable as it should be recorded.
- itr_var_valuefloat
Current value of the iteration variable.
- quietbool, default False
Silence printing the current report. Report will still be saved internally.
- parse_method(method='euler')
Parse the supplied string to return the corresponding function.
Expected call signature for each method is
(func, x, y, dy)where func(x, y) = dx/dy.- Supported methods are:
Forward Euler (
euler)4th Order Runge Kutta (
rk4)
- Parameters:
- method{“euler”, “rk4”}
Desired integration method.
- Returns:
- callable
The associated function from
pydmqmc.utils.integrators
- reset_rng(rng_seed=None)
Create a new psuedo-random number generator with the given seed.
If running in parallel, each processor will have a unique seed based on the supplied rng_seed.
- Parameters:
- rng_seedint or array_like of ints, optional
Seed or sequence of seeds for the psuedo-random number generator. See
numpy.random.default_rng(). If using MPI parallelization, each processor will have a unique seed based on this value.
- run()
Ensure calculations are only run once.
This base method handles a flag to ensure
runis only called once. Any other calculations must be defined by the child class.
- save_data(report_basename, index_quant=None, report_filetype='csv', pickle_protocol=None)
Save the iteration report to file.
- Parameters:
- report_basenamestr
Base filename for saving the iteration report. Will automatically be combined with the extension specified by
report_filetype.- index_quantstring, optional
Name of the quantity to put as the first column. Must be a key in the report.
- report_filetypestr, default “csv”
File type (aka extension) with which to save the report. Supported types are:
“csv” : comma-separated value file
“txt” : text file (space-delimited)
“pkl” : pickle file
- pickle_protocolunt, optional
Protocol version to use if either filetype is “pkl”. If none, uses pickle’s default.
- setup(report_values)
Create structures for periodically reporting calculation state.
This base method creates a data structure for reporting user-supplied values every iteration. Any other setup activities must be defined by the child class.
- Parameters:
- report_valueslist of strings
List of values to periodically report while performing the calculation. Each item must be recognized by the report_registry. The iteration variable will automatically be included.
- property is_reporter
Whether the current process is the designated reporter.
This process creates the iteration report and writes it to both stdout and to file. If running in serial, the current process is always designated as the reporter.
- property parallel
Whether this method is set up to run in parallel.
- property parallel_is_parent
Whether the current processor is the root if running in parallel.
- property parallel_rank
Rank of the current processor if running in parallel.
- property parallel_size
Number of processors if running in parallel.
- property ran_calculation
Whether or not the calculation has been run.
- property report
List of dictionaries with report values.
- property report_requirements
Dictionary of fulfilled requirements for each report value.
- property report_values
The list of values to be reported throughout the calculation.
- property system
The System object to which this method is applied.