Advanced Usage of GraphTemplate

Unlike the EventTemplate and SelectionTemplate classes, this template module is rather simplistic by construction, as such it will be a short section. Most of the content explained in the Graph Definitions is already considered advanced, however, there are some hidden features that this class has, which was not discussed previously.

class GraphTemplate
__scrapecode__(fx, str key) Code

A function which returns a dictionary which actually is a data type called code_t. This dictionary contains information about the code object and how it is preserved. For more details, see the Code Tracing documentation.

AddGraphFeature(fx, str name = "")
Parameters:

fx (function) – Function used to compute the graph feature.

AddNodeFeature(fx, str name = "")
Parameters:

fx (function) – Function used to compute the node feature.

AddEdgeFeature(fx, str name = "")
Parameters:

fx (function) – Function used to compute the edge feature.

AddGraphTruthFeature(fx, str name = "")
Parameters:

fx (function) – Function used to compute the graph feature.

AddNodeTruthFeature(fx, str name = "")
Parameters:

fx (function) – Function used to compute the node feature.

AddEdgeTruthFeature(fx, str name = "")
Parameters:

fx (function) – Function used to compute the edge feature.

AddPreSelection(fx, str name = "")
Parameters:

fx (function) – Function used to accept or reject this graph

SetTopology(fx=None)
Parameters:

fx (function) – Function used to impose a prior bias on the topology.

__buildthis__(str key, str co_hash, bool preselection, list this)

A method which builds the given feature.

Build()

A method which builds the graph object.

ImportCode(dict inpt)

A method which imports Code objects to the graph.

ParticleToIndex(ParticleTemplate val) int

Returns the index of the given particle object within the computation graph.

is_self(inpt) bool

Returns a boolean value on whether the input is of GraphTemplate type.

ImportMetaData(meta_t meta)

Import the MetaData object dictionary.

Import(graph_t graph)

Instantiate a graph object from a graph_t dictionary type.

clone() GraphTemplate

A function which creates a duplicate of the graph object. This does not clone the graph attributes, but rather only creates an empty clone of the given graph.

Topology -> list

Returns the current graph topology.

Export -> graph_t

Export the graph object as a dictionary.

Event

A variable used to indicate the event to be the target for graph compilation. Requires an EventTemplate object or any object which has the appropriate attributes.

Particles -> list

A list of particles to compute the topology/graph/node from.

self_loops -> bool

Connect nodes to themselves, i.e. the edge-index tensor will have values with i = j.

code_owner -> bool

A special attribute used to indicate whether the C++ backend should be owner of the code objects.

code -> dict[str, Code]

Returns a dictionary with the Code objects used to construct the graph.

index -> int

An index used to track which event the graph is being computed from.

Errors -> dict

Outputs a dictionary with errors encountered during graph construction.

PreSelectionMetric -> dict

Outputs information about the PreSelection function’s impact on graphs.

Train -> bool

Assign the graph for training sample.

Eval -> bool

Assign the graph to evaluation sample.

Validation -> bool

Assign the graph to validation sample.

EmptyGraph -> bool

Returns a True if the event has no particles/event passing the PreSelection or Topology functions.

SkipGraph -> bool

Exclude the graph from training/validation/evaluation.

Tag -> str

A variable used to tag the event with some string value.

cached -> bool

Indicates whether this graph has been cached and saved within a HDF5 file.

ROOT -> str

Returns the ROOT filename from which the event was compiled from.

hash -> str

Once set, an 18 character long string will be internally generated, which cannot be modified. The hash is computed from input/<event index>/, and assigns each event a unique identity such that the tracer can retrieve the specified event. If the getter (self.hash) has been called prior to the setter (self.hash = 'something'), then an empty string is returned.

Graph -> bool

Returns a boolean to indicate this graph to be of GraphTemplate type.

GraphName -> str

Returns the name of this graph type.

Tree -> str

Returns the ROOT Tree from which the graph was generated from.

Missing EventTemplate Attribute Behavior

from AnalysisG.Templates import GraphTemplate

class MyGraph(GraphTemplate):

    def __init__(self, Event = None):
        self.Event = Event
        self.Particles += self.Event.ArbitraryParticleName

Consider the code-block above, one might wonder what would happen if the Event implementation is missing an attribute? Generally, this would result in the code crashing and throwing the AttributeError exception. The framework in constructed to account for such instances using a pseudo-event object, which is instantiated when the self.Event variable is set. When the object does not contain the attribute ArbitraryParticleName, the pseudo-event will return an empty list, and thus populate an empty graph (although graph level features would still be included). This means, the event or event-graph would still be available, but with no particle nodes or edges.