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

[WIP] Make MigrationHop MSONable again #264

Closed
wants to merge 1 commit into from

Conversation

mkhorton
Copy link

Please add test @jmmshn thank you!

Please add test @jmmshn thank you!
@jmmshn
Copy link
Contributor

jmmshn commented Oct 15, 2021

So it looks like we are hitting a custom as_dict + from_dict

https://github.com/materialsproject/pymatgen/blob/dffcac644662d9657d17f872b3c397c5e5a17df7/pymatgen/symmetry/structure.py#L135

So when the decoding tries to process the symm_structure it does not know what to do.
Can we replace those upstream in pymatgen?

@mkhorton
Copy link
Author

From looking at it, it's not even clear to me that that custom as_dict() is necessary at all.

@mkhorton
Copy link
Author

That said, why is this an issue upstream?

@jmmshn
Copy link
Contributor

jmmshn commented Oct 16, 2021

OK so sit down for this one...

So right now I think when MigrationHop.from_dict getting called, and the parser hits the symm_structure it goes into the structure field of SymmetrizedStructure which then sees the
'@class': 'SymmetrizedStructure' part of the dictionary and tries to run the SymmetrizedStructure.as_dict on the structure field of serialized dictionary.

image

This is all because this line
https://github.com/materialsproject/pymatgen/blob/dffcac644662d9657d17f872b3c397c5e5a17df7/pymatgen/symmetry/structure.py#L140
is not doing what the author thinks it's doing. It is not calling the as_dict of the parent Structure and returning a Structure. It's calling Structure.as_dict on SymmetrizedStructure.

We gotta have some kind of auto test generation for these things...

@mkhorton
Copy link
Author

mkhorton commented Oct 16, 2021 via email

@jmmshn
Copy link
Contributor

jmmshn commented Oct 16, 2021

So the problem right now is

# Hop is some MigrationHop object
d = mg.as_dict()
MigrationHop.from_dict(d)  # errors out
MontyDecoder().process_decoded(d['symm_structure']) # errors out

The decoding errors out even though it's just a dictionary because when it gets to d["symm_structure"]["structure"] it sees a '@class': 'SymmetrizedStructure and just freaks out. (it will try to call the from_dict of SymmetrizedStructure but the present level of the data is actually made from the as_dict of Structure).

That's because this line is absolutely not OK.
https://github.com/materialsproject/pymatgen/blob/dffcac644662d9657d17f872b3c397c5e5a17df7/pymatgen/symmetry/structure.py#L140

@shyuep
Copy link
Contributor

shyuep commented Oct 17, 2021

This should be fixed in the pymatgen SymmetrizedStructure side, not in the diffusion package.

@acrutt
Copy link
Contributor

acrutt commented Jul 20, 2022

@jmmshn @mkhorton is there an update on if the necessary fixes for this were implemented in pymatgen? I'm now running into issues because this was never resolved.

@mkhorton
Copy link
Author

If someone else would like to take over this PR, please do, I think it only needs a test to be able to merge; if I recall I opened this during a debugging session, but I'm not involved in pymatgen-analysis-diffusion so would prefer someone else who is actively using it takes it on.

@acrutt
Copy link
Contributor

acrutt commented Jul 20, 2022

I can take over writing a test for this but was confused by the follow-up discussion. Is there still an issue with encoding SymmetrizedStructure as a dict?

@acrutt
Copy link
Contributor

acrutt commented Jul 21, 2022

This issues has been resolved in a new PR that was successfully merged: #312

@mkhorton
Copy link
Author

Fantastic, thanks @acrutt!

@jmmshn
Copy link
Contributor

jmmshn commented Jul 21, 2022

Thanks, @acrutt I'm on leave for the rest of this month so have been slow with emails.

@jmmshn
Copy link
Contributor

jmmshn commented Jul 21, 2022

So I think the underlying bug was still not fixed in pymatgen.
It's being addressed in a PR now after that all the code should work as expected.

@jmmshn
Copy link
Contributor

jmmshn commented Jul 21, 2022

@acrutt if you tried to serialize->deserialize with host_symm_structure does it throws an error still?

@acrutt
Copy link
Contributor

acrutt commented Jul 21, 2022

I'm not familiar with that part of the issue. When I create a MigrationHop with the host_symm_struct attribute initialized, the .as_dict() method works for me. I'm using pymatgen version 2022.7.19.

@jmmshn
Copy link
Contributor

jmmshn commented Jul 21, 2022

So the bug only triggers a problem if you read from a db or read via loadfn due to the order in which things load.

If you see a '@class': 'SymmetrizedStructure' after you run hop.as_dict() then the program will error out when you dumpfn -> loadfn any object that contains the hop.

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

Successfully merging this pull request may close these issues.

None yet

4 participants