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

Switching from .dat file writing to pickling #172

Open
ricalessandri opened this issue Jul 28, 2022 · 8 comments
Open

Switching from .dat file writing to pickling #172

ricalessandri opened this issue Jul 28, 2022 · 8 comments
Assignees

Comments

@ricalessandri
Copy link
Member

Writing the results in a .dat file is one way of doing this.
I think the more python way of doing it, would be to pickle the results.
But either is fine.

Originally posted by @InnocentBug in #171 (comment)

e.g.

# write free energy to file
dih_vs_A = np.stack([mesh[:, 0], A[:, 0]], axis=1)
np.savetxt("butane-fe.dat", dih_vs_A, header='"dih" "Free energy"')

@ricalessandri
Copy link
Member Author

ricalessandri commented Oct 18, 2022

May be a basic question but ... shouldn't this just be:

    import pickle

    ...
    # Analysis: Calculate free energy
    result = pysages.analyze(run_result)
    fes_fn = result["fes_fn"]

    # Pickle
    pickle.dump( result, open("result.pickle", "wb") )
    ...

?

I'm getting:

  File "adp_SpectralABF.py", line 133, in main
    pickle.dump( result, open("result.pickle", "wb") )
AttributeError: Can't pickle local object 'analyze.<locals>.build_fes_fn.<locals>.<lambda>'

@InnocentBug
Copy link
Member

Hmm, too bad.
that is a function it can’t pickle.
we probably have to rework this a bit.
Wither return data instead of a function.
or make it a pickable functor

@pabloferz
Copy link
Member

I believe that what we have guaranteed so far to be pickeable are the raw Results and not the analysis results. This might not be ideal, but performing analysis is generally cheap compared to running whole biased simulations, Of course, we might want to improve upon that in the future, but so far it should give us something reasonable to work with.

@ricalessandri
Copy link
Member Author

🤔 also raw_results seems to not work. The following:

import pickle
...
raw_result = pysages.run(method, generate_simulation, args.time_steps)
...
pickle.dump( raw_result, open("raw_result.pickle", "wb") )

Gives:

Traceback (most recent call last):
  File "adp_SpectralABF.py", line 137, in <module>
    main(sys.argv[1:])
  File "adp_SpectralABF.py", line 104, in main
    pickle.dump( raw_result, open("raw_result.pickle", "wb") )
_pickle.PicklingError: Can't pickle <class 'pysages.methods.core.Result[<class 'pysages.methods.spectral_abf.SpectralABF'>]'>: attribute lookup Result[<class 'pysages.methods.spectral_abf.SpectralABF'>] on pysages.methods.core failed

@ricalessandri
Copy link
Member Author

With #235 merged, I should now do this.

@InnocentBug
Copy link
Member

Is this is active?

@ricalessandri
Copy link
Member Author

I think this is only partially complete (i.e., only part of the examples have been converted). I should get back to this. Not sure whether we want to move this "issue" to the PySAGES-examples repo, though?

@pabloferz
Copy link
Member

Yeah. It does make sense to have one issue within PySAGES-examples, but I would like us to use the serialization support we have now here as well, just in case someone stumbles upon these examples right now.

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