本文整理汇总了Python中pynestml.utils.logger.Logger类的典型用法代码示例。如果您正苦于以下问题:Python Logger类的具体用法?Python Logger怎么用?Python Logger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: binary_operation_not_defined_error
def binary_operation_not_defined_error(self, _operator, _other):
from pynestml.symbols.error_type_symbol import ErrorTypeSymbol
result = ErrorTypeSymbol()
code, message = Messages.get_binary_operation_not_defined(lhs=self, operator=_operator, rhs=_other)
Logger.log_message(code=code, message=message, error_position=self.referenced_object.get_source_position(),
log_level=LoggingLevel.ERROR)
return result
示例2: is_vectorized_assignment
def is_vectorized_assignment(cls, assignment):
"""
Indicates whether the handed over assignment is vectorized, i.e., an assignment of vectors.
:param assignment: a single assignment.
:type assignment: ASTAssignment
:return: True if vectorized, otherwise False.
:rtype: bool
"""
from pynestml.symbols.symbol import SymbolKind
assert isinstance(assignment, ASTAssignment), \
'(PyNestML.CodeGeneration.Assignments) No or wrong type of assignment provided (%s)!' % type(assignment)
symbol = assignment.get_scope().resolve_to_symbol(assignment.get_variable().get_complete_name(),
SymbolKind.VARIABLE)
if symbol is not None:
if symbol.has_vector_parameter():
return True
else:
# otherwise we have to check if one of the variables used in the rhs is a vector
for var in assignment.get_expression().get_variables():
symbol = var.get_scope().resolve_to_symbol(var.get_complete_name(), SymbolKind.VARIABLE)
if symbol is not None and symbol.has_vector_parameter():
return True
return False
else:
Logger.log_message(message='No symbol could be resolved!', log_level=LoggingLevel.ERROR)
return False
示例3: check_co_co
def check_co_co(cls, _neuron=None):
"""
Checks the coco for the handed over neuron.
:param _neuron: a single neuron instance.
:type _neuron: ASTNeuron
"""
assert (_neuron is not None and isinstance(_neuron, ASTNeuron)), \
'(PyNestML.CoCo.FunctionCallsConsistent) No or wrong type of neuron provided (%s)!' % type(_neuron)
cls.__neuronName = _neuron.get_name()
for userDefinedFunction in _neuron.get_functions():
cls.processed_function = userDefinedFunction
symbol = userDefinedFunction.get_scope().resolve_to_symbol(userDefinedFunction.get_name(),
SymbolKind.FUNCTION)
# first ensure that the block contains at least one statement
if symbol is not None and len(userDefinedFunction.get_block().get_stmts()) > 0:
# now check that the last statement is a return
cls.__check_return_recursively(symbol.get_return_type(),
userDefinedFunction.get_block().get_stmts(), False)
# now if it does not have a statement, but uses a return type, it is an error
elif symbol is not None and userDefinedFunction.has_return_type() and \
not symbol.get_return_type().equals(PredefinedTypes.get_void_type()):
code, message = Messages.get_no_return()
Logger.log_message(neuron=_neuron, code=code, message=message,
error_position=userDefinedFunction.get_source_position(),
log_level=LoggingLevel.ERROR)
return
示例4: endvisit_assignment
def endvisit_assignment(self, node):
scope = node.get_scope()
var_name = node.get_variable().get_name()
_expr = node.get_expression()
var_symbol = scope.resolve_to_symbol(var_name, SymbolKind.VARIABLE)
_equals = var_symbol.get_type_symbol().equals(_expr.type)
message = 'line ' + str(_expr.get_source_position()) + ' : LHS = ' + \
var_symbol.get_type_symbol().get_symbol_name() + \
' RHS = ' + _expr.type.get_symbol_name() + \
' Equal ? ' + str(_equals)
if isinstance(_expr.type, UnitTypeSymbol):
message += " Neuroscience Factor: " + \
str(UnitConverter().get_factor(_expr.type.astropy_unit))
Logger.log_message(error_position=node.get_source_position(), code=MessageCode.TYPE_MISMATCH,
message=message, log_level=LoggingLevel.INFO)
if _equals is False:
Logger.log_message(message="Type mismatch in test!",
code=MessageCode.TYPE_MISMATCH,
error_position=node.get_source_position(),
log_level=LoggingLevel.ERROR)
return
示例5: visit_assignment
def visit_assignment(self, node):
symbol = node.get_scope().resolve_to_symbol(node.get_variable().get_complete_name(),
SymbolKind.VARIABLE)
if symbol is None:
code, message = Messages.get_variable_not_defined(node.get_variable().get_complete_name())
Logger.log_message(code=code, message=message, error_position=node.get_source_position(),
log_level=LoggingLevel.ERROR, neuron=self.neuron)
示例6: visit_simple_expression
def visit_simple_expression(self, node):
"""
Visits a single variable as contained in a simple expression and derives its type.
:param node: a single simple expression
:type node: ASTSimpleExpression
"""
assert isinstance(node, ASTSimpleExpression), \
'(PyNestML.Visitor.VariableVisitor) No or wrong type of simple expression provided (%s)!' % type(node)
assert (node.get_scope() is not None), \
'(PyNestML.Visitor.VariableVisitor) No scope found, run symboltable creator!'
scope = node.get_scope()
var_name = node.get_variable().get_name()
var_resolve = scope.resolve_to_symbol(var_name, SymbolKind.VARIABLE)
# update the type of the variable according to its symbol type.
if var_resolve is not None:
node.type = var_resolve.get_type_symbol()
node.type.referenced_object = node
else:
# check if var_name is actually a type literal (e.g. "mV")
var_resolve = scope.resolve_to_symbol(var_name, SymbolKind.TYPE)
if var_resolve is not None:
node.type = var_resolve
node.type.referenced_object = node
else:
message = 'Variable ' + str(node) + ' could not be resolved!'
Logger.log_message(code=MessageCode.SYMBOL_NOT_RESOLVED,
error_position=node.get_source_position(),
message=message, log_level=LoggingLevel.ERROR)
node.type = ErrorTypeSymbol()
return
示例7: visit_expression
def visit_expression(self, node):
"""
Visits an expression which uses a binary logic operator and updates the type.
:param node: a single expression.
:type node: ast_expression
"""
lhs_type = node.get_lhs().type
rhs_type = node.get_rhs().type
lhs_type.referenced_object = node.get_lhs()
rhs_type.referenced_object = node.get_rhs()
if isinstance(lhs_type, BooleanTypeSymbol) and isinstance(rhs_type, BooleanTypeSymbol):
node.type = PredefinedTypes.get_boolean_type()
else:
if isinstance(lhs_type, BooleanTypeSymbol):
offending_type = lhs_type
else:
offending_type = rhs_type
code, message = Messages.get_type_different_from_expected(BooleanTypeSymbol(), offending_type)
Logger.log_message(code=code, message=message,
error_position=lhs_type.referenced_object.get_source_position(),
log_level=LoggingLevel.ERROR)
node.type = ErrorTypeSymbol()
return
示例8: generate_module_code
def generate_module_code(self, neurons):
# type: (list(ASTNeuron)) -> None
"""
Generates code that is necessary to integrate neuron models into the NEST infrastructure.
:param neurons: a list of neurons
:type neurons: list(ASTNeuron)
"""
namespace = {'neurons': neurons,
'moduleName': FrontendConfiguration.get_module_name(),
'now': datetime.datetime.utcnow()}
if not os.path.exists(FrontendConfiguration.get_target_path()):
os.makedirs(FrontendConfiguration.get_target_path())
with open(str(os.path.join(FrontendConfiguration.get_target_path(),
FrontendConfiguration.get_module_name())) + '.h', 'w+') as f:
f.write(str(self._template_module_header.render(namespace)))
with open(str(os.path.join(FrontendConfiguration.get_target_path(),
FrontendConfiguration.get_module_name())) + '.cpp', 'w+') as f:
f.write(str(self._template_module_class.render(namespace)))
with open(str(os.path.join(FrontendConfiguration.get_target_path(),
'CMakeLists')) + '.txt', 'w+') as f:
f.write(str(self._template_cmakelists.render(namespace)))
if not os.path.isdir(os.path.realpath(os.path.join(FrontendConfiguration.get_target_path(), 'sli'))):
os.makedirs(os.path.realpath(os.path.join(FrontendConfiguration.get_target_path(), 'sli')))
with open(str(os.path.join(FrontendConfiguration.get_target_path(), 'sli',
FrontendConfiguration.get_module_name() + "-init")) + '.sli', 'w+') as f:
f.write(str(self._template_sli_init.render(namespace)))
code, message = Messages.get_module_generated(FrontendConfiguration.get_target_path())
Logger.log_message(None, code, message, None, LoggingLevel.INFO)
示例9: analyse_neuron
def analyse_neuron(self, neuron):
# type: (ASTNeuron) -> None
"""
Analyse and transform a single neuron.
:param neuron: a single neuron.
"""
code, message = Messages.get_start_processing_neuron(neuron.get_name())
Logger.log_message(neuron, code, message, neuron.get_source_position(), LoggingLevel.INFO)
# make normalization
# apply spikes to buffers
# get rid of convolve, store them and apply then at the end
equations_block = neuron.get_equations_block()
shape_to_buffers = {}
if neuron.get_equations_block() is not None:
# extract function names and corresponding incoming buffers
convolve_calls = OdeTransformer.get_sum_function_calls(equations_block)
for convolve in convolve_calls:
shape_to_buffers[str(convolve.get_args()[0])] = str(convolve.get_args()[1])
OdeTransformer.refactor_convolve_call(neuron.get_equations_block())
self.make_functions_self_contained(equations_block.get_ode_functions())
self.replace_functions_through_defining_expressions(equations_block.get_ode_equations(),
equations_block.get_ode_functions())
# transform everything into gsl processable (e.g. no functional shapes) or exact form.
self.transform_shapes_and_odes(neuron, shape_to_buffers)
self.apply_spikes_from_buffers(neuron, shape_to_buffers)
# update the symbol table
symbol_table_visitor = ASTSymbolTableVisitor()
symbol_table_visitor.after_ast_rewrite_ = True # ODE block might have been removed entirely: suppress warnings
neuron.accept(symbol_table_visitor)
示例10: visit_variable
def visit_variable(self, node):
"""
Visits each shape and checks if it is used correctly.
:param node: a single node.
:type node: AST_
"""
for shapeName in self.__shapes:
# in order to allow shadowing by local scopes, we first check if the element has been declared locally
symbol = node.get_scope().resolve_to_symbol(shapeName, SymbolKind.VARIABLE)
# if it is not a shape just continue
if symbol is None:
code, message = Messages.get_no_variable_found(shapeName)
Logger.log_message(neuron=self.__neuron_node, code=code, message=message, log_level=LoggingLevel.ERROR)
continue
if not symbol.is_shape():
continue
if node.get_complete_name() == shapeName:
parent = self.__neuron_node.get_parent(node)
if parent is not None:
if isinstance(parent, ASTOdeShape):
continue
grandparent = self.__neuron_node.get_parent(parent)
if grandparent is not None and isinstance(grandparent, ASTFunctionCall):
grandparent_func_name = grandparent.get_name()
if grandparent_func_name == 'curr_sum' or grandparent_func_name == 'cond_sum' or \
grandparent_func_name == 'convolve':
continue
code, message = Messages.get_shape_outside_convolve(shapeName)
Logger.log_message(error_position=node.get_source_position(),
code=code, message=message,
log_level=LoggingLevel.ERROR)
return
示例11: visit_neuron
def visit_neuron(self, node):
"""
Private method: Used to visit a single neuron and create the corresponding global as well as local scopes.
:return: a single neuron.
:rtype: ast_neuron
"""
# set current processed neuron
Logger.set_current_neuron(node)
code, message = Messages.get_start_building_symbol_table()
Logger.log_message(neuron=node, code=code, error_position=node.get_source_position(),
message=message, log_level=LoggingLevel.INFO)
# before starting the work on the neuron, make everything which was implicit explicit
# but if we have a model without an equations block, just skip this step
if node.get_equations_blocks() is not None:
make_implicit_odes_explicit(node.get_equations_blocks())
scope = Scope(scope_type=ScopeType.GLOBAL, source_position=node.get_source_position())
node.update_scope(scope)
node.get_body().update_scope(scope)
# now first, we add all predefined elements to the scope
variables = PredefinedVariables.get_variables()
functions = PredefinedFunctions.get_function_symbols()
types = PredefinedTypes.get_types()
for symbol in variables.keys():
node.get_scope().add_symbol(variables[symbol])
for symbol in functions.keys():
node.get_scope().add_symbol(functions[symbol])
for symbol in types.keys():
node.get_scope().add_symbol(types[symbol])
示例12: test
def test(self):
# Todo: this test is not yet complete, @ptraeder complete it
Logger.init_logger(LoggingLevel.INFO)
model = ModelParser.parse_model(
os.path.join(os.path.realpath(os.path.join(os.path.dirname(__file__),
'resources', 'MagnitudeCompatibilityTest.nestml'))))
# Logger.setCurrentNeuron(model.getNeuronList()[0])
ExpressionTestVisitor().handle(model)
示例13: visit_assignment
def visit_assignment(self, node):
symbol = node.get_scope().resolve_to_symbol(node.get_variable().get_name(), SymbolKind.VARIABLE)
if symbol is not None and (symbol.block_type == BlockType.INPUT_BUFFER_SPIKE or
symbol.block_type == BlockType.INPUT_BUFFER_CURRENT):
code, message = Messages.get_value_assigned_to_buffer(node.get_variable().get_complete_name())
Logger.log_message(code=code, message=message,
error_position=node.get_source_position(),
log_level=LoggingLevel.ERROR)
return
示例14: visit_ode_equation
def visit_ode_equation(self, node):
"""
Checks the coco.
:param node: A single ode equation.
:type node: ast_ode_equation
"""
if node.get_lhs().get_differential_order() == 0:
code, message = Messages.get_order_not_declared(node.get_lhs().get_name())
Logger.log_message(error_position=node.get_source_position(), code=code,
message=message, log_level=LoggingLevel.ERROR)
示例15: setUp
def setUp(self):
PredefinedUnits.register_units()
PredefinedTypes.register_types()
PredefinedFunctions.register_functions()
PredefinedVariables.register_variables()
SymbolTable.initialize_symbol_table(ASTSourceLocation(start_line=0, start_column=0, end_line=0, end_column=0))
Logger.init_logger(LoggingLevel.INFO)
self.target_path = str(os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.join(
os.pardir, 'target'))))