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

from_nucleus_info and from_name inconsitency #620

Closed
maxnoe opened this issue Sep 3, 2024 · 4 comments · Fixed by #622
Closed

from_nucleus_info and from_name inconsitency #620

maxnoe opened this issue Sep 3, 2024 · 4 comments · Fixed by #622

Comments

@maxnoe
Copy link
Contributor

maxnoe commented Sep 3, 2024

I.e. this does not round-trip, which is very surprising:

In [55]: p = Particle.from_nucleus_info(a=1, z=1)

In [56]: Particle.from_name(p.name)
---------------------------------------------------------------------------
ParticleNotFound                          Traceback (most recent call last)
Cell In[56], line 1
----> 1 Particle.from_name(p.name)

File ~/.local/conda/envs/cta-dev/lib/python3.11/site-packages/particle/particle/particle.py:1003, in Particle.from_name(cls, name)
   1001     return particle
   1002 except ValueError:
-> 1003     raise ParticleNotFound(f"Could not find name {name!r}") from None

ParticleNotFound: Could not find name 'p'
@maxnoe
Copy link
Contributor Author

maxnoe commented Sep 3, 2024

Same for a neutron btw.:

In [5]: p = Particle.from_nucleus_info(a=1, z=0)

In [6]: p.from_name(p.name)
---------------------------------------------------------------------------
ParticleNotFound                          Traceback (most recent call last)
Cell In[6], line 1
----> 1 p.from_name(p.name)

File ~/.local/conda/envs/cta-dev/lib/python3.11/site-packages/particle/particle/particle.py:1003, in Particle.from_name(cls, name)
   1001     return particle
   1002 except ValueError:
-> 1003     raise ParticleNotFound(f"Could not find name {name!r}") from None

ParticleNotFound: Could not find name 'n'

@eduardo-rodrigues
Copy link
Member

Hi @maxnoe. Thank you for stress-testing the package :-).

So, the reason for these 2, and only 2, exceptions (well, double to accout for their antiparticles), is what @HDembinski replied to you at #263 (comment). Basically, protons and neutrons can be "seen" as both particles and nuclei, hence the exceptions of non-unique PDG IDs for them.

I think there is no way out, as otherwise one would need to remove all nuclei info.

But you are totally right that, for the sake of argument, the "particle proton" and the "nucleus proton", with different PDG IDs, should compare to equal. And a fix will resolve this issue by construction since the round-trip works, as it should, for all other particles.

Would you be interested in making a contribution for the fix? That would be cool.

@maxnoe
Copy link
Contributor Author

maxnoe commented Sep 6, 2024

Yes, sure, happy to make a PR. Could you maybe roughly point me into the right general direction?

for the comparison part, I guess overloading __eq__ on Particle (and PDGID?)?

@eduardo-rodrigues
Copy link
Member

eduardo-rodrigues commented Sep 6, 2024

Brilliant 👍 !

Yep. Unfortunately the PR will not be tiny because one needs to overload the various comparison operators for Particle. I don't think one should change the PDGID class comparison methods because the PDGIDs are different, albeit refering to the same particle.

A little test will be great as well to keep coverage high.

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 a pull request may close this issue.

2 participants