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

Pytest Warnings Fix - 2 #2833

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

Conversation

KasukabeDefenceForce
Copy link
Contributor

📝 Description

Type: 🪲 bugfix | 🚀 feature | ☣️ breaking change | 🚦 testing | 📝 documentation | 🎢 infrastructure

This PR aims at removing the warnings shown by pytest in the logs. It is continuation of PR #2823 .

📌 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 Sep 30, 2024

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

5	RET505	[ ] Unnecessary `elif` after `return` statement
4	G004  	[ ] Logging statement uses f-string
3	F401  	[*] `numpy` imported but unused
1	PIE808	[*] Unnecessary `start` argument in `range`
1	I001  	[*] Import block is un-sorted or un-formatted

Complete output(might be large):

tardis/energy_input/util.py:387:5: RET505 Unnecessary `elif` after `return` statement
tardis/io/model/parse_radiation_field_configuration.py:118:13: G004 Logging statement uses f-string
tardis/model/matter/composition.py:206:9: RET505 Unnecessary `else` after `return` statement
tardis/plasma/properties/atomic.py:554:9: RET505 Unnecessary `else` after `return` statement
tardis/plasma/properties/atomic.py:585:9: RET505 Unnecessary `else` after `return` statement
tardis/plasma/properties/atomic.py:598:17: G004 Logging statement uses f-string
tardis/plasma/properties/atomic.py:639:9: RET505 Unnecessary `else` after `return` statement
tardis/plasma/properties/nlte_rate_equation_solver.py:302:25: G004 Logging statement uses f-string
tardis/plasma/properties/nlte_rate_equation_solver.py:309:25: G004 Logging statement uses f-string
tardis/visualization/widgets/shell_info.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/visualization/widgets/shell_info.py:1:25: F401 [*] `tardis.base.run_tardis` imported but unused
tardis/visualization/widgets/shell_info.py:2:51: F401 [*] `tardis.io.atom_data.atom_web_download.download_atom_data` imported but unused
tardis/visualization/widgets/shell_info.py:12:17: F401 [*] `numpy` imported but unused
tardis/visualization/widgets/shell_info.py:299:25: PIE808 [*] Unnecessary `start` argument in `range`
Found 14 errors.
[*] 5 fixable with the `--fix` option.

@KasukabeDefenceForce KasukabeDefenceForce marked this pull request as ready for review September 30, 2024 14:05
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 70.49%. Comparing base (b3af245) to head (e7d152c).

Files with missing lines Patch % Lines
tardis/energy_input/util.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2833      +/-   ##
==========================================
- Coverage   70.87%   70.49%   -0.39%     
==========================================
  Files         209      209              
  Lines       15580    15586       +6     
==========================================
- Hits        11043    10987      -56     
- Misses       4537     4599      +62     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tardis-bot
Copy link
Contributor

tardis-bot commented Oct 1, 2024

