pygsti.report.formatter

Defines the Formatter class

Module Contents

Classes

Formatter

Class defining the formatting rules for an object

class pygsti.report.formatter.Formatter(custom=None, stringreplacers=None, regexreplace=None, formatstring='%s', ebstring='%s +/- %s', nmebstring=None, stringreturn=None, defaults=None)

Bases: object

Class defining the formatting rules for an object

Once created, is used like a function with the signature: item, specs -> string See __call__ method for details

__call__ could be renamed to render() for compatibility with table.render(), row.render(), etc.. However, using __call__ allows for the user to drop in custom functions in place of Formatter objects, which is useful (i.e. in creating figure formatters)

Parameters

customfunction, optional

A custom-formatting function that has signature custom(item, specs) and returns item formatted as a string.

stringreplacerstuple, optional

A tuple of tuples of the form (pattern, replacement) where replacement is a normal string. Ex : [(‘rho’, ‘ρ’)]

regexreplacetuple, optional

A tuple of the form (regex, replacement) where replacement is formattable string, and gets formatted with grouped result of regex matching on item) Ex : (‘.*?([0-9]+)$’, ‘_{%s}’)

formatstringstr, optional

Outer formatting for after both replacements have been made

ebstringstr, optional

Format string used if the item being formatted has attached error bars.

nmebstringstr, optional

Alternate format string to use for non-Markovian error bars.

stringreturntuple

A (string, string) tuple that creates a formatting rules where the the second string is used if a label is equal to the first.

defaultsdictionary (string, any)

overriden values to the dictionary passed in during formatted. ie for rounded formatters, which override the precision key to be set to two

Create a Formatter object by supplying formatting rules to be applied

Parameters

stringreplacerstuples of the form (pattern, replacement) (optional)

(replacement is a normal string) Ex : [(‘rho’, ‘ρ’)]

regexreplaceA tuple of the form (regex, replacement) (optional)

(replacement is formattable string, gets formatted with grouped result of regex matching on item) Ex : (‘.*?([0-9]+)$’, ‘_{%s}’)

formatstringstring (optional)

Outer formatting for after both replacements have been made

ebstringstring (optional)

formatstring used if the item being formatted has attached error bars

stringreturntuple (string, string)

return the second string if the label is equal to the first

defaultsdictionary (string, any)

overriden values to the dictionary passed in during formatted. ie for rounded formatters, which override the precision key to be set to two

variant(**kwargs)

Create a Formatter object from an existing formatter object, tweaking it slightly.

Parameters
kwargsvarious

Arguments to Formatter.__init__().

Returns

Formatter