openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
765 stars 493 forks source link

Plot xs has TypeError with ostensibly allowable argument #3177

Open MicahGale opened 2 days ago

MicahGale commented 2 days ago

Bug Description

An unclear TypeError is raised by plot_xs when given the improper arguments.

Steps to Reproduce

import openmc
openmc.plot_xs({"U-238": "capture"})
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 openmc.plot_xs({"U-238": "capture"})

File ~/mambaforge/envs/openmc/lib/python3.12/site-packages/openmc/plotter.py:200, in plot_xs(reactions, divisor_types, temperature, axis, sab_name, ce_cross_sections, mg_cross_sections, enrichment, plot_CE, orders, divisor_orders, energy_axis_units, **kwargs)
    197 all_types = []
    199 for this, types in reactions.items():
--> 200     all_types = all_types + types
    202     if plot_CE:
    203         cv.check_type("this", this, (str, openmc.Material))

TypeError: can only concatenate list (not "str") to list

In my first reading the documentation {"U-238": "capture"} seemed completely valid:

reactions (dict) – keys can be either a nuclide or element in string form or an openmc.Material object. Values are the type of cross sections to include in the plot.

Environment

shimwell commented 1 day ago

might need to be something like this,

openmc.plot_xs({"U238": ["capture"]})

Would a change to the doc string like this PR help @MicahGale

MicahGale commented 1 day ago

Yes that is the correct way.

The docs should be clarified, but also the type enforcement should be stricter, and clearer.