documents/tutorials/elower_setting.ipynb
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Reducing Device Memory Use by Setting the Optimal Elower Maximum"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"PreMODIT make a grid of Elower. When the maximum value of Elower in the database is large, \n",
"the use of the device memory becomes too large for your GPU CUDA memory.\n",
"We can use the lines whose Elower are below user-defined value, by using elower_max option in mdb. \n",
"But, before that, we need to know the optimal value of the max Elower. This tutorial explains how to do that.\n",
"First use FP64 as usual. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from jax import config\n",
"config.update(\"jax_enable_x64\", True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make \"mdb\"."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-10-02 10:20:59.968678: W external/xla/xla/service/gpu/nvptx_compiler.cc:765] The NVIDIA driver's CUDA version is 12.2 which is older than the ptxas CUDA version (12.6.20). Because the driver is older than the ptxas version, XLA is disabling parallel compilation, which may slow down compilation. You should update your NVIDIA driver or use the NVIDIA-provided CUDA forward compatibility packages.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"xsmode = premodit\n",
"xsmode assumes ESLOG in wavenumber space: xsmode=premodit\n",
"======================================================================\n",
"The wavenumber grid should be in ascending order.\n",
"The users can specify the order of the wavelength grid by themselves.\n",
"Your wavelength grid is in *** descending *** order\n",
"======================================================================\n",
"HITRAN exact name= (12C)(16O)\n",
"radis engine = vaex\n",
"\t\t => Downloading from http://www.exomol.com/db/CO/12C-16O/Li2015/12C-16O__Li2015.def\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/kawahara/exojax/src/exojax/utils/grids.py:144: UserWarning: Resolution may be too small. R=224940.4617885842\n",
" warnings.warn(\"Resolution may be too small. R=\" + str(resolution), UserWarning)\n",
"/home/kawahara/exojax/src/exojax/utils/molname.py:197: FutureWarning: e2s will be replaced to exact_molname_exomol_to_simple_molname.\n",
" warnings.warn(\n",
"/home/kawahara/exojax/src/exojax/utils/molname.py:91: FutureWarning: exojax.utils.molname.exact_molname_exomol_to_simple_molname will be replaced to radis.api.exomolapi.exact_molname_exomol_to_simple_molname.\n",
" warnings.warn(\n",
"/home/kawahara/exojax/src/exojax/utils/molname.py:91: FutureWarning: exojax.utils.molname.exact_molname_exomol_to_simple_molname will be replaced to radis.api.exomolapi.exact_molname_exomol_to_simple_molname.\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\t\t => Downloading from http://www.exomol.com/db/CO/12C-16O/Li2015/12C-16O__Li2015.pf\n",
"\t\t => Downloading from http://www.exomol.com/db/CO/12C-16O/Li2015/12C-16O__Li2015.states.bz2\n",
"\t\t => Downloading from http://www.exomol.com/db/CO/12C-16O/12C-16O__H2.broad\n",
"\t\t => Downloading from http://www.exomol.com/db/CO/12C-16O/12C-16O__He.broad\n",
"\t\t => Downloading from http://www.exomol.com/db/CO/12C-16O/12C-16O__air.broad\n",
"Note: Caching states data to the vaex format. After the second time, it will become much faster.\n",
"Molecule: CO\n",
"Isotopologue: 12C-16O\n",
"Background atmosphere: H2\n",
"ExoMol database: None\n",
"Local folder: .database/CO/12C-16O/Li2015\n",
"Transition files: \n",
"\t => File 12C-16O__Li2015.trans\n",
"\t\t => Downloading from http://www.exomol.com/db/CO/12C-16O/Li2015/12C-16O__Li2015.trans.bz2\n",
"\t\t => Caching the *.trans.bz2 file to the vaex (*.h5) format. After the second time, it will become much faster.\n",
"\t\t => You can deleted the 'trans.bz2' file by hand.\n",
"Broadening code level: a0\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/kawahara/exojax/src/radis/radis/api/exomolapi.py:685: AccuracyWarning: The default broadening parameter (alpha = 0.07 cm^-1 and n = 0.5) are used for J'' > 80 up to J'' = 152\n",
" warnings.warn(\n"
]
}
],
"source": [
"from exojax.utils.grids import wavenumber_grid\n",
"from exojax.spec.api import MdbExomol\n",
"\n",
"nu_grid, wav, resolution = wavenumber_grid(2200.,\n",
" 2300.,\n",
" 10000,\n",
" unit=\"cm-1\",\n",
" xsmode=\"premodit\")\n",
"mdb = MdbExomol(\".database/CO/12C-16O/Li2015\", nurange=nu_grid)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Because the device memory use (and computational cost) is proportional to the maximum of Elower,\n",
"we should check what the maximum value of Elower is."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"522.4751 - 84862.9693 cm-1\n"
]
}
],
"source": [
"import numpy as np\n",
"print(np.min(mdb.elower),\"-\",np.max(mdb.elower),\"cm-1\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We assume we will use < 700K. Then, ~85000 cm-1 is enough high. \n",
"spec.optgrid.optelower can recommend the optimal value of Elower that does not change the cross section within 1 %."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Maximum Elower = 84862.9693\n",
"OpaPremodit: initialization without parameters setting\n",
"Call self.apply_params() to complete the setting.\n",
"OpaPremodit: params manually set.\n",
"OpaPremodit: Tref_broadening is set to 455.19226706964173 K\n",
"# of reference width grid : 2\n",
"# of temperature exponent grid : 2\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"uniqidx: 0it [00:00, ?it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Premodit: Twt= 700.0 K Tref= 296.0 K\n",
"Making LSD:|--------------------| 0%"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Making LSD:|####################| 100%\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"opt Emax: 84%|████████▍ | 711/845 [04:40<00:52, 2.53it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found the optimal maximum elower: 13922.4751 cm-1\n",
"optimal elower_max= 13922.4751\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"from exojax.spec.optgrid import optelower\n",
"\n",
"Tmax = 700.0 #K\n",
"Pmin = 1.e-8 #bar\n",
"\n",
"Eopt = optelower(mdb, nu_grid, Tmax, Pmin)\n",
"print(\"optimal elower_max=\",Eopt)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The optimal value of the maximum Elower is just 13923 cm-1. We can use elower_max option to set the user-defined Elower max value."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/kawahara/exojax/src/exojax/utils/molname.py:197: FutureWarning: e2s will be replaced to exact_molname_exomol_to_simple_molname.\n",
" warnings.warn(\n",
"/home/kawahara/exojax/src/exojax/utils/molname.py:91: FutureWarning: exojax.utils.molname.exact_molname_exomol_to_simple_molname will be replaced to radis.api.exomolapi.exact_molname_exomol_to_simple_molname.\n",
" warnings.warn(\n",
"/home/kawahara/exojax/src/exojax/utils/molname.py:91: FutureWarning: exojax.utils.molname.exact_molname_exomol_to_simple_molname will be replaced to radis.api.exomolapi.exact_molname_exomol_to_simple_molname.\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"HITRAN exact name= (12C)(16O)\n",
"radis engine = vaex\n",
"Molecule: CO\n",
"Isotopologue: 12C-16O\n",
"Background atmosphere: H2\n",
"ExoMol database: None\n",
"Local folder: .database/CO/12C-16O/Li2015\n",
"Transition files: \n",
"\t => File 12C-16O__Li2015.trans\n",
"Broadening code level: a0\n"
]
}
],
"source": [
"mdb = MdbExomol(\".database/CO/12C-16O/Li2015\", nurange=nu_grid, elower_max=13923.)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"522.4751 - 13791.2151 cm-1\n"
]
}
],
"source": [
"print(np.min(mdb.elower),\"-\",np.max(mdb.elower),\"cm-1\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.8 ('base')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.19"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "72bc7f8b1808a6f5ada3c6a20601509b8b1843160436d276d47f2ba819b3753b"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}