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

ArbNumerics.jl vs. JLD2.jl #69

Closed
dfriedan opened this issue May 28, 2024 · 5 comments
Closed

ArbNumerics.jl vs. JLD2.jl #69

dfriedan opened this issue May 28, 2024 · 5 comments

Comments

@dfriedan
Copy link

ArbNumerics.jl and JLD2.jl seem to be incompatible.

(My first time using github. Sorry for any formatting glitches.)

example (in JupyterLab with kernel Julia v"1.10.2")

in Notebook 'save'
using JLD2
using ArbNumerics
x = ArbFloat("1.1")
@save("file.jld2", x)

in Notebook 'load'
using JLD2
using ArbNumerics
@load("file.jld2", x)
x

0.0005682636956492356473207022587786823202077626484829105

The value of x reported in the 'load' notebook is not consistent. It changes from run to run. Sometimes, the Julia kernel bombs instead of showing a value for x. The bug does not seem to appear for x=ArbFloat(1), or x=ArbFloat(0), but only when the argument of ArbFloat() is a string.

Daniel Friedan
New High Energy Theory Center
and Department of Physics & Astronomy
Rutgers University

@JeffreySarnoff
Copy link
Owner

Thank you for the report and welcome to github.
Using Julia v10.2 directly (in the "REPL", not in a notebook) this does not occur.

using ArbNumerics, JLD2

x = ArbFloat("1.1")
@save("file.jld2", x)
@load("file.jld2", x)
x # 1.1

I have no information about the notebook application.
Please try this (in the notebook). Let me know what happens.

using ArbNumerics, JLD2

x = ArbFloat(BigFloat("1.1"))
@save("file.jld2", x)
@load("file.jld2", x)
x

FYI x = ArbFloat(1.1) Julia first converts 1.1 to a Float64 (C double) and only then calls ArbFloat, so there is much less precision doing it that way.

@dfriedan
Copy link
Author

dfriedan commented May 28, 2024 via email

@JeffreySarnoff
Copy link
Owner

As long as you have a way that works with the notebook, stay with the notebook. It is a good solution. And no, saving state in the "REPL" for another time is more involved .. although you can use JLD2 just like in the notebook. I will implement the use of BigFloat as an intermediary when converting strings to ArbFloat. Thanks again!
[If you need additional help with Julia, let me know]

@KlausC
Copy link
Collaborator

KlausC commented May 28, 2024

I fear, there is no support for serializing the Arb floating point objects in the current version.

ArbNumerics.jl doesn't support serialization/deserialization. The contained fields are of type Int or UInt , but sometimes are used to encode pointers to data areas, which lose their meanings in other processes (if you serialize to a file and try to deserialize in another session).
That means, if you store a value, which uses a pointer to a memory area, but which is disguised as a UInt64, this integer value is stored. When later read in a different process, this integer value is reproduced, but its interpretation as a pointer has no sensible meaning: it points to a random memory area or leads to a segmentation violation, as was observed by the OP.
It would be necessary to support explicitly the serialization/deserialization process of JLD2 in ArbNumerics to overcome this behavior. The same is true for all other serialization packages.

@dfriedan
Copy link
Author

dfriedan commented May 28, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants