JohannesBuchner / UltraNest

Fit and compare complex models reliably and rapidly. Advanced nested sampling.
https://johannesbuchner.github.io/UltraNest/
Other
142 stars 30 forks source link

Added NumpyEncoder to json.dump #136

Closed LucaMantani closed 3 months ago

LucaMantani commented 3 months ago

This PR adds a numpy encoder to the json.dump of the results, addressing the issue highlighted in the 1st comment of #135 . In particular, it now allows to run with float32 precision which is the default in JAX and often a preferred option on GPUs when speed and efficiency are relevant.

JohannesBuchner commented 3 months ago

Please add a unit test for this new code, ideally handling all kinds of types.

LucaMantani commented 3 months ago

Please add a unit test for this new code, ideally handling all kinds of types.

I added a test for the encoder checking int32, float32, np.arrays and the case of a non-numpy type, would you add more tests?

JohannesBuchner commented 3 months ago

verifying that it can be used with json.dump successfully would be worth adding. Maybe check the resulting json string for one or two simple cases.

JohannesBuchner commented 3 months ago

json.dumps should be enough actually...

LucaMantani commented 3 months ago

json.dumps should be enough actually...

Yes I implemented it with that.

JohannesBuchner commented 3 months ago

I'll close this for now, but we can reopen it later. To avoid increased code maintenance, I'd prefer to ingest this code only if there is a strong need.