3.1.1.3. obj_tables.math package

3.1.1.3.1. Submodules

3.1.1.3.2. obj_tables.math.expression module

Utilities for processing mathematical expressions used by obj_tables models

Author

Arthur Goldberg <Arthur.Goldberg@mssm.edu>

Author

Jonathan Karr <karr@mssm.edu>

Date

2018-12-19

Copyright

2016-2019, Karr Lab

License

MIT

class obj_tables.math.expression.OneToOneExpressionAttribute(related_class, related_name='', default=None, default_cleaned_value=None, related_default=None, none_value=None, min_related=0, min_related_rev=0, verbose_name='', verbose_related_name='', description='')[source]

Bases: obj_tables.core.OneToOneAttribute

Expression one-to-one attribute

Parameters
  • related_class (class) – related class

  • related_name (str, optional) – name of related attribute on related_class

  • default (callable, optional) – callable which returns default value

  • default_cleaned_value (callable, optional) – value to replace None values with during cleaning, or function which computes the value to replace None values

  • related_default (callable, optional) – callable which returns default related value

  • none_value (object, optional) – none value

  • min_related (int, optional) – minimum number of related objects in the forward direction

  • min_related_rev (int, optional) – minimum number of related objects in the reverse direction

  • verbose_name (str, optional) – verbose name

  • verbose_related_name (str, optional) – verbose related name

  • description (str, optional) – description

deserialize(value, objects, decoded=None)[source]

Deserialize value

Parameters
  • value (str) – String representation

  • objects (dict) – dictionary of objects, grouped by model

  • decoded (dict, optional) – dictionary of objects that have already been decoded

Returns

tuple of cleaned value and cleaning error

Return type

tuple of object, InvalidAttribute or None

get_xlsx_validation(sheet_models=None, doc_metadata_model=None)[source]

Get XLSX validation

Parameters
  • sheet_models (list of Model, optional) – models encoded as separate sheets

  • doc_metadata_model (type) – model whose worksheet contains the document metadata

Returns

validation

Return type

wc_utils.workbook.io.FieldValidation

serialize(expression, encoded=None)[source]

Serialize related object

Parameters
  • expression (obj_tables.Model) – the referenced Expression

  • encoded (dict, optional) – dictionary of objects that have already been encoded

Returns

simple Python representation

Return type

str

class obj_tables.math.expression.ManyToOneExpressionAttribute(related_class, related_name='', default=None, default_cleaned_value=None, related_default=[], none_value=None, min_related=0, min_related_rev=0, max_related_rev=inf, verbose_name='', verbose_related_name='', description='', related_manager=<class 'obj_tables.core.ManyToOneRelatedManager'>)[source]

Bases: obj_tables.core.ManyToOneAttribute

Expression many-to-one attribute

Parameters
  • related_class (class) – related class

  • related_name (str, optional) – name of related attribute on related_class

  • default (callable, optional) – callable which returns the default value

  • default_cleaned_value (callable, optional) – value to replace None values with during cleaning, or function which computes the value to replace None values

  • related_default (callable, optional) – callable which returns the default related value

  • none_value (object, optional) – none value

  • min_related (int, optional) – minimum number of related objects in the forward direction

  • min_related_rev (int, optional) – minimum number of related objects in the reverse direction

  • max_related_rev (int, optional) – maximum number of related objects in the reverse direction

  • verbose_name (str, optional) – verbose name

  • verbose_related_name (str, optional) – verbose related name

  • description (str, optional) – description

  • related_manager (type, optional) – related manager

deserialize(value, objects, decoded=None)[source]

Deserialize value

Parameters
  • value (str) – String representation

  • objects (dict) – dictionary of objects, grouped by model

  • decoded (dict, optional) – dictionary of objects that have already been decoded

Returns

tuple of cleaned value and cleaning error

Return type

tuple of object, InvalidAttribute or None

get_xlsx_validation(sheet_models=None, doc_metadata_model=None)[source]

Get XLSX validation

Parameters
  • sheet_models (list of Model, optional) – models encoded as separate sheets

  • doc_metadata_model (type) – model whose worksheet contains the document metadata

Returns

validation

Return type

