Skip to content

ENH: load particle definitions from pdg package - #371

Merged
redeboer merged 28 commits into
mainfrom
load_from_pdg
Sep 14, 2026
Merged

redeboer merged 28 commits into
mainfrom
load_from_pdg

Conversation

@Flomber

@Flomber Flomber commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes #332

⚙️ Enhancements

  • {func}.load_pdg now accepts a source keyword-only argument. With source="pdg" (default remains "particle"), particle definitions are loaded from the official PDG Python API instead of the particle package provided by scikit-hep, giving a larger and independently sourced set of particle definitions. As of writing, particles loaded this way do not have LaTeX names, because the pdg package does not yet support them (particledatagroup/api#42).

@Flomber Flomber added this to the 0.11.0 milestone Sep 7, 2026
@Flomber
Flomber requested a review from redeboer September 7, 2026 14:35
@Flomber Flomber self-assigned this Sep 7, 2026
@Flomber Flomber added ❗ Behavior Changes that may affect the framework output ⚙️ Enhancement Improvements and optimizations of existing features labels Sep 7, 2026
Comment thread src/qrules/_pdg_adapter.py
Comment thread src/qrules/_pdg_latex.py Outdated
Comment thread src/qrules/_pdg_latex.py Outdated
@Flomber

This comment was marked as resolved.

@Flomber Flomber changed the title Load definitions from pdg ENH: load particle definitions from pdg package Sep 7, 2026
@Flomber

This comment was marked as resolved.

Comment thread tests/conftest.py
redeboer

This comment was marked as resolved.

@Flomber Flomber added ✨ Feature New feature added to the package and removed ❗ Behavior Changes that may affect the framework output labels Sep 9, 2026
@mmikhasenko

Copy link
Copy Markdown

I think for particle names they can produce latex.
Internally, it is not latex, it is some set of customary scripts

https://pdg.lbl.gov/2026/api/index.html

if it is not in sqlite @Flomber checked already

They say

To provide feedback or report bugs, please contact api@pdg.lbl.gov.

there is issue tracker here
https://github.com/particledatagroup/api/issues

Dean, and Jurgen could add it at the next release.

@redeboer redeboer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! We just need some more cross-checks and documentation.

Comment thread src/qrules/particle.py
Comment thread src/qrules/particle.py
Comment thread tests/unit/test_pdg_adapter.py Outdated
Comment on lines +21 to +22
default_particles = load_pdg()
scikit_hep_particles = load_pdg(source="particle")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you test whether there are any mismatches between two collections from particle and from pdg? We can now directly use this new feature to find bugs in the particle databases (which are hardcoded).

Note

This is something for a follow-up issue. So just try it first and if you find some problems, post an issue. We don't need that mismatch search to be implemented in the unit tests.

@Flomber Flomber Sep 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have wrote a small script to compare both sources. This is the output:

image
Details

from collections.abc import Iterable

from qrules.particle import Particle, load_pdg

def index_by_pid(particles: Iterable[Particle]) -> dict[int, Particle]:
    """Index particles by their Monte Carlo particle ID."""
    return {particle.pid: particle for particle in particles}


def main() -> None:
    """Report source coverage and particles available only from the PDG API."""
    scikit_hep_particles = index_by_pid(load_pdg(source="particle"))
    pdg_particles = index_by_pid(load_pdg(source="pdg"))

    scikit_hep_ids = set(scikit_hep_particles)
    pdg_ids = set(pdg_particles)
    only_in_pdg = pdg_ids - scikit_hep_ids

    print(f"Scikit-HEP source: {len(scikit_hep_ids)} particles")
    print(f"PDG source:        {len(pdg_ids)} particles")
    print(f"All PDG particles are in Scikit-HEP: {pdg_ids <= scikit_hep_ids}")
    print(f"All Scikit-HEP particles are in PDG: {scikit_hep_ids <= pdg_ids}")
    print(f"\nParticles only in the PDG source ({len(only_in_pdg)}):")
    for pid in sorted(only_in_pdg):
        print(f"{pid:>9}  {pdg_particles[pid].name}")


if __name__ == "__main__":
    main()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a variation of that script could be used to update the corresponding database in the particle package? I mean, one that directly gets the data from pdg and then fetches the missing entries for that CSV file.

Comment thread tests/unit/test_pdg_adapter.py
@redeboer redeboer removed the ✨ Feature New feature added to the package label Sep 14, 2026
@redeboer
redeboer marked this pull request as ready for review September 14, 2026 11:27

@redeboer redeboer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM! 📖

@redeboer
redeboer merged commit 229802d into main Sep 14, 2026
48 of 49 checks passed
@redeboer
redeboer deleted the load_from_pdg branch September 14, 2026 11:29
@redeboer redeboer modified the milestones: 0.11.0, 0.10.14 Sep 14, 2026
@redeboer redeboer changed the title ENH: load particle definitions from pdg package ENH: load particle definitions from pdg package Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚙️ Enhancement Improvements and optimizations of existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Load particle definitions from pdg package

4 participants