pacman.utils package
Submodules
pacman.utils.graphs module
pacman.utils.simple_repr module
Simple Representation module.
This module provide utility methods and mixin to convert python objects to and from a so called ‘simple representation’.
A simple representation is composed only of simple python objects: * booleans * string * numbers * lists of simple python objects * dicts of simple python objects * namedtuple
When using namedtuple, they must obey the two following rules * be defined at module level (not in class /method) * the name of the class variable must match the name of the class. for
example:
Named = namedtuple(‘Named’, [‘foo’, ‘bar’])
- class pacman.utils.simple_repr.SimpleRepr[source]
Bases:
object
Mixin to transform python objects into a representation composed only of simple python types. The idea is that the simple repr can be directly converted into json or yaml. The simple representation can be obtained by calling simple_repr(o).
The class using this mixin must satisfy the following constraints: * All constructor’s parameters must be bool, string, number, objects
providing a _simple_repr() method (generally by using the the SimpleRep mixin) or list or dict of objects of these types.
the constructor parameter must map to an attribute with the same name preceded by ‘_’. If it not the case, the class may declare a _repr_mapping attribute which maps the argument name(s) with the attribute(s) names.
pacman.utils.expressionfunction module
- class pacman.utils.expressionfunction.ExpressionFunction(expression, source_file=None, **fixed_vars)[source]
Bases:
Callable
,SimpleRepr
Callable object representing a function from a python string. expression.
Example: f = ExpressionFunction(‘a + b’) f.variable_names -> [‘a’, ‘b’] f(a=1, b=3) -> 4 f.expression -> ‘a + b’
Note: this callable only works with keyword arguments.
- __init__(expression, source_file=None, **fixed_vars)[source]
Create a callable representing the expression.
- Parameters
expression (
str
) – a valid python expression (any builtin python
function can be used, e.g. abs, round, etc.). for example “abs(a1 - b)”
- Parameters
fixed_vars – extra keyword parameters will be interpreted as
fixed parameter for the expression and the produced callable will represent a partial evaluation if the expression with these parameter already fixed. If the name of these keyword parameter do not match any of the variables found in the expression, a ValueError is raised.
- property expression
- property variable_names: List[str]
return: a set of variable names that must be set when calling f
- Return type
List
[str
]