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

tests for composition #2944

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

Conversation

karthik11135
Copy link

📝 Description

composition tests written and also added a small test for line info

@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and couldn't find your records in my database. I think we don't know each other, or you changed your credentials recently.

Please add your name and email to .mailmap in your current branch and push the changes to this pull request.

In case you need to map an existing alias, follow this example.

@tardis-bot
Copy link
Contributor

tardis-bot commented Jan 12, 2025

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

28	W291  	[*] Trailing whitespace
14	E999  	[ ] SyntaxError: Expected ',', found ':'
10	E902  	[ ] No such file or directory (os error 2)
8	W293  	[*] Blank line contains whitespace
5	G004  	[ ] Logging statement uses f-string
5	I001  	[*] Import block is un-sorted or un-formatted
5	F401  	[*] `tardis.io.model.parse_atom_data.parse_atom_data` imported but unused
4	RET505	[ ] Unnecessary `else` after `return` statement
3	W292  	[*] No newline at end of file
2	INP001	[ ] File `tardis/model/matter/tests/test_composition.py` is part of an implicit namespace package. Add an `__init__.py`.
2	PTH117	[ ] `os.path.isabs()` should be replaced by `Path.is_absolute()`
2	W605  	[*] Invalid escape sequence: `\A`
1	ANN204	[ ] Missing return type annotation for special method `__getitem__`
1	RET506	[ ] Unnecessary `else` after `raise` statement
1	D202  	[*] No blank lines allowed after function docstring (found 1)
1	D406  	[*] Section name should end with a newline ("Returns")
1	D407  	[*] Missing dashed underline after section ("Returns")
1	F541  	[*] f-string without any placeholders

Complete output(might be large):

