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

add value error to ensure active virtual packet logging in SDECPlotter #1597

Merged

Conversation

yuyizheng1112
Copy link
Contributor

@yuyizheng1112 yuyizheng1112 commented May 31, 2021

This PR allows SDECPlotter to raise error if virtual_packet_logging is not set to True.

Motivation and context

Before this change, SDECPlotter can work even when virtual_packet_logging is not active. In this case, an index error is raised by function in matplotlib while calling the function plotter.generate_plot_mlp(), and the output is confusing.
Since SDECPlotter requires virtual_packet_logging, it should ensure the option is set to true.
How has this been tested?

  • Testing pipeline.
  • Other.

Examples

Before change:
image

After change:
截屏2021-06-21 下午4 25 57

Type of change

  • Bug fix.
  • New feature.
  • Breaking change.
  • None of the above.

Checklist

  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
    • (optional) I have built the documentation on my fork following the instructions.
  • I have assigned and requested two reviewers for this pull request.

@codecov
Copy link

codecov bot commented May 31, 2021

Codecov Report

Merging #1597 (fc9db95) into master (011f9b7) will decrease coverage by 5.81%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1597      +/-   ##
==========================================
- Coverage   67.70%   61.88%   -5.82%     
==========================================
  Files          68       62       -6     
  Lines        6091     5733     -358     
==========================================
- Hits         4124     3548     -576     
- Misses       1967     2185     +218     
Impacted Files Coverage Δ
...dis/tardis/montecarlo/montecarlo_numba/r_packet.py 25.43% <0.00%> (-5.54%) ⬇️
tardis/tardis/visualization/tools/sdec_plot.py 9.94% <0.00%> (-4.94%) ⬇️
tardis/tardis/io/config_reader.py 82.08% <0.00%> (-4.25%) ⬇️
tardis/tardis/montecarlo/spectrum.py 69.23% <0.00%> (-2.47%) ⬇️
tardis/tardis/plasma/properties/util/macro_atom.py 29.03% <0.00%> (-2.22%) ⬇️
tardis/tardis/util/base.py 75.78% <0.00%> (-1.99%) ⬇️
tardis/tardis/plasma/properties/nlte.py 39.21% <0.00%> (-1.74%) ⬇️
...s/tardis/montecarlo/montecarlo_numba/macro_atom.py 43.75% <0.00%> (-1.71%) ⬇️
...is/tardis/plasma/properties/continuum_processes.py 36.99% <0.00%> (-1.49%) ⬇️
.../montecarlo/montecarlo_numba/single_packet_loop.py 27.11% <0.00%> (-1.22%) ⬇️
... and 50 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14cf420...fc9db95. Read the comment docs.

@jamesgillanders
Copy link
Member

I don't understand why virtual_packet_logging needs to be set to True - I thought we left it so that we could make SDEC plots with either real or virtual packets?

@jamesgillanders
Copy link
Member

@jaladh-singhal do you know why this isn't working?

@wkerzendorf
Copy link
Member

@yuyizheng1112 can you write tests for the PR?

@yuyizheng1112
Copy link
Contributor Author

@jamesgillanders When calling generate_plot_mlp() in the case of virtual_packet_logging: False, the function will raise the error above, and I think this can be confusing for people unfamiliar with tardis.

I also think there is no need to set it to true for those who plot real packets only. But the instruction in sdec_plot.ipynb indicates that the option must set to true in order to generate SDEC plot. I did this to consist with the instruction & avoid the error raised by generate_plot_mlp().

Maybe I can put this exception in function generate_plot_mlp instead of when generating plotter. What do you think about it?

@jamesgillanders
Copy link
Member

So can I clarify something? There should be functionality to allow the SDEC plot to generate with real packets, but that does not currently work. And this PR will print an error message to explain that the real packets mode don't work. Is that right? Then at some point, after this fix has been implemented, will we fix the real packets mode so that it does work?

@jamesgillanders
Copy link
Member

If all of that is the case, then we will have to come back and remove this fix, so that the code will allow a plot to be generated using real packets. Or am I misunderstanding the problem being addressed here?

@yuyizheng1112
Copy link
Contributor Author

@jamesgillanders The default value for packets_mode is "virtual" in this function, so in this case, we are plotting using virtual packets. If virtual packet is not loaded in, it will raise the confusing exception above. As for the real mode, it works well no matter the option is active or not.
Does it make sense? :)

@jaladh-singhal
Copy link
Member

@jaladh-singhal do you know why this isn't working?

@jamesgillanders becuase there are currently no tests for SDEC plot hence test coverage is failing

@jaladh-singhal
Copy link
Member

