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

Saving Intermediate results #31

Open
jbuencuerpo opened this issue Jan 23, 2019 · 1 comment
Open

Saving Intermediate results #31

jbuencuerpo opened this issue Jan 23, 2019 · 1 comment

Comments

@jbuencuerpo
Copy link

jbuencuerpo commented Jan 23, 2019

There is some how to save intermediate results? It is not posible to pickle the Structure class, which could be beneficial for long simulations. I have tried for example after the MJ_solar_cell_tutorial.py :

import pickle
with open('solcore_test.p', 'wb') as ffile:
    pickle.dump(my_solar_cell, ffile, protocol=2)

AttributeError Traceback (most recent call last)
in ()
1 with open('solcore_test.p', 'wb') as ffile:
2 #pickle()
----> 3 pickle.dump(my_solar_cell, ffile)
AttributeError: Can't pickle local object 'MaterialSystem.sopra_material..SpecificMaterial'

Another option is using dill, which typically is smarter, but I am afraid not in this case, fails with the same class. There is another way to solve this?
Thanks.

@dalonsoa
Copy link
Collaborator

Unfortunately, the material system cannot be pickled. This is a long lost battle that I’m afraid can only be solved by refactoring the material system altogether. As it is now, it is useful but pretty obscure, with classes inside classes and funciona made available outside, as well as information retrieve from disk on the fly, as needed. It works and it has been useful for many years, but certainly not that helpful when it comes to expand it, maintain it or simply, as you want, pickle the objects.

What is exactly the part that is preventing a material to be saved, I’m not sure. Here is a discussion where the creator of Dill gives some tips of what might be going wrong.

https://stackoverflow.com/questions/29922373/when-can-a-python-object-be-pickled

Improving the material system might be tagged as a very useful enhancement, to be honest.

Cheers,
Diego

Sent with GitHawk

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

No branches or pull requests

2 participants