openmc icon indicating copy to clipboard operation
openmc copied to clipboard

Allow int-like floats for particles

Open MicahGale opened this issue 1 year ago • 5 comments

Description

model.settings.particles is quite often set to be large numbers that >=1e6. This makes it very annoying and error prone to specify as ints, since python treats all scientific notation as a float.

I propose that:

model.settings.particles = 1e6 be allowed but model.seetings.particles = 1.23e1 not be allowed as it not close to an integer value.

Alternatives

Teach users to use 10_000_000 notation. This isn't ideal as it relies on users being aware of certain features and not making mistakes.

Compatibility

This should have little impact on the user facing API, but will impact the test suite.

MicahGale avatar Apr 03 '24 18:04 MicahGale

Why not just have people use int(1e6)?

gridley avatar Apr 15 '24 18:04 gridley

That is a viable alternative too but is very annoying IMO and I don't think an apparent solution to the average novice.

MicahGale avatar Apr 15 '24 19:04 MicahGale

Would this change also cover the xmls? IIRC, in the xmls they also only accept integers and it is super annoying. Would definitely rather scientific

yrrepy avatar May 08 '24 16:05 yrrepy

I have thought about that. I think I would like to implement that, but that would be a much larger scope of revising XML schema and updating the parsers. I'm not sure if that should be a whole separate issue to discuss or not.

MicahGale avatar May 08 '24 19:05 MicahGale

I understand the motivation here but I would not personally be in favor of this change. The main problem to me is -- what about every other input in the API that is an integer? Should we allow those to take floats that are rounded to the nearest integer? To do so would be overkill, but to not do so would then be inconsistent. Writing either int(1e6) or 1_000_000 is very simple for a user and doesn't require us to overhaul the API or our XML format.

paulromano avatar May 09 '24 02:05 paulromano

You're right that this would need to be uniform. This could be implemented universally. However, after thinking about it more and more this wouldn't be pythonic to implement.

MicahGale avatar May 21 '24 19:05 MicahGale