.github/actions/setup_env/action.yml:4:8: E999 SyntaxError: Expected an expression
.github/actions/setup_env/action.yml:17:1: W293 [*] Blank line contains whitespace
.github/actions/setup_env/action.yml:19:15: W291 [*] Trailing whitespace
.github/actions/setup_env/action.yml:24:1: W293 [*] Blank line contains whitespace
.github/actions/setup_lfs/action.yml:5:8: E999 SyntaxError: Expected an expression
.github/workflows/benchmarks.yml:3:4: E999 SyntaxError: Expected an expression
.github/workflows/benchmarks.yml:20:5: W291 [*] Trailing whitespace
.github/workflows/benchmarks.yml:87:49: W291 [*] Trailing whitespace
.github/workflows/benchmarks.yml:117:81: W291 [*] Trailing whitespace
.github/workflows/benchmarks.yml:118:54: W291 [*] Trailing whitespace
.github/workflows/benchmarks.yml:205:1: W293 [*] Blank line contains whitespace
.github/workflows/benchmarks.yml:224:22: W291 [*] Trailing whitespace
.github/workflows/benchmarks.yml:225:170: W291 [*] Trailing whitespace
.github/workflows/benchmarks.yml:227:84: W291 [*] Trailing whitespace
.github/workflows/benchmarks.yml:244:1: W293 [*] Blank line contains whitespace
.github/workflows/build-docs.yml:7:4: E999 SyntaxError: Expected an expression
.github/workflows/lfs-cache.yml:1:1: E902 No such file or directory (os error 2)
.github/workflows/tests.yml:7:4: E999 SyntaxError: Expected an expression
.mailmap:1:38: E999 SyntaxError: Expected an expression
.mailmap:294:39: W292 [*] No newline at end of file
CHANGELOG.md:4:15: E999 SyntaxError: Expected ',', found ':'
CITATION.cff:3:1: E999 SyntaxError: Invalid annotated assignment target
README.rst:1:1: E999 SyntaxError: Expected a statement
docs/contributing/development/benchmarks.rst:1:1: E999 SyntaxError: Expected a statement
docs/contributing/development/continuous_integration.rst:1:1: E999 SyntaxError: Expected a statement
docs/contributing/development/continuous_integration.rst:16:76: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:18:68: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:21:92: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:22:86: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:48:1: W293 [*] Blank line contains whitespace
docs/contributing/development/continuous_integration.rst:82:70: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:97:78: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:98:94: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:99:83: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:100:96: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:102:97: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:103:62: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:110:90: W291 [*] Trailing whitespace
docs/contributing/development/continuous_integration.rst:111:19: W292 [*] No newline at end of file
docs/contributing/development/running_tests.rst:1:1: E999 SyntaxError: Expected a statement
docs/contributing/development/running_tests.rst:59:112: W291 [*] Trailing whitespace
docs/contributing/development/running_tests.rst:60:124: W291 [*] Trailing whitespace
docs/contributing/development/running_tests.rst:64:92: W291 [*] Trailing whitespace
docs/contributing/development/running_tests.rst:65:107: W291 [*] Trailing whitespace
docs/contributing/development/running_tests.rst:75:62: W291 [*] Trailing whitespace
docs/contributing/development/running_tests.rst:76:85: W292 [*] No newline at end of file
docs/io/output/how_to_rpacket_tracking.ipynb:cell 12:1:62: W291 [*] Trailing whitespace
docs/physics/plasma/equilibrium/tardis_solver_cmfgen.ipynb:1:1: E902 No such file or directory (os error 2)
docs/physics/setup/model.ipynb:cell 2:2:1: I001 [*] Import block is un-sorted or un-formatted
docs/physics/setup/model.ipynb:cell 25:19:12: F541 [*] f-string without any placeholders
docs/quickstart.ipynb:cell 12:1:39: W291 [*] Trailing whitespace
docs/quickstart.ipynb:cell 12:5:35: W291 [*] Trailing whitespace
docs/quickstart.ipynb:cell 16:10:26: W605 [*] Invalid escape sequence: `\A`
docs/quickstart.ipynb:cell 16:11:40: W605 [*] Invalid escape sequence: `\A`
docs/resources/credits.rst:1:1: E999 SyntaxError: Expected a statement
docs/workflows/v_inner_solver_workflow.ipynb:1:1: E902 No such file or directory (os error 2)
tardis/io/configuration/config_reader.py:53:29: G004 Logging statement uses f-string
tardis/io/configuration/config_reader.py:117:9: RET505 Unnecessary `else` after `return` statement
tardis/io/configuration/config_reader.py:141:13: RET505 Unnecessary `else` after `return` statement
tardis/io/configuration/config_reader.py:218:29: G004 Logging statement uses f-string
tardis/io/configuration/schemas/montecarlo_definitions.yml:1:13: E999 SyntaxError: Expected an expression
tardis/io/model/parse_geometry_configuration.py:50:12: PTH117 `os.path.isabs()` should be replaced by `Path.is_absolute()`
tardis/model/base.py:340:12: PTH117 `os.path.isabs()` should be replaced by `Path.is_absolute()`
tardis/model/base.py:375:21: G004 Logging statement uses f-string
tardis/model/matter/tests/test_composition.py:1:1: INP001 File `tardis/model/matter/tests/test_composition.py` is part of an implicit namespace package. Add an `__init__.py`.
tardis/model/matter/tests/test_composition.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/model/matter/tests/test_composition.py:7:45: F401 [*] `tardis.io.model.parse_atom_data.parse_atom_data` imported but unused
tardis/model/matter/tests/test_composition.py:39:1: W293 [*] Blank line contains whitespace
tardis/model/matter/tests/test_composition.py:44:1: W293 [*] Blank line contains whitespace
tardis/model/matter/tests/test_composition.py:60:1: W293 [*] Blank line contains whitespace
tardis/opacities/macro_atom/macroatom_state.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/opacities/opacity_state.py:210:9: ANN204 Missing return type annotation for special method `__getitem__`
tardis/opacities/opacity_state.py:216:9: D407 [*] Missing dashed underline after section ("Returns")
tardis/opacities/opacity_state.py:216:9: D406 [*] Section name should end with a newline ("Returns")
tardis/opacities/opacity_state.py:251:5: D202 [*] No blank lines allowed after function docstring (found 1)
tardis/opacities/tests/__init__.py:1:1: E902 No such file or directory (os error 2)
tardis/opacities/tests/test_opacity_state_numba.py:1:1: INP001 File `tardis/opacities/tests/test_opacity_state_numba.py` is part of an implicit namespace package. Add an `__init__.py`.
tardis/opacities/tests/test_opacity_state_numba.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/plasma/equilibrium/rates/__init__.py:2:5: F401 `tardis.plasma.equilibrium.rates.collision_strengths.UpsilonCMFGENSolver` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/plasma/equilibrium/rates/__init__.py:3:5: F401 `tardis.plasma.equilibrium.rates.collision_strengths.UpsilonRegemorterSolver` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/plasma/equilibrium/rates/__init__.py:6:5: F401 `tardis.plasma.equilibrium.rates.collisional_rates.ThermalCollisionalRateSolver` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/plasma/equilibrium/rates/__init__.py:9:5: F401 `tardis.plasma.equilibrium.rates.radiative_rates.RadiativeRatesSolver` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
tardis/plasma/equilibrium/rates/collisional_ionization_rates.py:1:1: E902 No such file or directory (os error 2)
tardis/plasma/equilibrium/rates/collisional_ionization_strengths.py:1:1: E902 No such file or directory (os error 2)
tardis/plasma/equilibrium/rates/photoionization_rates.py:1:1: E902 No such file or directory (os error 2)
tardis/plasma/equilibrium/rates/photoionization_strengths.py:1:1: E902 No such file or directory (os error 2)
tardis/spectrum/formal_integral.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/spectrum/formal_integral.py:358:13: RET506 Unnecessary `else` after `raise` statement
tardis/spectrum/formal_integral.py:698:5: RET505 Unnecessary `else` after `return` statement
tardis/spectrum/formal_integral.py:734:5: RET505 Unnecessary `else` after `return` statement
tardis/workflows/simple_tardis_workflow.py:230:17: G004 Logging statement uses f-string
tardis/workflows/simple_tardis_workflow.py:449:17: G004 Logging statement uses f-string
tardis/workflows/util.py:1:1: E902 No such file or directory (os error 2)
tardis/workflows/v_inner_solver.py:1:1: E902 No such file or directory (os error 2)
Found 94 errors.
[*] 51 fixable with the `--fix` option.

