pynestml.symbols package
Submodules
pynestml.symbols.boolean_type_symbol module
- class pynestml.symbols.boolean_type_symbol.BooleanTypeSymbol
Bases:
TypeSymbol- is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
- negate()
pynestml.symbols.error_type_symbol module
- class pynestml.symbols.error_type_symbol.ErrorTypeSymbol
Bases:
TypeSymbolOriginally intended to only be a “Null type” for the TypeSymbol hierarchy, it is now also a device to communicate errors and warnings back to a place where they can be properly logged (we cant do that here because we don’t know t he source-position). Thought about using Exceptions but that would lead to loads of code duplication in the visitors responsible for expression typing. In the end a little bit of ugliness here saves us a lot throughout the project -ptraeder
p.s. could possibly resolve this by associating type-symbol objects with expressions they belong to. The field for that is already present from Symbol and we already instantiate types for every expression anyways
- is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
- negate()
pynestml.symbols.function_symbol module
- class pynestml.symbols.function_symbol.FunctionSymbol(name, param_types, return_type, element_reference, scope=None, is_predefined=False)
Bases:
SymbolThis class is used to store a single function symbol, e.g. the definition of the function max. .. attribute:: param_types
A list of the types of parameters.
- type:
list(TypeSymbol)
- return_type
The type of the returned value.
- Type:
type_symbol
- add_parameter_type(new_type)
Adds the handed over type to the list of argument types. :param new_type: a single type symbol :type new_type: type_symbol
- equals(_other=None)
Compares the handed over instance of function symbol to this one and returns true, if the they are equal. :param _other: a different function symbol :type _other: FunctionSymbol :return: True if equal, otherwise False. :rtype: bool
- get_parameter_types()
Returns a list of all parameter types. :return: a list of parameter types. :rtype: list(TypeSymbol)
- get_return_type()
Returns the return type of this function symbol :return: a single type symbol. :rtype: type_symbol
- set_return_type(new_type)
Sets the return type to the handed over one. :param new_type: a single type symbol :type new_type: type_symbol
pynestml.symbols.integer_type_symbol module
- class pynestml.symbols.integer_type_symbol.IntegerTypeSymbol
Bases:
TypeSymbol- is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
pynestml.symbols.predefined_functions module
- class pynestml.symbols.predefined_functions.PredefinedFunctions
Bases:
objectThis class is used to represent all predefined functions of NESTML.
- ABS = 'abs'
- CEIL = 'ceil'
- CLIP = 'clip'
- CONVOLVE = 'convolve'
- COS = 'cos'
- COSH = 'cosh'
- DELTA = 'delta'
- EMIT_SPIKE = 'emit_spike'
- ERF = 'erf'
- ERFC = 'erfc'
- EXP = 'exp'
- EXPM1 = 'expm1'
- FLOOR = 'floor'
- INTEGRATE_ODES = 'integrate_odes'
- LN = 'ln'
- LOG10 = 'log10'
- LOGGER_INFO = 'info'
- LOGGER_WARNING = 'warning'
- MAX = 'max'
- MIN = 'min'
- POW = 'pow'
- PRINT = 'print'
- PRINTLN = 'println'
- RANDOM_NORMAL = 'random_normal'
- RANDOM_POISSON = 'random_poisson'
- RANDOM_UNIFORM = 'random_uniform'
- ROUND = 'round'
- SIFT = 'sift'
- SIN = 'sin'
- SINH = 'sinh'
- TAN = 'tan'
- TANH = 'tanh'
- TIME_RESOLUTION = 'resolution'
- TIME_STEPS = 'steps'
- TIME_TIMESTEP = 'timestep'
- classmethod get_function(name: str)
Returns a copy of a element in the set of defined functions if one exists, otherwise None
- Parameters:
name – the name of the function symbol
- Returns:
a copy of the element if such exists in the dict, otherwise None
- Return type:
None or FunctionSymbol
- classmethod get_function_symbols()
Returns a copy of the dict containing all predefined functions symbols. :return: a copy of the dict containing the functions symbols :rtype: dict(FunctionSymbol)
- name2function: Mapping[str, FunctionSymbol] = {}
- classmethod register_function(name, params, return_type, element_reference)
- classmethod register_functions()
Registers all predefined functions.
pynestml.symbols.predefined_types module
- class pynestml.symbols.predefined_types.PredefinedTypes
Bases:
objectThis class represents all types which are predefined in the system.
- name2type A dict from names of variables to the corresponding type symbols. Type
dict(str->TypeSymbol)
- REAL_TYPE The identifier of the type "real". Type
str
- VOID_TYPE The identifier of the type "void". Type
str
- BOOLEAN_TYPE The identifier of the type "boolean". Type
str
- STRING_TYPE The identifier of the type "string". Type
str
- INTEGER_TYPE The identifier of the type "integer". Type
str
- BOOLEAN_TYPE = 'boolean'
- INTEGER_TYPE = 'integer'
- REAL_TYPE = 'real'
- STRING_TYPE = 'string'
- VOID_TYPE = 'void'
- classmethod get_boolean_type()
Returns a copy of the type symbol of type boolean. :return: a boolean symbol. :rtype: type_symbol
- classmethod get_integer_type()
Returns a new type symbol of type integer. :return: a new integer symbol. :rtype: type_symbol
- classmethod get_real_type()
Returns a copy of the type symbol of type real. :return: a real symbol. :rtype: type_symbol
- classmethod get_string_type()
Returns a copy of the type symbol of type string. :return: a new string symbol. :rtype: type_symbol
- classmethod get_template_type(i)
Returns a new type symbol for argument type templating. The template types are uniquely identified with an integer number i (see TemplateTypeSymbol). :return: a new integer symbol. :rtype: type_symbol
- classmethod get_type(name)
Return a TypeSymbol for -registered types -Correct SI Units in name (“ms”) -Correct Serializations of a UnitRepresentation
In Case of UNITS always return a TS with serialization as name :param name: the name of the symbol. :type name: str or unit :return: a single symbol copy or none :rtype: type_symbol or None
- classmethod get_types()
Returns the list of all predefined types. :return: a copy of a list of all predefined types. :rtype: copy(list(TypeSymbol)
- classmethod get_variadic_type()
Returns a new type symbol for a variadic type (variable-length list of arguments). :return: a new variadic type symbol :rtype: type_symbol
- classmethod get_void_type()
Returns a copy of the type symbol of type void. :return: a void symbol. :rtype: type_symbol
- name2type: Mapping[str, TypeSymbol] = {}
- classmethod register_type(symbol)
Registers a new type into the system. :param: a single type symbol. :type: UnitTypeSymbol
- classmethod register_types()
Adds a set of primitive and unit data types to the set of predefined types. It assures that those types are valid and can be used.
- classmethod register_unit(unit)
Registers a new astropy unit into the system :param unit: an astropy Unit object :type unit: astropy.units.core.Unit
pynestml.symbols.predefined_units module
- class pynestml.symbols.predefined_units.PredefinedUnits
Bases:
objectThis class represents a collection of physical units. Units can be retrieved by means of get_unit(name). Attribute:
name2unit (dict): Dict of all predefined units, map from name to unit object.
- classmethod get_unit(name: str) UnitType
Returns a single UnitType if the corresponding unit has been predefined. :param name: the name of a unit :return: a single UnitType object, or None
- classmethod get_units() Sequence[UnitType]
Returns the list of all currently defined units. :return: a list of all defined units.
- classmethod is_unit(name: str) bool
Indicates whether the handed over name represents a stored unit. :param name: a single name :return: True if unit name, otherwise False.
- classmethod register_unit(unit: UnitType) None
Registers the handed over unit in the set of the predefined units. :param unit: a single unit type.
- classmethod register_units()
Registers all units in astropy.units (more specifically, from the si, cgs and astrophys submodules) as predefined units into NESTML.
pynestml.symbols.predefined_variables module
- class pynestml.symbols.predefined_variables.PredefinedVariables
Bases:
objectThis class is used to store all predefined variables as generally available.
- classmethod get_euler_constant()
Returns a copy of the variable symbol representing the euler constant e. :return: a variable symbol. :rtype: VariableSymbol
- classmethod get_time_constant()
Returns a copy of the variable symbol representing the time constant t. :return: a variable symbol. :rtype: VariableSymbol
- classmethod get_variable(name)
Returns the variable symbol belonging to the handed over name if such an element exists. :param name: the name of a symbol. :type name: str :return: a variable symbol if one exists, otherwise none :rtype: None or VariableSymbol
- classmethod get_variables()
Returns the list of all defined variables. :return: a list of variable symbols. :rtype: list(VariableSymbol)
- name2variable: Mapping[str, VariableSymbol] = {}
- classmethod register_variables()
Registers the predefined variables.
pynestml.symbols.real_type_symbol module
- class pynestml.symbols.real_type_symbol.RealTypeSymbol
Bases:
TypeSymbol- is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
- print_nestml_type()
pynestml.symbols.string_type_symbol module
- class pynestml.symbols.string_type_symbol.StringTypeSymbol
Bases:
TypeSymbol- is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
- print_nestml_type()
pynestml.symbols.symbol module
- class pynestml.symbols.symbol.Symbol(element_reference, scope, name, symbol_kind)
Bases:
objectThis abstract class represents a super-class for all concrete symbols as stored in a symbol table. .. attribute:: element_reference
A reference to an AST node which defined this symbol. This has to be in the super-class, since variables as well as functions can be user defined.
- type:
- scope
The scope in which this element is stored in.
- symbol_kind
The type of this symbol, i.e., either variable, function or type.
- Type:
- get_comment()
Returns the comment of this symbol. :return: the comment. :rtype: list(str)
- get_corresponding_scope()
Returns the scope in which this symbol is embedded in. :return: a scope object. :rtype: Scope
- get_referenced_object()
Returns the referenced object. :return: the referenced object. :rtype: ASTObject
- get_symbol_kind()
Returns the type of this symbol. :return: the type of this symbol. :rtype: SymbolKind
- has_comment()
Indicates whether this symbols is commented. :return: True if comment is stored, otherwise False. :rtype: bool
- is_defined_before(source_position)
For a handed over source position, this method checks if this symbol has been defined before the handed over position. :param source_position: the position of a different element. :type source_position: ast_source_location :return: True, if defined before or at the source position, otherwise False. :rtype: bool
- abstract print_symbol()
Returns a string representation of this symbol.
- set_comment(comment)
Updates the comment of this element. :param comment: a list comment lines. :type comment: list(str)
pynestml.symbols.template_type_symbol module
- class pynestml.symbols.template_type_symbol.TemplateTypeSymbol(i)
Bases:
TypeSymbolFunction type templates for predefined NESTML functions. This allows e.g. functions like max() and min() to have a return type equal to the type of their arguments, regardless of what type the arguments are (integers, meters, nanosiemens…)
Template type symbols are uniquely identified with an integer number i, i.e. TemplateTypeSymbol(n) == TemplateTypeSymbol(m) iff n == m.
- is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
- print_nestml_type()
pynestml.symbols.type_symbol module
- class pynestml.symbols.type_symbol.TypeSymbol(name)
Bases:
SymbolThis class is used to represent a single type symbol which represents the type of a element, e.g., a variable. .. attribute:: is_buffer Indicates whether it is a buffer symbol.
- binary_operation_not_defined_error(_operator, _other)
- differs_only_in_magnitude(other_type)
Indicates whether both type represent the same unit but with different magnitudes. This case is still valid, e.g., mV can be assigned to volt. :param other_type: a type :type other_type: TypeSymbol :return: True if both elements equal or differ in magnitude, otherwise False. :rtype: bool
- equals(other)
Checks if the handed over type symbol object is equal to this (value-wise). :param other: a type symbol object. :type other: Symbol or subclass. :return: True if equal, otherwise False. :rtype: bool
- classmethod inverse_of_unit(other)
- Parameters:
other (UnitTypeSymbol) – the unit to invert
- Returns:
UnitTypeSymbol
- abstract is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_instance_of(_other)
wrapper around isinstance to make things more readable/intuitive. instance checks abound for all members of the TypeSymbol hierarchy, (specifically the operator functions) though i have tried to limit them to situations that would otherwise have been covered by function overloading in e.g. Java -ptraeder
- abstract is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_numeric_primitive()
Returns whether this symbol represents a primitive numeric type, i.e., real or integer. :return: True if numeric primitive, otherwise False. :rtype: bool
- abstract is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
- negate()
- abstract print_nestml_type()
- print_symbol()
Returns a string representation of this symbol. :return: a string representation. :rtype: str
- unary_operation_not_defined_error(_operator)
- warn_implicit_cast_from_to(_from, _to)
pynestml.symbols.unit_type_symbol module
- class pynestml.symbols.unit_type_symbol.UnitTypeSymbol(unit)
Bases:
TypeSymbol- add_or_sub_another_unit(other)
- property astropy_unit
- attempt_magnitude_cast(other)
- divide_by(other)
- equals(other=None)
Checks if the handed over type symbol object is equal to this (value-wise). :param other: a type symbol object. :type other: Symbol or subclass. :return: True if equal, otherwise False. :rtype: bool
- classmethod get_conversion_factor(_from, to) float | None
Calculates the conversion factor from _convertee_unit to target_unit. Behaviour is only well-defined if both units have the same physical base type.
- is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
- multiply_by(other)
- print_nestml_type()
- to_the_power_of(power)
pynestml.symbols.variable_symbol module
- class pynestml.symbols.variable_symbol.BlockType(value)
Bases:
EnumIndicates in which type of block this variable has been declared.
- COMMON_PARAMETERS = 3
- EQUATION = 5
- INPUT = 7
- INTERNALS = 4
- LOCAL = 6
- ON_RECEIVE = 10
- OUTPUT = 8
- PARAMETERS = 2
- PREDEFINED = 9
- STATE = 1
- class pynestml.symbols.variable_symbol.VariableSymbol(element_reference=None, scope: Scope | None = None, name: str | None = None, block_type: BlockType | None = None, vector_parameter: str | None = None, delay_parameter: str | None = None, declaring_expression: ASTExpression | None = None, is_predefined: bool = False, is_inline_expression: bool = False, is_recordable: bool = False, type_symbol: TypeSymbol | None = None, initial_value: ASTExpression | None = None, variable_type: VariableType | None = None, decorators=None, namespace_decorators=None, attribute: str | None = None)
Bases:
SymbolThis class is used to store a single variable symbol containing all required information.
- block_type The type of block in which this symbol has been declared. Type
BlockType
- vector_parameter The parameter indicating the position in an array. Type
str
- delay_parameter The parameter indicating the delay value for this variable. Type
str
- declaring_expression The rhs defining the value of this symbol. Type
ASTExpression
- is_predefined Indicates whether this symbol is predefined, e.g., t or e. Type
bool
- is_inline_expression Indicates whether this symbol belongs to an inline expression. Type
bool
- is_recordable Indicates whether this symbol belongs to a recordable element. Type
bool
- type_symbol The concrete type of this variable.
- ode_declaration Used to store the corresponding ode declaration.
- initial_value Indicates the initial value if such is declared.
- variable_type The type of the variable, either a buffer or function. Type
VariableType
- equals(other)
Compares the handed over object to this value-wise. :param other: the element to which this is compared to. :type other: Symbol or subclass :return: True if equal, otherwise False. :rtype: bool
- get_block_type()
Returns the block type :return: the block type :rtype: BlockType
- get_declaring_expression()
Returns the rhs declaring the value of this symbol. :return: the rhs declaring the value. :rtype: ASTExpression
- get_decorators()
Returns PyNESTMLLexer static variable codes
- get_delay_parameter()
Returns the delay value associated with this variable :return: the delay parameter
- get_initial_value()
Returns the initial value of this variable symbol if one exists. :return: the initial value rhs. :rtype: ASTSimpleExpression or ASTExpression
- get_namespace_decorator(namespace)
- get_namespace_decorators()
- get_ode_or_kernel()
Returns the ODE defining the value of this variable symbol. :return: the rhs defining the value. :rtype: ASTExpression or ASTSimpleExpression
- get_type_symbol()
Returns the corresponding type symbol. :return: the current type symbol. :rtype: type_symbol
- get_variable_type()
Returns the type of this variable. :return: the type of the variable :rtype: VariableType
- get_vector_parameter()
Returns the vector parameter of this symbol if any available, e.g., spike[12] :return: the vector parameter of this variable symbol. :rtype: str
- has_declaring_expression() bool
Indicates whether a declaring rhs is present. :return: True if present, otherwise False.
- has_decorators()
- has_delay_parameter()
Returns whether this variable has a delay value associated with it. :return: bool
- has_initial_value()
Returns whether this variable symbol has an initial value or not. :return: True if has initial value, otherwise False. :rtype: bool
- has_vector_parameter()
Returns whether this variable symbol has a vector parameter. :return: True if vector parameter available, otherwise False. :rtype: bool
- is_buffer() bool
Returns whether this variable symbol represents a buffer or not. :return: True if buffer, otherwise False.
- is_continuous_input_port() bool
Returns whether this symbol represents a continuous time input port. :return: True if continuous time input port, otherwise False.
- is_equation() bool
Returns whether this variable symbol has been declared in a equation block. :return: True if declared in a equation block, otherwise False. :rtype: bool
- is_homogeneous()
- is_input() bool
Returns whether this variable symbol has been declared as an input port. :return: True if input port, otherwise False.
- is_internals() bool
Returns whether this variable symbol has been declared in a internals block. :return: True if declared in a internals block, otherwise False. :rtype: bool
- is_kernel() bool
Returns whether this variable belongs to the definition of a kernel. :return: True if part of a kernel definition, otherwise False.
- is_local() bool
Returns whether this variable symbol has been declared in a local (e.g., update) block. :return: True if declared in a local block, otherwise False. :rtype: bool
- is_ode_defined()
Returns whether this element is defined by a ode. :return: True if ode defined, otherwise False. :rtype: bool
- is_output() bool
Returns whether this variable symbol has been declared as output block element. :return: True if output element, otherwise False.
- is_parameters() bool
Returns whether this variable symbol has been declared in a parameters block. :return: True if declared in a parameters block, otherwise False. :rtype: bool
- is_spike_input_port() bool
Returns whether this symbol represents a spike input port. :return: True if spike input port, otherwise False.
- is_state() bool
Returns whether this variable symbol has been declared in a state block. :return: True if declared in a state block, otherwise False.
- print_symbol()
Returns a string representation of this symbol.
- set_delay_parameter(delay)
Sets the delay value for this variable
- set_initial_value(value)
Updates the initial value of this variable. :param value: a new initial value. :type value: ASTExpression or ASTSimpleExpression
- set_ode_or_kernel(expression)
Updates the currently stored ode-definition to the handed-over one. :param expression: a single rhs object. :type expression: ASTExpression
- set_type_symbol(type_symbol)
Updates the current type symbol to a new one. :param type_symbol: a new type symbol. :type type_symbol: type_symbol
- set_variable_type(v_type)
Updates the v_type of this variable symbol. :return: a single variable v_type :rtype: VariableType
pynestml.symbols.variadic_type_symbol module
- class pynestml.symbols.variadic_type_symbol.VariadicTypeSymbol
Bases:
TypeSymbolVariadic type symbol for a variadic parameters list (variable-length list of parameters).
- is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
- print_nestml_type()
pynestml.symbols.void_type_symbol module
- class pynestml.symbols.void_type_symbol.VoidTypeSymbol
Bases:
TypeSymbol- is_castable_to(_other_type)
Test castability of this SymbolType to _other_type.
The implementation of this function in TypeSymbol takes care of casting to `TemplateTypeSymbol`s, hence, any children that override this function need to always call the parent implementation, before doing their own castability checks. :return: True if castable, otherwise False :rtype: bool
- is_numeric()
Returns whether this symbol represents a numeric type. :return: True if numeric, otherwise False. :rtype: bool
- is_primitive()
Returns whether this symbol represents a primitive type. :return: true if primitive, otherwise false. :rtype: bool
- print_nestml_type()