pyiron_contrib.protocol.generic module
- class pyiron_contrib.protocol.generic.CompoundVertex(**kwargs)[source]
Bases:
Vertex
Vertices which contain a graph and produce output only after traversing their graph to its exit point.
- Input:
graph (Graph): The graph of vertices to traverse. protocol_finished (Event): protocol_started (Event): vertex_processing (Event): vertex_processed (Event): finished (bool):
- property default_whitelist
- abstract define_information_flow()[source]
Connect input and output information inside the graph. Also set the archive clock for all vertices.
- execute_parallel(n, all_child_output)[source]
How to execute in parallel when there’s a list of these vertices together.
- format_whitelist(format='tree', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]
- from_hdf(hdf=None, group_name=None)[source]
Load the Protocol from an HDF5 file.
- Parameters
hdf (ProjectHDFio) – HDF5 group object - optional
group_name (str) – HDF5 subgroup name - optional
- abstract get_output()[source]
Define the output dictionary to be returned when the graph traversal completes. This synchronizes the behaviour of primitive vertices and compound vertices when they themselves are the child vertex in another graph.
- restore_default_whitelist()[source]
If the protcol type has an attribute DefaultWhitelist, it will be restored
- set_archive_period(n)[source]
Sets the archive period for all key for both input and output dictionaries :param n: (int) the archiving period
- set_whitelist(dictionary)[source]
Sets the whitelist for this protocol. The first level of keys must contain valid vertex ids. (A warning will be printed otherwise.
Level one: graph vertex ids -> specifies to which vertices the nested whitelist will be applied to
Level two: “input” or “output” -> defines which dictionary is affected by the archiving periods
Level three: the properties of the corresponding dictionary which will be affected
- { ‘calc_static’{
‘input’: 5 #sets all keys of input dict to 5, ‘output’: {
‘energy_pot’: 1, ‘structure’: None
}
- Parameters
dictionary – (dict) the whitelist configuration
- to_hdf(hdf, group_name=None)[source]
Store the Protocol in an HDF5 file.
- Parameters
hdf (ProjectHDFio) – HDF5 group object.
group_name (str) – HDF5 subgroup name - optional
- property whitelist
- class pyiron_contrib.protocol.generic.Edges(**kwargs)[source]
Bases:
dict
A collection of dictionaries connecting each state of a given vertex to another vertex.
- class pyiron_contrib.protocol.generic.Graph(**kwargs)[source]
Bases:
dict
,LoggerMixin
A directed graph of vertices and edges, and a method for iterating through the graph.
Vertices and edges are the graph are explicitly stored as child classes inheriting from dict so that all ‘graphiness’ is fully decoupled from the objects sitting at the vertices.
- restarting_vertex
The element of vertices for the graph to restart on if the graph has been loaded.
- Type
- make_pipeline(*args)[source]
Adds an edge between every argument, in the order they’re given. The edge is added for the vertex state “next”, so this is only appropriate for vertices which don’t have a non-trivial vertex_state.
- Parameters
*args (Vertex/str) – Vertices to connect in a row, or the state connecting two vertices.
- step()[source]
Follows the edge out of the active vertex to get the name of the next vertex and set it as the active vertex. If the active vertex has multiple possible states, the outbound edge for the current state will be chosen.
- Returns
(str) The name of the next vertex.
- visualize(protocol_name, execution=True, dataflow=True)[source]
Plot a visual representation of the graph.
- Parameters
protocol_name –
execution (bool) – Show the lines dictating the flow of graph traversal.
dataflow (bool) – Show the lines dictating where vertex input comes from.
- Returns
(graphviz.Digraph) The image representation of the protocols workflow
- class pyiron_contrib.protocol.generic.PrimitiveVertex(**kwargs)[source]
Bases:
Vertex
Vertices which do not contain their a sub-graph but directly produce output from input.
- class pyiron_contrib.protocol.generic.Protocol(project=None, job_name=None)[source]
Bases:
CompoundVertex
,GenericJob
A parent class for compound vertices which are being instantiated as regular pyiron jobs, i.e. the highest level graph in their context. Example: if X inherits from CompoundVertex and performs the desired logic, then ``` class ProtocolX(Protocol, X):
pass
``` can be added to the pyiron_contrib-level __init__ file and jobs performing X-logic can be instantiated with in a project pr with the name job_name using pr.create_job(pr.job_type.ProtocolX, job_name).
- collect_output()[source]
Collect the output files of the external executable and store the information in the HDF5 file. This method has to be implemented in the individual hamiltonians.
- from_hdf(hdf=None, group_name=None)[source]
Load the Protocol from an HDF5 file. :param hdf: HDF5 group object - optional :type hdf: ProjectHDFio :param group_name: HDF5 subgroup name - optional :type group_name: str
- run(delete_existing_job=False, repair=False, debug=False, run_mode=None, continue_run=False)[source]
A wrapper for the run which allows us to simply keep going with a new variable continue_run
- run_static()[source]
If this CompoundVertex is the highest level, it can be run as a regular pyiron job.
- class pyiron_contrib.protocol.generic.Vertex(**kwargs)[source]
Bases:
LoggerMixin
,ABC
A parent class for objects which are valid vertices of a directed acyclic graph.
- input
A pointer-capable dictionary for inputs, including a sub-dictionary for defaults. (Default is a clean dictionary.)
- Type
- output
A pointer-capable dictionary for outputs. (Default is a clean dictionary.)
- Type
- archive
A pointer-capable dictionary for sampling the history of inputs and outputs. (Default is a clean dictionary.)
- Type
- vertex_state
Which edge to follow out of this vertex. (Default is “next”.)
- Type
str
- possible_vertex_states
Allowable exiting edge names. (Default is [“next”], one edge only!)
- Type
list[str]
- vertex_name
Vertex name. (Default is None, gets set automatically when if the vertex is being added to a graph, or if the vertex is a Protocol being instantiated.)
- Type
str
- n_history
The length of each list stored in the output dictionary. (Default is 1, keep only the most recent output.)
- Type
int
- on
Whether to execute the vertex when it is the active vertex of the graph, or simply skip over it. (default is True – actually execute!)
- Type
bool
- graph_parent
The object who owns the graph that this vertex resides in. (Default is None.)
- Type
- Input attributes:
- default (IODictionary): A dictionary for fall-back values in case a key is requested that isn’t in the main
input dictionary.
- Archive attributes:
- whitelist (IODictionary): A nested dictionary of periods for archiving input and output values. Stores on
executions where clock % period = 0.
clock (int): The timer for whether whether or not input/output should be archived to hdf5.
- abstract execute()[source]
What to do when this vertex is the active vertex during graph traversal.
- from_hdf(hdf, group_name=None)[source]
Load the Vertex from an HDF5 file.
- Parameters
hdf (ProjectHDFio) – HDF5 group object.
group_name (str) – HDF5 subgroup name. (Default is None.)
- parallel_setup()[source]
How to prepare to execute in parallel when there’s a list of these vertices together.
- set_whitelist(dictionary)[source]
Sets whitelist of the current vertex. Argument defines the form: ```
- {‘input’: 5,
‘output’: 1}
# sets all keys of input to dump at every fith execution cycle # sets all keys of output to dump at every execution cycle {‘input’: {‘structure’: None,
‘forces’: 5}
} # disables the archiveing of input.structure but keeps forces
``` :param dictionary: The whitelist specification. :type dictionary: dict
- to_hdf(hdf, group_name=None)[source]
Store the Vertex in an HDF5 file.
- Parameters
hdf (ProjectHDFio) – HDF5 group object.
group_name (str) – HDF5 subgroup name. (Default is None.)
- property vertex_state
- property whitelist