Skip to content

Conversation

pv
Copy link
Member

@pv pv commented Jan 11, 2020

Closes gh-14467, gh-11341

The CODATA data sheets do not list exact constants to full double precision, but mark missing decimals with '...'.

Revise the way the exact values are calculated: recalculate only values with missing decimals, and do it separately for each CODATA dataset.

The previous way was error-prone, because it could also override values that are not listed as exact, and since the replacements were done on the final list, what value should be filled in was not clear. This PR changes the missing decimals to be filled in for each CODATA list separately, and only values that are marked to be truncated and exact in the listing are processed. The replacement computation is also now done so that it's harder to make mistakes by using inexact values or forgetting to supply some of the required values.

CODATA2018 contains many more derived exact values than the previous revisions, so their computation becomes now a bit more involved. That the computed values are compared against the listed ones should make errors unlikely.

@pvanmulbregt
Copy link
Contributor

Are gh-11343 and gh-11345 going to be accepted and integrated any time soon? A couple of PRs want to remove the unused sqrt from scipy/constants/codata.py but gh-11345 needs it again.

@rgommers
Copy link
Member

Cc @jakobjakobson13 for this one as well. Related to gh-11343

@jakobjakobson13
Copy link
Contributor

@rgommers I'm a bit busy at the moment, so it could take a week or two till I get to it. If that's no problem, I'd be honoured to do it even though I'm surprised that you ask me as I introduced the bug #11341 with my commit.

@jakobjakobson13
Copy link
Contributor

Cc @jakobjakobson13 for this one as well. Related to gh-11343

The pull request looks good in my eyes and also makes pull request #11343 obsolete (as far as I understand).

pv added 3 commits May 21, 2020 15:53
The CODATA data sheets do not list exact constants to full double
precision, but mark missing decimals with '...'.

Revise the way the exact values are calculated: recalculate only values
with missing decimals, and do it separately for each CODATA dataset.
Ensure the old names for electric/magnetic constants return the current
codata values instead.
All the other constants are obtained from CODATA, so do the same for
hbar.
@pv pv force-pushed the exact-constants branch from f5b8c4b to 93321f9 Compare May 21, 2020 13:15
@jakobjakobson13
Copy link
Contributor

@pv As scipy 1.5 got released and I still feel kind of responsible, I wanted to check on your pull pull request. Should it be discussed again?

@jakobjakobson13
Copy link
Contributor

@pv Are there any news on this pull request?

@jakobjakobson13
Copy link
Contributor

@pv ping

1 similar comment
@jakobjakobson13
Copy link
Contributor

@pv ping

@jakobjakobson13
Copy link
Contributor

This pull request looks very well. Would you consider to merge it into the master branch?
Also an additional question: Would you be interested in an "energy equivalent conversion" function similar to https://www.physics.nist.gov/cuu/pdf/factors_2018.pdf ?

@tupui tupui added this to the 1.11.0 milestone Dec 9, 2022
@tupui
Copy link
Member

tupui commented Dec 10, 2022

@jakobjakobson13 is this PR still in good shape? We need to resolve the conflicts though. If you are interested to do this let me know. It would be fine to do another PR starting from this one.

@jakobjakobson13
Copy link
Contributor

@jakobjakobson13 is this PR still in good shape? We need to resolve the conflicts though. If you are interested to do this let me know. It would be fine to do another PR starting from this one.

I have to recheck the PR as some time passed since the last time. Is it urgent?

@tupui
Copy link
Member

tupui commented Dec 11, 2022

Nothing urgent 😃 I just saw the backlog is small and most things are actually in the pipeline and just need some push to get to the finish line.

jakobjakobson13 added a commit to jakobjakobson13/scipy that referenced this pull request Dec 11, 2022
@h-vetinari h-vetinari removed this from the 1.11.0 milestone May 20, 2023
@tylerjereddy
Copy link
Contributor

This hasn't had commit activity in years, bumping the milestone ahead of 1.13.0 branching.

@mdhaber
Copy link
Contributor

mdhaber commented Sep 30, 2024

I've merged this with main and the contents of gh-17584.

Here's a checklist before merge:

Copy link
Contributor

@mdhaber mdhaber left a comment

Choose a reason for hiding this comment

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

Just some comments to record my thoughts during review. I still need to check the exact<year> functions for accuracy.

What was the reference for the formulas? When i go to the "Extensive Listings" and click a constant, I can get an equation when I click the symbol:

image

Is that what I should compare against? This could use a comment. Update: I'm not sure there is something very useful to say. These come from all over the place, so aside from showing the source and derivation of each one, there's not much to be written.

MAINT: constants: ensure `c` is defined in `_codata.py`
@jakobjakobson13
Copy link
Contributor

