dwavesystems / dwavesystems/dwave-optimization

Consider adding a debug mode

Open
#415 0 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
31
Forks
36
Avg merge
16h 55m
Merged PRs (30d)
8

Description

Currently, as I am debugging/developing a model I find myself using a lot of print statements using functions like the below:
```python
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```)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.