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

Yaml config files #355

Merged
merged 13 commits into from
Nov 19, 2024
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*.pyc
Untitled.ipynb
.coverage
Configuration/
Experimental_Results/
*/test.ipynb

# These are generated folders for cache
Expand Down
3 changes: 2 additions & 1 deletion docs/source/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ f4enix >= 0.8.1
sphinx
esbonio
myst-parser
sphinx_rtd_theme
sphinx_rtd_theme
pyyaml
60 changes: 39 additions & 21 deletions docs/source/usage/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,36 @@ Computational benchmark post-processing configuration
It is possible to control (to some extent) the post-processing of each benchmark via its
specific configuration file. These files are located in the ``<JADE_root>\Configuration\Benchmarks_Configuration``
folder and their name must be identical to the one used in the ``File Name`` field in the main configuration file
(using the .xlsx extension instead of the .i). These files are available only for computational benchmarks,
since the high degree of customization needed for an experimental benchmark makes quite difficult to
standardize them. While computational benchmarks can be added to the JADE suite without the need for additional
(using the .yaml extension instead of the .i). Computational benchmark configuration files must be in YAML format, while
experimental benchmark configuration files are in Excel format due to the high degreee of customisation required.

While computational benchmarks can be added to the JADE suite without the need for additional
coding, this is not true also for experimental one.

The files contain two main sheets, that respectively regulate the Excel and the Word/PDF (i.e., Atlas) post-processing output.
The files contain two main sections, that respectively regulate the Excel and the Word/PDF (i.e., Atlas) post-processing output.

Excel
-----

.. image:: ../img/conf/excelbench.png
:width: 600
.. codeblock:: yaml

# Example of an extract from a benchmark configuration file, Excel section
Excel:
4.0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some cases the tally number is a float, other cases just an integer. Minor, I guess just by product of conversion script?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct, I kept both to be sure that it works in both cases just to be sure

cut_y: 20.0
identifier: 4
x: Energy
x_name: Energy [MeV]
y: Cells
y_name: Cell


This sheet regulates the Excel output derived from the benchmark. It consists of a table where each row regulates
the output of a single tally present in the MCNP input.
This section regulates the Excel output derived from the benchmark. Each entry
corresponds to a different tally present in the input file (tally number).

Hereinafter a description of the available fields is reported.

Tally
identifier
tally number according to MCNP input file.
x, y
select the binnings to be used for the presentation of the excel results of the specific tally. Clearly,
Expand Down Expand Up @@ -254,10 +265,10 @@ x, y
If a 1D FMESH is defined in the MCNP input, JADE will automatically transform it to a "binned" tally and handle it
as any other tally using the ``Cor A``, ``Cor B`` or ``Cor C`` field.

x name, y name
x_name, y_name
These will be the names associated to the **x** and **y** axis printed in the excel file.

cut Y
cut_y
The idea behind JADE is to produce outputs that are easy to investigate simply by scrolling and concentrate on the
main results highlighted through colors. Having a high number of bins both in the x and y axis may cause a problem
in this sense, forcing the user to scroll on both axis. For this reason, a maximum number of columns can be set to
Expand All @@ -267,30 +278,37 @@ cut Y
Atlas
-----

.. image:: ../img/conf/atlasbench.png
:width: 600
.. codeblock:: yaml

# Example of an extract from a benchmark configuration file, Atlas section
Atlas:
4:
identifier: 4
plot_type: Binned graph
quantity: Neutron Flux
unit: '#/cm^2'

This sheet regulates the Atlas output (Word) derived from the benchmark. It consists of a table where each row regulates
the output of a single tally present in the input.
Hereinafter a description of the available fields is reported.

Tally
identifier
tally number according to input file.
Quantity
Physical quantity that will be plotted on the y-axis of the plot. For the x-axis the one specified in the Excel sheet
quantity
Physical quantity that will be plotted on the y-axis of the plot. For the x-axis the one specified in the excel section
under **x** will be considered. The quantity selected for plotting will always be the tallied quantity.

.. important::
when two binnings are specified in the Excel sheet, a different plot for each of the **y** bins will be produced.
when two binnings are specified in the Excel section, a different plot for each of the **y** bins will be produced.
For example, let's consider a neutron flux tally binned both in energy (selected as **x**) and cells (selected as **y**).
Then, a plot showing the neutron flux as a function of energy will be produced for each cell. On the contrary, if the cell
binning is assigned to **x** and the energy one to **y**, a plot showing the neutron flux as a function of the cell would
be produced for each energy interval.
Unit
unit
Unit associated to the Quantity.
<Graph type>
Different columns can be added where it can be specified if a plot in the style indicated by the column name
should be generated (``true``) or not (``false``). The available plot styles are *Binned graph*, *Ratio Graph*,
plot_type
The type of plot that will be produced.
The available plot styles are *Binned graph*, *Ratio Graph*,
*Experimental points* and *Grouped bars*.

