pynucastro.reduction package
Routines for nuclear reaction network reduction.
Submodules
pynucastro.reduction.drgep module
- pynucastro.reduction.drgep.calc_interaction_matrix(net, rvals)[source]
Calculate direct interaction coefficients.
- pynucastro.reduction.drgep.calc_interaction_matrix_numpy(net, rvals_arr)[source]
Calculate direct interaction coefficients using NumPy.
- pynucastro.reduction.drgep.drgep(net, conds, targets, tols, returnobj='net', use_mpi=False, use_numpy=False)[source]
Implementation of Directed Relation Graph with Error Propagation (DRGEP) reduction method described in Pepiot-Desjardins and Pitsch [2008] and Niemeyer and Sung [2011].
- Parameters:
net – The network (RateCollection) to reduce.
conds – A set of conditions to reduce over. Should either be a sequence of (composition, density, temperature) sequences/tuples if running in standard mode, or a sequence of 3 sequences ((composition, density, temperature) ordering) if running in NumPy mode. In the latter case, the sequences will be permuted to create the dataset. The compositions should be pynucastro Composition objects.
targets – A collection of target nuclei (or a single target nucleus) to run the graph search algorithm from. Should be supplied as pynucastro Nucleus objects or strings.
tols – Tolerance(s) or cutoff threshold(s) to use for paths from each of the target nuclei. Nuclei whose interaction coefficients do not meet the specified tolerance will have their interaction coefficients set to 0.0. Can be a single number (will be the same for all targets) or a separate value for each target nucleus.
returnobj – The type of object to return. Options are ‘net’ (a reduced network, the default setting), ‘nuclei’ (unique nuclei with nonzero interaction coefficients, ordered so the interaction coefficients are descending), and ‘coeff’ (the interaction coefficients as a NumPy array, with entries corresponding to nuclei in net.unique_nuclei).
use_mpi – Whether to divide up the set of conditions across MPI processes or not. Default setting is False.
use_numpy – Whether to use NumPy to vectorize the interaction coefficient calculations or not. This is more memory intensive and may actually hinder performance for some setups. Conditions should be supplied as 3 lists that will be permuted to form the dataset (see conds parameter). Default setting is False.
pynucastro.reduction.generate_data module
- pynucastro.reduction.generate_data.dataset(network, n=10, permute=True, b_rho=None, b_T=None, b_Z=None)[source]
Generate a dataset with n datapoints. Will either be returned as a sequence of tuples, each with order (composition, density, temperature) if permute is True (default), or the transpose of that if permute is False. The parameters b_rho, b_T, and b_Z are tuples giving the bounds on density, temperature, and metallicity respectively.
pynucastro.reduction.load_network module
pynucastro.reduction.reduction module
- class pynucastro.reduction.reduction.NetInfo(y, ydot, z, a, ebind, m)
Bases:
tuple
- a
Alias for field number 3
- ebind
Alias for field number 4
- m
Alias for field number 5
- y
Alias for field number 0
- ydot
Alias for field number 1
- z
Alias for field number 2
- pynucastro.reduction.reduction.abar_dot(net_info)[source]
Calculate the time rate of change of mean molecular weight.
- pynucastro.reduction.reduction.enuc_dot(net_info)[source]
Calculate the nuclear energy generation rate.
- pynucastro.reduction.reduction.get_errfunc_enuc(net_old, conds)[source]
Function for computing error in nuclear energy generation.
- pynucastro.reduction.reduction.map_comp(comp, net)[source]
Create new composition object with nuclei in net, and copy their mass fractions over.
pynucastro.reduction.reduction_utils module
- class pynucastro.reduction.reduction_utils.FailedMPIImport(error=None, msg=None)[source]
Bases:
object
Class that can replace an mpi4py.MPI import and will throw an error if used.
- pynucastro.reduction.reduction_utils.mpi_importer()[source]
Lazy MPI import, where we only throw an error if the import failed and then we attempt to use the object.
- pynucastro.reduction.reduction_utils.mpi_numpy_decomp(MPI_N, MPI_rank, n)[source]
Decompose a set of conditions for MPI_N MPI processes, where the conditions are a sequence of 3 sequences with ordering (composition_sequence, density_sequence, temperature_sequence). This structure for the dataset is necessary for the vectorized reduction algorithms.
pynucastro.reduction.sensitivity_analysis module
- pynucastro.reduction.sensitivity_analysis.binary_search_trim(network, nuclei, errfunc, thresh=0.05)[source]
Given an array of nuclei sorted roughly by relative importance, perform a binary search to trim out nuclei from the network until the error is as close as possible to the given threshold without exceeding it. Nuclei whose removal will result in only a small increase in error need to be packed towards the back of the array for the binary search to work effectively.
- Parameters:
network – The network to reduce.
nuclei – Nuclei to consider for the final network, sorted by decreasing importance (i.e. most important nuclei first). Importance can be determined by something like the drgep function.
errfunc – Error function to use when evaluating error. Should take a reduced network as an argument and return the relative error produced by the reduction. This can be a parallel (MPI) function.
thresh – Threshold for acceptable error. Default is 0.05.
- Returns:
A reduced reaction network with an evaluated error approximately equal to the supplied threshold.
- pynucastro.reduction.sensitivity_analysis.sens_analysis(network, errfunc, thresh=0.05, use_mpi=False, print_prog=True)[source]
Given a reaction network, remove nuclei from the network one-by-one until the induced error is as close to the given threshold as possible without exceeding it. This will test nuclei for removal individually and remove the one that induces the smallest error on each pass. Since it requires O(n^2) error function evaluations, this routine is much more expensive than binary_search, but it will typically trim the network down significantly more.
- Parameters:
network – The network to reduce.
errfunc – Error function to use when evaluating error. Should take a reduced network as an argument and return the relative error produced by the reduction. If use_mpi is False, the error function can be parallelized with MPI. Otherwise sens_analysis will be parallelized and the error function should not be.
thresh – Threshold for acceptable error. Default is 0.05.
use_mpi – Whether to parallelize the loop over nuclei with each pass or not using MPI. For p MPI processes, the parallelized function will require O(n^2/p) error function evaluations per process. This option is False by default. If the error function is parallelized using MPI, this option should be set to False.
print_prog – Whether to print out the progress of the function as it runs or not. Includes a progress bar for each pass and messages indicating when the algorithm starts and ends.
- Returns:
A reduced reaction network with an evaluated error approximately equal to the supplied threshold.