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_execution_flow()[source]

Wire the logic for traversing the graph edges.

abstract define_information_flow()[source]

Connect input and output information inside the graph. Also set the archive clock for all vertices.

abstract define_vertices()[source]

Add child vertices to the graph.

execute()[source]

Traverse graph until the active vertex is None.

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_graph_archive_clock(clock, recursive=False)[source]
set_input_archive_period(n, keys=None)[source]
set_input_whitelist(**kwargs)[source]
set_output_archive_period(n, keys=None)[source]
set_output_whitelist(**kwargs)[source]
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.

  1. Level one: graph vertex ids -> specifies to which vertices the nested whitelist will be applied to

  2. Level two: “input” or “output” -> defines which dictionary is affected by the archiving periods

  3. Level three: the properties of the corresponding dictionary which will be affected

Example: ```

{ ‘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

visualize(execution=True, dataflow=True)[source]
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.

from_hdf(hdf, group_name)[source]
initialize(vertex)[source]

Set an outbound edge to None for each allowable vertex state.

Parameters

vertex (Vertex) – The vertex to assign an edge to.

to_hdf(hdf, group_name='edges')[source]
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.

vertices

Vertices of the graph.

Type

Vertices

edges

Directed edges between the vertices.

Type

Edges

starting_vertex

The element of vertices for the graph to begin on.

Type

Vertex

active_vertex

The element of vertices for the vertex the graph iteration is on.

Type

Vertex

restarting_vertex

The element of vertices for the graph to restart on if the graph has been loaded.

Type

Vertex

from_hdf(hdf, group_name='graph')[source]
make_edge(start, end, state='next')[source]

Makes a directed edge connecting two vertices.

Parameters
  • start (Vertex) – The vertex for the edge to start at.

  • end (Vertex) – The vertex for the edge to end at.

  • state (str) – The state for the vertex to be in when it points to this particular end. (Default, “next”, is the parent-level state for vertices without multiple outbound edges.)

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.

to_hdf(hdf, group_name='graph')[source]
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.

abstract command(*args, **kwargs)[source]

The command method controls the physics

execute()[source]

Just parse the input and do your physics, then store the output.

execute_parallel(n, return_dict)[source]

How to execute in parallel when there’s a list of these vertices together.

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.

execute()[source]

Traverse graph until the active vertex is None.

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.

to_hdf(hdf=None, group_name=None)[source]

Store the Protocol in an HDF5 file. :param hdf: HDF5 group object - optional :type hdf: ProjectHDFio :param group_name: HDF5 subgroup name - optional :type group_name: str

write_input()[source]

Write the input files for the external executable. This method has to be implemented in the individual hamiltonians.

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

InputDictionary

output

A pointer-capable dictionary for outputs. (Default is a clean dictionary.)

Type

IODictionary

archive

A pointer-capable dictionary for sampling the history of inputs and outputs. (Default is a clean dictionary.)

Type

IODictionary

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

Vertex

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.

finish()[source]
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.)

get_graph_location()[source]
parallel_setup()[source]

How to prepare to execute in parallel when there’s a list of these vertices together.

set_archive_period(n)[source]
set_input_archive_period(n, keys=None)[source]
set_input_whitelist(**kwargs)[source]
set_output_archive_period(n, keys=None)[source]
set_output_whitelist(**kwargs)[source]
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.)

update_and_archive(output_data)[source]
property vertex_state
property whitelist
class pyiron_contrib.protocol.generic.Vertices(**kwargs)[source]

Bases: dict

A dictionary of vertices whose keys are the vertex name.

from_hdf(hdf, group_name='vertices')[source]
to_hdf(hdf, group_name='vertices')[source]