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

Numba formal integral #1549

Merged
merged 40 commits into from
Apr 30, 2021
Merged

Numba formal integral #1549

merged 40 commits into from
Apr 30, 2021

Conversation

Rodot-
Copy link
Contributor

@Rodot- Rodot- commented Apr 23, 2021

Description

Implementation of the formal integral with numba. New tests added for the numba version of various helper functions used to compute the formal integral.

Motivation and context

We would like to move TARDIS fully away from C. The formal integral was the last component of TARDIS written entirely in C.

How has this been tested?

New tests have been added for the numba implementation. Full runs that compute formal integrals are compared to reference-data generated using the C formal integral. All tests pass.

  • Testing pipeline.
  • Other.

Type of change

  • Bug fix.
  • New feature.
  • Breaking change.
  • None of the above.

Refactor from C to Python

Checklist

  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
    • (optional) I have built the documentation on my fork following the instructions.
  • I have assigned and requested two reviewers for this pull request.

@Rodot-
Copy link
Contributor Author

Rodot- commented Apr 27, 2021

/AzurePipelines run compare-refdata

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Rodot-
Copy link
Contributor Author

Rodot- commented Apr 28, 2021

One thing to note: I removed tardis/montecarlo/tests/test_montecarlo.py since it was mostly C tests, but when I merged I noticed there had been some updates to it. Should this file be added back in and modified to only do the numba side of things or is it fine being removed? @andrewfullard

@Rodot-
Copy link
Contributor Author

Rodot- commented Apr 28, 2021

Okay, well, I added them back in just in case, they all skip anyway and I modified them not to include any C code references. But I left them just in case we want to move some of these tests over to a different file later so the work isn't lost.

I think this is ready to go

@@ -1,53 +1,236 @@

import sys

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

Comment on lines 16 to 17
from tardis.montecarlo.montecarlo_numba.numba_interface \
import numba_plasma_initialize, NumbaModel, NumbaPlasma
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
from tardis.montecarlo.montecarlo_numba.numba_interface \
import numba_plasma_initialize, NumbaModel, NumbaPlasma
from tardis.montecarlo.montecarlo_numba.numba_interface (
import numba_plasma_initialize, NumbaModel, NumbaPlasma)

from tardis.montecarlo.spectrum import TARDISSpectrum

C_INV = 3.33564e-11
M_PI = np.arccos(-1)
KB_CGS = 1.3806488e-16
H_CGS = 6.62606957e-27
SIGMA_THOMSON = 6.652486e-25

#SIGMA_THOMSON = 6.652486e-25
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#SIGMA_THOMSON = 6.652486e-25

Helper class for performing the formal integral
with numba.
'''
#def __init__(self, model, plasma, runner, points=1000):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#def __init__(self, model, plasma, runner, points=1000):

Comment on lines 669 to 671
#for i in range(N):
# opp[i] = R_max / (N - 1) * (i)
#return opp
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#for i in range(N):
# opp[i] = R_max / (N - 1) * (i)
#return opp

@Rodot- Rodot- linked an issue Apr 30, 2021 that may be closed by this pull request
@wkerzendorf wkerzendorf merged commit 923e59d into master Apr 30, 2021
@Molkree Molkree mentioned this pull request May 12, 2021
2 tasks
atharva-2001 pushed a commit to atharva-2001/tardis that referenced this pull request Oct 1, 2021
* Readded the numba formal integral changes

* Update base.py to match main

* Reverted formal integral instantiation to be more similar to the original C version for consistency

* Moved numba implimentation to the montecarlo_numba folder since this is a numba implementation

* Removed extra ravel

* Added back old formal integral for testing

* Added test for function in the numba formal integral

* Changed the way the shell size is computed, should be correct now

* nevermind

* Moved numba formal integral tests so that paths work out for testing framework

* Moved pointer incrementation to the end of the loop

* Fixed typo

* Switched tests to use numba models

* numba models instantiate with proper data types now

* Fixed numba_formal_integral tests to instantiate numba models with numba compatable types

* Added a couple docstrings with some notes about future improvements

* Streamlined the interface slightly to better catch bugs

* Added some debug statements to watch array sizes in tests

* Changed way size_line and size_shell are created using tau_sobolevs

* Changed the most inner for-loop to be more similar to the C code and updated the njit dict to no longer use fastmath

* Added back in the check for interpolate shells

* Added back in old code for interpolate shells and now computes over the interpolated shells

* Fixed interpolate shells function and made sure dataframes are properly returned when computing the intergral

* Fixed bug in counter for Jred_lu pointer

* More explicit about typing.  the value for SIGMA_THOMSON now comes from the numba config (which is should have in the past).  Should now match C code within test criteria

* Finished tests for the numba formal integral helper functions

* Added some docstrings and removed some commented out code

* Removed old import of C formal integral

* Removed deprecated formal integral import

* Changed test to generate a new numba model as to not interfere with other tests

* removed old C interface

* Updated tests and environment to exclude compilers and Cython

* Reformatted conftest so black doesn't complain

* Removed commented out lines, made cleaner

* Added back montecarlo tests since it apepars some r_packet tests are at least set up here.  Also, readded the setup_package.py file

* Removed commented out packages from the environment file

* Slight optimization and readability improvements

* Further optimization, now pre-computes indices of next resonance point

* Removed old binary search, made formatting fixed

Co-authored-by: Andrew Fullard <andrewgfullard@gmail.com>
Co-authored-by: Wolfgang Kerzendorf <wkerzendorf@gmail.com>
@andrewfullard andrewfullard deleted the numba_formal_integral branch July 20, 2022 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tardis/montecarlo/montecarlo.pyx: negative indices inside 'wraparound=False' causing undefined behavior
3 participants