Skip to content

Update constants to CODATA 2022 Values#590

Draft
E-W-Jones wants to merge 9 commits intoyt-project:mainfrom
E-W-Jones:update_constants
Draft

Update constants to CODATA 2022 Values#590
E-W-Jones wants to merge 9 commits intoyt-project:mainfrom
E-W-Jones:update_constants

Conversation

@E-W-Jones
Copy link
Copy Markdown

After the yt workshop in Edinburgh I looked this issue in yt which stems from yt sometimes using its internal, and old, units, and sometimes unyt.

In doing so I discovered that a couple of unyt's constants could be updated to the CODATA 2022 values. I am getting confused by the conversion between SI and CGS units for electromagnetism, and so would appreciate someone else's eyes to tell me if Im missing something.

The issue stems from the fact that the SI had a shift in how they define/measure units, including the permeability of free space, $\mu_0$. It used to be defined as exactly $4\pi \times 10^7~\mathrm{NA}^{-2}$. Now it has to be measured as $1.25663706127(20)\times10^{-6}~\mathrm{NA}^{-2}$. This new value is within an error bar of the old one, and they differ at the 10th decimal place. This is useful because it means you can get away with just not changing it.

When we update this value of $\mu_0$ it raises an error in testing our conversion between SI (metre, kilogram, second, coulomb) and CGS (centimetre, gram, second, statcoulomb) units. Specifically converting the B-field from tesla to gauss. To convert B field you introduce factors of $\sqrt{\frac{4\pi}{\mu_0}}$. This is how you get the equation of energy density used to test the conversion:

B = 1.0 * u.T
B_cgs = B.in_base("cgs")
u_mks = B * B / (2 * u.mu_0)
assert_equal(u_mks.units.dimensions, dimensions.pressure)
u_cgs = B_cgs * B_cgs / (8 * np.pi)

However, this doesn't happen when we convert from tesla to gauss. And it is only sometimes mentioned (for example not on the Gauss (unit) wikipedia page, but is on the Gaussian units but in a way that is unclear to me if it part of the definition of the units. What I do know is that the ratio of u_mks to u_cgs when you convert them between unit systems is the same as the ratio of $\mu_0$ to $4\pi\times10^{-7}~\mathrm{NA}^{-2}$.

