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

Numerical error on conversion of coulomb to statcoulomb #24325

Merged
merged 10 commits into from
Dec 17, 2022

Conversation

1e9abhi1e10
Copy link
Contributor

@1e9abhi1e10 1e9abhi1e10 commented Nov 29, 2022

References to other Issues or PRs

fixes #24319 ,#24381 ,#24281

Brief description of what is fixed or changed

fixes numerical error in the conversion of coulomb and statcoulomb

Other comments

Release Notes

  • physics.units
    • fixed numerical error in conversion of statcoulomb and coulomb

@sympy-bot
Copy link

sympy-bot commented Nov 29, 2022

Hi, I am the SymPy bot (v169). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.12.

Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
fixes #24319 ,#24381 ,#24281
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed
fixes numerical error in the conversion of `coulomb` and `statcoulomb` 




#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

or if no release note(s) should be included use:



See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* physics.units
     *  fixed numerical error in conversion of statcoulomb and coulomb

<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@1e9abhi1e10 1e9abhi1e10 changed the title Numerical error on conversion of coulomb to statcoulomb #24319 Numerical error on conversion of coulomb to statcoulomb Nov 29, 2022
@1e9abhi1e10
Copy link
Contributor Author

Why it is showing an AssertionError, In my former PRs also faced the same issue. How can I fix it!

@1e9abhi1e10
Copy link
Contributor Author

Why is it showing an AssertionError, In my former PRs also faced the same issue. How can I fix it!

When I am using try except statements it doesn't show any error, Can I use these statements?

@github-actions
Copy link

github-actions bot commented Nov 29, 2022

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

Significantly changed benchmark results (master vs previous release)

       before           after         ratio
     [41d90958]       [48018712]
     <sympy-1.11.1^0>                 
-     1.27±0.04ms         830±50μs     0.65  solve.TimeSparseSystem.time_linear_eq_to_matrix(10)
-     3.63±0.09ms      1.49±0.06ms     0.41  solve.TimeSparseSystem.time_linear_eq_to_matrix(20)
-      7.03±0.1ms      2.09±0.09ms     0.30  solve.TimeSparseSystem.time_linear_eq_to_matrix(30)

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

@ThePauliPrinciple
Copy link
Contributor

You get an AssertionError when an assert fails, so you can not use try-except here, because that means you're allowing a failed test. It's not surprising that the test fails, because you changed the test, without changing the underlying algorithm that obtains the test result.

@1e9abhi1e10
Copy link
Contributor Author

You get an AssertionError when an assert fails, so you can not use try-except here, because that means you're allowing a failed test. It's not surprising that the test fails, because you changed the test, without changing the underlying algorithm that obtains the test result.

Okay Sir ,I will!

@1e9abhi1e10
Copy link
Contributor Author

You get an AssertionError when an assert fails, so you can not use try-except here, because that means you're allowing a failed test. It's not surprising that the test fails, because you changed the test, without changing the underlying algorithm that obtains the test result.

I tried a lot but cannot able to fix the !assertion error. Can you pls guide me for moving ahead

@faze-geek
Copy link
Contributor

I tried a lot but cannot able to fix the !assertion error. Can you pls guide me for moving ahead

The assertion error is obvious if you just change the tests without making corresponding changes in the code.
I checked the premise of this Pull Request and the expected output you show is indeed correct. The following git diff will correct the code and make your tests work (you will have to change some other tests related to statcoulomb too which I have shown below) -

--- a/sympy/physics/units/systems/cgs.py
+++ b/sympy/physics/units/systems/cgs.py
@@ -56,7 +56,7 @@
 cgs_gauss.set_quantity_scale_factor(maxwell, sqrt(centimeter**3*gram)/second)

 # SI units expressed in CGS-gaussian units:
-cgs_gauss.set_quantity_scale_factor(coulomb, speed_of_light*statcoulomb/10)
+cgs_gauss.set_quantity_scale_factor(coulomb, 10*speed_of_light*statcoulomb)

--- a/sympy/physics/units/tests/test_unit_system_cgs_gauss.py
+++ b/sympy/physics/units/tests/test_unit_system_cgs_gauss.py
@@ -11,10 +11,10 @@

 def test_conversion_to_from_si():

-    assert convert_to(statcoulomb, coulomb, cgs_gauss) == 5*coulomb/149896229
-    assert convert_to(coulomb, statcoulomb, cgs_gauss) == 149896229*statcoulomb/5
+    assert convert_to(statcoulomb, coulomb, cgs_gauss) == coulomb/2997924580
+    assert convert_to(coulomb, statcoulomb, cgs_gauss) == 2997924580*statcoulomb
     assert convert_to(statcoulomb, sqrt(gram*centimeter**3)/second, cgs_gauss) == centimeter**(S(3)/2)*sqrt(gram)/second
-    assert convert_to(coulomb, sqrt(gram*centimeter**3)/second, cgs_gauss) == 149896229*centimeter**(S(3)/2)*sqrt(gram)/(5*second)
+    assert convert_to(coulomb, sqrt(gram*centimeter**3)/second, cgs_gauss) == 2997924580*centimeter**(S(3)/2)*sqrt(gram)/second

     # SI units have an additional base unit, no conversion in case of electromagnetism:
     assert convert_to(coulomb, statcoulomb, SI) == coulomb
@@ -37,7 +37,7 @@ def test_cgs_gauss_convert_constants():
     assert convert_to(speed_of_light, centimeter/second, cgs_gauss) == 29979245800*centimeter/second

     assert convert_to(coulomb_constant, 1, cgs_gauss) == 1
-    assert convert_to(coulomb_constant, newton*meter**2/coulomb**2, cgs_gauss) == 22468879468420441*meter**2*newton/(25000000000*coulomb**2)
+    assert convert_to(coulomb_constant, newton*meter**2/coulomb**2, cgs_gauss) == 22468879468420441*meter**2*newton/(2500000*coulomb**2)

@faze-geek
Copy link
Contributor

Ping @dyc3 for review. This pull request seems correct . Could you have a look if it is good to go in ?

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

I'm concerned with the lack of sources to justify this change, but if we are sure this is mathematically correct, then I'm good to merge this in.

This needs to have a release notes entry, please edit the PR description to add it.

@1e9abhi1e10
Copy link
Contributor Author

I'm concerned with the lack of sources to justify this change, but if we are sure this is mathematically correct, then I'm good to merge this in.

This needs to have a release notes entry, please edit the PR description to add it.

Now it is fine ?
If something is wrong pls correct me .
Thank you!

@faze-geek
Copy link
Contributor

faze-geek commented Dec 9, 2022

I'm concerned with the lack of sources to justify this change, but if we are sure this is mathematically correct, then I'm good to merge this in.

The mathematical correctness of this change can be verified on wikipedia here in the relation between Statcoulomb and Coulomb section.

@dyc3
Copy link
Contributor

dyc3 commented Dec 10, 2022

Yup, release notes look good, thank you!

@faze-geek
Copy link
Contributor

I think this also resolves issue #24281. Could you check on your branch if the output is as desired. If yes, you should add "fixes # 24281" to the OP of the PR too.

@1e9abhi1e10
Copy link
Contributor Author

I think this also resolves issue #24281. Could you check on your branch if the output is as desired. If yes, you should add "fixes # 24281" to the OP of the PR too.

cgs_gauss.set_quantity_scale_factor(coulomb, speed_of_light*statcoulomb/10)
cgs_gauss.set_quantity_scale_factor(ampere, speed_of_light*statcoulomb/second/10)
cgs_gauss.set_quantity_scale_factor(volt, speed_of_light*statvolt/10**6)
#cgs_gauss.set_quantity_scale_factor(weber, 10**8*maxwell)
#cgs_gauss.set_quantity_scale_factor(tesla, 10**4*gauss)
#cgs_gauss.set_quantity_scale_factor(debye, One/10**18*statcoulomb*centimeter)
#cgs_gauss.set_quantity_scale_factor(oersted, sqrt(gram/centimeter)/second)
cgs_gauss.set_quantity_scale_factor(ohm, 10**9/speed_of_light**2*second/centimeter)
cgs_gauss.set_quantity_scale_factor(farad, One/10**9*speed_of_light**2*centimeter)
cgs_gauss.set_quantity_scale_factor(henry, 10**9/speed_of_light**2/centimeter*second**2)

This changes should be required

cgs_gauss.set_quantity_scale_factor(coulomb, 10*speed_of_light*statcoulomb)
cgs_gauss.set_quantity_scale_factor(ampere,10*speed_of_light*statcoulomb/second)
cgs_gauss.set_quantity_scale_factor(volt, 10**6/speed_of_light*statvolt)
#cgs_gauss.set_quantity_scale_factor(weber, 10**8*maxwell)
#cgs_gauss.set_quantity_scale_factor(tesla, 10**4*gauss)
#cgs_gauss.set_quantity_scale_factor(debye, One/10**18*statcoulomb*centimeter)
#cgs_gauss.set_quantity_scale_factor(oersted, sqrt(gram/centimeter)/second)
cgs_gauss.set_quantity_scale_factor(ohm, 10**5/speed_of_light**2*second/centimeter)
cgs_gauss.set_quantity_scale_factor(farad, One/10**5*speed_of_light**2*centimeter)
cgs_gauss.set_quantity_scale_factor(henry, 10**5/speed_of_light**2/centimeter*second**2)

I need to add a commit that makes these changes.
Let me know if something is wrong.

@1e9abhi1e10
Copy link
Contributor Author

@dyc3 pls review it!

assert NS(convert_to(2*henry,second**2/centimeter,cgs_gauss)) == '2.22530011210724e-12*second**2/centimeter'

def test_volt_cgs_gauss():
assert convert_to(volt,statvolt,cgs_gauss) == 10**6*statvolt/299792458
Copy link
Contributor Author

@1e9abhi1e10 1e9abhi1e10 Dec 16, 2022

Choose a reason for hiding this comment

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

We can check there
1volt = 0.0033356409519815205*statvolt
1statvolt = 299.792458

@smichr
Copy link
Member

smichr commented Dec 16, 2022

Regarding V vs statVolt, chatGPT got it wrong, too - if this PR is right, though it gets the relationship between feet and inches right. So what is the definitive source that is being used to check this?

The volt is larger than the statvolt. The volt is the unit of electrical potential difference in the International System of Units (SI), which is the modern metric system of units. One volt is equal to 1 joule per coulomb.

The statvolt is the unit of electrical potential difference in the centimeter-gram-second (CGS) system of units. One statvolt is equal to 1 g^1/2 cm^1/2 s^-3/2.

There is a conversion factor between statvolts and volts, which is equal to about 299.792458 statvolts per volt. This means that to convert from statvolts to volts, you would multiply the number of statvolts by this conversion factor. For example, if you had 100 statvolts, this would be equal to about 29,979.2458 volts.

To summarize, the volt is larger than the statvolt. The volt is the unit of electrical potential difference in the SI system, while the statvolt is the unit of electrical potential difference in the CGS system. There is a conversion factor of about 299.792458 statvolts per volt, which can be used to convert between these two units.

@1e9abhi1e10
Copy link
Contributor Author

Regarding V vs statVolt, chatGPT got it wrong, too - if this PR is right, though it gets the relationship between feet and inches right. So what is the definitive source that is being used to check this?

The volt is larger than the statvolt. The volt is the unit of electrical potential difference in the International System of Units (SI), which is the modern metric system of units. One volt is equal to 1 joule per coulomb.

The statvolt is the unit of electrical potential difference in the centimeter-gram-second (CGS) system of units. One statvolt is equal to 1 g^1/2 cm^1/2 s^-3/2.

There is a conversion factor between statvolts and volts, which is equal to about 299.792458 statvolts per volt. This means that to convert from statvolts to volts, you would multiply the number of statvolts by this conversion factor. For example, if you had 100 statvolts, this would be equal to about 29,979.2458 volts.

To summarize, the volt is larger than the statvolt. The volt is the unit of electrical potential difference in the SI system, while the statvolt is the unit of electrical potential difference in the CGS system. There is a conversion factor of about 299.792458 statvolts per volt, which can be used to convert between these two units.

As we know that 1 volt = 1 joule / 1 coulomb
and 1 statvolt = 1 erg / 1 statcoulomb
so we can write 1 volt = 10**7 erg / 2997924580 statcoulomb
then 1 volt = 0.003335640951981521*erg / statcoulomb
then 1 volt = 0.003335640951981521*statvolt
And in CGS base units 1 statvolt is equal to cm^1/2⋅g^1/2⋅s^(-1) Reference

@1e9abhi1e10
Copy link
Contributor Author

Regarding V vs statVolt, chatGPT got it wrong, too - if this PR is right, though it gets the relationship between feet and inches right. So what is the definitive source that is being used to check this?

The volt is larger than the statvolt. The volt is the unit of electrical potential difference in the International System of Units (SI), which is the modern metric system of units. One volt is equal to 1 joule per coulomb.

The statvolt is the unit of electrical potential difference in the centimeter-gram-second (CGS) system of units. One statvolt is equal to 1 g^1/2 cm^1/2 s^-3/2.

There is a conversion factor between statvolts and volts, which is equal to about 299.792458 statvolts per volt. This means that to convert from statvolts to volts, you would multiply the number of statvolts by this conversion factor. For example, if you had 100 statvolts, this would be equal to about 29,979.2458 volts.

To summarize, the volt is larger than the statvolt. The volt is the unit of electrical potential difference in the SI system, while the statvolt is the unit of electrical potential difference in the CGS system. There is a conversion factor of about 299.792458 statvolts per volt, which can be used to convert between these two units.

The main thing is that statvolt is greater than volt

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

The math seems to check out to me, and there seems to be sufficient test coverage for what's being changed here. Looks good.

@smichr smichr enabled auto-merge December 17, 2022 08:21
@smichr smichr merged commit 32af55d into sympy:master Dec 17, 2022
@1e9abhi1e10 1e9abhi1e10 deleted the physicsunit branch January 30, 2023 10:03
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.

Numerical error on conversion of coulomb to statcoulomb
6 participants