Skip to content

Commit

Permalink
fix the widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
wkerzendorf committed Jul 28, 2024
1 parent d381f02 commit fcce9e0
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 97 deletions.
228 changes: 161 additions & 67 deletions docs/physics/plasma/construction_simple_plasma.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,73 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"LOADING\n",
"Scalene extension successfully loaded. Note: Scalene currently only\n",
"supports CPU+GPU profiling inside Jupyter notebooks. For full Scalene\n",
"profiling, use the command line version. To profile in line mode, use\n",
"`%scrun [options] statement`. To profile in cell mode, use `%%scalene\n",
"[options]` followed by your code.\n",
"\n",
"NOTE: in Jupyter notebook on MacOS, Scalene cannot profile child\n",
"processes. Do not run to try Scalene with multiprocessing in Jupyter\n",
"Notebook.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/wkerzend/python/tardis/tardis/__init__.py:20: UserWarning: Astropy is already imported externally. Astropy should be imported after TARDIS.\n",
" warnings.warn(\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "72ded6233c124eeba35259b3c035ab59",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Iterations: 0/? [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "32dafcfb559b481e902613c28442602a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Packets: 0/? [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from astropy import units as u\n",
"\n",
"%load_ext scalene\n",
"from tardis.io.atom_data import AtomData\n",
"from tardis.plasma.assembly.base import PlasmaSolverFactory\n",
"from tardis.plasma.radiation_field import DilutePlanckianRadiationField\n",
"#from tardis.plasma.properties.plasma_input import T"
"#from tardis.plasma.properties.plasma_input import T\n",
"\n",
"%load_ext pyinstrument\n"
]
},
{
Expand All @@ -29,7 +84,9 @@
"metadata": {},
"outputs": [],
"source": [
"atom_data = AtomData.from_hdf('kurucz_cd23_chianti_H_He.h5')"
"NO_OF_CELLS = 1000\n",
"temperatures_rad = np.ones(NO_OF_CELLS) * 10000 * u.K\n",
"dilution_factor = np.ones(NO_OF_CELLS) * 0.1"
]
},
{
Expand All @@ -38,8 +95,7 @@
"metadata": {},
"outputs": [],
"source": [
"temperatures_rad = np.ones(10) * 10000 * u.K\n",
"dilution_factor = np.ones(10) * 0.1"
"d_radfield = DilutePlanckianRadiationField(temperature=temperatures_rad, dilution_factor=dilution_factor)"
]
},
{
Expand All @@ -48,7 +104,9 @@
"metadata": {},
"outputs": [],
"source": [
"d_radfield = DilutePlanckianRadiationField(temperature=temperatures_rad, dilution_factor=dilution_factor)"
"base_density = 1e-15 * u.Unit('g/cm^3')\n",
"number_densities = pd.DataFrame(columns=range(NO_OF_CELLS), index=[1,26,28])\n",
"number_densities.values[:] = 0.5 * (base_density / u.u).to(1/u.cm**3).value\n"
]
},
{
Expand All @@ -57,92 +115,128 @@
"metadata": {},
"outputs": [],
"source": [
"plasma_solver_factory = PlasmaSolverFactory(atom_data, selected_atomic_numbers=[1, 2])"
"atom_data = AtomData.from_hdf('kurucz_cd23_chianti_H_He.h5')\n",
"plasma_solver_factory = PlasmaSolverFactory(atom_data, selected_atomic_numbers=[1,26,28])\n",
"plasma_solver_factory.setup_factory()\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"base_density = 1e-15 * u.Unit('g/cm^3')\n",
"number_densities = pd.DataFrame(columns=[1], index=[1,2])\n",
"number_densities.loc[1] = 0.5 * (base_density / u.u).to(1/u.cm**3).value\n",
"number_densities.loc[2] = 0.5 * (base_density / u.u).to(1/u.cm**3).value"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"ename": "PlasmaMissingModule",
"evalue": "Module PartitionFunction requires input level_boltzmann_factor which has not been added to this plasma",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mPlasmaMissingModule\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[14], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mplasma_solver_factory\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43massemble\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnumber_densities\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43md_radfield\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mu\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mday\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/python/tardis/tardis/plasma/assembly/base.py:506\u001b[0m, in \u001b[0;36mPlasmaSolverFactory.assemble\u001b[0;34m(self, number_densities, dilute_planckian_radiation_field, time_explosion, electron_densities)\u001b[0m\n\u001b[1;32m 504\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msetup_electron_densities(electron_densities)\n\u001b[1;32m 505\u001b[0m kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhelium_treatment\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhelium_treatment\n\u001b[0;32m--> 506\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mBasePlasma\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 507\u001b[0m \u001b[43m \u001b[49m\u001b[43mplasma_properties\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mplasma_modules\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 508\u001b[0m \u001b[43m \u001b[49m\u001b[43mproperty_kwargs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mproperty_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 509\u001b[0m \u001b[43m \u001b[49m\u001b[43mplasma_solver_settings\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mplasma_solver_settings\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 510\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 511\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/python/tardis/tardis/io/util.py:195\u001b[0m, in \u001b[0;36mHDFWriterMixin.__new__\u001b[0;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m 193\u001b[0m instance \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msuper\u001b[39m(HDFWriterMixin, \u001b[38;5;28mcls\u001b[39m)\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__new__\u001b[39m(\u001b[38;5;28mcls\u001b[39m)\n\u001b[1;32m 194\u001b[0m instance\u001b[38;5;241m.\u001b[39moptional_hdf_properties \u001b[38;5;241m=\u001b[39m []\n\u001b[0;32m--> 195\u001b[0m \u001b[43minstance\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 196\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m instance\n",
"File \u001b[0;32m~/python/tardis/tardis/plasma/base.py:39\u001b[0m, in \u001b[0;36mBasePlasma.__init__\u001b[0;34m(self, plasma_properties, property_kwargs, plasma_solver_settings, **kwargs)\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mplasma_properties \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_init_properties(\n\u001b[1;32m 36\u001b[0m plasma_properties, property_kwargs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs\n\u001b[1;32m 37\u001b[0m )\n\u001b[1;32m 38\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mplasma_solver_settings \u001b[38;5;241m=\u001b[39m plasma_solver_settings\n\u001b[0;32m---> 39\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_build_graph\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 40\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mupdate(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
"File \u001b[0;32m~/python/tardis/tardis/plasma/base.py:101\u001b[0m, in \u001b[0;36mBasePlasma._build_graph\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 99\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m \u001b[38;5;28minput\u001b[39m \u001b[38;5;129;01min\u001b[39;00m plasma_property\u001b[38;5;241m.\u001b[39minputs:\n\u001b[1;32m 100\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28minput\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutputs_dict:\n\u001b[0;32m--> 101\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m PlasmaMissingModule(\n\u001b[1;32m 102\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mModule \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mplasma_property\u001b[38;5;241m.\u001b[39mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m requires input \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 103\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28minput\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m which has not been added\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 104\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m to this plasma\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 105\u001b[0m )\n\u001b[1;32m 106\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 107\u001b[0m position \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutputs_dict[\u001b[38;5;28minput\u001b[39m]\u001b[38;5;241m.\u001b[39moutputs\u001b[38;5;241m.\u001b[39mindex(\u001b[38;5;28minput\u001b[39m)\n",
"\u001b[0;31mPlasmaMissingModule\u001b[0m: Module PartitionFunction requires input level_boltzmann_factor which has not been added to this plasma"
"name": "stdout",
"output_type": "stream",
"text": [
"SCRUN MAGIC\n"
]
},
{
"data": {
"text/html": [
"\n",
" <iframe\n",
" width=\"100%\"\n",
" height=\"400\"\n",
" src=\"http://localhost:8182\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" \n",
" ></iframe>\n",
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x31e16f5c0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plasma_solver_factory.assemble(number_densities, d_radfield, 5 * u.day)"
"%scrun plasma_solver = plasma_solver_factory.assemble(number_densities, d_radfield, 5 * u.day)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>0</th>\n",
" </tr>\n",
" <tr>\n",
" <th>atomic_number</th>\n",
" <th>ion_number</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">1</th>\n",
" <th>0</th>\n",
" <td>2.245918e-04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>3.011070e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"3\" valign=\"top\">2</th>\n",
" <th>0</th>\n",
" <td>1.405189e-15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2.206015e-03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3.011070e+08</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"[tardis.plasma.properties.plasma_input.DilutePlanckianRadField,\n",
" tardis.plasma.properties.plasma_input.DilutePlanckianRadField,\n",
" tardis.plasma.properties.plasma_input.NumberDensity,\n",
" tardis.plasma.properties.plasma_input.TimeExplosion,\n",
" tardis.plasma.properties.plasma_input.AtomicData,\n",
" tardis.plasma.properties.plasma_input.JBlues,\n",
" tardis.plasma.properties.plasma_input.LinkTRadTElectron,\n",
" tardis.plasma.properties.plasma_input.HeliumTreatment,\n",
" tardis.plasma.properties.plasma_input.ContinuumInteractionSpecies,\n",
" tardis.plasma.properties.plasma_input.NLTEIonizationSpecies,\n",
" tardis.plasma.properties.plasma_input.NLTEExcitationSpecies,\n",
" tardis.plasma.properties.plasma_input.TRadiative,\n",
" tardis.plasma.properties.plasma_input.DilutionFactor,\n",
" tardis.plasma.properties.general.BetaRadiation,\n",
" tardis.plasma.properties.atomic.Levels,\n",
" tardis.plasma.properties.atomic.Lines,\n",
" tardis.plasma.properties.partition_function.PartitionFunction,\n",
" tardis.plasma.properties.general.GElectron,\n",
" tardis.plasma.properties.atomic.IonizationData,\n",
" tardis.plasma.properties.atomic.LinesLowerLevelIndex,\n",
" tardis.plasma.properties.atomic.LinesUpperLevelIndex,\n",
" tardis.opacities.tau_sobolev.TauSobolev,\n",
" tardis.plasma.properties.radiative_properties.StimulatedEmissionFactor,\n",
" tardis.plasma.properties.general.SelectedAtoms,\n",
" tardis.plasma.properties.general.ElectronTemperature,\n",
" tardis.plasma.properties.partition_function.LevelBoltzmannFactorLTE,\n",
" tardis.plasma.properties.ion_population.PhiSahaLTE,\n",
" tardis.plasma.properties.level_population.LevelNumberDensity,\n",
" tardis.plasma.properties.ion_population.IonNumberDensity]"
" 0\n",
"atomic_number ion_number \n",
"1 0 2.245918e-04\n",
" 1 3.011070e+08\n",
"2 0 1.405189e-15\n",
" 1 2.206015e-03\n",
" 2 3.011070e+08"
]
},
"execution_count": 16,
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plasma_solver_factory.plasma_modules"
"plasma_solver.ion_number_density"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class SimulationState(HDFWriterMixin):
"density",
"r_inner",
"time_explosion",
"abundance",
]
hdf_name = "simulation_state"

Expand Down
Loading

0 comments on commit fcce9e0

Please sign in to comment.