Was failing a pytest --doctest-modules test, and unphysical to say the index of an array has the same units as the array, I think.
See [https://pml.nist.gov/cuu/Constants/](https://pml.nist.gov/cuu/Constants/) for CODATA 2022 values.

Link at the top was broken so added what I think is the same information. There are probably a lot of other units that could do with checking.

Each constant I have updated I have included a comment following it with the fact it's from CODATA 2022, and any other information. I think any future updates should also include a comment immediately with the value, as opposed to all sources at the top of the file.

The big change in constants is where some are no longer experimentally determined, but rather have been exactly defined, and vice versa. For example, Avogadro's constant is no longer defined by the mass of a kilogram and determined experimentally, but is exactly defined as 6.02214076e23 1/mol. Inversely, the permeability of free space is no longer exactly defined at 4pi x 10^-7 N A^-2, but is experimentally determined (to within 1 part per billion of the previous value). [https://www.npl.co.uk/resources/the-si-units/the-redefinition-of-the-si-units](https://www.npl.co.uk/resources/the-si-units/the-redefinition-of-the-si-units) has some more general information about the redefinitions.

Changed:
 - electron mass
 - amu
 - proton mass
 - gravitational constant (G)
 - planck constant (h)
 - elementary charge (e)
 - permeability of free space (mu_0)
 - Avogadro's number
 - bolztmann constant
 - erg_per_eV

Changing both G and h mean that the planck units (length, mass, etc.) have also all changed.

speed of light and acceleration due to gravity (g) I haven't changed but I have added the note that these values are the same as CODATA 2022
This function is for testing if the two inputs are both lists of the same length, and that the elements are all close (using the unyt array isclose method)
Changing the number of decimal places in kB (to the CODATA value) meant that assert_equals wasn't working. So I have changed it to assert_allclose, which is consistent with every other comparison in the same block. This meant writing and using the `assert_lists_allclose` function from 87fe8f1.

This commit fails because of electromagnetic units. This is something I'm working on.
@neutrinoceros neutrinoceros marked this pull request as ready for review October 3, 2025 07:50
@neutrinoceros neutrinoceros marked this pull request as draft October 3, 2025 07:51
@E-W-Jones
Copy link
Copy Markdown
Author

An update in light of #636:

I have put the new values in and updated most tests to reflect this, currently there are two things left to do which I need some input on:

  1. test_old_registry_json looks like it justs reads in a saved registry and compares it to the default, but needed to check before updating the saved one with the new values.
    a. Is my interpretation correct, and
    b. is there a preferred way to do this, or is just editing the JSON fine?
  2. CGS EM units are weird and the change to $\mu_0$ is small, I need someone to either
    a. say we should just ignore it (I have put a lot of work into not ignoring it so you know I'm not just being lazy suggesting it), or
    b. check my updated conversions are correct

To convert between CGS and SI units you are switching dimensions but you can work out the conversion between gauss and tesla (derived below, needs checking) as:
$$1\mathrm{G} \leftrightarrow \frac{10^4}{\sqrt{1+\delta}}\mathrm{T}$$
where $\delta = (-1.3\pm1.6)\times10^{-10}$ for the 2022 measurement of $\mu_0$ (this was previously defined with $\delta=0$). This is consistent within 1 error bar with the previous definition.

I think it might be easier for everyone if we just ignore this. So a PR where we add all new values for every other constant, and ignore the 1e-10 error (that I believe will be subdominant in any cases of interest, as an example most tests are to 7 sig fig.). Perhaps I can add some notes to the EM conversion section about it.

Otherwise we will make changes like 1e4 -> 1.000000000066e4... that I really struggle to imagine makes any difference.


Conversion:
There are a couple of ways you could end up with
$$\frac{B_{CGS}}{B_{SI}} = \sqrt{\frac{4\pi}{\mu_0}}\quad(1)$$
but I like starting with magnetic energy density $\frac{B^2_{CGS}}{8\pi} = \frac{B^2_{SI}}{2\mu_0}$ and rearranging.

This constant on the RHS will (and you can check) have units $\mathrm{G}^{2} / \mathrm{T}^2$, and we can start by defining the new measured $\mu_0 = 4\pi(1+\delta)\times 10^{-7}\mathrm{N}\mathrm{A}^{-2}$ where as a reminder $\delta\sim10^{-10}$.

So the LHS of (1) will evaluate to $$\sqrt{\frac{4\pi}{4\pi(1+\delta)\times 10^{-7}\mathrm{N}\mathrm{A}^{-2}}} = \sqrt{\frac{10^{7}\mathrm{A}^{2}\mathrm{N}^{-1}}{(1+\delta)}}\quad(2)$$

The next question is how to write amperes squared per newton in gauss per tesla:
$$\mathrm{G}^2 = \mathrm{erg}\mathrm{cm}^{-3} = 0.1\mathrm{N}\mathrm{m}^{-2}$$
$$\mathrm{T}^2 = \mathrm{N}^2\mathrm{A}^{-2}\mathrm{m}^{-2}$$
Divide these two by each other:
$$\frac{\mathrm{G}^2}{\mathrm{T}^2} = \frac{0.1\mathrm{N}\mathrm{m}^{-2}}{\mathrm{N}^2\mathrm{A}^{-2}\mathrm{m}^{-2}} = 0.1\mathrm{A}^{2}\mathrm{N}^{-1}$$
which is exactly what we want for (2)! Lets plug it in:
$$\frac{B_{CGS}}{B_{SI}} = \sqrt{\frac{10^{8}}{(1+\delta)}\frac{\mathrm{G}^2}{\mathrm{T}^2}} = \frac{10^{4}}{\sqrt{{1+\delta}}}\frac{\mathrm{G}}{\mathrm{T}}$$
which for the pre-2019 defintion of $\delta=0$ is what we would expect to convert between CGS and SI units.

E-W-Jones and others added 4 commits April 17, 2026 14:36
I don't know how this was generated but doesn't seem to just be saving unyt.UnitRegistry().to_json, so I updated the failing values by hand. These were planck "geometrized" units as they rely on Newton's gravitational constant.

Doesn't change based on the two decisions for mu_0 (see [this comment](yt-project#590 (comment)) for what I mean by decisions)
But do provide a comment explaining why not, and how we might need to change it later.
Plus one instance (to make tests pass) where the expected return was `np.int64(49995000)` but it actually returns `49995000`, still as a np.int64.
@chrishavlin
Copy link
Copy Markdown
Contributor

just fyi @E-W-Jones , I pinged yt slack dev channel on your behalf, hoping someone with more domain expertise than myself can give you some feedback on your questions above!

@jzuhone
Copy link
Copy Markdown
Collaborator

jzuhone commented Apr 29, 2026

I will try to have a look at this during this week.

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.

3 participants