wc_utils.workbook.io.FieldValidation

serialize(expression, encoded=None)[source]

Serialize related object

Parameters
  • expression (Expression) – the related Expression

  • encoded (dict, optional) – dictionary of objects that have already been encoded

Returns

simple Python representation of the rate law expression

Return type

str

class obj_tables.math.expression.ObjTablesTokenCodes[source]

Bases: int, enum.Enum

ObjTablesToken codes used in parsed expressions

math_func_id = 2[source]
number = 3[source]
obj_id = 1[source]
op = 4[source]
other = 5[source]
class obj_tables.math.expression.IdMatch[source]

Bases: tuple

IdMatch(model_type, token_pattern, match_string): Matched token pattern used by tokenize

Create new instance of IdMatch(model_type, token_pattern, match_string)

property match_string[source]

The matched string

property model_type[source]

The type of Model matched

property token_pattern[source]

The token pattern used by the match

class obj_tables.math.expression.ObjTablesToken[source]

Bases: tuple

ObjTablesToken(code, token_string, model_type, model_id, model): ObjTablesToken in a parsed obj_tables expression

Create new instance of ObjTablesToken(code, token_string, model_type, model_id, model)

property code[source]

ObjTablesTokenCodes encoding

property model[source]

When code is obj_id, the obj_tables obj

property model_id[source]

When code is obj_id, the obj_tables obj’s id

property model_type[source]

When code is obj_id, the obj_tables obj’s type

property token_string[source]

The token’s string

class obj_tables.math.expression.LexMatch[source]

Bases: tuple

LexMatch(obj_tables_tokens, num_py_tokens): container for an unambiguous Model id

Create new instance of LexMatch(obj_tables_tokens, num_py_tokens)

property num_py_tokens[source]

Number of Python tokens consumed

property obj_tables_tokens[source]

List of ObjTablesToken’s created

class obj_tables.math.expression.ExpressionTermMeta[source]

Bases: object

Metadata for subclasses that can appear in expressions

expression_term_token_pattern[source]

token pattern for the name of the term in expression

Type

tuple

expression_term_units[source]

name of attribute which describes the units of the expression term

Type

str

expression_term_token_pattern = (1,)[source]
expression_term_units = 'units'[source]
class obj_tables.math.expression.ExpressionStaticTermMeta[source]

Bases: obj_tables.math.expression.ExpressionTermMeta

Metadata for subclasses with static values that can appear in expressions

expression_term_value[source]

name of attribute which encodes the value of the term

Type

str

expression_term_value = 'value'[source]
class obj_tables.math.expression.ExpressionDynamicTermMeta[source]

Bases: obj_tables.math.expression.ExpressionTermMeta

Metadata for subclasses with dynamic values that can appear in expressions

class obj_tables.math.expression.ExpressionExpressionTermMeta[source]

Bases: obj_tables.math.expression.ExpressionTermMeta

Metadata for subclasses with expressions that can appear in expressions

expression_term_model[source]

name of attribute which encodes the expression for the term

Type

str

expression_term_model = None[source]
class obj_tables.math.expression.Expression[source]

Bases: object

Generic methods for mathematical expressions

_parsed_expression[source]

parsed expression

Type

ParsedExpression

class Meta[source]

Bases: object

Metadata for subclasses of Expression

expression_term_models[source]

names of classes which can appear as terms in the expression

Type

tuple of str

expression_valid_functions[source]

Python functions which can appear in the expression

Type

tuple of types.FunctionType

expression_is_linear[source]

if True, validate that the expression is linear

Type

bool

expression_type[source]

type of the expression

Type

type

expression_unit_registry[source]

unit registry

Type

pint.UnitRegistry

expression_is_linear = False[source]
expression_term_models = ()[source]
expression_type = None[source]
expression_unit_registry = None[source]
expression_valid_functions = (<class 'float'>, <built-in function fabs>, <built-in function ceil>, <built-in function floor>, <built-in function round>, <built-in function exp>, <built-in function expm1>, <built-in function pow>, <built-in function sqrt>, <built-in function log>, <built-in function log1p>, <built-in function log10>, <built-in function log2>, <built-in function factorial>, <built-in function sin>, <built-in function cos>, <built-in function tan>, <built-in function acos>, <built-in function asin>, <built-in function atan>, <built-in function atan2>, <built-in function hypot>, <built-in function degrees>, <built-in function radians>, <built-in function min>, <built-in function max>)[source]
classmethod deserialize(model_cls, value, objects)[source]

Deserialize value into an Expression

Parameters
  • model_cls (type) – Expression class or subclass

  • value (str) – string representation of the mathematical expression, in a Python expression

  • objects (dict) – dictionary of objects which can be used in Expression, grouped by model

Returns

on error return (None, InvalidAttribute),

otherwise return (object in this class with instantiated _parsed_expression, None)

Return type

tuple

static make_expression_obj(model_type, expression, objs)[source]

Make an expression object

Parameters
  • model_type (type) – an Model that uses a mathemetical expression, like Function and Observable

  • expression (str) – the expression used by the model_type being created

  • objs (dict of dict) – all objects that are referenced in expression

Returns

if successful, (Model, None) containing a new instance of

model_type’s expression helper class; otherwise, (None, InvalidAttribute) reporting the error

Return type

tuple

classmethod make_obj(model, model_type, primary_attr, expression, objs, allow_invalid_objects=False)[source]

Make a model that contains an expression by using its expression helper class

For example, this uses FunctionExpression to make a Function.

Parameters
  • model (Model) – an instance of Model which is the root model

  • model_type (type) – a subclass of Model that uses a mathemetical expression, like Function and Observable

  • primary_attr (object) – the primary attribute of the model_type being created

  • expression (str) – the expression used by the model_type being created

  • objs (dict of dict) – all objects that are referenced in expression

  • allow_invalid_objects (bool, optional) – if set, return object - not error - if the expression object does not validate

Returns

a new instance of model_type, or,

if an error occurs, an InvalidAttribute reporting the error

Return type

Model or InvalidAttribute

merge_attrs(other, other_objs_in_self, self_objs_in_other)[source]

Merge attributes of two objects

Parameters
  • other (Model) – other model

  • other_objs_in_self (dict) – dictionary that maps instances of objects in another model to objects in a model

  • self_objs_in_other (dict) – dictionary that maps instances of objects in a model to objects in another model

serialize()[source]

Generate string representation

Returns

value of primary attribute

Return type

str

classmethod validate(model_obj, parent_obj)[source]

Determine whether an expression model is valid

One check eval’s its deserialized expression

Parameters
  • model_obj (Expression) – expression object

  • parent_obj (Model) – parent of expression object

Returns

None if the object is valid,

otherwise return a list of errors in an InvalidObject instance

Return type

InvalidObject or None

exception obj_tables.math.expression.ParsedExpressionError(message=None)[source]

Bases: ValueError

Exception raised for errors in ParsedExpression

message[source]

the exception’s message

Type

str

Parameters

message (str, optional) – the exception’s message

class obj_tables.math.expression.ParsedExpression(model_cls, attr, expression, objs)[source]

Bases: object

An expression in an ObjTables Model

These expressions are limited Python expressions with specific semantics:

  • They must be syntactically correct Python, except that an identifier can begin with numerical digits.

  • No Python keywords, strings, or tokens that do not belong in expressions are allowed.

  • All Python identifiers must be the primary attribute of an ObjTables object or the name of a function in the math package. Objects in the model are provided in _objs, and the allowed subset of functions in math must be provided in an iterator in the expression_valid_functions attribute of the Meta class of a model whose whose expression is being processed.

  • Currently (July, 2018), an identifier may refer to a Species, Parameter, Reaction, Observable or DfbaObjReaction.

  • Cycles of references are illegal.

  • An identifier must unambiguously refer to exactly one related Model in a model.

  • Each Model that can be used in an expression must have an ID that is an identifier, or define expression_term_token_pattern as an attribute that describes the Model’s syntactic Python structure. See Species for an example.

  • Every expression must be computable at any time during a simulation. The evaluation of an expression always occurs at a precise simulation time, which is implied by the expression but not explicitly represented. E.g., a reference to a Species means its concentration at the time the expression is evaled. These are the meanings of references:

    • Species: its current concentration

    • Parameter: its value, which is static

    • Observable: its current value, whose units depend on its definition

    • Reaction: its current flux

    • DfbaObjReaction: its current flux

