Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress warning and stdout messages in Jupyter notebooks #1161

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 87 additions & 170 deletions doc/tutorials/active_dendrite/nestml_active_dendrite_tutorial.ipynb

Large diffs are not rendered by default.

219 changes: 33 additions & 186 deletions doc/tutorials/inhomogeneous_poisson/inhomogeneous_poisson.ipynb

Large diffs are not rendered by default.

129 changes: 13 additions & 116 deletions doc/tutorials/izhikevich/nestml_izhikevich_tutorial.ipynb

Large diffs are not rendered by default.

213 changes: 32 additions & 181 deletions doc/tutorials/ornstein_uhlenbeck_noise/nestml_ou_noise_tutorial.ipynb

Large diffs are not rendered by default.

329 changes: 74 additions & 255 deletions doc/tutorials/sequence_learning/sequence_learning.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

5,843 changes: 180 additions & 5,663 deletions doc/tutorials/stdp_dopa_synapse/stdp_dopa_synapse.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6,165 changes: 329 additions & 5,836 deletions doc/tutorials/stdp_windows/stdp_windows.ipynb

Large diffs are not rendered by default.

2,757 changes: 193 additions & 2,564 deletions doc/tutorials/triplet_stdp_synapse/triplet_stdp_synapse.ipynb

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions pynestml/codegeneration/nest_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,15 +923,14 @@ def ode_toolbox_analysis(self, neuron: ASTModel, kernel_buffers: Mapping[ASTKern

return analytic_solver, numeric_solver

def update_symbol_table(self, neuron) -> None:
def update_symbol_table(self, model) -> None:
"""
Update symbol table and scope.
"""
SymbolTable.delete_model_scope(neuron.get_name())
SymbolTable.delete_model_scope(model.get_name())
symbol_table_visitor = ASTSymbolTableVisitor()
neuron.accept(symbol_table_visitor)
CoCosManager.check_cocos(neuron, after_ast_rewrite=True)
SymbolTable.add_model_scope(neuron.get_name(), neuron.get_scope())
model.accept(symbol_table_visitor)
SymbolTable.add_model_scope(model.get_name(), model.get_scope())

def get_spike_update_expressions(self, neuron: ASTModel, kernel_buffers, solver_dicts, delta_factors) -> Tuple[Dict[str, ASTAssignment], Dict[str, ASTAssignment]]:
r"""
Expand Down
9 changes: 8 additions & 1 deletion pynestml/codegeneration/nest_code_generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
import re
import tempfile
import uuid
from pynestml.meta_model.ast_node import ASTNode

from pynestml.meta_model.ast_node import ASTNode
from pynestml.meta_model.ast_variable import ASTVariable
from pynestml.symbols.symbol import SymbolKind
from pynestml.symbols.variable_symbol import BlockType
from pynestml.symbols.variable_symbol import VariableSymbol
from pynestml.visitors.ast_visitor import ASTVisitor
from pynestml.utils.logger import Logger


class NESTCodeGeneratorUtils:
Expand Down Expand Up @@ -82,6 +83,9 @@ def generate_code_for(cls,
"""
from pynestml.frontend.pynestml_frontend import generate_nest_target

# convert string to level to check correct formatting
Logger.string_to_level(logging_level)

# generate temporary install directory
install_path = tempfile.mkdtemp(prefix="nestml_target_")

Expand Down Expand Up @@ -130,6 +134,9 @@ def generate_code_for(cls,
if codegen_opts:
_codegen_opts.update(codegen_opts)

if logging_level.upper() != "DEBUG":
_codegen_opts["redirect_build_output"] = True # hide stdout and stderr if not in DEBUG log level

if not module_name:
# generate unique ID
uniq_id = str(uuid.uuid4().hex)
Expand Down
9 changes: 7 additions & 2 deletions pynestml/utils/ast_source_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,12 @@ def get_end_column(self):
"""
return self.end_column

def equals(self, source_position):
def equals(self, source_position) -> bool:
"""
Checks if the handed over position is equal to this.
:param source_position: a source position.
:type source_position: ASTSourceLocation
:return: True if equal, otherwise False.
:rtype: bool
"""
if not isinstance(source_position, ASTSourceLocation):
return False
Expand All @@ -112,6 +111,12 @@ def equals(self, source_position):
and self.get_end_line() == source_position.get_end_line()
and self.get_end_column() == source_position.get_end_column())

def __eq__(self, other) -> bool:
return self.equals(other)

def __hash__(self) -> int:
return hash((self.get_start_line(), self.get_start_column(), self.get_end_line(), self.get_end_column()))

def before(self, source_position):
"""
Checks if the handed over position is smaller than this.
Expand Down
14 changes: 9 additions & 5 deletions pynestml/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def set_log(cls, log, counter):
cls.curr_message = counter

@classmethod
def log_message(cls, node: ASTNode = None, code: MessageCode = None, message: str = None, error_position: ASTSourceLocation = None, log_level: LoggingLevel = None):
def log_message(cls, node: ASTNode = None, code: MessageCode = None, message: str = None, error_position: ASTSourceLocation = None, log_level: LoggingLevel = None, allow_duplicates: bool = False):
"""
Logs the handed over message on the handed over node. If the current logging is appropriate, the message is also printed.

Expand All @@ -121,6 +121,7 @@ def log_message(cls, node: ASTNode = None, code: MessageCode = None, message: st
:param error_position: the position on which the error occurred.
:param message: a message.
:param log_level: the corresponding log level.
:param allow_duplicates: whether to ignore or suppress duplicate messages.
"""
if cls.log_frozen:
return
Expand All @@ -137,16 +138,19 @@ def log_message(cls, node: ASTNode = None, code: MessageCode = None, message: st
from pynestml.meta_model.ast_model import ASTModel

if isinstance(node, ASTModel):
cls.log[cls.curr_message] = (
node.get_artifact_name(), node, log_level, code, error_position, message)
new_log_entry = (node.get_artifact_name(), node, log_level, code, error_position, message)
else:
if cls.current_node is not None:
artifact_name = cls.current_node.get_artifact_name()
else:
artifact_name = ""

cls.log[cls.curr_message] = (artifact_name, cls.current_node,
log_level, code, error_position, message)
new_log_entry = (artifact_name, cls.current_node, log_level, code, error_position, message)

if not allow_duplicates and new_log_entry in cls.log.values():
return

cls.log[cls.curr_message] = new_log_entry

cls.curr_message += 1
if cls.no_print:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cocos.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_valid_numerator_of_unit_one(self):

def test_invalid_names_of_neurons_unique(self):
model = self._parse_and_validate_model(os.path.join(os.path.realpath(os.path.join(os.path.dirname(__file__), 'invalid')), 'CoCoMultipleNeuronsWithEqualName.nestml'))
assert len(Logger.get_all_messages_of_level_and_or_node(model, LoggingLevel.ERROR)) == 3
assert len(Logger.get_all_messages_of_level_and_or_node(model, LoggingLevel.ERROR)) == 2

def test_valid_names_of_neurons_unique(self):
self._parse_and_validate_model(os.path.join(os.path.realpath(os.path.join(os.path.dirname(__file__), 'valid')), 'CoCoMultipleNeuronsWithEqualName.nestml'))
Expand Down
Loading