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

Table writer errors when writing values equal to zero #1625

Closed
tcmoore3 opened this issue Sep 23, 2023 · 0 comments · Fixed by #1627
Closed

Table writer errors when writing values equal to zero #1625

tcmoore3 opened this issue Sep 23, 2023 · 0 comments · Fixed by #1627
Labels
bug Something isn't working

Comments

@tcmoore3
Copy link
Member

Description

The recent fixes to the table writer for small values leads to a domain error when trying to write 0 because of the log10 call in the _digits_from_decimal function.

Script

import hoomd
from io import StringIO

logger = hoomd.logging.Logger(categories=['scalar'])
logger[('zero',)] = (lambda: 0.0, 'scalar')
table_writer = hoomd.write.Table(1, logger, StringIO(""))
sim = hoomd.util.make_example_simulation()
sim.operations.add(table_writer)
sim.run(1)

Input files

No response

Output

Traceback (most recent call last):
  File "/Users/mtimc/sandbox/test-table.py", line 9, in <module>
    sim.run(1)
  File "/Users/mtimc/mambaforge/lib/python3.10/site-packages/hoomd/simulation.py", line 562, in run
    self._cpp_sys.run(steps_int, write_at_start)
  File "/Users/mtimc/mambaforge/lib/python3.10/site-packages/hoomd/write/table.py", line 317, in act
    self._write_row(output_dict)
  File "/Users/mtimc/mambaforge/lib/python3.10/site-packages/hoomd/write/table.py", line 296, in _write_row
    self.delimiter.join(
  File "/Users/mtimc/mambaforge/lib/python3.10/site-packages/hoomd/write/table.py", line 297, in <genexpr>
    (self._fmt(data[k], headers[k]) for k in headers)))
  File "/Users/mtimc/mambaforge/lib/python3.10/site-packages/hoomd/write/table.py", line 97, in __call__
    return self.format_num(value, column_width)
  File "/Users/mtimc/mambaforge/lib/python3.10/site-packages/hoomd/write/table.py", line 122, in format_num
    min_len_repr = self._digits_from_decimal(value) + 1
  File "/Users/mtimc/mambaforge/lib/python3.10/site-packages/hoomd/write/table.py", line 102, in _digits_from_decimal
    digits = int(log10(abs(num)))
ValueError: math domain error

Expected output

No errors.

Platform

CPU, macOS

Installation method

Conda package

HOOMD-blue version

4.2.0

Python version

3.10.12

@tcmoore3 tcmoore3 added the bug Something isn't working label Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant