Diagnostics – Reference Guide

This guide is for versions 1.0.0rc.2+ (Release Candidate)

Source code

Class Diagnostics

    For the management of reaction diagnostic data
    
nameargumentsreturns
__init__chem_data

nameargumentsreturns
save_rxn_datarxn_index :int, system_time, time_step, increment_vector_single_rxn: Union[np.array, None], aborted=False, rate=None, caption=""None
        Save up diagnostic data for 1 reaction, for a simulation step
        (by convention, regardless of whether the step is completed or aborted)

        :param rxn_index:                   The integer index (0-based) to identify the reaction of interest
        :param system_time:                 The START time of the reaction step
        :param time_step:                   The duration of the current simulation step
        :param increment_vector_single_rxn: A Numpy array of size equal to the total number of chemical species,
                                                containing the "delta concentrations" caused by this reaction
                                                for ALL the chemicals (whether involved in the reaction or not);
                                                it may be None if the current reaction step was aborted
                                                Note: diagnostic data is saved only for the chemicals involved in this reaction
        :param aborted:                     True is the current reaction step was aborted (i.e. will get repeated);
                                                False (default) for normal situations
        :param rate:                        [OPTIONAL] The value of the reaction rate (aka reaction velocity) at this step
        :param caption:                     [OPTIONAL] string to describe the snapshot
        :return:                            None
        
nameargumentsreturns
save_diagnostic_aborted_rxnssystem_time, time_step, caption=""None
        Save up diagnostic data, for ALL reactions, in case of aborted simulation step

        :param system_time: The START time of the reaction step
        :param time_step:   The duration of the current simulation step
        :param caption:     [OPTIONAL] string to describe the snapshot
        :return:            None
        
nameargumentsreturns
annotate_abort_rxn_datamsg: strNone
        Store the given value in the caption field of the last record
        for EACH of the reaction-specific dataframes.
        Also, set the "aborted" fields to "True"

        :param msg: Value to set the comment field to
        :return:    None
        
nameargumentsreturns
get_rxn_ratesrxn_index :intUnion[pd.DataFrame, None]
        Return a Pandas dataframe with 2 columns: "START_TIME" and "rate",
        with the rates of the specified reaction at those times.

        Note that the dataframe will have 1 LESS ROW than a corresponding dataframe of concentration history,
        because the rate at the final time won't be known (since that time would be the start of a simulation step
        that has not been done)

        Also, aborted time steps are eliminated (only the rate of the final "re-do" is included)

        :param rxn_index:   The integer index (0-based) to identify the reaction of interest
        :return:            A Pandas dataframe with times and their corresponding reaction rates
        
nameargumentsreturns
get_rxn_datarxn_index :int, head=None, tail=None, t=None, print_reaction=TrueUnion[pd.DataFrame, None]
        Return a Pandas dataframe with the diagnostic run data of the requested SINGLE reaction,
        from the time that the diagnostics were enabled by instantiating this class.

        In particular, the dataframe contains the reaction rate at the start time,
        and the "Delta" values for each of the chemicals
        involved in the reaction - i.e. the change in their concentrations
        over the time interval that *STARTS* at the value in the "START_TIME" column.
        (So, there'll be no row with the final current System Time)

        Note: entries are always added, even if an interval run is aborted and automatically re-done;
              therefore, some entries will be duplicates in the "START_TIME" column.
              Those entries with have a value of True in the "aborted" column.

        Optionally, print out a brief description of the reaction.

        Optionally, limit the dataframe to a specified numbers of rows at the end,
        or just return one entry corresponding to a specific time
        (the row with the CLOSEST time to the requested one, which will appear in an extra column
        called "search_value")

        :param rxn_index:       The integer index (0-based) to identify the reaction of interest

        :param head:            (OPTIONAL) Number of records to return,
                                    from the start of the diagnostic dataframe.
        :param tail:            (OPTIONAL) Number of records to return,
                                    from the end of the diagnostic dataframe.
                                    If either the "head" arguments is passed, this argument will get ignored

        :param t:               (OPTIONAL) Individual time to pluck out from the dataframe;
                                    the row with closest time will be returned.
                                    If this parameter is specified, an extra column - called "search_value" -
                                    is inserted at the beginning of the dataframe
                                    If either the "head" or the "tail" arguments are passed, this argument will get ignored

        :param print_reaction:  (OPTIONAL) If True (default), concisely print out the requested reaction

        :return:                If present, return a Pandas data frame with (all or some of)
                                    the diagnostic data of the specified reaction.
                                    Columns of the dataframes:
                                    'START_TIME','time_step','aborted','Delta A','Delta B'...,'rate','caption'
                                If not present, return None
        
nameargumentsreturns
save_diagnostic_conc_datasystem_data, system_time, caption=""None
        Save the diagnostic concentration data during the run, indexed by the current System Time.
        Note: if an interval run is aborted, by convention NO entry is created here

        :return: None
        
nameargumentsreturns
get_diagnostic_conc_dataselfpd.DataFrame
        Return the diagnostic concentration data saved during the run.
        This will be a complete set of simulation steps,
        even if the user elected to only save part of the history during the run.

        Note: if the run of an interval step is aborted,
              by convention NO entry is created here

        :return: A Pandas dataframe, with the columns:
                    'TIME' 	'A' 'B' ... 'caption'
                    where 'A', 'B', ... are the labels of all the chemicals
        
nameargumentsreturns
save_diagnostic_decisions_datasystem_time, data :dict, delta_conc_arr :Union[np.ndarray, None], caption=""None
        Used to save the diagnostic concentration data during the run, indexed by the given System Time.
        Note: if an interval run is aborted, by convention an entry is STILL created here

        :param system_time:
        :param data:
        :param delta_conc_arr:  A Numpy array of "delta concentrations".  EXAMPLE: array[1.23, 52.2]
        :param caption:         [OPTIONAL] String with a caption for this record
        :return:                None
        
nameargumentsreturns
get_decisions_dataselfpd.DataFrame
        Determine and return the diagnostic data about concentration changes at every step - by convention,
        EVEN aborted ones
    
        :return:    A Pandas dataframe with a "TIME" column, and columns for all the "Delta concentration" values
        
nameargumentsreturns
explain_reactionsselfbool
        Provide a detailed explanation of all the steps of the reactions,
        from the saved diagnostic data

        WARNING: Currently designed only for exactly 2 reactions!  

        :return:    True if the diagnostic data is consistent for all the steps of all the reactions,
                    or False otherwise
        
nameargumentsreturns
explain_time_advancereturn_times=False, silent=False, sys_history=NoneUnion[None, tuple]
        Use the saved-up diagnostic data, to print out details of the timescales of the reaction run

        If diagnostics weren't enabled ahead of calling this function, an Exception is raised

        EXAMPLE of output:
            From time 0 to 0.0304, in 17 FULL steps of 0.0008
            (for a grand total of 38 FULL steps)

        :param return_times:    If True, all the critical times (times where the interval steps change)
                                    are saved and returned as a list
        :param silent:          If True, nothing gets printed out
        :param sys_history:     [OPTIONAL] The system history.
                                    If passed, use it in lieu of the diagnostic data;
                                    a consideration is the fact that the user might only have asked
                                    for PART of the history to be saved
        :return:                Depending on the argument "return_times", it returns either None, or a pair with 2 lists:
                                        1 - list of time values
                                        2 - list of step sizes  (will have one less element than the first list)
        
nameargumentsreturns
stoichiometry_checkerrxn_index :int, conc_arr_before: np.array, conc_arr_after: np.arraybool
        For the indicated reaction, investigate the change in the concentration of the involved chemicals,
        to ascertain whether the change is consistent with the reaction's stoichiometry.
        See https://life123.science/reactions

        IMPORTANT: this function is currently meant for simulations involving only 1 reaction

        NOTE: the concentration changes in chemicals not involved in the specified reaction are ignored

        :param rxn_index:       The integer index (0-based) to identify the reaction of interest
        :param conc_arr_before: Numpy array with the concentrations of ALL the chemicals (whether involved
                                    in the reaction or not), in their index order, BEFORE the reaction step
        :param conc_arr_after:  Same as above, but after the reaction

        :return:                True if the change in reactant/product concentrations is consistent with the
                                    reaction's stoichiometry, or False otherwise
        
nameargumentsreturns
stoichiometry_checker_entire_runselfbool
        Verify that the stoichiometry is satisfied in all the reaction steps,
        using the diagnostic data from an earlier run

        IMPORTANT: this function is currently meant for simulations involving only 1 reaction

        :return:    True if everything checks out, or False otherwise