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

Merged
merged 32 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
73a2176
Basic skeleton
andrewfullard Jul 23, 2024
5fa2533
Lots of progress
andrewfullard Jul 23, 2024
2854354
Adds setup method, refactors some functions, removes unused items
andrewfullard Jul 23, 2024
0dd2e4c
Move convergence setup to setup method
andrewfullard Jul 23, 2024
8d4b043
Add docs notebook, fix a couple of errors
andrewfullard Jul 23, 2024
8d49aaf
Move setup to init
andrewfullard Jul 23, 2024
55d352f
Fix iteration and convergence
andrewfullard Jul 23, 2024
3fc1e26
Simplify spectrumsolver init
andrewfullard Jul 23, 2024
14ad513
Separate plasma "solver" and simulation state updates
andrewfullard Jul 23, 2024
b7befb5
Simplify convergence solver setup with a dict.
andrewfullard Jul 23, 2024
099d046
Minor formatting change
andrewfullard Jul 23, 2024
c75b5ba
Minor refactoring
andrewfullard Jul 24, 2024
b215d57
Fixes plasma update step
andrewfullard Jul 29, 2024
25fc7fe
Fixes loggers and progress bars
andrewfullard Aug 12, 2024
774015c
Fixes convergence plot rendering
andrewfullard Aug 12, 2024
dc65b19
Fixes convergence plots in the final iteration
andrewfullard Aug 12, 2024
453e8d1
black
andrewfullard Aug 12, 2024
f6db396
Simplify convergence plot updating
andrewfullard Aug 12, 2024
d51c868
Move logging handling to a separate class
andrewfullard Aug 12, 2024
62127e6
Add HDF output capability to solver
andrewfullard Aug 12, 2024
8a002fa
Move more basic logging back into workflow
andrewfullard Aug 12, 2024
894fabc
Add not-converged error message
andrewfullard Aug 12, 2024
1d5c843
Update notebook with export option
andrewfullard Aug 12, 2024
4ebe0d0
Added simple base workflow and changed some verbiage
andrewfullard Aug 13, 2024
587bddc
Fix typo
andrewfullard Aug 13, 2024
03e9d47
Black format
andrewfullard Aug 15, 2024
ece6a62
Fixes spectrum solver test
andrewfullard Aug 15, 2024
f18a3c2
Some suggested refactoring
andrewfullard Aug 16, 2024
8f24d7f
Fix and rename workflows
andrewfullard Oct 1, 2024
a0fcb09
Apply black
andrewfullard Oct 1, 2024
9e3c968
Match Jack's opacity state setup for easier fixing later
andrewfullard Oct 7, 2024
05e2b82
Ruff formatting
andrewfullard Oct 14, 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": 8,
"metadata": {},
"outputs": [],
"source": [
"from tardis.io.configuration.config_reader import Configuration\n",
"from tardis.workflows.simple_tardis_workflow import SimpleTARDISWorkflow\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"config = Configuration.from_yaml('../tardis_example.yml')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"workflow = SimpleTARDISWorkflow(config)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"workflow.run()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"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.4"
}
},
"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.io.configuration.config_reader import Configuration\n",
"from tardis.workflows.standard_tardis_workflow import StandardTARDISWorkflow\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"config = Configuration.from_yaml('../tardis_example.yml')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"workflow = StandardTARDISWorkflow(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": 5,
"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.4"
}
},
"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