io¶
This submodule takes care of storing operator bases and reading them file.
Reading relies heavily on use of regular expressions. As long as custom
Block implementations adhere to the common index-conventions, all of this
should work out of the box.
- class CompressedBasis(fname: str, model: Model, checkModule: bool = True)¶
Bases:
objectAllows easy access to storing the overcomplete set of operators for various templates in separate files which are combined into a single zip-archive. If the file already exists, allows to extract stored
LinearComb.Important
Requires the Python module of the provided Model to be imported to ensure the availability of any custom implementations of
Blockdefined within.- Parameters:
- Raises:
AssertionError – If the Python module of the provided model is not already imported.
ValueError – If the provided model does not agree with the one stored in the zip-archive.
- __contains__(template: str) bool¶
Allows simple use of the in statement to check if template has already been added previously either through a call to add or manually.
- add(template: TemplateRep, ops: list[LinearComb])¶
Appends a file with the name template.ops containing the string- representation of the operators ops. Raises a ValueError in case template.ops already exists.
- Parameters:
template (TemplateRep) – Carries details about the building blocks used in the template when deriving the associated operator basis as well as the actual mass-dimension.
ops (list[LinearComb]) – Collection of operators found for this specific template that are compatible with the model-specific transformation properties.
- Raises:
ValueError – If the template to be added is already present.
- get(template: str, model: Model) list[LinearComb]¶
Reads all operators contained in template.ops and parses them into
LinearComb. The resulting list of operators is returned.- Parameters:
template (str) – String representation of the template for ansätze to be used.
- Returns:
Collection of
LinearCombstored for the given template.- Return type:
- Raises:
ValueError – If template.ops does not exist in the archive.
- getTemplates()¶
Reads all templates currently available including their
TemplateRepfor customised ordering.- Returns:
Collection of
TemplateReprepresenting all the operators stored and grouped according to their template.- Return type:
- _parseBilinear(expr: str, flavourMask: str, oBlock: str, model: Model) Bilinear¶
Parses the string-representation of an instance of
Bilinearusing regular expressions, which are specified in flavourMask and oBlock.- Parameters:
- Returns:
Instance of
Bilinearas parsed from string.- Return type:
- _parseLinearComb(expr: str, term: str, bilin: str, oTrace: str, flavourMask: str, oBlock: str, model: Model) LinearComb¶
Turns the string representation of
LinearCombback into an instance of this type.- Parameters:
expr (str) – String expression of the full
LinearComb.term (str) – Regular expression to identify one term.
oTrace (str) – Regular expression to identify a non-algebra
Trace.flavourMask (str) – Regular expression to identify flavours.
oBlock (str) – Regular expression to identify of (also custom) instances
Block.model (Model) – Descriptor of the considered theory.
- Returns:
Parsed instance of
LinearComb.- Return type:
- parseLinearCombs(expr: str, model: Model) list[LinearComb]¶
Identifies all
LinearCombseparated by linebreaks and hands them to the function _parseLinearComb to be parsed.- Parameters:
expr (str) – String containing instances of
LinearCombseparated by linebreaks.model (Model) – Descriptor of the Model the various
LinearCombcorrespond to.
- Returns:
Collection of all instances of
LinearCombparsed from expr.- Return type:
- Raises:
ValueError – If the formatting encountered does not fit to the regular expression, e.g., due to use of the wrong Model or typos.