Expression Function Plugins¶
Table of Contents
Expression Functions are plugins that define the functions that can be used in Pavilion expressions, both within normal Pavilion strings and in result evaluations.
-
pavilion.expression_functions.
get_plugin
(name: str) → pavilion.expression_functions.base.FunctionPlugin¶ Get the function plugin called ‘name’.
-
pavilion.expression_functions.
list_plugins
()¶ Return the list of function plugin names.
-
pavilion.expression_functions.
register_core_plugins
()¶ Find all the core function plugins and activate them.
FunctionPlugin Base Classes¶
Contains the base Expression Function plugin class.
-
pavilion.expression_functions.base.
num
(val)¶ Return val as an int, float, or bool, depending on what it most closely resembles.
-
class
pavilion.expression_functions.base.
FunctionPlugin
(name, arg_specs, description=None, priority=10)¶ Bases:
yapsy.IPlugin.IPlugin
Plugin base class for math functions.
Child classes must override
__init__
(as is typical for Pavilion plugin), and must also provide a method to act as the function itself. This method must have the same name as the plugin (ie. The ‘max’ plugin must have a ‘max’ method), and take the arguments the function expects.-
VALID_SPEC_TYPES
= (<class 'int'>, <class 'float'>, <class 'str'>, <class 'bool'>, <function num>, None)¶
-
NAME_RE
= re.compile('[a-zA-Z][a-zA-Z0-9_]*$')¶
-
PRIO_CORE
= 0¶
-
PRIO_COMMON
= 10¶
-
PRIO_USER
= 20¶
-
core
= False¶
-
path
¶ The path to the file containing this result parser plugin.
-
signature
¶ Generate a function signature for this function. :newlines: Put each argument on a separate line.
-
long_description
¶ Return the docstring for the function.
-
activate
()¶ Yapsy runs this when adding the plugin. Add our plugin to the registry of function plugins.
-
deactivate
()¶ Yapsy runs this when removing the plugin. Plugins will only be removed by unit tests.
-
register_core
()¶ Find all the core function plugins and activate them.
-
Core Function Plugins¶
Contains the base expression plugins in a single module to speed Pavilion loading.
-
class
pavilion.expression_functions.core.
AllPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Return whether all of the items in the given list are true.
-
static
all
(items)¶ Just use the built-in all function.
-
static
-
class
pavilion.expression_functions.core.
AnyPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Return whether any of the items in the given list are true.
-
static
any
(items)¶ Just use the built-in any function.
-
static
-
class
pavilion.expression_functions.core.
AvgPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Get the average of the given numbers.
-
static
avg
(vals)¶ Get the average of vals. Will always return a float.
-
static
-
class
pavilion.expression_functions.core.
CeilPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Get the integer ceiling of the given number.
-
static
ceil
(val)¶ Round the given number up to the nearest int.
-
static
-
class
pavilion.expression_functions.core.
CoreFunctionPlugin
(name, arg_specs, description=None)¶ Bases:
pavilion.expression_functions.base.FunctionPlugin
A function plugin that sets defaults for core plugins. Use when adding additional function plugins to the core_functions module. Classes that inherit from this will automatically be added as function plugins. If adding non-core functions, use the standard plugin mechanisms.
-
core
= True¶
-
-
class
pavilion.expression_functions.core.
FloorPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Get the floor of the given number.
-
static
floor
(val)¶ Round the given number down to the nearest int.
-
static
-
class
pavilion.expression_functions.core.
IntPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Convert integer strings to ints of arbitrary bases.
-
static
int
(value, base)¶ Convert the given string ‘value’ as an integer of the given base. Bases from 2-32 are allowed.
-
static
-
class
pavilion.expression_functions.core.
KeysPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Return the keys of a given dict.
-
static
keys
(arg)¶ Return a (sorted) list of keys for the given dictionary.
-
signature
= 'keys(dict)'¶
-
static
-
class
pavilion.expression_functions.core.
LenPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Return the length of the given item, where item can be a string, list, or dict.
-
static
len
(arg)¶ Just return the length of the argument.
-
signature
= 'len(list|dict|str)'¶
-
static
-
class
pavilion.expression_functions.core.
Outliers
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Calculate outliers given a list of values and a separate list of their associated names. The lists should be the same length, and in matching order (which Pavilion should generally guarantee). A value is flagged as an outlier if it is more than ‘limit’ standard deviations from the mean of the values.
Produces a dict of name -> (val - mean)/stddev for only those values flagged as outliers.
Ex: ‘bad_nodes: ‘outliers(n.*.speed, keys(n), 2.0)` This would find any nodes with a speed more than 2.0 std deviations from the mean.
-
static
outliers
(values: List[pavilion.expression_functions.base.num], names: List[str], limit: float)¶ Create the outlier dict.
-
static
-
class
pavilion.expression_functions.core.
RandomPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Return a random number in [0,1).
-
static
random
()¶ Return a random float in [0,1).
-
static
-
class
pavilion.expression_functions.core.
RegexSearch
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Search for the given regular expression. Returns the matched text or, if a matching group (limit 1) was used, the matched group. Returns an empty string on no match. Regexes use Python’s regex syntax.
-
static
re_search
(regex, data)¶ Search for the given regex in data.
-
static
-
class
pavilion.expression_functions.core.
Replace
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Replace substrings from a given string.
-
static
replace
(string: str, find: str, replacement: str)¶ Replace all instances of ‘find’ with ‘replacement’ in ‘string’.
-
static
-
class
pavilion.expression_functions.core.
RoundPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Round the given number to the nearest integer.
-
static
round
(val: float)¶ Round the given number to the nearest int.
-
static
-
class
pavilion.expression_functions.core.
SumPlugin
¶ Bases:
pavilion.expression_functions.core.CoreFunctionPlugin
Get the floating point sum of the given numbers.
-
static
sum
(vals)¶ Get the sum of the given numbers. Will return an int if all arguments are ints, otherwise returns a float.
-
static