I think the pull request looks good.
And regarding the issue of Klitzing constant: You could recalculate it as all other constants (apart from the base constants) but I doubt that you want to make it that complicated. So taking the value from the file seems like a reasonable way to go for me.

@mdhaber
Copy link
Contributor

mdhaber commented Oct 3, 2024

And regarding the issue of Klitzing constant: You could recalculate it as all other constants (apart from the base constants) but I doubt that you want to make it that complicated. So taking the value from the file seems like a reasonable way to go for me.

I don't understand. The value of the von Klitzing constant in the file has ellipses, so it is not as precise as it should be. All values with ellipses correspond with exact quantities, and all are re-calculated using the exact function appropriate for that year's CODATA values. So I wasn't asking about Klitzing's constant in particular; I don't intent to treat it as a special case. It just needs to be calculated correctly like all other quantities with ellipses, and so I was asking where the formula should come from.

@jakobjakobson13
Copy link
Contributor

I don't understand. The value of the Klitzing constant in the file has ellipses, so it is not as precise as it should be.

Sorry, you are right. I was looking in the wrong year for the Klitzing constant and since the redefinition of the SI system it's not exact anymore.

and so I was asking where the formula should come from.

Good but fundamental question. From my point of view, I would accept the sources (and its content) listed on the CODATA NIST homepage as they list solid scientific papers. But I understand your issue.

@mdhaber
Copy link
Contributor

mdhaber commented Oct 4, 2024

Thanks, that helps. (Except the von Klitzing constant is listed as exact now but has ellipses. My point is that everything with ellipses gets recomputed from a formula.) I'm surprised, but if NIST doesn't actually provide formulas for everything, then I suppose there's not much to be done about it. I wanted to make sure I wasn't missing anything.

I'll check what I can, add a comment about this, then merge.

In the meantime, If you'd be interested in updating gh-20055 according to Ralf's comment, I can help you finish that one, too.

The "slim down module" PRs are a bit too sweeping as they are, but they have some good elements. For instance, we can't just remove the module attributes; we'd first need to emit a deprecation warning when a user tries to access them (for two versions). Please consider closing those PRs and, after we finish gh-20055, consider opening a PR with a narrower immediate goal. It's easier to get things through in small steps.

Copy link
Contributor

@mdhaber mdhaber left a comment

Choose a reason for hiding this comment

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

OK, I can't say I checked all of these, but I did check several. It is implausible to me that the author would have taken the time to find these definitions in terms of base constants and the 1990 conventional electric constants and for there to be some that give results correct to 9 decimal places without them actually being correct. This LGTM.

'reduced Planck constant in eV s': hbar / e,
'reduced Planck constant times c in MeV fm': hbar * c / (e * 1e6 * 1e-15),
'second radiation constant': h * c / k,
'Stefan-Boltzmann constant': 2 * math.pi**5 * k**4 / (15 * h**3 * c**2),
Copy link
Contributor

Choose a reason for hiding this comment

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

image

Comment on lines +1614 to +1615
'molar volume of ideal gas (273.15 K, 100 kPa)': R * 273.15 / 100e3,
'molar volume of ideal gas (273.15 K, 101.325 kPa)': R * 273.15 / 101.325e3,
Copy link
Contributor

Choose a reason for hiding this comment

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

$PV = nRT \rightarrow \frac{V}{n} = \frac{RT}{P}$

Comment on lines +1537 to +1541
c = exact['speed of light in vacuum']
h = exact['Planck constant']
e = exact['elementary charge']
k = exact['Boltzmann constant']
N_A = exact['Avogadro constant']
Copy link
Contributor

Choose a reason for hiding this comment

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

image

Comment on lines +1551 to +1552
alpha_W = 2.821439372122078893403 # 3 + lambertw(-3 * exp(-3))
x_W = 4.965114231744276303699 # 5 + lambertw(-5 * exp(-5))
Copy link
Contributor

Choose a reason for hiding this comment

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

Checked with mpmath.

@mdhaber mdhaber merged commit 5af3657 into scipy:main Oct 5, 2024
39 checks passed
zingale pushed a commit to pynucastro/pynucastro that referenced this pull request Jan 22, 2025
SciPy 1.15.0 updated how exact constants are calculated (scipy/scipy#11345) and rewrote MINPACK in C (scipy/scipy#21131, used by fsolve), leading to roundoff diffs when running the test suite with earlier versions of SciPy.

Summary of changes:

* update the exact constants we provide in pynucastro.constants (k_MeV and hbar) to match the more accurate values from 1.15.0

* update the NSE tests to allow both of the MINPACK implementations to pass

* fix one missed instance of constants.m_u_MeV in the mass values for Python networks

* use constants.m_u_C18 in the screening routines for consistency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.constants
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: constants: explain 0.0 uncertainty
10 participants