|
ADCT Python
Python client API implementation for publishing ADCT data
|
ADC Toolkit message and subsection construction class. More...

Public Member Functions | |
| __init__ (self) | |
| adc_types.Field | get_value (self, str path_full) |
| get the existing named nested field in the builder. | |
| get_value_string (self, str path) | |
| get the existing named nested scalar string value. | |
| get_value_int64 (self, str path) | |
| get the existing named nested scalar int64-equivalent value. | |
| get_value_uint64 (self, str path) | |
| get the existing named nested scalar uint64-equivalent value. | |
| __json__ (self) | |
| add_header_section (self, str application_name) | |
| Create or replace the 'header' section using application_name. | |
| add_host_section (self, osinfo=False, ramsize=False, env=False, cpu=False, gpu=False, numa=False, all_hs=False) | |
| Add the 'host' section, with optional subgroups of properties. | |
| add_app_data_section (self, 'Builder' app_data) | |
| Create the "app_data" section with data defined by the application writer. | |
| add_model_data_section (self, 'Builder' model_data) | |
| populate application run-time physics (re)configuration or result to "model_data" section. | |
| add_code_section (self, str tag, 'Builder' version, 'Builder|None' code_details=None) | |
| Add the 'code' section, with user-specified version subsection and optional code_details section describing things which do not normally vary with invocation. | |
| add_code_configuration_section (self, 'Builder' build_details) | |
| add_exit_data_section (self, 'int|str' return_code, str status, 'Builder|None' status_details=None) | |
| populate "exit_data" section with return code and status string & user provided details. | |
| add_memory_usage_section (self) | |
| Populate "memory_usage" section with current host /proc/meminfo data in the style of free(1). | |
| 'Builder|None' | get_section (self, str name) |
| get the existing named section. | |
| 'list[str]' | get_section_names (self) |
| Get the names of sections. | |
| add_mpi_section (self, name, communicator, bool rank=False, bool size=False, bool mpi_name=False, bool hostlist=False, bool rank_host=False, bool ver=False, bool lib_ver=False, bool mpiall=False, bool local=False) | |
| Unimplemented: python with mpi is not yet supported. | |
| add_gitlab_ci_section (self) | |
| Add gitlab_ci environment variable dictionary. | |
| add_workflow_section (self, str|None wfid=None, str|None parent=None, list[str]|str|None children=None) | |
| add data from adc_wfid_ environment variables. | |
| add_workflow_children (self, collections.abc.Iterable[str] child_uuids) | |
| Add list of child uuids to "adc_workflow" section after add_workflow_section has been called. | |
| add_slurm_section (self, collections.abc.Iterable[str]|None output_vars=None) | |
| Add slurm output environment variable dictionary elements. | |
| add_section (self, str name, 'Builder|collections.abc.Mapping[str,...]' section) | |
| Add or replace a user-defined, named section. | |
| str | serialize (self) |
| get json string of the builder. | |
| add (self, str name, any value, value_type=None) | |
| add named item and its datatype information to the builder. | |
| add_path (self, name, str path) | |
| Add string file path. | |
| add_json_string (self, str name, str js) | |
| Add stringified json. | |
| add_yaml_string (self, str name, str yaml) | |
| Add stringified yaml. | |
| add_xml_string (self, str name, str xml) | |
| Add stringified xml. | |
| add_number_string (self, str name, decimal.Decimal dec) | |
| Add stringified number of arbitrary precision. | |
| add_epoch (self, name, int epoch) | |
| add unix epoch seconds (gettimeofday) | |
| add_mime (self, str name, str mime_type, str encoding, str file_name, str data) | |
| add a string encoded object (e.g. | |
| add_array_typed_string (self, name, adc_types.ScalarType st, collections.abc.Iterable[str] strings) | |
| Add string group tagged with scalar type. | |
Static Public Member Functions | |
| 'Builder' | BasicBuilder (str app_name) |
| DEPRECATED. | |
Static Public Attributes | |
| API_VERSION = adc_version.AdcVersion()._dict() | |
Protected Member Functions | |
| _set_attr (self, name, value) | |
| _get_attr (self, name) | |
| _find_path (self, obj, path) | |
| dict | _flatten (self, depth=0) |
| Get a dictionary tree-copy constructed from keys and sections. | |
| adc_types.KeyType | _kind (self, str name) |
ADC Toolkit message and subsection construction class.
Use of the Builder ensures that adctk messages:
| adctk.builder.Builder.__init__ | ( | self | ) |
Reimplemented in adctk.builder.Memory, adctk.builder.Host, and adctk.builder.Header.
| adctk.builder.Builder.__json__ | ( | self | ) |
|
protected |
look up value in nested string-named structures using /-delimited path
|
protected |
Get a dictionary tree-copy constructed from keys and sections.
Changes made to the returned dictionary are not reflected in the Builder instance.
|
protected |
|
protected |
return the type that name resolves to in this builder.
|
protected |
| adctk.builder.Builder.add | ( | self, | |
| str | name, | ||
| any | value, | ||
value_type = None |
|||
| ) |
add named item and its datatype information to the builder.
Supported value types are
Any value not explicitly supported which cannot be converted to a json string will be silently ignored.
Notes:
| adctk.builder.Builder.add_app_data_section | ( | self, | |
| 'Builder' | app_data | ||
| ) |
Create the "app_data" section with data defined by the application writer.
It is recommended that any relationship identifiers to previous jobs or higher level environments goes in app_data, unless supported by add_workflow_section, add_slurm_section or other normalized sections.
Example: app_data = Factory.get_builder(); app_data.add("saw_id", getenv("SAW_WORKFLOW_ID"); builder.add_app_data_section(app_data)
| adctk.builder.Builder.add_array_typed_string | ( | self, | |
| name, | |||
| adc_types.ScalarType | st, | ||
| collections.abc.Iterable[str] | strings | ||
| ) |
Add string group tagged with scalar type.
| st | the ScalarType |
| strings | a one-dimensional string group |
| name | the field name. |
| ValueError | if strings cannot be converted. |
| adctk.builder.Builder.add_code_configuration_section | ( | self, | |
| 'Builder' | build_details | ||
| ) |
@brief Populate build/install "configuration" information such as options enabled
@param build_details option list.
| adctk.builder.Builder.add_code_section | ( | self, | |
| str | tag, | ||
| 'Builder' | version, | ||
| 'Builder|None' | code_details = None |
||
| ) |
Add the 'code' section, with user-specified version subsection and optional code_details section describing things which do not normally vary with invocation.
Automatic contents include tag, base program, full path, loaded modules and shared libraries. Shared libraries detected may vary with invocation if LD_LIBRARY_PATH or related environment settings change.
| adctk.builder.Builder.add_epoch | ( | self, | |
| name, | |||
| int | epoch | ||
| ) |
add unix epoch seconds (gettimeofday)
| adctk.builder.Builder.add_exit_data_section | ( | self, | |
| 'int|str' | return_code, | ||
| str | status, | ||
| 'Builder|None' | status_details = None |
||
| ) |
populate "exit_data" section with return code and status string & user provided details.
| return_code | numeric value of exit status |
| status | one-line summary of the execution |
| status_details | any final or summary results of interest to application users or developers. |
| adctk.builder.Builder.add_gitlab_ci_section | ( | self | ) |
Add gitlab_ci environment variable dictionary.
The section added is named "gitlab_ci". The variables collected from env() are:
Where the values are strings from the corresponding env() values.
| adctk.builder.Builder.add_header_section | ( | self, | |
| str | application_name | ||
| ) |
Create or replace the 'header' section using application_name.
To reuse a Builder object for a new message, call add_header_section on it again before sending it to publish again.
| adctk.builder.Builder.add_host_section | ( | self, | |
osinfo = False, |
|||
ramsize = False, |
|||
env = False, |
|||
cpu = False, |
|||
gpu = False, |
|||
numa = False, |
|||
all_hs = False |
|||
| ) |
Add the 'host' section, with optional subgroups of properties.
builder.add_host_section(os=True, ramsize=True, env=True, cpu=True, gpu=True, numa=True) is equivalent to builder.add_host_section(all_hs=True)
| adctk.builder.Builder.add_json_string | ( | self, | |
| str | name, | ||
| str | js | ||
| ) |
Add stringified json.
| adctk.builder.Builder.add_memory_usage_section | ( | self | ) |
Populate "memory_usage" section with current host /proc/meminfo data in the style of free(1).
Values included are: mem_total mem_used mem_free mem_shared mem_buffers mem_cache mem_available swap_total swap_used swap_free
| adctk.builder.Builder.add_mime | ( | self, | |
| str | name, | ||
| str | mime_type, | ||
| str | encoding, | ||
| str | file_name, | ||
| str | data | ||
| ) |
add a string encoded object (e.g.
image)
| name | the name in the message of this field |
| mime_type | e.g. "image/png" |
| encoding | e.g. "base64" |
| file_name | e.g. "origin.png" |
| data | character array of the encoded object. |
| adctk.builder.Builder.add_model_data_section | ( | self, | |
| 'Builder' | model_data | ||
| ) |
populate application run-time physics (re)configuration or result to "model_data" section.
For example initial or changes in mesh or particle decomp go here.
| adctk.builder.Builder.add_mpi_section | ( | self, | |
| name, | |||
| communicator, | |||
| bool | rank = False, |
||
| bool | size = False, |
||
| bool | mpi_name = False, |
||
| bool | hostlist = False, |
||
| bool | rank_host = False, |
||
| bool | ver = False, |
||
| bool | lib_ver = False, |
||
| bool | mpiall = False, |
||
| bool | local = False |
||
| ) |
Unimplemented: python with mpi is not yet supported.
| adctk.builder.Builder.add_number_string | ( | self, | |
| str | name, | ||
| decimal.Decimal | dec | ||
| ) |
Add stringified number of arbitrary precision.
| adctk.builder.Builder.add_path | ( | self, | |
| name, | |||
| str | path | ||
| ) |
Add string file path.
| adctk.builder.Builder.add_section | ( | self, | |
| str | name, | ||
| 'Builder|collections.abc.Mapping[str,...]' | section | ||
| ) |
Add or replace a user-defined, named section.
Using a string-keyed dictionary instead of a Builder is allowed but is not recommended for numeric or path or markup data because this omits variable type information needed for correct extraction in languages other than python. An exception occurs replacing a key/value pair with a section is attempted.
| adctk.builder.Builder.add_slurm_section | ( | self, | |
| collections.abc.Iterable[str]|None | output_vars = None |
||
| ) |
Add slurm output environment variable dictionary elements.
The section added is named "slurm".
The variables collected from env() are:
Where the values are strings from the corresponding env() values.
| adctk.builder.Builder.add_workflow_children | ( | self, | |
| collections.abc.Iterable[str] | child_uuids | ||
| ) |
Add list of child uuids to "adc_workflow" section after add_workflow_section has been called.
This call is optional.
This call may be repeated if necessary, incrementally building the child list. wfid_children: [ user defined list of ids ]
Where a workflow can track its immediate children, it may substantially improve downstream workflow analyses if the child items can be captured. The result appears in the resulting json as wfid_children: $ADC_WFID_CHILDREN
| adctk.builder.Builder.add_workflow_section | ( | self, | |
| str|None | wfid = None, |
||
| str|None | parent = None, |
||
| list[str]|str|None | children = None |
||
| ) |
add data from adc_wfid_ environment variables.
The section name is "adc_workflow".
The env variables collected are: wfid: ADC_WFID wfid_parent: $ADC_WFID_PARENT wfid_path: $ADC_WFID_PATH
The suggested format of an adc workflow identifier (wfid) is as: uuid -v1 -F STR run at the appropriate scope. For example, when starting numerous processes with mpi under slurm, in the sbatch script before launching anything else do: export ADC_WFID=$(uuid -v1 -F STR) and then make sure it gets propagated to all the processes via the launch mechamism. This ties all the messages from mpi ranks together in adc.
Where a workflow parent (such as an agent launching multiple slurm jobs) can, export ADC_WFID_PARENT=$(uuid -v1 -F STR) and then make sure this value is propagated to the slurm environments.
Where possible (requires coordination at all workflow levels) export ADC_WFID_PATH=(higher_level_wfid_path)/$ADC_WFID the entire task hierarchy identifier can be collected.
The choice of uuid version is up to the user.
| adctk.builder.Builder.add_xml_string | ( | self, | |
| str | name, | ||
| str | xml | ||
| ) |
Add stringified xml.
| adctk.builder.Builder.add_yaml_string | ( | self, | |
| str | name, | ||
| str | yaml | ||
| ) |
Add stringified yaml.
|
static |
DEPRECATED.
| 'Builder|None' adctk.builder.Builder.get_section | ( | self, | |
| str | name | ||
| ) |
get the existing named section.
| 'list[str]' adctk.builder.Builder.get_section_names | ( | self | ) |
Get the names of sections.
| adc_types.Field adctk.builder.Builder.get_value | ( | self, | |
| str | path_full | ||
| ) |
get the existing named nested field in the builder.
| path_full | a simple json path such as /a/b/c which resolves to a value added via one of the add* functions. |
| adctk.builder.Builder.get_value_int64 | ( | self, | |
| str | path | ||
| ) |
get the existing named nested scalar int64-equivalent value.
| path | a simple json path such as /a/b/c which resolves to a value added via one of the add* functions. |
| adctk.builder.Builder.get_value_string | ( | self, | |
| str | path | ||
| ) |
get the existing named nested scalar string value.
| path | a simple json path such as /a/b/c which resolves to a value added via one of the add* functions. |
| adctk.builder.Builder.get_value_uint64 | ( | self, | |
| str | path | ||
| ) |
get the existing named nested scalar uint64-equivalent value.
| path | a simple json path such as /a/b/c which resolves to a uint64-equivalent value added via one of the add* functions. |
| str adctk.builder.Builder.serialize | ( | self | ) |
get json string of the builder.
Items within builder must already be json compatible; custom encoders/decoders for json to handle numpy and complex correctly are not provided.
|
static |