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

Fix units and unit-conversion factors #2891

Merged
merged 9 commits into from
Jun 4, 2024
Merged

Fix units and unit-conversion factors #2891

merged 9 commits into from
Jun 4, 2024

Conversation

OceanNuclear
Copy link
Contributor

Linked Issues

Closes #2853 with caveats: YR_TO_S and S_TO_YR cannot be removed completely as bluemira/plasma_physics/tools.py uses them, and cannot be converted to raw_uc there due to numba.jit.

Closes #2857 with caveats: get_species_data needs to be overhauled if this change were to be made, so it has been left unchanged, and may be ultimately solved in issue #2890.

Description

Solves issue #2853 and #2857 simultaneously, so all temperature units are in keV or K (as opposed to a mix of eV/keV/K); and no more conversion multiplies (*_TO_*) are required.

Interface Changes

bluemira.plasma_physics.rules_of_thumb.estimate_loop_voltage now takes in electron temperature in keV instead of eV.
bluemira.plasma_physics.collisions.spitzer_conductivity now takes in electron temperature in keV instead of eV.

Checklist

I confirm that I have completed the following checks:

  • Tests run locally and pass pytest tests --reactor
  • Code quality checks run locally and pass pre-commit run --from-ref develop --to-ref HEAD
  • Documentation built locally and checked sphinx-build -W documentation/source documentation/build

@OceanNuclear OceanNuclear requested review from a team as code owners December 20, 2023 11:56
@OceanNuclear OceanNuclear changed the title Ocean/plasma units Fix units and unit-conversion factors Dec 20, 2023
Copy link

sonarcloud bot commented Dec 20, 2023

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

3 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

github-actions bot commented Dec 20, 2023

⚠️ Warning Report

Found 0 new warnings, 0 fixed warnings. 🎉

All warnings (5)

On runtest

  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/ufl/core/expr.py:275: DeprecationWarning: Expr.ufl_domain() is deprecated, please use extract_unique_domain(expr) instead.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/ffcx/element_interface.py:23: DeprecationWarning: Use of elements created by UFL is deprecated. You should create elements directly using Basix.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/ffcx/element_interface.py:26: DeprecationWarning: Converting elements created in UFL to Basix elements is deprecated. You should create the elements directly using basix.ufl.element instead
  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/basix/ufl.py:1909: DeprecationWarning: Converting elements created in UFL to Basix elements is deprecated. You should create the elements directly using basix.ufl.element instead

On collect

  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/ufl/core/ufl_type.py:56: DeprecationWarning: attach_operators_from_hash_data deprecated, please use UFLObject instead.

Copy link

codecov bot commented Dec 20, 2023

Codecov Report

Attention: Patch coverage is 62.96296% with 10 lines in your changes missing coverage. Please review.

Project coverage is 74.29%. Comparing base (fb8a051) to head (c17dd4a).
Report is 100 commits behind head on develop.

Files Patch % Lines
bluemira/fuel_cycle/cycle.py 0.00% 6 Missing ⚠️
bluemira/fuel_cycle/lifecycle.py 0.00% 1 Missing ⚠️
bluemira/fuel_cycle/timeline.py 0.00% 1 Missing ⚠️
bluemira/plasma_physics/collisions.py 75.00% 1 Missing ⚠️
bluemira/plasma_physics/rules_of_thumb.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2891      +/-   ##
===========================================
- Coverage    79.98%   74.29%   -5.69%     
===========================================
  Files          222      242      +20     
  Lines        24759    26861    +2102     
===========================================
+ Hits         19804    19957     +153     
- Misses        4955     6904    +1949     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@OceanNuclear
Copy link
Contributor Author

(Manually checked and confirmed that this change does not lead to conflict in any other branches)

@je-cook
Copy link
Contributor

je-cook commented Dec 21, 2023

I'm only starting going through this one. My first thought is that the reduction in the use of the S_TO_YR and YR_TO_S will increase the number of calculations that have to be undertaken. In one instance as the conversion happens within a for loop its a many times increase.

Most of the other conversions are fairly sensible but I think there is no need to reduce so drastically the time conversions especially as its so widely used

@OceanNuclear
Copy link
Contributor Author

OceanNuclear commented Dec 21, 2023

I thought the number of calculations would be the same across

raw_uc(delta_t, "yr", "s")

and

delta_t * YR_TO_S

? As raw_uc does the multiplication under the hood, plus a few other unit lookup calls inside pint.

The only place where this might be a significant problem is in the for-loop inside EUDEMOFuelCycleModel.tbreed, but I thought that's not a function needing optimization because it re-calculated the temporary variable (YR_TO_S * dt) four times in a row, so I thought my method of initializing the local variable dts would still be faster as it removes the need for 3 multiplications.

@je-cook
Copy link
Contributor

je-cook commented Jan 4, 2024

I agree with your second point but your first point raw_uc has at least 2 extra operations; decoding of unit strings to numbers. Therefore if we only have to do that once for some speed relevant code thats a good thing especially as we can't remove YR_TO_S completely anyway.

Its only in that usecase no need to apply the logic everywhere

@je-cook je-cook force-pushed the develop branch 5 times, most recently from 5a50acb to 7574352 Compare May 15, 2024 08:13
Copy link

sonarcloud bot commented Jun 4, 2024

Quality Gate Passed Quality Gate passed

Issues
7 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@je-cook je-cook left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@je-cook je-cook self-assigned this Jun 4, 2024
@je-cook je-cook added the quality Tasks relating to quality issues or improvements label Jun 4, 2024
@je-cook je-cook merged commit e730bb8 into develop Jun 4, 2024
6 of 8 checks passed
@je-cook je-cook deleted the ocean/plasma-units branch June 4, 2024 08:58
OceanNuclear added a commit that referenced this pull request Jun 17, 2024
* Removed redundant units

* Removed all 'years' variable and YR_TO_S variables. Found two possible errors.

* Made units more understandable

* Undid all the raw_uc conversions in tools.py as they are not compatible with numba.jit's optimization. Using the constants YR_TO_S and S_TO_YR.

* Removed as many S_TO_YR and YR_TO_S as possible.

* Fixed the problem of missing elementary charge (e) constant in base.constants

* Undid all S_TO_YR/YR_TO_S changes

* Minor fixes to the YR_TO_S

* Added back in C_LIGHT

* Made sure all of the units used in neutronics matches the units used in plasma_physics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
quality Tasks relating to quality issues or improvements
Projects
None yet
2 participants