@tardis-bot
Copy link
Contributor

tardis-bot commented Jan 12, 2025

*beep* *bop*
Hi human,
I ran benchmarks as you asked comparing master (0fc2c76) and the latest commit (665a7f2).
Here are the logs produced by ASV.
Results can also be downloaded as artifacts here.

Significantly changed benchmarks:

All benchmarks:

Benchmarks that have stayed the same:

| Change   | Before [5e2d0bb3] <master>   | After [665a7f24]    | Ratio   | Benchmark (Parameter)                                                                                                               |
|----------|------------------------------|---------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------|
|          | 43.7±30μs                    | 48.8±20μs           | ~1.12   | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_line_emission                                         |
|          | 601±100ns                    | 541±100ns           | ~0.90   | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_pair_creation_opacity_calculation                                |
|          | 3.53±0.2μs                   | 3.18±0.4μs          | ~0.90   | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket_within_shell                              |
|          | 1.70±0.4μs                   | 1.51±0.4μs          | ~0.89   | transport_geometry_calculate_distances.BenchmarkTransportGeometryCalculateDistances.time_calculate_distance_line                    |
|          | 7.66±1μs                     | 6.83±0.6μs          | ~0.89   | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket                                           |
|          | 59.0±30μs                    | 51.7±30μs           | ~0.88   | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_line_scatter                                          |
|          | 691±200ns                    | 561±200ns           | ~0.81   | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_photoabsorption_opacity_calculation                              |
|          | 511±100ns                    | 551±200ns           | 1.08    | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_compton_opacity_calculation                                      |
|          | 2.74±0.03ms                  | 2.92±0.02ms         | 1.07    | opacities_opacity_state.BenchmarkOpacitiesOpacityState.time_opacity_state_initialize('scatter')                                     |
|          | 2.21±1μs                     | 2.32±1μs            | 1.05    | transport_montecarlo_estimators_radfield_estimator_calcs.BenchmarkMontecarloMontecarloNumbaPacket.time_update_line_estimators       |
|          | 735±0.8ns                    | 748±0.2ns           | 1.02    | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_thomson_scatter                                       |
|          | 37.5±0.06μs                  | 38.4±0.04μs         | 1.02    | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_generate_rpacket_tracker_list                  |
|          | 39.2±0.09s                   | 39.0±0.03s          | 1.00    | run_tardis.BenchmarkRunTardis.time_run_tardis                                                                                       |
|          | 1.06±0m                      | 1.06±0m             | 1.00    | run_tardis.BenchmarkRunTardis.time_run_tardis_rpacket_tracking                                                                      |
|          | 2.08±0m                      | 2.08±0m             | 1.00    | spectrum_formal_integral.BenchmarkTransportMontecarloFormalIntegral.time_FormalIntegrator_functions                                 |
|          | 206±0.3ns                    | 207±0.09ns          | 1.00    | spectrum_formal_integral.BenchmarkTransportMontecarloFormalIntegral.time_intensity_black_body                                       |
|          | 1.22±0μs                     | 1.22±0μs            | 1.00    | transport_geometry_calculate_distances.BenchmarkTransportGeometryCalculateDistances.time_calculate_distance_boundary                |
|          | 65.1±0.01ms                  | 65.4±0.5ms          | 1.00    | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_rpacket_trackers_to_dataframe                  |
|          | 2.77±0.5ms                   | 2.76±0.5ms          | 1.00    | transport_montecarlo_single_packet_loop.BenchmarkTransportMontecarloSinglePacketLoop.time_single_packet_loop                        |
|          | 7.41±2μs                     | 7.32±1μs            | 0.99    | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket_volley                                    |
|          | 1.70±0.01ms                  | 1.66±0ms            | 0.98    | transport_montecarlo_main_loop.BenchmarkTransportMontecarloMontecarloMainLoop.time_montecarlo_main_loop                             |
|          | 3.88±0.02ms                  | 3.74±0ms            | 0.96    | opacities_opacity_state.BenchmarkOpacitiesOpacityState.time_opacity_state_initialize('macroatom')                                   |
|          | 3.33±0.4μs                   | 3.16±0.4μs          | 0.95    | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_bad_vpacket                                       |
|          | 22.7±6μs                     | 20.9±4μs            | 0.92    | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_generate_rpacket_last_interaction_tracker_list |

If you want to see the graph of the results, you can check it here

def test_elemental_mass_fraction(composition_instance):
elemental_mass_fraction = composition_instance.elemental_mass_fraction
assert isinstance(elemental_mass_fraction, pd.DataFrame)
np.testing.assert_allclose(elemental_mass_fraction.sum(), 1.0, rtol=1e-3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only a tolerance of 1e-3? That seems large.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No specific reason why exactly 1e-3. thought it would be acceptable tolerance. Will remove.

mass_fractions.index
)

expected_density = mass_fractions.multiply(density_value).divide(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to expected_number_density

@@ -53,6 +53,13 @@ def test_get_species_interactions(
)
assert species_interactions_df.shape == (expected_df_length, 1)

def test_get_middle_half_edges(self, wavelength_range, filter_mode):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this part of this PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought a separate PR for this small test wouldnt look good. I'll create a separate one for this to keep everything clean 👍



@pytest.fixture(scope="function")
def composition_instance(config_verysimple):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at some of the other fixtures we have defined throughout the code. We would prefer a more consistent naming scheme than this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have made changes. Kindly take a look. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants