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

Enhance NLTE Solver First Guess with Multiple Estimation Methods #2971

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rudrakshnalbalwar
Copy link

@rudrakshnalbalwar rudrakshnalbalwar commented Feb 14, 2025

📝 Description

Type: 🚀 feature

Overview
This PR improves the NLTE solver by introducing multiple approaches for computing the first guess for ion number densities and electron density. Previously, the solver assumed all ions were singly ionized as the initial guess. Now, additional methods are supported to improve accuracy and robustness.
fixes #2486
Key Changes
✅ Added multiple methods for computing the first guess:

Singly ionized assumption (default): Maintains existing behavior.
LU decomposition: Uses a one-iteration result from a linearized solver for a better estimate.
Previous solution reuse: Uses results from a prior iteration if available.
Auto mode: Automatically cycles through methods, switching if one fails.

✅ Implemented a fallback mechanism

If one method fails, the solver tries another to prevent failures.

📌 Resources

Examples, notebooks, and links to useful references.

🚦 Testing

How did you test these changes?

  • Testing pipeline
  • Other method (describe)
  • My changes can't be tested (explain why)

☑️ Checklist

  • I requested two reviewers for this pull request
  • I updated the documentation according to my changes
  • I built the documentation by applying the build_docs label

Note: If you are not allowed to perform any of these actions, ping (@) a contributor.

@tardis-bot
Copy link
Contributor

tardis-bot commented Feb 14, 2025

*beep* *bop*
Hi human,
I ran ruff on the latest commit (d52c631).
Here are the outputs produced.
Results can also be downloaded as artifacts here.
Summarised output:

14	W293  	[*] Blank line contains whitespace
9	G004  	[ ] Logging statement uses f-string
3	INP001	[ ] File `tardis/analysis/opacities.py` is part of an implicit namespace package. Add an `__init__.py`.
3	E999  	[ ] SyntaxError: Expected an expression
3	W291  	[*] Trailing whitespace
2	PIE808	[*] Unnecessary `start` argument in `range`
2	I001  	[*] Import block is un-sorted or un-formatted
2	E712  	[*] Avoid equality comparisons to `False`; use `if not ...:` for false checks
2	E722  	[ ] Do not use bare `except`
2	F811  	[ ] Redefinition of unused `monkeysession` from line 6
1	TD005 	[ ] Missing issue description after `TODO`
1	E703  	[*] Statement ends with an unnecessary semicolon
1	F401  	[*] `tardis.tests.test_util.monkeysession` imported but unused

Complete output(might be large):

