Nektar++
|
Classes | |
class | LUTState |
Public Member Functions | |
def | __init__ (self) |
def | config (self) |
def | var_is_membrane_potential (self, var) |
def | is_allowed_variable (self, var) |
def | is_keying_var (self, var) |
def | set_params (self, **kw) |
def | get_param (self, param_name, table_var) |
def | create_state_from_annotations (self, expr) |
def | analyse_for_lut (self, expr, var_checker_fn) |
def | check_divide_by_table (self, expr, operand_states) |
def | check_commutative_tables (self, expr, operand_states) |
def | annotate_as_suitable (self, expr, table_var) |
def | remove_lut_annotations (self, expr, remove_reason=False) |
def | analyse_model (self, doc, solver_info, annotate_failures=True, annotate_outermost_only=True) |
def | calculate_dependencies (self, expr) |
Static Public Member Functions | |
def | copy_lut_annotations (from_expr, to_expr) |
Public Attributes | |
doc | |
solver_info | |
annotate_failures | |
annotate_outermost_only | |
Static Public Attributes | |
lut_expensive_funcs | |
Private Member Functions | |
def | _find_tables (self, expr, table_dict) |
def | _determine_unneeded_tables (self) |
def | _determine_duplicate_tables (self) |
Static Private Attributes | |
dictionary | _LT_DEFAULTS |
Analyses & annotates a CellML model to indicate where lookup tables can be used.
Definition at line 384 of file optimize.py.
def CellMLToNektar.optimize.LookupTableAnalyser.__init__ | ( | self | ) |
Create an analyser.
Definition at line 390 of file optimize.py.
|
private |
Determine whether we have multiple tables for the same expression. Any expression that is identical to a previous table will be re-annotated to refer to the previous table, instead of declaring a new one. This is a temporary measure until we have proper sub-expression elimination for the Jacobian and residual calculations.
Definition at line 860 of file optimize.py.
References Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, and CellMLToNektar.translators.ConfigurationStore.doc.
|
private |
Determine whether some expressions identified as lookup tables aren't actually used. This occurs if some ODEs have been linearised, in which case the original definitions will have been analysed for lookup tables, but aren't actually used. TODO: The original definitions might be used for computing derived quantities...
Definition at line 834 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser._find_tables(), CellMLToNektar.utilities.DEBUG(), Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.optimize.LookupTableAnalyser.remove_lut_annotations(), CellMLToNektar.optimize.PartialEvaluator.solver_info, and CellMLToNektar.optimize.LookupTableAnalyser.solver_info.
|
private |
Helper method for _determine_unneeded_tables.
Definition at line 826 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser._find_tables(), Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, and CellMLToNektar.translators.ConfigurationStore.doc.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser._determine_unneeded_tables(), and CellMLToNektar.optimize.LookupTableAnalyser._find_tables().
def CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut | ( | self, | |
expr, | |||
var_checker_fn | |||
) |
Check if the given expression can be replaced by a lookup table. The first argument is the expression to check; the second is a function which takes a variable object and returns True iff this variable is permitted within a lookup table expression. If self.annotate_failures is True then annotate <apply> and <piecewise> expressions which don't qualify with the reason why they do not. This can be: 'no_var' - doesn't contain the table variable 'bad_var <vname>' - contains a variable which isn't permitted 'no_func' - doesn't contain an expensive function or a comma separated combination of the above. The annotation is stored as the lut:reason attribute. If self.annotate_outermost_only is True then only annotate the outermost qualifying expression, rather than also annotating qualifying subexpressions.
Definition at line 556 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut(), CellMLToNektar.optimize.LookupTableAnalyser.annotate_as_suitable(), CellMLToNektar.optimize.LookupTableAnalyser.annotate_failures, CellMLToNektar.optimize.LookupTableAnalyser.annotate_outermost_only, CellMLToNektar.optimize.LookupTableAnalyser.check_commutative_tables(), CellMLToNektar.optimize.LookupTableAnalyser.check_divide_by_table(), CellMLToNektar.pycml.child_i(), CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), CellMLToNektar.optimize.LookupTableAnalyser.create_state_from_annotations(), CellMLToNektar.utilities.DEBUG(), CellMLToNektar.optimize.LookupTableAnalyser.is_keying_var(), and CellMLToNektar.optimize.LookupTableAnalyser.lut_expensive_funcs.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut().
def CellMLToNektar.optimize.LookupTableAnalyser.analyse_model | ( | self, | |
doc, | |||
solver_info, | |||
annotate_failures = True , |
|||
annotate_outermost_only = True |
|||
) |
Analyse the given document. This method checks all expressions (and subexpressions) in the given document for whether they could be converted to use a lookup table, and annotates them appropriately. By default expressions which don't qualify will be annotated to indicate why; set annotate_failures to False to suppress this. Also by default only the outermost suitable expression in any given tree will be annotated; if you want to annotate suitable subexpressions of a suitable expression then pass annotate_outermost_only as False.
Definition at line 758 of file optimize.py.
References Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, and CellMLToNektar.translators.ConfigurationStore.doc.
def CellMLToNektar.optimize.LookupTableAnalyser.annotate_as_suitable | ( | self, | |
expr, | |||
table_var | |||
) |
Annotate the given expression as being suitable for a lookup table.
Definition at line 714 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser.annotate_outermost_only, Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.optimize.LookupTableAnalyser.get_param(), and CellMLToNektar.optimize.LookupTableAnalyser.remove_lut_annotations().
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut(), CellMLToNektar.optimize.LookupTableAnalyser.check_commutative_tables(), and CellMLToNektar.optimize.LookupTableAnalyser.check_divide_by_table().
def CellMLToNektar.optimize.LookupTableAnalyser.calculate_dependencies | ( | self, | |
expr | |||
) |
Determine the dependencies of an expression that might use a lookup table. This method is suitable for use as the needs_special_treatment function in mathml_apply.classify_variables. It is used to override the default recursion into sub-trees. It takes a single sub-tree as argument, and returns either the dependency set for that sub-tree, or None to use the default recursion. Expressions that can use a lookup table only depend on the keying variable.
Definition at line 881 of file optimize.py.
def CellMLToNektar.optimize.LookupTableAnalyser.check_commutative_tables | ( | self, | |
expr, | |||
operand_states | |||
) |
Check whether we can combine suitable operands into a new expression. If expr has a commutative (and associative) n-ary operator, but is not suitable as a whole to become a lookup table (checked by caller) then we might still be able to do slightly better than just analysing its operands. If multiple operands can be replaced by tables keyed on the same variable, these can be combined into a new application of the same operator as expr, which can then be replaced as a whole by a single lookup table, and made an operand of expr. Alternatively, if at least one operand can be replaced by a table, and a subset of other operands do not contain other variables, then they can be included in the single table.
Definition at line 664 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser.annotate_as_suitable().
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut().
def CellMLToNektar.optimize.LookupTableAnalyser.check_divide_by_table | ( | self, | |
expr, | |||
operand_states | |||
) |
Convert division by a table into multiplication. This is called if expr, a division, cannot be replaced as a whole by a lookup table. If the denominator can be replaced by a table, then convert expr into a multiplication by the reciprocal, moving the division into the table.
Definition at line 647 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser.annotate_as_suitable().
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut().
def CellMLToNektar.optimize.LookupTableAnalyser.config | ( | self | ) |
Get the current document's configuration store.
Definition at line 398 of file optimize.py.
References Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, and CellMLToNektar.translators.ConfigurationStore.doc.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut(), CellMLToNektar.optimize.LookupTableAnalyser.get_param(), CellMLToNektar.optimize.LookupTableAnalyser.is_allowed_variable(), CellMLToNektar.optimize.LookupTableAnalyser.is_keying_var(), CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods(), CellMLToNektar.translators.CellMLTranslator.output_single_lookup(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code().
|
static |
Copy any lookup table annotations from one expression to another.
Definition at line 727 of file optimize.py.
def CellMLToNektar.optimize.LookupTableAnalyser.create_state_from_annotations | ( | self, | |
expr | |||
) |
Create a LUTState instance from an already annotated expression.
Definition at line 537 of file optimize.py.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut().
def CellMLToNektar.optimize.LookupTableAnalyser.get_param | ( | self, | |
param_name, | |||
table_var | |||
) |
Get the value of the lookup table parameter. table_var is the variable object being used to key this table. If the document has a config store, lookup the value there. If that doesn't give us a value, use that given using set_params.
Definition at line 453 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser.config(), and CellMLToNektar.translators.CellMLTranslator.config().
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.annotate_as_suitable().
def CellMLToNektar.optimize.LookupTableAnalyser.is_allowed_variable | ( | self, | |
var | |||
) |
Return True iff the given variable is allowed in a lookup table. This method uses the config store in the document to check the variable object.
Definition at line 410 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), CellMLToNektar.optimize.PartialEvaluator.solver_info, and CellMLToNektar.optimize.LookupTableAnalyser.solver_info.
def CellMLToNektar.optimize.LookupTableAnalyser.is_keying_var | ( | self, | |
var | |||
) |
Return True iff the given variable can be used as a table key. Will check the config store if it exists. If not, the variable name must match self.table_var.
Definition at line 421 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), and CellMLToNektar.optimize.LookupTableAnalyser.LUTState.table_var.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut().
def CellMLToNektar.optimize.LookupTableAnalyser.remove_lut_annotations | ( | self, | |
expr, | |||
remove_reason = False |
|||
) |
Remove lookup table annotations from the given expression. By default this will only remove annotations from expressions (and sub-expressions) that can be converted to use lookup tables. If remove_reason is True, then the lut:reason attributes on non-qualifying expressions will also be removed.
Definition at line 733 of file optimize.py.
References Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, and CellMLToNektar.optimize.LookupTableAnalyser.remove_lut_annotations().
Referenced by CellMLToNektar.optimize.LookupTableAnalyser._determine_unneeded_tables(), CellMLToNektar.optimize.LookupTableAnalyser.annotate_as_suitable(), and CellMLToNektar.optimize.LookupTableAnalyser.remove_lut_annotations().
def CellMLToNektar.optimize.LookupTableAnalyser.set_params | ( | self, | |
** | kw | ||
) |
Set parameters controlling lookup table generation. Keyword parameters control the lookup table settings, which are stored as attributes on suitable expressions. table_min - minimum table entry (unicode) -> lut:min table_max - maximum table entry (unicode) -> lut:max table_step - table step size (unicode) -> lut:step table_var - the name of the variable indexing the table (unicode) -> lut:var
Definition at line 435 of file optimize.py.
References CellMLToNektar.optimize.LookupTableAnalyser._LT_DEFAULTS.
def CellMLToNektar.optimize.LookupTableAnalyser.var_is_membrane_potential | ( | self, | |
var | |||
) |
Determine if the given variable represents the transmembrane potential. This method takes an instance of cellml_variable and returns a boolean.
Definition at line 402 of file optimize.py.
|
staticprivate |
Definition at line 431 of file optimize.py.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.set_params().
CellMLToNektar.optimize.LookupTableAnalyser.annotate_failures |
Definition at line 778 of file optimize.py.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut().
CellMLToNektar.optimize.LookupTableAnalyser.annotate_outermost_only |
Definition at line 779 of file optimize.py.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut(), and CellMLToNektar.optimize.LookupTableAnalyser.annotate_as_suitable().
CellMLToNektar.optimize.LookupTableAnalyser.doc |
Definition at line 393 of file optimize.py.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser._determine_duplicate_tables(), CellMLToNektar.optimize.LookupTableAnalyser._determine_unneeded_tables(), CellMLToNektar.optimize.PartialEvaluator._do_reduce_eval_loop(), CellMLToNektar.optimize.LookupTableAnalyser._find_tables(), CellMLToNektar.translators.ConfigurationStore._find_transmembrane_currents_from_voltage_ode(), CellMLToNektar.translators.ConfigurationStore._find_variable(), CellMLToNektar.optimize.PartialEvaluator._get_assignment_exprs(), CellMLToNektar.optimize.LookupTableAnalyser.analyse_model(), CellMLToNektar.optimize.LookupTableAnalyser.annotate_as_suitable(), CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), CellMLToNektar.translators.ConfigurationStore.expose_variables(), CellMLToNektar.translators.ConfigurationStore.find_current_vars(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.get_stimulus_assignment(), CellMLToNektar.optimize.PartialEvaluator.is_instantiable(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lut_parameters(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_intracellular_calcium(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), CellMLToNektar.translators.CellMLTranslator.output_lut_declarations(), CellMLToNektar.translators.CellMLTranslator.output_lut_deletion(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_indices(), CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_memory(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation(), CellMLToNektar.translators.ConfigurationStore.read_configuration_file(), CellMLToNektar.optimize.LookupTableAnalyser.remove_lut_annotations(), CellMLToNektar.translators.CellMLTranslator.scan_for_lookup_tables(), and CellMLToNektar.translators.ConfigurationStore.validate_metadata().
|
static |
Definition at line 469 of file optimize.py.
Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut().
CellMLToNektar.optimize.LookupTableAnalyser.solver_info |