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

Simulation solver workflow #2730

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bf4fca1
Basic skeleton
andrewfullard Jul 23, 2024
73f55a4
Lots of progress
andrewfullard Jul 23, 2024
ffbc45e
Adds setup method, refactors some functions, removes unused items
andrewfullard Jul 23, 2024
e85a6c9
Move convergence setup to setup method
andrewfullard Jul 23, 2024
76ae414
Add docs notebook, fix a couple of errors
andrewfullard Jul 23, 2024
1bb1d47
Move setup to init
andrewfullard Jul 23, 2024
516fa65
Fix iteration and convergence
andrewfullard Jul 23, 2024
550f4e7
Simplify spectrumsolver init
andrewfullard Jul 23, 2024
afca806
Separate plasma "solver" and simulation state updates
andrewfullard Jul 23, 2024
3a47c9f
Simplify convergence solver setup with a dict.
andrewfullard Jul 23, 2024
83dd33a
Minor formatting change
andrewfullard Jul 23, 2024
bf127de
Minor refactoring
andrewfullard Jul 24, 2024
6b11f0b
Fixes plasma update step
andrewfullard Jul 29, 2024
6f705bf
Fixes loggers and progress bars
andrewfullard Aug 12, 2024
0f369af
Fixes convergence plot rendering
andrewfullard Aug 12, 2024
01e5cc3
Fixes convergence plots in the final iteration
andrewfullard Aug 12, 2024
2351c8b
black
andrewfullard Aug 12, 2024
692e3b9
Simplify convergence plot updating
andrewfullard Aug 12, 2024
dfca04e
Move logging handling to a separate class
andrewfullard Aug 12, 2024
b67f6cb
Add HDF output capability to solver
andrewfullard Aug 12, 2024
f9f31d4
Move more basic logging back into workflow
andrewfullard Aug 12, 2024
4de0e1f
Add not-converged error message
andrewfullard Aug 12, 2024
94f749b
Update notebook with export option
andrewfullard Aug 12, 2024
c2a636a
Added simple base workflow and changed some verbiage
andrewfullard Aug 13, 2024
011c415
Fix typo
andrewfullard Aug 13, 2024
a68ebaa
Black format
andrewfullard Aug 15, 2024
e36ccd5
Fixes spectrum solver test
andrewfullard Aug 15, 2024
79df0e3
Some suggested refactoring
andrewfullard Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions docs/workflows/simple_workflow.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from tardis.workflows.simple_simulation import SimpleSimulation\n",
"from tardis.io.configuration.config_reader import Configuration"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"config = Configuration.from_yaml('../tardis_example.yml')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"workflow = SimpleSimulation(config)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"workflow.run()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spectrum = workflow.spectrum_solver.spectrum_real_packets\n",
"spectrum_virtual = workflow.spectrum_solver.spectrum_virtual_packets\n",
"spectrum_integrated = workflow.spectrum_solver.spectrum_integrated"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"plt.figure(figsize=(10, 6.5))\n",
"\n",
"spectrum.plot(label=\"Normal packets\")\n",
"spectrum_virtual.plot(label=\"Virtual packets\")\n",
"spectrum_integrated.plot(label='Formal integral')\n",
"\n",
"plt.xlim(500, 9000)\n",
"plt.title(\"TARDIS example model spectrum\")\n",
"plt.xlabel(\"Wavelength [$\\AA$]\")\n",
"plt.ylabel(\"Luminosity density [erg/s/$\\AA$]\")\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "tardis",
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
110 changes: 110 additions & 0 deletions docs/workflows/standard_workflow.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from tardis.workflows.standard_simulation import StandardSimulation\n",
"from tardis.io.configuration.config_reader import Configuration"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"config = Configuration.from_yaml('../tardis_example.yml')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"workflow = StandardSimulation(config, show_convergence_plots=True,show_progress_bars=True,convergence_plots_kwargs={\"export_convergence_plots\":True})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"workflow.run()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spectrum = workflow.spectrum_solver.spectrum_real_packets\n",
"spectrum_virtual = workflow.spectrum_solver.spectrum_virtual_packets\n",
"spectrum_integrated = workflow.spectrum_solver.spectrum_integrated"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"plt.figure(figsize=(10, 6.5))\n",
"\n",
"spectrum.plot(label=\"Normal packets\")\n",
"spectrum_virtual.plot(label=\"Virtual packets\")\n",
"spectrum_integrated.plot(label='Formal integral')\n",
"\n",
"plt.xlim(500, 9000)\n",
"plt.title(\"TARDIS example model spectrum\")\n",
"plt.xlabel(\"Wavelength [$\\AA$]\")\n",
"plt.ylabel(\"Luminosity density [erg/s/$\\AA$]\")\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "tardis",
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion tardis/spectrum/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SpectrumSolver(HDFWriterMixin):
hdf_name = "spectrum"

def __init__(
self, transport_state, spectrum_frequency_grid, integrator_settings=None
self, transport_state, spectrum_frequency_grid, integrator_settings
):
self.transport_state = transport_state
self.spectrum_frequency_grid = spectrum_frequency_grid
Expand Down
8 changes: 4 additions & 4 deletions tardis/spectrum/tests/test_spectrum_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_initialization(self, simulation):
transport_state = simulation.transport.transport_state
spectrum_frequency_grid = simulation.transport.spectrum_frequency_grid

solver = SpectrumSolver(transport_state, spectrum_frequency_grid)
solver = SpectrumSolver(transport_state, spectrum_frequency_grid, None)
assert solver.transport_state == transport_state
assert np.array_equal(
solver.spectrum_frequency_grid.value, spectrum_frequency_grid.value
Expand All @@ -60,7 +60,7 @@ def test_spectrum_real_packets(self, simulation):
transport_state = simulation.transport.transport_state
spectrum_frequency_grid = simulation.transport.spectrum_frequency_grid

solver = SpectrumSolver(transport_state, spectrum_frequency_grid)
solver = SpectrumSolver(transport_state, spectrum_frequency_grid, None)
result = solver.spectrum_real_packets.luminosity
key = "simulation/spectrum_solver/spectrum_real_packets/luminosity"
expected = self.get_expected_data(key)
Expand All @@ -76,7 +76,7 @@ def test_spectrum_real_packets_reabsorbed(self, simulation):
transport_state = simulation.transport.transport_state
spectrum_frequency_grid = simulation.transport.spectrum_frequency_grid

solver = SpectrumSolver(transport_state, spectrum_frequency_grid)
solver = SpectrumSolver(transport_state, spectrum_frequency_grid, None)
result = solver.spectrum_real_packets_reabsorbed.luminosity
key = "simulation/spectrum_solver/spectrum_real_packets_reabsorbed/luminosity"
expected = self.get_expected_data(key)
Expand All @@ -92,7 +92,7 @@ def test_solve(self, simulation):
transport_state = simulation.transport.transport_state
spectrum_frequency_grid = simulation.transport.spectrum_frequency_grid

solver = SpectrumSolver(transport_state, spectrum_frequency_grid)
solver = SpectrumSolver(transport_state, spectrum_frequency_grid, None)
result_real, result_virtual, result_integrated = solver.solve(
transport_state
)
Expand Down
Empty file added tardis/workflows/__init__.py
Empty file.
Loading
Loading