Skip to content

Consider adding a debug mode #415

@p-ortmann

Description

@p-ortmann

Currently, as I am debugging/developing a model I find myself using a lot of print statements using functions like the below:

def model_print(
    model: Model, var: ArraySymbol, name: str
) -> None:
    """Utility function for debugging."""
    model.lock()
    model.states.resize(1)
    print(name, var.state())
    model.unlock()

which I then remove once I am done developing/debugging.
To better support modern debuggers and avoid the workaround above it would be great if we had more meaningful __repr__ for the symbols. However, I understand that locking is slow so we probably should not by default incorporate that into the __repr__.

My request is to support a debug mode that can be enabled with an environment variable. If debug mode is enabled the __repr__ should produce both variable names and whichever state is at index 0. If no state exists, it should initialize and return the default state.

This is similar to a feature that numba has, where JIT compilation can be disabled completely to enable the use of the debugger, see https://numba.readthedocs.io/en/stable/reference/envvars.html?highlight=environment+variables (NUMBA_DISABLE_JIT)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions