sierra.core.experiment.definition#
Functionality for reading, writing, etc., experiment definitions.
Format-specific bits handled at a lower level via plugin; this is generic functionality for experiment definitions.
Classes#
Specification for a change to an existing expdef attribute. |
|
Data structure for |
|
Base class for experiment definitions. |
|
Specification for adding a new expdef tag. |
|
Data structure for |
|
Specification for removal of an existing expdef tag. |
|
Data structure for |
|
Specification for a null-change (no change) to an existing expdef. |
|
Config for writing |
Module Contents#
- class sierra.core.experiment.definition.AttrChange(path: str, attr: str, value: str | int | float)[source]#
Specification for a change to an existing expdef attribute.
- class sierra.core.experiment.definition.AttrChangeSet(*args: AttrChange | NullMod)[source]#
Data structure for
AttrChangeobjects.The order in which attributes are changed doesn't matter from the standpoint of correctness (i.e., different orders won't cause crashes).
- static unpickle(fpath: pathlib.Path) AttrChangeSet[source]#
Unpickle changes.
You don't know how many there are, so go until you get an exception.
- class sierra.core.experiment.definition.BaseExpDef(input_fpath: pathlib.Path, write_config: WriterConfig | None = None)[source]#
Base class for experiment definitions.
- abstract attr_add(path: str, attr: str, value: str | int | float, noprint: bool = False) bool[source]#
Add the specified attribute to the element matching the specified path.
Only the FIRST element matching the specified path searching from the tree root is modified.
- Parameters:
path -- An expression uniquely identifying the element containing the attribute to add. The element must exist or an error will be raised.
attr -- An expression uniquely identifying the attribute to change within the enclosing element.
value -- The value to set the attribute to.
- abstract attr_change(path: str, attr: str, value: str | int | float, noprint: bool = False) bool[source]#
Change the specified attribute of the element at the specified path.
Only the attribute of the FIRST element matching the specified path is changed.
- Parameters:
path -- An expression uniquely identifying the element containing the attribute to change. The element must exist or an error will be raised.
attr -- An expression uniquely identify the attribute to change within the enclosing element.
value -- The value to set the attribute to.
- abstract attr_get(path: str, attr: str) str | int | float | None[source]#
Retrieve the specified attribute of the element at the specified path.
If it does not exist, None is returned.
- abstract element_add(path: str, tag: str, attr: sierra.core.types.StrDict | None = None, allow_dup: bool = True, noprint: bool = False) bool[source]#
Add tag name as a child element of enclosing parent.
- abstract element_change(path: str, tag: str, value: str) bool[source]#
Change the specified tag of the element matching the specified path.
- Parameters:
path -- An expression uniquely identifying the element containing the tag to change. The element must exist or an error will be raised.
tag -- An expression uniquely identifying the tag to change within the enclosing element.
value -- The value to set the tag to.
- abstract element_remove(path: str, tag: str, noprint: bool = False) bool[source]#
Remove the specified child
tagin the enclosing parent.If more than one tag matches, only one is removed. If the path does not exist, nothing is done.
- Parameters:
path -- An expression uniquely identifying the element containing the tag to remove. The element must exist or an error will be raised.
tag -- An expression uniquely identifying the tag to remove within the enclosing element.
- abstract element_remove_all(path: str, tag: str, noprint: bool = False) bool[source]#
Remove the specified child tag(s) in the enclosing parent.
If more than one tag matches in the parent, all matching child tags are removed.
- Parameters:
path -- An expression uniquely identifying the element containing the tag(s) to remove. The element must exist or an error will be raised.
tag -- An expression uniquely identifying the tag to remove within the enclosing element.
- abstract flatten(keys: list[str]) None[source]#
Replace the specified filepath attributes with their contents.
Filepaths are interpreted relative to the directory in which the original experiment definition template resides, and assumed to be defined as such.
- abstract has_attr(path: str, attr: str) bool[source]#
Determine if the attribute uniquely identified by
pathexists.
- abstract has_element(path: str) bool[source]#
Determine if the element uniquely identified by
pathexists.
- abstract write(base_opath: pathlib.Path) None[source]#
Write the definition stored in the object to the filesystem.
- class sierra.core.experiment.definition.ElementAdd(path: str, tag: str, attr: sierra.core.types.StrDict, allow_dup: bool, as_root: bool = False)[source]#
Specification for adding a new expdef tag.
The tag may be added idempotently, or duplicates can be allowed.
- class sierra.core.experiment.definition.ElementAddList(*args: ElementAdd)[source]#
Data structure for
ElementAddobjects.The order in which tags are added matters (i.e., if you add dependent tags in the wrong order you will get an exception), hence the list representation.
- static unpickle(fpath: pathlib.Path) ElementAddList | None[source]#
Unpickle modifications.
You don't know how many there are, so go until you get an exception.
- class sierra.core.experiment.definition.ElementRm(path: str, tag: str)[source]#
Specification for removal of an existing expdef tag.
- class sierra.core.experiment.definition.ElementRmList(*args: ElementRm)[source]#
Data structure for
ElementRmobjects.The order in which tags are removed matters (i.e., if you remove dependent tags in the wrong order you will get an exception), hence the list representation.
- class sierra.core.experiment.definition.NullMod[source]#
Specification for a null-change (no change) to an existing expdef.
- class sierra.core.experiment.definition.WriterConfig(values: list[dict])[source]#
Config for writing
BaseExpDef.Different parts of the AST can be written to multiple files, as configured.
The order of operations for the applying the config should be:
Extraction of subtree
Renaming subtree root
Adding new children
Adding grafts
Attributes: values: Dict with the following possible key, value pairs:
src_parent- The parent of the root of the AST specifying a sub-tree to write out as a child ofnew_children_parent, orNoneto write out entire AST. This key is required. IfNoneomitted then then tree rooted atsrc_tagis written out. Otherwise, the subtree rooted at<src_parent>/<src_tag>is written out instead.src_tag- Unique query path expression for the child element withinsrc_parentto write out; that is this tag is the root of the sub-tree within the experiment definition to write out. This key is required.rename_to- String to rename the root of the AST written out. This key is optional, and should be processed after{src_parent, src_tag}.new_children_parent- Unique query path expression for the parent element to create new child elements under vianew_children. This key is optional; can be omitted or set toNone.new_children- Ordered List ofElementAddobjects to use to create new child elements undernew_children_parent. Must form a tree with a single root when added in order.opath_leaf- Additional bits added to whatever the opath file stem that is set for theBaseExpDefinstance. This key is optional. Can be used to add an extension; this is helpful because some engines require input files to have a certain extension, and SIERRA strips out the extension passed to--expdef-templateused as the bases for creating experiments.child_grafts_parent- Unique query path expression for the parent element to for grafting elements under viachild_grafts. This path expression is relative to<src_tag>due to ordering. This key is optional; can be omitted or set toNone.child_grafts- Additional bits of the current AST to add underchild_grafts_parentin the written out experiment definition, specified as a list of query path strings. This key is optional.