*beep* *bop*
Hi human,
I ran benchmarks as you asked comparing master (b3af245) and the latest commit (e7d152c).
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 [b3af2456] <master>   | After [e7d152ca]    | Ratio   | Benchmark (Parameter)                                                                                                               |
|----------|------------------------------|---------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------|
|          | 39.3±10μs                    | 47.0±10μs           | ~1.20   | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_line_emission                                         |
|          | 3.25±0.3μs                   | 3.64±0.5μs          | ~1.12   | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket_within_shell                              |
|          | 3.38±0.4μs                   | 3.03±0.7μs          | ~0.90   | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_bad_vpacket                                       |
|          | 1.61±0.3μs                   | 1.43±0.4μs          | ~0.89   | transport_geometry_calculate_distances.BenchmarkTransportGeometryCalculateDistances.time_calculate_distance_line                    |
|          | 651±100ns                    | 551±200ns           | ~0.85   | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_compton_opacity_calculation                                      |
|          | 2.60±1μs                     | 1.88±1μs            | ~0.72   | transport_montecarlo_estimators_radfield_estimator_calcs.BenchmarkMontecarloMontecarloNumbaPacket.time_update_line_estimators       |
|          | 7.32±2μs                     | 7.79±2μs            | 1.06    | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket_volley                                    |
|          | 551±200ns                    | 581±200ns           | 1.05    | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_pair_creation_opacity_calculation                                |
|          | 3.84±0.06ms                  | 3.99±0.03ms         | 1.04    | opacities_opacity_state.BenchmarkOpacitiesOpacityState.time_opacity_state_initialize('macroatom')                                   |
|          | 2.53±0.4ms                   | 2.62±0.4ms          | 1.04    | transport_montecarlo_single_packet_loop.BenchmarkTransportMontecarloSinglePacketLoop.time_single_packet_loop                        |
|          | 592±200ns                    | 611±100ns           | 1.03    | opacities_opacity.BenchmarkMontecarloMontecarloNumbaOpacities.time_photoabsorption_opacity_calculation                              |
|          | 66.2±0.08ms                  | 67.7±1ms            | 1.02    | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_rpacket_trackers_to_dataframe                  |
|          | 2.08±0m                      | 2.08±0m             | 1.00    | spectrum_formal_integral.BenchmarkTransportMontecarloFormalIntegral.time_FormalIntegrator_functions                                 |
|          | 22.2±5μs                     | 22.2±5μs            | 1.00    | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_generate_rpacket_last_interaction_tracker_list |
|          | 1.03±0m                      | 1.02±0m             | 0.99    | run_tardis.BenchmarkRunTardis.time_run_tardis_rpacket_tracking                                                                      |
|          | 1.71±0.03ms                  | 1.69±0ms            | 0.99    | transport_montecarlo_main_loop.BenchmarkTransportMontecarloMontecarloMainLoop.time_montecarlo_main_loop                             |
|          | 38.6±0.1s                    | 37.9±0.06s          | 0.98    | run_tardis.BenchmarkRunTardis.time_run_tardis                                                                                       |
|          | 1.23±0μs                     | 1.20±0.01μs         | 0.98    | transport_geometry_calculate_distances.BenchmarkTransportGeometryCalculateDistances.time_calculate_distance_boundary                |
|          | 6.25±0.7μs                   | 6.14±0.9μs          | 0.98    | transport_montecarlo_vpacket.BenchmarkMontecarloMontecarloNumbaVpacket.time_trace_vpacket                                           |
|          | 2.81±0.01ms                  | 2.72±0ms            | 0.97    | opacities_opacity_state.BenchmarkOpacitiesOpacityState.time_opacity_state_initialize('scatter')                                     |
|          | 53.6±30μs                    | 50.4±20μs           | 0.94    | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_line_scatter                                          |
|          | 33.0±0.03μs                  | 30.8±0.06μs         | 0.93    | transport_montecarlo_packet_trackers.BenchmarkTransportMontecarloPacketTrackers.time_generate_rpacket_tracker_list                  |
|          | 227±0.08ns                   | 207±0.04ns          | 0.91    | spectrum_formal_integral.BenchmarkTransportMontecarloFormalIntegral.time_intensity_black_body                                       |
|          | 795±3ns                      | 724±0.5ns           | 0.91    | transport_montecarlo_interaction.BenchmarkTransportMontecarloInteraction.time_thomson_scatter                                       |

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

@KasukabeDefenceForce KasukabeDefenceForce force-pushed the more_warnings branch 4 times, most recently from d8b8b08 to bc2c160 Compare October 3, 2024 14:02
@KasukabeDefenceForce KasukabeDefenceForce marked this pull request as draft October 3, 2024 14:33
@KasukabeDefenceForce KasukabeDefenceForce force-pushed the more_warnings branch 2 times, most recently from 71e7f0a to b52bece Compare October 4, 2024 10:21
@KasukabeDefenceForce KasukabeDefenceForce marked this pull request as ready for review October 4, 2024 12:08
)
value = np.clip(value, 0, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

What warning does this resolve?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RuntimeWarning: invalid value encountered in sqrt
- np.sqrt(

tardis/plasma/properties/atomic.py Outdated Show resolved Hide resolved
tardis/plasma/properties/atomic.py Outdated Show resolved Hide resolved
@@ -937,7 +935,7 @@ def ion_matrix(ion_coefficients, atomic_number, ion_number):
offdiag = np.zeros(atomic_number)
index = ion_coefficients.index
for i in index:
offdiag[i] = ion_coefficients.loc[i]
offdiag[i] = float(ion_coefficients.loc[i].iloc[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need to have nested .loc.iloc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, to make sure it only extracts a single value and not a series. I will replace iloc with values for consistency and it is slightly faster than iloc.

@@ -961,7 +959,7 @@ def recomb_matrix(recomb_coefficients, atomic_number, ion_number):
offdiag = np.zeros(atomic_number)
index = recomb_coefficients.index
for i in index:
offdiag[i] = recomb_coefficients.loc[i]
offdiag[i] = float(recomb_coefficients.loc[i].values[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this use .loc.values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it does the same thing as iloc, I will update the previous function with values instead of iloc

@@ -48,6 +48,7 @@ def test_atom_data_levels(levels):


def test_atom_data_lines(lines):
lines = lines.sort_index()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't want to overwrite or change pytest fixtures like this. We ran into problems awhile back with tests passing when they were run in a specific order, but not otherwise because of changing the fixtures in tests.

Probably just save the sorted lines to a new variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@@ -935,7 +933,7 @@ def ion_matrix(ion_coefficients, atomic_number, ion_number):
offdiag = np.zeros(atomic_number)
index = ion_coefficients.index
for i in index:
offdiag[i] = ion_coefficients.loc[i]
offdiag[i] = float(ion_coefficients.loc[i].values[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm somewhat surprised you have to cast this to a float. Are ion coefficients ever not floats? Or is this something to do with trying to obtain the value instead of getting a pandas series?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran it again and it showed no warnings without float so I think its fine without it.

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.

6 participants