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

Utility functions to save and load instances of Group and Representations #74

Open
Danfoa opened this issue Aug 22, 2023 · 2 comments
Open

Comments

@Danfoa
Copy link
Contributor

Danfoa commented Aug 22, 2023

Hi @Gabri95,

I have been facing some (perhaps unnecessary) issues in saving and loading instances of classes from ESCNN.

Say I want to generate a dataset of Equivariant dynamical systems, I would like to save in files the actual symmetry group (subgroup) and the representations of each of the measurements taken.

The representations are ok to save using the irreps ids and the change of basis, but the group itself it's proven a bit harder to save and load elegantly. The group and representation classes are not serializable and thus cannot be pickled. But storing the entire object also seems unnecessary.

I am assuming you have already faced that issue, or if not, that you might have a good idea of how to do this as quickly. Any ideas?

Perhaps I can build (at some point) the protocol for storing and loading this instances

PS: I will answer all other threads we have active after ICLR. Sorry for the delay.

@Gabri95
Copy link
Collaborator

Gabri95 commented Aug 23, 2023

Hi @Danfoa

To efficiently store groups, I implemented this feature (which I also use for caching inside the library).

Each group has a method _keys() which returns a dictionary containing the essential information to instantiate this group.
These attributes are precisely the ones you should pass to a groups' _generator() static method to instantiate it.

The only problem you have left is accessing the _generator() method of the right group class.
This is done with the groups_dict dictionary which associates to each class's name the actual python class.

In other words, to cache an instance g of Group, you just need to cache g.__name__ and g._keys().
Then, you can reinstantiate the group via groups_keys[name]._generator(**keys).

However, I agree the library should include a nice and simple method which hides away these details and can be used to simply cache a representation.
Let me get back to this when I have a little more time.

Let me know if this helps!

Best,
Gabriele

@Danfoa
Copy link
Contributor Author

Danfoa commented Aug 23, 2023

Hi @Gabri95,

Yes, this is precisely what I was looking for, and I agree there should be a method for this. A custom serialization and deserialization method can enable pickle saving and loading.

Thanks for the swift answer. Please update if you are taking on this effort; otherwise, whenever I have time, I could try to give it a go.

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

2 participants