@yuyizheng1112 @jamesgillanders I think I understand both of your reasoning. I see an intersecting solution for this problem:

  • First, inside SDECPlotter.from_simulation, if sim.runner.virt_logging is False then return dictionary with virtual=None, otherwise keep it as it is i.e. virtual=SDECData.from_simulation(sim, "virtual").

  • Then, in _calculate_plotting_data(), if packets_mode is virtual and data[packets_mode] is None then raise ValueError that "SDECPlotter doesn't have any data for virtual packets population and SDEC plot for the same was requested. Either set virtual_packet_logging: True in your simulation's configuration file to generate SDEC plot for virtual packets population, or pass packets_mode="real" in your function call to generate SDEC plot for real packets population."

This way even when virtual packets logging is not enabled, SDEC plot can still be obtained for real packets mode (what @jamesgillanders is saying) and will only give error when virtual packets mode is requested by user (what @yuyizheng1112 is trying to do).

@jaladh-singhal
Copy link
Member

But the instruction in sdec_plot.ipynb indicates that the option must set to true in order to generate SDEC plot. I did this to consist with the instruction & avoid the error raised by generate_plot_mlp().

@yuyizheng1112 Good point! The instruction should actually be changed to "The virtual packet logging capability must be active in order to produce SDEC Plot for virtual packets population. Thus ..." and it should be moved right after 5th cell's output.

Copy link
Member

@jaladh-singhal jaladh-singhal left a comment

Choose a reason for hiding this comment

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

@yuyizheng1112 can you please change this as per my comments?

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@yuyizheng1112
Copy link
Contributor Author

@jaladh-singhal Sure. I've changed both ValueError and instruction.

@github-actions
Copy link

github-actions bot commented Jun 4, 2021

Before a PR is accepted, it must meet the following criteria:

  • Is the necessary information provided?
    • Does the PR have a complete description? Does it explain what the PR is attempting to do/fix, does it explain how it does this?
    • Is there an explanation of why this PR is needed?
    • Please use the TARDIS PR template
  • Is this a duplicate PR?
    • If a new PR is clearly a duplicate, ask how this PR is different from the original PR?
    • If this PR is about to be merged, close the original PR with a link to this new PR that solved the issue.
  • Does it pass existing tests and are new tests provided if required?
    • The test coverage should not decrease, and for new features should be at or very close to 100%.
  • Is the code properly documented?
    • If this modifies existing code, then the docs should be updated. If this adds a new feature, additional documentation should be created.
    • Sphinx and docstrings in the code (in numpydoc format)
  • Does this conform to PEP 8 and the TARDIS style guidelines?
  • Does the PR fix the problem it describes?
    • Make sure it doesn’t e.g. just fix the problem for a specific case
    • Is this the best way of fixing the problem?
  • Is the code tidy?
    • No unnecessary print lines or code comments

Copy link
Member

@jaladh-singhal jaladh-singhal left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @yuyizheng1112 - I had a one minor comment.

Also, I hope you've tested this for config files with vpacket logging not enabled - can you post screenshots of that?

@@ -568,6 +576,11 @@ def _calculate_plotting_data(
"allowed values are 'virtual' or 'real'"
)

if packets_mode == "virtual" and self.data[packets_mode] is None:
raise ValueError(
'SDECPlotter doesn\'t have any data for virtual packets population and SDEC plot for the same was requested.\nEither set virtual_packet_logging: True in your configuration file to generate SDEC plot with virtual packets, or pass packets_mode="real" in your function call to generate SDEC plot with real packets.'
Copy link
Member

Choose a reason for hiding this comment

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

It's better to break long string to multiple lines following 80 char limit. Also if you use "..." for your string you will not need to escape ' used inside your string - see how L575-L576 does this

@tardis-bot
Copy link
Contributor

Before a pull request is accepted, it must meet the following criteria:

  • Is the necessary information provided?
  • Is this a duplicate PR?
    • If a new PR is clearly a duplicate, ask how this PR is different from the original PR?
    • If this PR is about to be merged, close the original PR with a link to this new PR that solved the issue.
  • Does it pass existing tests and are new tests provided if required?
    • The test coverage should not decrease, and for new features should be close to 100%.
  • Is the code tidy?
    • No unnecessary print lines or code comments.

Copy link
Member

@jaladh-singhal jaladh-singhal left a comment

Choose a reason for hiding this comment

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

Excellent!

@andrewfullard andrewfullard merged commit 1d7ce51 into tardis-sn:master Jun 22, 2021
atharva-2001 pushed a commit to atharva-2001/tardis that referenced this pull request Oct 1, 2021
…ter (tardis-sn#1597)

* add value error to ensure active virtual packet logging

* move ValueError and edit docs

* format

* Split long string
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.

None yet

7 participants