xdl.readwrite.xml_interpreter module
- xdl.readwrite.xml_interpreter.apply_step_record(step: Step, step_record_step: tuple[str, dict])[source]
- xdl.readwrite.xml_interpreter.blueprints_from_xdl(xdl_tree: ET.ElementTree, step_type_dict: dict[str, Step], context: Context) list[Blueprint] [source]
- xdl.readwrite.xml_interpreter.extract_tags(xdl_tree: ET.ElementTree, xpath: str, recursive=False) tuple[str, dict] [source]
Parse XDL XML tree for a given XPath (part of the XML document).
- Parameters
xdl_tree (ET.ElementTree) – ElementTree constructed from XML string.
xpath (str) – path to extract.
recursive (bool, optional) – If true, will look for ‘children’ within element and save them as an element attribute. Defaults to False.
- Returns
[description]
- Return type
Tuple[str, Dict]
- xdl.readwrite.xml_interpreter.find_element(xml_obj: ET.Element | ET.ElementTree, tag: str = 'Synthesis', recursive: bool = False) ET.Element | None [source]
Searches XML Element or ElementTree for child element with matching tag. Currently used to get Synthesis element from XDL2 XMLs.
- Parameters
xml_obj (Union[ET.Element, ET.ElementTree]) – XML Element or ElementTree.
tag (str, optional) – tag to search for in xml_obj. Defaults to ‘Synthesis’.
recursive (bool, optional) – True to search recursively through whole tree. False to look only at direct children. Defaults to False.
- Returns
- Synthesis Element if found in xml_obj;
otherwise NoneType.
- Return type
Optional[ET.Element]
- xdl.readwrite.xml_interpreter.get_base_steps(step: ET.Element) list[AbstractBaseStep] [source]
Return all base steps from step XML tree, recursively.
- Parameters
step (ET.Element) – Step XML tree to get base steps from.
- xdl.readwrite.xml_interpreter.get_full_step_record(procedure_tree: ET.Element) list[tuple] [source]
Get the full step record for the procedure section of a xdlexe file. The step record is a nested representation of all steps and properties. It is needed so that top level steps can be initialised, and then properties of lower level steps are applied afterwards directly to the lower level steps. This allows editing of the xdlexe.
- Parameters
procedure_tree (ET.Element) – XML tree of procedure section of XDL.
- Returns
Returns step record in format
[(step_name, step_properties, substeps)...]
- Return type
List[Tuple]
- xdl.readwrite.xml_interpreter.get_single_step_record(step_element: ET.Element) tuple[str, dict, list] [source]
Get step record for a single step.
- Parameters
step_element (ET.Element) – XML tree for single step.
- Returns
Step record in the form
(step_name, step_properties, substeps)
- Return type
Tuple[str, Dict, List]
- xdl.readwrite.xml_interpreter.map_xdl_to_parameter(value: str, parameters: list[Parameter]) Any [source]
Map a non-blueprint (global) parameter to a Parameter value.
- Parameters
value (str) – string to be mapped to a Parameter (must match a parameter
matched). (id to be) –
parameters (List[Parameter]) – List of Parameter objects to map to.
- Returns
final mapped parameter value
- Return type
parameter.value (Any)
- xdl.readwrite.xml_interpreter.metadata_from_xdl(xdl_tree: xml.etree.ElementTree.ElementTree) xdl.metadata.Metadata [source]
Given XDL str return Metadata object.
- Parameters
xdl_tree (ET.ElementTree) – ElementTree constructed from XML string.
- Returns
Metadata object with any parameters included in XDL loaded
- Return type
- xdl.readwrite.xml_interpreter.retrieve_blueprint(name: str, context: xdl.context.Context, folder: Optional[str] = None)[source]
Given a blueprint name (str), this function searches that given folder for any .xdl files containing that blueprint. If no folder is specified, it will use the working directory.
- Parameters
name (str) – blueprint id to be resolved.
context (Context) – Context container class for bringing root XDL attributes (e.g. reagents, hardware) in scope within steps. Must contain ‘platform’ as a minimum.
folder (str) – Folder containing xdl files to search through.
- Returns
- list of blueprints associated with the xdl files
in the folder.
- Return type
List[Blueprint]
- xdl.readwrite.xml_interpreter.steps_from_xml(procedure: ET.ElementTree, context: Context, blueprints: list[Blueprint] | None = None, parameters: list[Parameter] | None = None) list[Step] [source]
Given standard, non-blueprint XDL ElementTree return list of Step objects.
- Parameters
- Returns
List of Step objects corresponding to procedure described in
xdl_str
.- Return type
List[Step]
- xdl.readwrite.xml_interpreter.synthesis_attrs_from_xdl(xdl_tree: ET.ElementTree) dict[str, Any] [source]
Return attrs from
<Synthesis>
tag.- Parameters
xdl_tree (ET.ElementTree) – ElementTree constructed from XML string.
- Returns
Attr dict from
<Synthesis>
tag.- Return type
Dict[str, Any]
- xdl.readwrite.xml_interpreter.xml_to_blueprint(xml_blueprint_element: ET.Element, step_type_dict: dict[str, Step], context: Context) type[Blueprint] [source]
Given XDL blueprint element return corresponding Blueprint object.
- Parameters
xml_blueprint_element (ET.Element) – XDL step lxml element.
step_type_dict (dict) – library of valid step classes.
- Returns
Blueprint object for spawning steps as required.
- Return type
- xdl.readwrite.xml_interpreter.xml_to_component(xdl_component_element: xml.etree.ElementTree.Element) xdl.hardware.Component [source]
Given XDL component element return corresponding Component object.
- Parameters
xdl_component_element (ET.Element) – XDL component lxml element.
- Returns
Component object corresponding to component in
xdl_component_element
.- Return type
- xdl.readwrite.xml_interpreter.xml_to_parameter(xdl_parameter_element: xml.etree.ElementTree.Element) xdl.parameters.Parameter [source]
Given XDL parameter element return corresponding Parameter object.
- Parameters
xdl_parameter_element (ET.Element) – XDL component lxml element.
- Returns
Parameter object corresponding to parameter in
xdl_parameter_element
.- Return type
- xdl.readwrite.xml_interpreter.xml_to_reagent(xdl_reagent_element: xml.etree.ElementTree.Element) xdl.reagents.Reagent [source]
Given XDL reagent element return corresponding Reagent object.
- Parameters
xdl_reagent_element (ET.Element) – XDL reagent lxml element.
- Returns
Reagent object corresponding to reagent in
xdl_reagent_element
.- Return type
- xdl.readwrite.xml_interpreter.xml_to_step(xdl_step_element: ET.Element, step_type_dict: dict[str, type], context: Context, blueprints: list[Blueprint] | None = None, parameters: list[Parameter] | None = None) Step [source]
Given XDL step element return corresponding Step object.
- Parameters
xdl_step_element (ET.Element) – XDL step lxml element.
step_type_dict – Dict[str, type]: Dict of step names to step classes, e.g.
{ 'Add': Add... }
context (Context) – Context container class for bringing root XDL attributes (e.g. reagents, hardware) in scope within steps.
blueprint (bool, False) – specifies whether step can be instantiated as is, or if it is part of a blueprint XDL. Defaults to False.
blueprints (List[Blueprint]) – list of blueprints associated with the xdl file. Defaults to None.
parameters (List[Parameter]) – list of parameters associated with the xdl file. Defaults to None.
- Returns
Step object corresponding to step in
xdl_step_element
.- Return type
- xdl.readwrite.xml_interpreter.xml_to_step_template(element: ET.Element, step_type_dict: dict[str, type], context: Context) Step [source]
Generate a blueprint Step template from XML blueprint step element.
- Parameters
element (ET.Element) – XML Element.
- Returns
- Step object. This will later be replaced with fully instantiated,
final step(s) upon compilation.
- Return type
- xdl.readwrite.xml_interpreter.xml_to_variable(xdl_variable_element: ET.Element, platform: AbstractPlatform) Variable [source]
Given XDL variable element return corresponding Variable object.
- Parameters
xdl_variable_element (ET.Element) – XDL component lxml element.
- Returns
Variable object corresponding to variable in
xdl_variable_element
.- Return type