.github/actions/setup_lfs/action.yml:5:8: E999 SyntaxError: Expected an expression
.github/actions/setup_lfs/action.yml:37:1: W293 [*] Blank line contains whitespace
.github/workflows/lfs-cache.yml:1:12: E999 SyntaxError: Simple statements must be separated by newlines or semicolons
.github/workflows/lfs-cache.yml:38:1: W293 [*] Blank line contains whitespace
.github/workflows/lfs-cache.yml:50:1: W293 [*] Blank line contains whitespace
.github/workflows/lfs-cache.yml:58:1: W293 [*] Blank line contains whitespace
.github/workflows/lfs-cache.yml:63:1: W293 [*] Blank line contains whitespace
.github/workflows/lfs-cache.yml:68:1: W293 [*] Blank line contains whitespace
.github/workflows/lfs-cache.yml:72:1: W293 [*] Blank line contains whitespace
.mailmap:1:38: E999 SyntaxError: Expected an expression
docs/io/grid/how_to_TardisGridTutorial.ipynb:cell 2:1:1: I001 [*] Import block is un-sorted or un-formatted
docs/io/grid/how_to_TardisGridTutorial.ipynb:cell 7:2:74: W291 [*] Trailing whitespace
docs/io/grid/how_to_TardisGridTutorial.ipynb:cell 14:1:47: W291 [*] Trailing whitespace
docs/io/grid/how_to_TardisGridTutorial.ipynb:cell 14:4:46: E703 [*] Statement ends with an unnecessary semicolon
docs/io/grid/how_to_TardisGridTutorial.ipynb:cell 15:2:55: W291 [*] Trailing whitespace
tardis/analysis/opacities.py:1:1: INP001 File `tardis/analysis/opacities.py` is part of an implicit namespace package. Add an `__init__.py`.
tardis/grid/tests/test_grid.py:1:1: INP001 File `tardis/grid/tests/test_grid.py` is part of an implicit namespace package. Add an `__init__.py`.
tardis/io/model/readers/tests/test_arepo_parser.py:1:1: INP001 File `tardis/io/model/readers/tests/test_arepo_parser.py` is part of an implicit namespace package. Add an `__init__.py`.
tardis/plasma/properties/nlte_rate_equation_solver.py:318:25: G004 Logging statement uses f-string
tardis/plasma/properties/nlte_rate_equation_solver.py:325:25: G004 Logging statement uses f-string
tardis/plasma/properties/nlte_rate_equation_solver.py:584:1: W293 [*] Blank line contains whitespace
tardis/plasma/properties/nlte_rate_equation_solver.py:587:1: W293 [*] Blank line contains whitespace
tardis/plasma/properties/nlte_rate_equation_solver.py:592:1: W293 [*] Blank line contains whitespace
tardis/plasma/properties/nlte_rate_equation_solver.py:594:1: W293 [*] Blank line contains whitespace
tardis/plasma/properties/nlte_rate_equation_solver.py:598:13: E722 Do not use bare `except`
tardis/plasma/properties/nlte_rate_equation_solver.py:601:1: W293 [*] Blank line contains whitespace
tardis/plasma/properties/nlte_rate_equation_solver.py:602:17: E722 Do not use bare `except`
tardis/plasma/properties/nlte_rate_equation_solver.py:604:1: W293 [*] Blank line contains whitespace
tardis/plasma/properties/nlte_rate_equation_solver.py:612:1: W293 [*] Blank line contains whitespace
tardis/transport/montecarlo/tests/conftest.py:14:5: F811 Redefinition of unused `opacity_state_initialize` from line 7
tardis/visualization/tools/tests/test_convergence_plot.py:3:1: I001 [*] Import block is un-sorted or un-formatted
tardis/visualization/tools/tests/test_convergence_plot.py:6:36: F401 [*] `tardis.tests.test_util.monkeysession` imported but unused
tardis/visualization/tools/tests/test_convergence_plot.py:87:24: PIE808 [*] Unnecessary `start` argument in `range`
tardis/visualization/tools/tests/test_convergence_plot.py:111:22: PIE808 [*] Unnecessary `start` argument in `range`
tardis/visualization/tools/tests/test_convergence_plot.py:198:9: E712 Avoid equality comparisons to `False`; use `if not ...:` for false checks
tardis/visualization/tools/tests/test_convergence_plot.py:215:9: E712 Avoid equality comparisons to `False`; use `if not ...:` for false checks
tardis/visualization/tools/tests/test_convergence_plot.py:220:40: F811 Redefinition of unused `monkeysession` from line 6
tardis/workflows/simple_tardis_workflow.py:230:17: G004 Logging statement uses f-string
tardis/workflows/simple_tardis_workflow.py:451:17: G004 Logging statement uses f-string
tardis/workflows/standard_tardis_workflow.py:172:13: G004 Logging statement uses f-string
tardis/workflows/standard_tardis_workflow.py:212:17: G004 Logging statement uses f-string
tardis/workflows/v_inner_solver.py:16:3: TD005 Missing issue description after `TODO`
tardis/workflows/v_inner_solver.py:180:17: G004 Logging statement uses f-string
tardis/workflows/v_inner_solver.py:207:17: G004 Logging statement uses f-string
tardis/workflows/v_inner_solver.py:315:17: G004 Logging statement uses f-string
Found 45 errors.
[*] 23 fixable with the `--fix` option (2 hidden fixes can be enabled with the `--unsafe-fixes` option).

@rudrakshnalbalwar
Copy link
Author

Hey @wkerzendorf , @andrewfullard , @DeerWhale , @atharva-2001
Could you please review this and let me know if any changes are needed? Thanks

@rudrakshnalbalwar rudrakshnalbalwar changed the title Feature Enhance NLTE Solver First Guess with Multiple Estimation Methods Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the first guess for NLTE solver
3 participants