The modeller is responsible for ensuring that units in expressions are internally consistent and appropriate for the expression’s use.

model_cls[source]

the Model which has an expression

Type

type

attr[source]

the attribute name of the expression in model_cls

Type

str

expression[source]

the expression defined in the obj_tables Model

Type

str

_py_tokens[source]

a list of Python tokens generated by tokenize.tokenize()

Type

list of collections.namedtuple

_objs[source]

dict of obj_tables Models that might be referenced in expression; maps model type to a dict mapping ids to Model instances

Type

dict

valid_functions[source]

the union of all valid_functions attributes for _objs

Type

set

unit_registry[source]

unit registry

Type

pint.UnitRegistry

related_objects[source]

models that are referenced in expression; maps model type to dict that maps model id to model instance

Type

dict

lin_coeffs[source]

linear coefficients of models that are referenced in expression; maps model type to dict that maps models to coefficients

Type

dict

errors[source]

errors found when parsing an expression fails

Type

list of str

_obj_tables_tokens[source]

tokens obtained when an expression is successfully tokenized; if empty, then this ParsedExpression cannot use eval

Type

list of ObjTablesToken

_compiled_expression[source]

compiled expression that can be evaluated by eval

Type

str

_compiled_expression_with_units[source]

compiled expression with units that can be evaluated by eval

Type

str

_compiled_namespace[source]

compiled namespace for evaluation by eval

Type

dict

_compiled_namespace_with_units[source]

compiled namespace with units for evaluation by eval

Type

dict

Create an instance of ParsedExpression

Parameters
  • model_cls (type) – the Model which has an expression

  • attr (str) – the attribute name of the expression in model_cls

  • expression (obj) – the expression defined in the obj_tables Model

  • objs (dict) – dictionary of model objects (instances of Model) organized by their type

Raises

ParsedExpressionError – if model_cls is not a subclass of Model, or lexical analysis of expression raises an exception, or objs includes model types that model_cls should not reference

FUNC_PATTERN = (1, 7)[source]
LEGAL_TOKENS = {1, 2, 7, 8, 9, 10, 12, 14, 15, 16, 17, 20, 21, 23, 27, 28, 29, 30, 35}[source]
LEGAL_TOKENS_NAMES = ('NUMBER', 'NAME', 'LSQB', 'RSQB', 'DOT', 'COMMA', 'DOUBLESTAR', 'MINUS', 'PLUS', 'SLASH', 'STAR', 'LPAR', 'RPAR', 'EQEQUAL', 'GREATER', 'GREATEREQUAL', 'LESS', 'LESSEQUAL', 'NOTEQUAL')[source]
MODEL_TYPE_DISAMBIG_PATTERN = (1, 23, 1)[source]
eval(values, with_units=False)[source]

Evaluate the expression

Approach:

  1. Ensure that the expression is compiled

  2. Prepare namespace with model values

  3. eval the Python expression

Parameters
  • values (dict) – dictionary that maps model types to dictionaries that map model ids to values

  • with_units (bool, optional) – if True, include units

Returns

the value of the expression

Return type

float, int, or bool

Raises

ParsedExpressionError – if the expression has not been compiled or the evaluation fails

get_str(obj_tables_token_to_str, with_units=False, number_units=' * __dimensionless__')[source]

Generate string representation of expression, e.g. for evaluation by eval

Parameters
  • obj_tables_token_to_str (callable) – method to get string representation of a token that represents an instance of Model.

  • with_units (bool, optional) – if True, include units

  • number_units (str, optional) – default units for numbers

Returns

string representation of expression

Return type

str

Raises

ParsedExpressionError – if the expression is invalid

legal_token = 28[source]
legal_token_name = 'NOTEQUAL'[source]
recreate_whitespace(expr)[source]

Insert the whitespace in this object’s expression into an expression with the same token count

Used to migrate an expression to a different set of model type names.

Parameters

expr (str) – a syntactically correct Python expression

Returns

expr with the whitespace in this instance’s expression inserted between

its Python tokens

Return type

str

Raises

ParsedExpressionError – if tokenizing expr raises an exception, or if expr doesn’t have the same number of Python tokens as self.expression

test_eval(values=1.0, with_units=False)[source]

Test evaluate this ParsedExpression with the value of all models given by values

This is used to validate this ParsedExpression, as well as for testing.

Parameters
  • values (float or dict, optional) – value(s) of models used by the test evaluation; if a scalar, then that value is used for all models; if a dict then it maps model types to their values, or it maps model types to dictionaries that map model ids to the values of individual models used in the test

  • with_units (bool, optional) – if True, evaluate units

Returns

the value of the expression

Return type

float, int, or bool

Raises

ParsedExpressionError – if the expression evaluation fails

tokenize(case_fold_match=False)[source]

Tokenize a Python expression in self.expression

Parameters

case_fold_match (bool, optional) – if set, casefold identifiers before matching; identifier keys in self._objs must already be casefold’ed; default = False

Returns

  • list: of ObjTablesTokens

  • dict: dict of Model instances used by this list, grouped by Model type

  • list of str: list of errors

Return type

tuple

Raises

ParsedExpressionError – if model_cls does not have a Meta attribute

class obj_tables.math.expression.LinearParsedExpressionValidator[source]

Bases: object

Verify whether a ParsedExpression is equivalent to a linear function of variables

A linear function of identifiers has the form a1 * v1 + a2 * v2 + … an * vn, where a1 … an are floats or integers and v1 … vn are variables.

expression[source]

the expression

Type

str

parsed_expression[source]

parsed_expression

Type

ParsedExpression

tree[source]

the abstract syntax tree

Type

_ast.Expression

is_linear[source]

whether the ParsedExpression is linear

Type

boolean

opaque_ids[source]

map from Model ids that are not valid Python identifiers to opaque ids

Type

dict

next_id[source]

suffix of next opaque Python identifier

Type

int

class DistributeMult[source]

Bases: ast.NodeTransformer

visit_BinOp(node)[source]
class DistributeSub[source]

Bases: ast.NodeTransformer

visit_BinOp(node)[source]
class MoveCoeffsToLeft[source]

Bases: ast.NodeTransformer

visit_BinOp(node)[source]
class MultiplyNums[source]

Bases: ast.NodeTransformer

visit_BinOp(node)[source]
class RemoveUnaryOps[source]

Bases: ast.NodeTransformer

visit_UnaryOp(node)[source]
VALID_NOTE_TYPES = {<class '_ast.Name'>, <class '_ast.Sub'>, <class '_ast.Add'>, <class '_ast.Load'>, <class '_ast.Num'>, <class '_ast.USub'>, <class '_ast.Constant'>, <class '_ast.UAdd'>, <class '_ast.UnaryOp'>, <class '_ast.Mult'>, <class '_ast.BinOp'>}[source]
VALID_PYTHON_ID_PREFIX = 'opaque_model_id_'[source]
static ast_eq(ast1, ast2)[source]

Are two abstract syntax trees equal

get_cls_and_model(id)[source]

Get the class and instance of a related model with id id

Parameters

id (str) – id

Returns

(:obj:`type, Model)`: the class and instance of a related model with id id

Return type

tuple

Raises

ParsedExpressionError – if multiple related models have id id

validate(parsed_expression, set_linear_coeffs=True)[source]

Determine whether the expression is a valid linear expression

Parameters
  • parsed_expression (ParsedExpression) – a parsed expression

  • set_linear_coeffs (boolean, optional) – if True:, set the linear coefficients for the related objects

Returns

(False, error) if self.expression does not represent a linear expression,

or (True, None) if it does

Return type

tuple

3.1.1.3.3. obj_tables.math.numeric module

Math attributes

Author

Jonathan Karr <karr@mssm.edu>

Date

2017-05-10

Copyright

2017, Karr Lab

License

MIT

class obj_tables.math.numeric.ArrayAttribute(min_length=0, max_length=inf, default=None, none_value=None, verbose_name='', description='', primary=False, unique=False)[source]

Bases: obj_tables.core.LiteralAttribute

numpy.ndarray attribute

min_length[source]

minimum length

Type

int

max_length[source]

maximum length

Type

int

default[source]

default value

Type

numpy.ndarray

Parameters
  • min_length (int, optional) – minimum length

  • max_length (int, optional) – maximum length

  • default (numpy.array, optional) – default value

  • none_value (object, optional) – none value

  • verbose_name (str, optional) – verbose name

  • description (str, optional) – description

  • primary (bool, optional) – indicate if attribute is primary attribute

  • unique (bool, optional) – indicate if attribute value must be unique

deserialize(value)[source]

Deserialize value

Parameters

value (str) – semantically equivalent representation

Returns

tuple of cleaned value and cleaning error

Return type

tuple of numpy.array, core.InvalidAttribute or None

from_builtin(json)[source]

Decode a simple Python representation (dict, list, str, float, bool, None) of a value of the attribute that is compatible with JSON and YAML

Parameters

json (list) – simple Python representation of a value of the attribute

Returns

decoded value of the attribute

Return type

numpy.array

serialize(value)[source]

Serialize string

Parameters

value (numpy.array) – Python representation

Returns

simple Python representation

Return type

str

to_builtin(value)[source]

Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML

Parameters

value (numpy.array) – value of the attribute

Returns

simple Python representation of a value of the attribute

Return type

list

validate(obj, value)[source]

Determine if value is a valid value

Parameters
  • obj (Model) – class being validated

  • value (numpy.array) – value of attribute to validate

Returns

None if attribute is valid, other return

list of errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

validate_unique(objects, values)[source]

Determine if the attribute values are unique

Parameters
  • objects (list of Model) – list of Model objects

  • values (list of numpy.array) – list of values

Returns

None if values are unique, otherwise return a

list of errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

class obj_tables.math.numeric.TableAttribute(default=None, none_value=None, verbose_name='', description='', primary=False, unique=False)[source]

Bases: obj_tables.core.LiteralAttribute

pandas.DataFrame attribute

default[source]

default value

Type

pandas.DataFrame

Parameters
  • default (pandas.DataFrame, optional) – default value

  • none_value (object, optional) – none value

  • verbose_name (str, optional) – verbose name

  • description (str, optional) – description

  • primary (bool, optional) – indicate if attribute is primary attribute

  • unique (bool, optional) – indicate if attribute value must be unique

deserialize(value)[source]

Deserialize value

Parameters

value (str) – semantically equivalent representation

Returns

tuple of cleaned value and cleaning error

Return type

tuple of pandas.DataFrame, core.InvalidAttribute or None

from_builtin(json)[source]

Decode a simple Python representation (dict, list, str, float, bool, None) of a value of the attribute that is compatible with JSON and YAML

Parameters

json (dict) – simple Python representation of a value of the attribute

Returns

decoded value of the attribute

Return type

pandas.DataFrame

serialize(value)[source]

Serialize string

Parameters

value (pandas.DataFrame) – Python representation

Returns

simple Python representation

Return type

str

to_builtin(value)[source]

Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML

Parameters

value (pandas.DataFrame) – value of the attribute

Returns

simple Python representation of a value of the attribute

Return type

dict

validate(obj, value)[source]

Determine if value is a valid value

Parameters
  • obj (Model) – class being validated

  • value (pandas.DataFrame) – value of attribute to validate

Returns

None if attribute is valid, other return list of

errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

validate_unique(objects, values)[source]

Determine if the attribute values are unique

Parameters
  • objects (list of Model) – list of Model objects

  • values (list of pandas.DataFrame) – list of values

Returns

None if values are unique, otherwise return a

list of errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

3.1.1.3.4. obj_tables.math.symbolic module

Attributes for symbolic math

Author

Jonathan Karr <karr@mssm.edu>

Date

2017-05-10

Copyright

2017, Karr Lab

License

MIT

class obj_tables.math.symbolic.SymbolicBasicAttribute(sympy_type=<class 'sympy.core.basic.Basic'>, default=None, none_value=None, verbose_name='', description='', primary=False, unique=False, unique_case_insensitive=False)[source]

Bases: obj_tables.core.LiteralAttribute

Base class for SymPy expression, symbol attributes

sympy_type[source]

attribute type (e.g. sympy.Basic, sympy.Expr, sympy.Symbol)

Type

sympy.core.assumptions.ManagedProperties

default[source]

default value

Type

sympy.Basic

Parameters
  • sympy_type (sympy.core.assumptions.ManagedProperties, optional) – attribute type (e.g. sympy.Basic, sympy.Expr, sympy.Symbol)

  • default (sympy.Basic, optional) – default value

  • none_value (object, optional) – none value

  • verbose_name (str, optional) – verbose name

  • description (str, optional) – description

  • primary (bool, optional) – indicate if attribute is primary attribute

  • unique (bool, optional) – indicate if attribute value must be unique

  • unique_case_insensitive (bool, optional) – if true, conduct case-insensitive test of uniqueness

deserialize(value)[source]

Deserialize value

Parameters

value (str) – semantically equivalent representation

Returns

tuple of cleaned value and cleaning error

Return type

tuple of sympy.Basic, core.InvalidAttribute or None

from_builtin(json)[source]

Decode a simple Python representation (dict, list, str, float, bool, None) of a value of the attribute that is compatible with JSON and YAML

Parameters

json (list) – simple Python representation of a value of the attribute

Returns

decoded value of the attribute

Return type

sympy.Basic

serialize(value)[source]

Serialize string

Parameters

value (sympy.Basic) – Python representation

Returns

simple Python representation

Return type

str

to_builtin(value)[source]

Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML

Parameters

value (sympy.Basic) – value of the attribute

Returns

simple Python representation of a value of the attribute

Return type

str

validate(obj, value)[source]

Determine if value is a valid value

Parameters
  • obj (Model) – class being validated

  • value (sympy.Basic) – value of attribute to validate

Returns

None if attribute is valid, other return list of errors

as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

validate_unique(objects, values)[source]

Determine if the attribute values are unique

Parameters
  • objects (list of Model) – list of Model objects

  • values (list of sympy.Basic) – list of values

Returns

None if values are unique, otherwise return a list

of errors as an instance of core.InvalidAttribute

Return type

core.InvalidAttribute or None

class obj_tables.math.symbolic.SymbolicSymbolAttribute(default=None, none_value=None, verbose_name='', description='', primary=False, unique=False, unique_case_insensitive=False)[source]

Bases: obj_tables.math.symbolic.SymbolicBasicAttribute

SymPy symbol attribute

default[source]

default value

Type

sympy.Symbol

Parameters
  • default (sympy.Symbol, optional) – default value

  • none_value (object, optional) – none value

  • verbose_name (str, optional) – verbose name

  • description (str, optional) – description

  • primary (bool, optional) – indicate if attribute is primary attribute

  • unique (bool, optional) – indicate if attribute value must be unique

  • unique_case_insensitive (bool, optional) – if true, conduct case-insensitive test of uniqueness

serialize(value)[source]

Serialize string

Parameters

value (sympy.Symbol) – Python representation

Returns

simple Python representation

Return type

str

to_builtin(value)[source]

Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML

Parameters

value (sympy.Symbol) – value of the attribute

Returns

simple Python representation of a value of the attribute

Return type

str

class obj_tables.math.symbolic.SymbolicExprAttribute(default=None, none_value=None, verbose_name='', description='', primary=False, unique=False, unique_case_insensitive=False)[source]

Bases: obj_tables.math.symbolic.SymbolicBasicAttribute

SymPy expression attribute

default[source]

default value

Type

sympy.Expr

Parameters
  • default (sympy.Expr, optional) – default value

  • none_value (object, optional) – none value

  • verbose_name (str, optional) – verbose name

  • description (str, optional) – description

  • primary (bool, optional) – indicate if attribute is primary attribute

  • unique (bool, optional) – indicate if attribute value must be unique

  • unique_case_insensitive (bool, optional) – if true, conduct case-insensitive test of uniqueness

serialize(value)[source]

Serialize string

Parameters

value (sympy.Expr) – Python representation

Returns

simple Python representation

Return type

str

to_builtin(value)[source]

Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML

Parameters

value (sympy.Expr) – value of the attribute

Returns

simple Python representation of a value of the attribute

Return type

str

3.1.1.3.5. Module contents