Add ability to suppress progress print statements during model run

Issue #1 new
Tue Jensen created an issue

The following function calls have "mandatory" print statements:

  • scheduler.sim_process ('Progress: %.2f%%')
  • scenario.World.start

The first of these is of particular importance when using mosaik in a Jupyter notebook, since all print statements are saved in the .ipynb file. When running long models or looping over many model runs, the amount of print statements saved can be in excess of 500 000, which causes the notebook to fail due to http transfer limits.

As a workaround, the user can redirect stdout using

sys.stdout = open(os.devnull, 'w')

sys.stdout = sys.__stdout__

but a better solution would be to be able to suppress the output directly in the call to

Therefore I propose to add an option to suppress these statements. I see two possible options here:

  1. Define a 'printing level' through the mosaik configuration
  2. Add an optional parameter to the function call which blocks all print statements (e.g. verbose=True)
  3. Add an optional parameter to the function call which blocks only the "progress" print statement (e.g. print_progress=True)

I would personally prefer option 3 to make it more apparent to the user that the option exists, while still reporting on scenario setup information.

Comments (5)

  1. André El-Ama

    We intend to carry out this adjustment in the next release, but at the latest when we add a logging component to mosaic. For now I suggest to use capture:

        %%capture --no-stderr

    in IPython / jupyter which suppresses any output on stdout but prints stderr to be on the safe side. Only with


    everything is suppressed from output. If you are interested in the outputs write them into a file

    %%capture cap --no-stderr
    print("Your outputs like:")
    scheduler.sim_process ('Progress: %.2f%%')
    with open('output.txt', 'w') as f:

    which doesn't violate your http transfer limits.

  2. Log in to comment