From 4ea7e4ff6fa13456c35fdbe70cebd410679d3fc0 Mon Sep 17 00:00:00 2001 From: yardasol Date: Mon, 7 Nov 2022 10:42:52 -0600 Subject: [PATCH] read_depcode_info() -> read_step_metadata(); sim_info -> step_metadata consistency changes associated with this name changes --- doc/releasenotes/v0.5.0.rst | 8 +++-- saltproc/abc.py | 14 ++++---- saltproc/openmc_depcode.py | 12 +++---- saltproc/serpent_depcode.py | 34 +++++++++--------- saltproc/simulation.py | 36 +++++++++---------- .../database_storage/test.py | 4 +-- tests/unit_tests/test_depcode_serpent.py | 24 ++++++------- 7 files changed, 68 insertions(+), 64 deletions(-) diff --git a/doc/releasenotes/v0.5.0.rst b/doc/releasenotes/v0.5.0.rst index 3cee61738..dfc204c18 100644 --- a/doc/releasenotes/v0.5.0.rst +++ b/doc/releasenotes/v0.5.0.rst @@ -108,21 +108,25 @@ Python API Changes longer be initialized by the user during object creation. -- New/changed classes and methods: +- New/changed classes, methods, and attributes: - ``Depcode`` - ``template_inputfile_path`` → ``template_input_file_path`` - Changed `iter_inputfile` and `iter_matfile` to be attributes instead of parameters + - ``read_depcode_info()`` → ``read_step_metadata()`` + - ``sim_info`` → ``step_metadata`` - ``DepcodeSerpent`` → ``SerpentDepcode`` - ``template_inputfile_path`` → ``template_input_file_path`` - Changed `iter_inputfile` and `iter_matfile` to be attributes instead of parameters + - ``read_depcode_info()`` → ``read_depletion_step_metadata()`` + - ``sim_info`` → ``step_metadata`` - ``OpenMCDepcode`` is a ``Depcode`` subclass that interfaces with ``openmc``. This class implements the following functions - + - ``read_depletion_step_metadata()`` - ``run_depcode()`` - ``switch_to_next_geometry()`` - ``write_depcode_input()`` diff --git a/saltproc/abc.py b/saltproc/abc.py index 2438ee1e2..6a6d74462 100644 --- a/saltproc/abc.py +++ b/saltproc/abc.py @@ -12,9 +12,9 @@ class Depcode(ABC): param : dict of str to type Holds depletion step parameter information. Parameter names are keys and parameter values are values. - sim_info : dict of str to type - Holds simulation settings information. Setting names are keys - and setting values are values. + step_metadata : dict of str to type + Holds depletion code depletion step metadata. Metadata labels are keys + and metadata values are values. iter_inputfile : str Path to depletion code input file for depletion code rerunning. iter_matfile : str @@ -64,14 +64,14 @@ def __init__(self, self.active_cycles = active_cycles self.inactive_cycles = inactive_cycles self.param = {} - self.sim_info = {} + self.step_metadata = {} self.iter_inputfile = './iter_input' self.iter_matfile = './iter_mat' @abstractmethod - def read_depcode_info(self): - """Parses initial depletion code info data from depletion code - output and stores it in the `Depcode` object's ``sim_info`` attribute. + def read_step_metadata(self): + """Reads depletion code's depletion step metadata and stores it in the + :class:`Depcode` object's :attr:`step_metadata` attribute. """ @abstractmethod diff --git a/saltproc/openmc_depcode.py b/saltproc/openmc_depcode.py index 67ec1c250..4a0025b1c 100644 --- a/saltproc/openmc_depcode.py +++ b/saltproc/openmc_depcode.py @@ -23,9 +23,9 @@ class OpenMCDepcode(Depcode): param : dict of str to type Holds depletion step parameter information. Parameter names are keys and parameter values are values. - sim_info : dict of str to type - Holds simulation settings information. Setting names are keys - and setting values are values. + step_metadata : dict of str to type + Holds OpenMC depletion step metadata. Metadata labels are keys + and metadata values are values. iter_inputfile : dict of str to str Paths to OpenMC input files for OpenMC rerunning. iter_matfile : str @@ -79,9 +79,9 @@ def __init__(self, 'settings': './settings.xml'}, self.iter_matfile = './materials.xml' - def read_depcode_info(self): - """Parses initial OpenMC simulation info from the OpenMC output files - and stores it in the `Depcode` object's ``sim_info`` attribute. + def read_step_metadata(self): + """Reads OpenMC's depletion step metadata and stores it in the + :class:`OpenMCDepcode` object's :attr:`step_metadata` attribute. """ def read_depcode_step_param(self): diff --git a/saltproc/serpent_depcode.py b/saltproc/serpent_depcode.py index aecdddbe5..f0769304a 100644 --- a/saltproc/serpent_depcode.py +++ b/saltproc/serpent_depcode.py @@ -21,9 +21,9 @@ class SerpentDepcode(Depcode): param : dict of str to type Holds Serpent depletion step parameter information. Parameter names are keys and parameter values are values. - sim_info : dict of str to type - Holds Serpent simulation settings information. Setting names are keys - and setting values are values. + step_metadata : dict of str to type + Holds Serpent2 depletion step metadata. Metadata labels are keys + and metadata values are values. iter_inputfile : str Path to Serpent2 input file for Serpent2 rerunning. iter_matfile : str @@ -302,26 +302,26 @@ def read_dep_comp(self, read_at_end=False): self.create_nuclide_name_map_zam_to_serpent() return mats - def read_depcode_info(self): - """Parses initial simulation info data from Serpent2 output and stores - it in the `SerpentDepcode` object's ``sim_info`` attributes. + def read_step_metadata(self): + """Reads Serpent2 depletion step metadata and stores it in the + :class:`SerpentDepcode` object's :attr:`step_metadata` attribute. """ res = serpent.parse_res(self.iter_inputfile + "_res.m") depcode_name, depcode_ver = res['VERSION'][0].decode('utf-8').split() - self.sim_info['depcode_name'] = depcode_name - self.sim_info['depcode_version'] = depcode_ver - self.sim_info['title'] = res['TITLE'][0].decode('utf-8') - self.sim_info['depcode_input_filename'] = \ + self.step_metadata['depcode_name'] = depcode_name + self.step_metadata['depcode_version'] = depcode_ver + self.step_metadata['title'] = res['TITLE'][0].decode('utf-8') + self.step_metadata['depcode_input_filename'] = \ res['INPUT_FILE_NAME'][0].decode('utf-8') - self.sim_info['depcode_working_dir'] = \ + self.step_metadata['depcode_working_dir'] = \ res['WORKING_DIRECTORY'][0].decode('utf-8') - self.sim_info['xs_data_path'] = \ + self.step_metadata['xs_data_path'] = \ res['XS_DATA_FILE_PATH'][0].decode('utf-8') - self.sim_info['OMP_threads'] = res['OMP_THREADS'][0] - self.sim_info['MPI_tasks'] = res['MPI_TASKS'][0] - self.sim_info['memory_optimization_mode'] = res['OPTIMIZATION_MODE'][0] - self.sim_info['depletion_timestep'] = res['BURN_DAYS'][1][0] - self.sim_info['depletion_timestep'] = res['BURN_DAYS'][1][0] + self.step_metadata['OMP_threads'] = res['OMP_THREADS'][0] + self.step_metadata['MPI_tasks'] = res['MPI_TASKS'][0] + self.step_metadata['memory_optimization_mode'] = res['OPTIMIZATION_MODE'][0] + self.step_metadata['depletion_timestep'] = res['BURN_DAYS'][1][0] + self.step_metadata['depletion_timestep'] = res['BURN_DAYS'][1][0] def read_depcode_step_param(self): """Parses data from Serpent2 output for each step and stores it in diff --git a/saltproc/simulation.py b/saltproc/simulation.py index bfee76c72..f54106b74 100644 --- a/saltproc/simulation.py +++ b/saltproc/simulation.py @@ -367,7 +367,7 @@ def store_run_init_info(self): # numpy arraw row storage for run info # delete and make this datatype specific # to Depcode subclasses - sim_info_dtype = np.dtype([ + step_metadata_dtype = np.dtype([ ('neutron_population', int), ('active_cycles', int), ('inactive_cycles', int), @@ -383,24 +383,24 @@ def store_run_init_info(self): ('depletion_timestep', float) ]) # Read info from depcode _res.m File - self.sim_depcode.read_depcode_info() + self.sim_depcode.read_step_metadata() # Store information about material properties in new array row - sim_info_row = ( + step_metadata_row = ( self.sim_depcode.npop, self.sim_depcode.active_cycles, self.sim_depcode.inactive_cycles, # delete the below - self.sim_depcode.sim_info['depcode_name'], - self.sim_depcode.sim_info['depcode_version'], - self.sim_depcode.sim_info['title'], - self.sim_depcode.sim_info['depcode_input_filename'], - self.sim_depcode.sim_info['depcode_working_dir'], - self.sim_depcode.sim_info['xs_data_path'], - self.sim_depcode.sim_info['OMP_threads'], - self.sim_depcode.sim_info['MPI_tasks'], - self.sim_depcode.sim_info['memory_optimization_mode'], - self.sim_depcode.sim_info['depletion_timestep'] + self.sim_depcode.step_metadata['depcode_name'], + self.sim_depcode.step_metadata['depcode_version'], + self.sim_depcode.step_metadata['title'], + self.sim_depcode.step_metadata['depcode_input_filename'], + self.sim_depcode.step_metadata['depcode_working_dir'], + self.sim_depcode.step_metadata['xs_data_path'], + self.sim_depcode.step_metadata['OMP_threads'], + self.sim_depcode.step_metadata['MPI_tasks'], + self.sim_depcode.step_metadata['memory_optimization_mode'], + self.sim_depcode.step_metadata['depletion_timestep'] ) - sim_info_array = np.array([sim_info_row], dtype=sim_info_dtype) + step_metadata_array = np.array([step_metadata_row], dtype=step_metadata_dtype) # Open or restore db and append datat to it db = tb.open_file( @@ -408,14 +408,14 @@ def store_run_init_info(self): mode='a', filters=self.compression_params) try: - sim_info_table = db.get_node(db.root, 'initial_depcode_siminfo') + step_metadata_table = db.get_node(db.root, 'initial_depcode_siminfo') except Exception: - sim_info_table = db.create_table( + step_metadata_table = db.create_table( db.root, 'initial_depcode_siminfo', - sim_info_array, + step_metadata_array, "Initial depletion code simulation parameters") - sim_info_table.flush() + step_metadata_table.flush() db.close() def read_k_eds_delta(self, current_timestep): diff --git a/tests/integration_tests/database_storage/test.py b/tests/integration_tests/database_storage/test.py index 7bfc3f99e..28f99d1eb 100644 --- a/tests/integration_tests/database_storage/test.py +++ b/tests/integration_tests/database_storage/test.py @@ -268,8 +268,8 @@ def test_store_run_init_info(simulation): """ # read data - simulation.sim_depcode.read_depcode_info() - init_info = simulation.sim_depcode.sim_info + simulation.sim_depcode.read_step_metadata() + init_info = simulation.sim_depcode.step_metadata # we want to keep the old path for other sims, but for this # test we'll want a fresh db diff --git a/tests/unit_tests/test_depcode_serpent.py b/tests/unit_tests/test_depcode_serpent.py index 06ad3f919..c1fb65bfe 100644 --- a/tests/unit_tests/test_depcode_serpent.py +++ b/tests/unit_tests/test_depcode_serpent.py @@ -53,22 +53,22 @@ def test_get_nuc_name(serpent_depcode): assert serpent_depcode.get_nuc_name('491142')[0] == 'In114m2' -def test_read_depcode_info(serpent_depcode): - serpent_depcode.read_depcode_info() - assert serpent_depcode.sim_info['depcode_name'] == 'Serpent' - assert serpent_depcode.sim_info['depcode_version'] == '2.1.31' - assert serpent_depcode.sim_info['title'] == 'Untitled' - assert serpent_depcode.sim_info['depcode_input_filename'] == \ +def test_read_step_metadata(serpent_depcode): + serpent_depcode.read_step_metadata() + assert serpent_depcode.step_metadata['depcode_name'] == 'Serpent' + assert serpent_depcode.step_metadata['depcode_version'] == '2.1.31' + assert serpent_depcode.step_metadata['title'] == 'Untitled' + assert serpent_depcode.step_metadata['depcode_input_filename'] == \ '/home/andrei2/Desktop/git/saltproc/develop/saltproc/data/saltproc_tap' - assert serpent_depcode.sim_info['depcode_working_dir'] == \ + assert serpent_depcode.step_metadata['depcode_working_dir'] == \ '/home/andrei2/Desktop/git/saltproc/develop/saltproc' - assert serpent_depcode.sim_info['xs_data_path'] == \ + assert serpent_depcode.step_metadata['xs_data_path'] == \ '/home/andrei2/serpent/xsdata/jeff312/sss_jeff312.xsdata' - assert serpent_depcode.sim_info['MPI_tasks'] == 1 - assert serpent_depcode.sim_info['OMP_threads'] == 4 - assert serpent_depcode.sim_info['memory_optimization_mode'] == 4 - assert serpent_depcode.sim_info['depletion_timestep'] == 3.0 + assert serpent_depcode.step_metadata['MPI_tasks'] == 1 + assert serpent_depcode.step_metadata['OMP_threads'] == 4 + assert serpent_depcode.step_metadata['memory_optimization_mode'] == 4 + assert serpent_depcode.step_metadata['depletion_timestep'] == 3.0 def test_read_depcode_step_param(serpent_depcode):