delphi.GrFN package

Submodules

delphi.GrFN.linking module

get_argument_lists(GrFN)[source]
get_call_conventions(GrFN)[source]
print_table_data(table_data)[source]
merge_similar_vars(vars)[source]
format_long_text(text)[source]
get_id(el_data)[source]

delphi.GrFN.networks module

class ComputationalGraph(*args, **kwargs)[source]

Bases: networkx.classes.digraph.DiGraph

static var_shortname(long_var_name)[source]
get_input_nodes() List[str][source]

Get all input nodes from a network.

get_output_nodes() List[str][source]

Get all output nodes from a network.

to_FCG()[source]
build_function_sets()[source]
run(inputs: Dict[str, Union[float, Iterable]]) Union[float, Iterable][source]

Executes the GrFN over a particular set of inputs and returns the result.

Parameters:

inputs – Input set where keys are the names of input nodes in the GrFN and each key points to a set of input values (or just one).

Returns:

A set of outputs from executing the GrFN, one for every set of inputs.

to_CAG()[source]

Export to a Causal Analysis Graph (CAG) PyGraphviz AGraph object. The CAG shows the influence relationships between the variables and elides the function nodes.

class GroundedFunctionNetwork(G, scope_tree, outputs)[source]

Bases: delphi.GrFN.networks.ComputationalGraph

Representation of a GrFN model as a DiGraph with a set of input nodes and currently a single output. The DiGraph is composed of variable nodes and function nodes. Function nodes store an actual Python function with the expected set of ordered input arguments that correspond to the variable inputs of that node. Variable nodes store a value. This value can be any data type found in Python. When no value exists for a variable the value key will be set to None. Importantly only function nodes can be children or parents of variable nodes, and the reverse is also true. Both variable and function nodes can be inputs, but the output will always be a variable node.

traverse_nodes(node_set, depth=0)[source]

BFS traversal of nodes that returns name traversal as large string.

Parameters:
  • node_set – Set of input nodes to begin traversal.

  • depth – Current traversal depth for child node viewing.

Returns:

type – String containing tabbed traversal view.

classmethod from_json_and_lambdas(file: str, lambdas)[source]

Builds a GrFN from a JSON object.

Parameters:
  • cls – The class variable for object creation.

  • file – Filename of a GrFN JSON file.

  • lambdas – A lambdas module

Returns:

type – A GroundedFunctionNetwork object.

classmethod from_dict(data: Dict, lambdas_path)[source]

Builds a GrFN object from a set of extracted function data objects and an associated file of lambda functions.

Parameters:
  • cls – The class variable for object creation.

  • data – A set of function data object that specify the wiring of a GrFN object.

  • lambdas_path – Path to a lambdas file containing functions to be computed during GrFN execution.

Returns:

A GroundedFunctionNetwork object.

static create_container_dict(G: networkx.classes.digraph.DiGraph)[source]
classmethod from_python_file(python_file, lambdas_path, json_filename: str, stem: str)[source]

Builds GrFN object from Python file.

classmethod from_python_src(pySrc, python_file: str, fortran_file: str, module_log_file_path: str, mod_mapper_dict: list, processing_modules: bool)[source]
classmethod from_fortran_file(fortran_file: str, tmpdir: str = '.')[source]

Builds GrFN object from a Fortran program.

classmethod from_fortran_src(fortran_src: str, dir: str = '.')[source]

Create a GroundedFunctionNetwork instance from a string with raw Fortran code.

Parameters:
  • fortran_src – A string with Fortran source code.

  • dir – (Optional) - the directory in which the temporary Fortran file will be created (make sure you have write permission!) Defaults to the current directory.

Returns:

A GroundedFunctionNetwork instance

to_json()[source]

Experimental outputting a GrFN to a JSON file.

to_json_file(filename)[source]
to_AGraph()[source]

Export to a PyGraphviz AGraph object.

CAG_to_AGraph()[source]

Returns a variable-only view of the GrFN in the form of an AGraph.

Returns:

type – A CAG constructed via variable influence in the GrFN object.

FCG_to_AGraph()[source]

Build a PyGraphviz AGraph object corresponding to a call graph of functions.

class ForwardInfluenceBlanket(G: delphi.GrFN.networks.GroundedFunctionNetwork, shared_nodes: Set[str])[source]

Bases: delphi.GrFN.networks.ComputationalGraph

This class takes a network and a list of a shared nodes between the input network and a secondary network. From this list a shared nodes and blanket network is created including all of the nodes between any input/output pair in the shared nodes, as well as all nodes required to blanket the network for forward influence. This class itself becomes the blanket and inherits from the ComputationalGraph class.

classmethod from_GrFN(G1, G2)[source]

Creates a ForwardInfluenceBlanket object representing the intersection of this model with the other input model.

Parameters:
  • G1 – The GrFN model to use as the basis for this FIB

  • G2 – The GroundedFunctionNetwork object to compare this model to.

Returns:

A ForwardInfluenceBlanket object to use for model comparison.

run(inputs: Dict[str, Union[float, Iterable]], covers: Dict[str, Union[float, Iterable]]) Union[float, Iterable][source]

Executes the FIB over a particular set of inputs and returns the result. :param inputs: Input set where keys are the names of input nodes in the

GrFN and each key points to a set of input values (or just one).

Returns:

A set of outputs from executing the GrFN, one for every set of inputs.

to_AGraph()[source]

delphi.GrFN.sensitivity module

delphi.GrFN.utils module

timeit(func)[source]

Record the runtime of the decorated function.

class ScopeNode(container_dict, occ, parent=None)[source]

Bases: object

results_to_csv(filepath: str, inputMat: Iterable, outputMat: Iterable) None[source]
results_to_json(filepath: str, inputMat: Iterable, outputMat: Iterable) None[source]
bounds_from_csv(filepath: str) dict[source]
bounds_from_json(filepath: str) dict[source]

delphi.GrFN.visualization module

class SensitivityVisualizer(S: list)[source]

Bases: object

This class is responsible for generating plots of the first and second order sensitivity indices as well as the runtime of each computation as a function of the logarithm of the sample sizes.

S

List of python dictionaries with the following keys - ‘N’,

Type:

list

'S1', 'S2', 'sampling time', 'execution time', 'analysis time'.
N -- sample size
Type:

log 10 scale

S1 -- numpy array of First Order Sensitivity Indices
S2 -- pandas dataframe of Second Order Sensitivity Indices
sampling time -- time taken to complete the sampling process after
invoking a method from the SALib library
execution time -- time taken for executing the GrFN
analysis time -- time taken for the computation of Sensitivity Indices
create_S1_plot(filename='s1_plot.pdf')[source]

Creates a plot of S1 versus log (base 10) of sample sizes. :param filename: Filename to save plot to.

create_S2_plot(filename='s2_plot.pdf')[source]

Creates gridplot with second order Sobol index matrices for largest sample size on log (base 10) scale.

Parameters:

filename – Filename to save plot to.

create_clocktime_plot(filename='clocktime_plot.pdf')[source]

Creates plot of runtime (Sample Time, Execution Time, and Analysis Time) versus log (base 10) of sample sizes

Module contents