Skip to content

Commit

Permalink
suppress warning and stdout messages in Jupyter notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
C.A.P. Linssen committed Jan 22, 2025
1 parent 10f721a commit 823ce08
Show file tree
Hide file tree
Showing 14 changed files with 1,469 additions and 18,327 deletions.
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
6 changes: 6 additions & 0 deletions pynestml/codegeneration/nest_code_generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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 +133,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

0 comments on commit 823ce08

Please sign in to comment.