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: object

Allows 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 LinearCombs.

CAVEAT: Requires the Python module of the provided Model to be imported to ensure the availability of any custom implementations of Block defined within.

Parameters:
  • fname (str) – Name of the archive.

  • model (Model) – Description of the Model the overcomplete bases found belong to.

  • checkModule (bool, optional) – Compare model as stored in the archive with the currently used model. Defaults to True.

Raises:
  • AssertionError – If the Pyhon 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.

Parameters:

template (str) – String representation of the template for ansätze to be used.

Returns:

Boolean indicating whether the template is contained within the archive.

Return type:

bool

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 LinearComb stored for the given template.

Return type:

list[LinearComb]

Raises:

ValueError – If template.ops does not exist in the archive.

getTemplates()

Reads all templates currently available including their TemplateRep for customised ordering.

Returns:

Collection of TemplateRep representing all the operators stored and grouped according to their template.

Return type:

list[TemplateRep]

_parseBilinear(expr: str, flavourMask: str, oBlock: str, model: Model) Bilinear

Parses the string-representation of an instance of Bilinear using regular expressions, which are specified in flavourMask and oBlock.

Parameters:
  • expr (str) – String-representation of the Bilinear.

  • flavourMask (str) – Regular expression to identify flavours.

  • oBlock (str) – Regular expression to identify non-algebra-valued instances of Block.

  • model (Model) – Descriptor of the considered theory.

Returns:

Instance of Bilinear as parsed from string.

Return type:

Bilinear

_parseLinearComb(expr: str, term: str, bilin: str, oTrace: str, flavourMask: str, oBlock: str, model: Model) LinearComb

Turns the string representation of LinearComb back into an instance of this type.

Parameters:
  • expr (str) – String expression of the full LinearComb.

  • term (str) – Regular expression to identify one term.

  • bilin (str) – Regular expression to identify a Bilinear.

  • 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:

LinearComb

parseLinearCombs(expr: str, model: Model) list[LinearComb]

Identifies all LinearComb separated by linebreaks and hands them to the function _parseLinearComb to be parsed.

Parameters:
  • expr (str) – String containing instances of LinearComb separated by linebreaks.

  • model (Model) – Descriptor of the Model the LinearCombs correspond to.

Returns:

Collection of all instances of LinearComb parsed from expr.

Return type:

list[LinearComb]

Raises:

ValueError – If the formatting encountered does not fit to the regular expression, e.g., due to use of the wrong Model or typos.