You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Update physical constants to CODATA 2022, and check for new editions automatically #278
quantities/constants/NIST_codata.txt, which _codata.py is generated from, contains the CODATA 2006 recommended values. It was last updated in 2009. Since then there have been the 2010, 2014, 2018 and 2022 adjustments, as well as the 2019 redefinition of the SI. That redefinition fixed the Planck constant, the elementary charge, the Boltzmann constant and the Avogadro constant at exact values. As a result, constants in quantities.constants differ from current values, and some have non-zero uncertainties where the current values are exact. For example, the atomic mass constant is 1.660538782(83)e-27 kg here and 1.66053906892(52)e-27 kg in CODATA 2022.
What updating involves
The file format has changed. The generator in setup.py parses NIST_codata.txt using fixed positions: it skips 10 header lines and assumes a 55-character name column. The current file has 11 header lines and a 60-character name column, so the generator needs to find the separator line and work out the column positions from the header.
Constants have been renamed or removed. 29 of the 322 names used in quantities/constants/*.py are not in the 2022 file. Most are renames, e.g. Planck constant over 2 pi → reduced Planck constant, electric constant → vacuum electric permittivity, magnetic constant → vacuum mag. permeability, and the ... over 2 pi gyromagnetic ratios and Compton wavelengths. Some are no longer listed at all, e.g. {220} lattice spacing of silicon, Cu x unit, Mo x unit and the triton magnetic moment ratios. The Python names in quantities.constants (hbar, epsilon_0, mu_0, …) should stay the same and map to the new CODATA names. For constants that CODATA no longer lists, we need to decide whether to keep the old value, derive it, or deprecate the name.
Values change. Results that depend on these constants will shift slightly, so the change needs a clear entry in CHANGES.txt and probably a minor version bump.
Checking for new editions in CI
CODATA publishes a new adjustment every four years. A scheduled workflow could compare the edition in NIST_codata.txt with the one NIST currently publishes. Both files state it in the header (2022 CODATA adjustment), and the generator records it in _codata.py. When the two differ, the workflow opens an issue, unless one with the same title already exists:
name: Check for a new CODATA editionon:
schedule:
- cron: "0 6 1 * *"# monthlyworkflow_dispatch:
permissions:
contents: readissues: writejobs:
check:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v4
- env:
GH_TOKEN: ${{ github.token }}run: | set -euo pipefail pattern='[0-9]{4} CODATA adjustment' current=$(grep -oE "$pattern" quantities/constants/NIST_codata.txt | cut -c1-4) latest=$(curl -fsSL https://physics.nist.gov/cuu/Constants/Table/allascii.txt | grep -oE "$pattern" | cut -c1-4) echo "current: $current, latest: $latest" if [ "$latest" -gt "$current" ]; then title="CODATA $latest constants are available" if [ -z "$(gh issue list --state all --search "\"$title\" in:title" --json number --jq '.[]')" ]; then gh issue create --title "$title" --body "NIST now publishes the CODATA $latest adjustment; quantities uses CODATA $current. See https://physics.nist.gov/cuu/Constants/Table/allascii.txt" fi fi
Notes:
Opening an issue is more visible than a failing scheduled run, whose failure notifications only go to whoever last edited the cron schedule. If NIST's site can't be reached, the job fails without opening an issue.
GitHub disables scheduled workflows in public repositories after 60 days without repository activity. That's likely for this repository between releases, so the workflow may need re-enabling from time to time, or a keep-alive action.
This check stays out of the regular test workflow, so that test runs don't depend on NIST's site.
The edition check relies on NIST_codata.txt stating its edition in its header. The 2006 file has no such line; a pending change (alongside fixing the Ruff warnings in the generated _codata.py) adds 2006 CODATA adjustment there and makes the generator record the edition in _codata.py.
Activity
Add tests for quantities.constants