.. seealso::
Expand Down
164 changes: 164 additions & 0 deletions jade/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,36 @@
You should have received a copy of the GNU General Public License
along with JADE. If not, see <http://www.gnu.org/licenses/>.
"""

from __future__ import annotations

import datetime
import logging
import os
import sys
from dataclasses import dataclass
from enum import Enum

import pandas as pd
import yaml

from jade.exceptions import fatal_exception
from jade.plotter import PlotType


class BinningType(Enum):
ENERGY = "Energy"
CELLS = "Cells"
TIME = "Time"
TALLY = "tally"
DIR = "Dir"
USER = "User"
SEGMENTS = "Segments"
MULTIPLIER = "Multiplier"
COSINE = "Cosine"
CORA = "Cor A"
CORB = "Cor B"
CORC = "Cor C"


class Configuration:
Expand Down Expand Up @@ -208,3 +230,145 @@
except KeyError:
name = suffix
return name


@dataclass
class ComputationalConfig:
"""Configuration for a computational benchmark.

Attributes
----------
excel_options : dict[int, ExcelOptions]
Options for the Excel benchmark.
atlas_options : dict[int, AtlasOptions]
Options for the Atlas benchmark.
"""

excel_options: dict[int, ExcelOptions]
atlas_options: dict[int, AtlasOptions]

@classmethod
def from_yaml(cls, file: str | os.PathLike) -> ComputationalConfig:
"""Build the configuration for a computational benchmark from a yaml file.

Parameters
----------
file : str | os.PathLike
path to the yaml file.

Returns
-------
ComputationalConfig
The configuration for the computational benchmark.
"""
with open(file) as f:
cfg = yaml.safe_load(f)

atlas_options = {}
for key, value in cfg["Atlas"].items():
atlas_options[int(key)] = AtlasOptions(**value)

excel_options = {}
for key, value in cfg["Excel"].items():
excel_options[int(key)] = ExcelOptions(**value)

return cls(excel_options=excel_options, atlas_options=atlas_options)


@dataclass
class ExcelOptions:
"""Dataclass storing options for the Excel benchmark.

Attributes
----------
identifier : int
Identifier of the tally.
x : BinningType | list[BinningType]
Tally dataframe column name to use for x axis. If a list, two binnings are
combined together to form a single binning. The only valid combination is
Cells-Segments for the moment.
x_name : str
X axis label.
y : BinningType | list[BinningType]
Tally dataframe column name to use for y axis. If a list, two binnings are
combined together to form a single binning. The only valid combination is
Cells-Segments for the moment.
y_name : str
Y axis label.

Raises
------
ValueError
If an invalid BinningType is provided.
"""

identifier: int # identifier of the tally
x: BinningType | list[BinningType] # tally dataframe column name to use for x axis
x_name: str # x label
y: BinningType | list[BinningType] # tally dataframe column name to use for y axis
y_name: str # y label
cut_y: int | None = (
None # max number of columns, after that the DF is split and goes to next line
)

def __post_init__(self):
# enforce that the binning type is a valid one, try to convert if possible
for attribute in [self.x, self.y]:
if type(attribute) is str:
split = attribute.split("-")
if len(split) > 1:
attribute = []
for bintype in split:
try:
attribute.append(BinningType(bintype))
except ValueError:
raise ValueError(f"Invalid binning type: {bintype}")

Check warning on line 325 in jade/configuration.py

View check run for this annotation

Codecov / codecov/patch

jade/configuration.py#L324-L325

Added lines #L324 - L325 were not covered by tests
else:
try:
attribute = BinningType(attribute)
except ValueError:
raise ValueError(f"Invalid binning type: {attribute}")
# try:
# self.x = BinningType(self.x)
# except ValueError:
# raise ValueError(f"Invalid binning type for x: {self.x}")
# try:
# self.y = BinningType(self.y)
# except ValueError:
# raise ValueError(f"Invalid binning type for y: {self.y}")


@dataclass
class AtlasOptions:
"""
AtlasOptions is a configuration data class for specifying options related to plotting
in the Atlas application.

Attributes
----------
identifier : int
Identifier of the tally.
plot_type : PlotType
Type of plot.
quantity : str, optional
Quantity plotted (goes on the y axis of plots). Default is None.
unit : str, optional
Unit of the quantity. Default is None.

Raises
------
ValueError
if an invalid PlotType is provided.
"""

identifier: int # identifier of the tally
plot_type: PlotType # type of plot
quantity: str | None = None # quantity plotted (goes on the y axis of plots)
unit: str | None = None # unit of the quantity

def __post_init__(self):
# enforce that the plot type is a valid one
try:
self.plot_type = PlotType(self.plot_type)
except ValueError:
raise ValueError(f"Invalid plot type: {self.plot_type}")
Binary file not shown.
Loading