-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1e175e
commit aade0aa
Showing
19 changed files
with
653 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ exclude = | |
old, | ||
build, | ||
dist, | ||
tests/*.py | ||
tests/*.py | ||
opac_mixer/patches/*.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.. prt_phasecurve documentation master file, created by | ||
sphinx-quickstart on Mon Jan 11 14:18:49 2021. | ||
You can adapt this file completely to your liking, but it should at least | ||
contain the root `toctree` directive. | ||
API Documentation | ||
================= | ||
|
||
emulator.py | ||
----------- | ||
|
||
.. automodule:: opac_mixer.emulator | ||
|
||
.. autoclass:: Emulator | ||
:members: | ||
|
||
read.py | ||
------- | ||
|
||
.. automodule:: opac_mixer.read | ||
|
||
.. autoclass:: ReadOpac | ||
:members: | ||
.. autoclass:: ReadOpacChubb | ||
:members: | ||
|
||
mix.py | ||
------ | ||
|
||
.. automodule:: opac_mixer.mix | ||
|
||
.. autoclass:: CombineOpacGrid | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
.. prt_phasecurve documentation master file, created by | ||
sphinx-quickstart on Mon Jan 11 14:18:49 2021. | ||
You can adapt this file completely to your liking, but it should at least | ||
contain the root `toctree` directive. | ||
Deployment in code | ||
================== | ||
|
||
Coupling the DeepSet mixing to a radiative transfer solver is easy to do, if you have already some mixing in your radiative transfer solver. | ||
It requires two steps: | ||
|
||
1. Reading in your custom k-tables (see :ref:`Tutorial: Add custom k-tables`) from your radiative transfer solver and training the DeepSet on these (see :ref:`Tutorial: Quick Start`). | ||
|
||
2. Implementing the inference of the neural network in your code | ||
|
||
Here, we will talk about the second step, since the first step is defined at other places in this documentation. | ||
|
||
Numpy implementation | ||
-------------------- | ||
|
||
First, lets start with a simple numpy implementation of the DeepSet: | ||
|
||
.. code-block:: | ||
python | ||
mlp_weights = [weights.numpy() for weights in em.model.weights] | ||
def simple_mlp(kappas): | ||
rep = np.tensordot(kappas, mlp_weights[0], axes=(1,0)) # first dense | ||
rep[rep <= 0.0] = 0.0 | ||
sum_rep = np.sum(rep, axis=1) # sum | ||
dec = np.tensordot(sum_rep, mlp_weights[1], axes=(-1,0)) # second dense | ||
return dec | ||
.. Note:: | ||
|
||
We use input and output scaling! It is therefore important to feed the scaled input to the function and to transform the output back using the inverse output scaling. | ||
|
||
General remarks | ||
--------------- | ||
|
||
The exact deployment deployment depends on the code, language and framework you want to couple it to. | ||
Some general recommendations can be found in the paper (Appendix). | ||
|
||
Basically, the following things are always needed: | ||
|
||
0. (Implement the read in and interpolation of the individual k-tables and the chemistry in your model) | ||
|
||
1. Export the weights (there is an ``export`` function on the ``Emulator`` class) | ||
|
||
2. Read the weights into your model | ||
|
||
3. Implement the scaling functions (see ``opac_mixer/utils/scaling.py``) | ||
|
||
4. Implement the DeepSet mixing consisting of: | ||
|
||
- A first matrix vector multiplication for each of the individual species | ||
|
||
- A relu activation | ||
|
||
- A sum over all hidden representations | ||
|
||
- Another matrix vector multiplication | ||
|
||
.. Note:: | ||
|
||
It would generally be the fastest option to stack the matrix vector multiplications and deploy them using a vectorized matrix vector multiplication. Keep that in mind. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,23 +5,30 @@ | |
Welcome to opac_mixer's documentation! | ||
========================================== | ||
opacity mixing accelerated | ||
There is a pressing need for fast opacity mixing in the correlated-k approximation. | ||
This python package builds a framework for machine learning on grids of k-tables. | ||
|
||
To get the most out of this code, start by installing the code (see :ref:`Installation`). | ||
Once installed, head over to :ref:`Tutorial: Quick Start` to see a quick explanation of how to use the code. | ||
|
||
Finally, if you want to couple the code to your own radiative transfer, you might need to read in your own k-tables. | ||
Thats easy, and its explained in :ref:`Tutorial: Add custom k-tables`. You also need to write a short code passage to deploy the mixing in the radiative transfer solver (see :ref:`Deployment in code`). | ||
|
||
If you find this work useful, please consider to cite the following paper: | ||
Schneider et al. (in review) | ||
|
||
WARNING: The paper is not yet published, please do not use this code, before it is published | ||
|
||
.. toctree:: | ||
:maxdepth: 0 | ||
:caption: Contents | ||
|
||
Installation | ||
notebooks/training.ipynb | ||
Coupling | ||
notebooks/extend_reader.ipynb | ||
API | ||
notebooks/petitRADTRANS.ipynb | ||
notebooks/hp_tuning.ipynb | ||
notebooks/extend_reader.ipynb | ||
|
||
Indices and tables | ||
================== | ||
|
||
* :ref:`genindex` | ||
* :ref:`search` | ||
|
||
Copyright 2023 Aaron Schneider. Feel free to contact me for any questions via `mail <mailto:[email protected]>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.