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

Cleanup Depcode class #172

Merged
merged 37 commits into from
Dec 6, 2022
Merged

Cleanup Depcode class #172

merged 37 commits into from
Dec 6, 2022

Conversation

yardasol
Copy link
Contributor

@yardasol yardasol commented Nov 3, 2022

Summary of changes

This PR makes several changes and improvements to the Depcode family of classes with the goal of improving code and documentation readability, as well as making future development and use easier by tweaking the program flow.

Specifically, this PR does the following:

  • Cleans up the docstrings and makes them consistent (TODO)
  • Makes it so the runtime files are put in the data storage directory instead of the working directory
  • Makes the following changes to the following methods and attributes:
    • Remove junk default paths from depcode class parameters

    • Makes npop, active_cycles, inactive_cycles Depcode class attributes and removes them from the input schema.

    • Add some default values to the input schema

    • Depcode

      • read_depcode_info() -> read_step_metadata()
      • sim_info -> step_metadata
      • read_depcode_step_param() -> read_neutronics_parameters()
      • param -> neutronics_parameters
      • read_dep_comp() -> read_depleted_materials()
      • run_depcode() -> run_depletion_step()
      • write_depcode_input() -> write_runtime_input()
      • write_mat_file() -> update_depletable_materials()
      • iter_inputfile -> runtime_inputfile
      • iter_matfile -> runtime_matfile
    • SerpentDepcode

      • read_depcode_info() -> read_step_metadata()
      • sim_info -> step_metadata
      • read_depcode_step_param() -> read_neutronics_parameters()
      • param -> neutronics_parameters
      • read_dep_comp() -> read_depleted_materials()
      • run_depcode() -> run_depletion_step()
      • write_mat_file() -> update_depletable_materials()
      • create_nuclide_name_map_zam_to_serpent() -> map_nuclide_code_zam_to_serpent()
      • convert_nuclide_name_serpent_to_zam() -> convert_nuclide_code_to_zam()
      • get_nuc_name() -> convert_nuclide_code_to_name()
      • change_sim_par() -> apply_neutron_settings() remove change_sim_par()
      • added get_neutron_settings()
      • create_iter_matfile() -> create_runtime_matfile()
      • replace_burnup_parameters() -> set_power_load()
      • write_depcode_input() -> write_runtime_input()
      • cleanup switch_to_next_geometry()
      • cleanup insert_path_to_geometry()
      • iter_inputfile -> runtime_inputfile
      • iter_matfile -> runtime_matfile
    • OpenMCDepcode

      • read_depcode_info() -> read_step_metadata()
      • sim_info -> step_metadata
      • read_depcode_step_param() -> read_neutronics_parameters()
      • param -> neutronics_parameters
      • read_dep_comp() -> read_depleted_materials()
      • run_depcode() -> run_depletion_step()
      • write_mat_file() -> update_depletable_materials()
      • write_depcode_input() -> write_runtime_input()
      • iter_inputfile -> runtime_inputfile
      • iter_matfile -> runtime_matfile
  • Consistency changes in test files and documentation to reflect new class, function, and variable names:

The following changes will be made in a PR after this one is merged:

  • moves abc.py to abstract_depcode.py (TODO)
  • rearrange function order (TODO)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Required for Merging

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • My change is a source code change
    • I have added/modified tests to cover my changes
    • I have explained why my change does not require new/modified tests
  • My change is a user-facing change
    • I have recorded my changes in the changelog for the upcoming release
  • My change is exclusively related to the repository (e.g. GitHub actions workflows, PR/issue templates, etc.)
    • I have verified or justified that my change will work as intended.
  • All new and existing tests passed.
    • CI tests pass
    • Local tests pass (including Serpent2 integration tests)

Associated Issues and PRs

Associated Developers

  • Dev: @

Checklist for Reviewers

Reviewers should use this link to get to the
Review Checklist before they begin their review.

@yardasol yardasol force-pushed the cleanup-depcode branch 2 times, most recently from b2a849b to fc06882 Compare November 7, 2022 17:14
consistency changes associated with this name changes
…eutronics_parameters

conistency changes associated with function and attribute name change
…erpent()

- variable name adjustments in function
- consitency changes in relevant test files
- docstring changes
- adjust docstrings
- associated changes in other files
@yardasol yardasol force-pushed the cleanup-depcode branch 2 times, most recently from ed7b8fb to 0568fc6 Compare November 7, 2022 21:16
- docstring changes
- associated testfile changes
- get_nuc_name() -> convert_nuclide_code_to_name()
- convert_nuclide_name_serpent_to_zam() -> convert_nuclide_code_to_zam()
- docstring cleanup and fixes
- consitency changes in other relevant files
@yardasol yardasol mentioned this pull request Nov 9, 2022
17 tasks
@yardasol yardasol marked this pull request as ready for review November 29, 2022 22:37
Copy link
Contributor

@samgdotson samgdotson left a comment

Choose a reason for hiding this comment

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

There are a few changes that I made as suggestions. This PR is 90+% renaming variables. The one change I really wanted was for saltproc/abc.py to be renamed to something else.

saltproc/app.py Outdated
@@ -247,12 +240,10 @@ def _create_depcode_object(depcode_input):
raise ValueError(
f'{depcode_input["codename"]} is not a supported depletion code')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
f'{depcode_input["codename"]} is not a supported depletion code')
f'{codename} is not a supported depletion code. Accepts: "serpent" or "openmc".')

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't make a suggestion for code that isn't modified in this PR, but you should use (on line 234)

codename = depcode_input["codename"].lower()
# instead of
codename = depcode_input["codename"]

That way your code isn't case sensitive.

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 believe this gets handled by JSON Schema verification.

Copy link
Contributor

Choose a reason for hiding this comment

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

The code suggestion in the first comment is still valid. Forcing lower doesn't add any overhead really, but if you're confident then okay.

"geo_file_paths": {
"description": "Path(s) to geometry file(s) to switch to in depletion code runs",
"type": "array",
"items": { "type": "string"},
"minItems": 1,
"uniqueItems": false
"uniqueItems": true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My rationale was that we will not want to switch to a geometry that we've already cycled through, but that may not actually be the case; we could 'oscillate' between a set of particular geometries. I'll change this back to false

Comment on lines 76 to 78
{'geometry': (output_path / 'geometry.xml').resolve().as_posix(),
'settings': (output_path / 'settings.xml').resolve().as_posix()}
self.runtime_matfile = (output_path / 'materials.xml').resolve().as_posix()
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 have to be posix? What if a user has a Windows machine? I think .resolve() automatically provides the correct format.

Suggested change
{'geometry': (output_path / 'geometry.xml').resolve().as_posix(),
'settings': (output_path / 'settings.xml').resolve().as_posix()}
self.runtime_matfile = (output_path / 'materials.xml').resolve().as_posix()
{'geometry': (output_path / 'geometry.xml').resolve(),
'settings': (output_path / 'settings.xml').resolve()}
self.runtime_matfile = (output_path / 'materials.xml').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.

I wanted the paths as strings. I didn't think about what would happen if a user was on windows. I'll change this to str()

Copy link
Contributor

Choose a reason for hiding this comment

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

Has this been changed? It's not showing up for me

saltproc/openmc_depcode.py Show resolved Hide resolved
saltproc/openmc_depcode.py Show resolved Hide resolved
Comment on lines +24 to 48
parser.add_argument('--materials',
type=str,
default=1,
help='path to openmc material \
material xml file')
parser.add_argument('-geo',
parser.add_argument('--geometry',
type=str,
default=1,
help='path to openmc geometry \
xml file')
parser.add_argument('-set',
parser.add_argument('--settings',
type=str,
default=None,
help='path to openmc settings \
xml file')
parser.add_argument('-tal',
parser.add_argument('--tallies',
type=str,
default=None,
help='path to openmc tallies \
xml file')
parser.add_argument('-dep',
parser.add_argument('--depletion_settings',
type=str,
default=None,
help='path to saltproc depletion \
settings json file')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you create single-letter flags? I agree that it's clearer but you're making the CLI more cumbersome.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This CLI is not for the user. It is used internally for running openmc depletion via a script.

@yardasol yardasol requested a review from samgdotson November 30, 2022 20:56
@yardasol
Copy link
Contributor Author

yardasol commented Dec 2, 2022

The one change I really wanted was for saltproc/abc.py to be renamed to something else.

I will do this in a future PR, otherwise the changes to abc.py will be obscured by the name change.

Copy link
Contributor

@abachma2 abachma2 left a comment

Choose a reason for hiding this comment

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

Hi @yardasol, great work on this PR. I agree with Sam that the vast majority of this PR is documentation and function names. Things seem to be consistent across your code, and the changes do improve the readability of the documentation. I am really curious as to the benefit of making the npop, active_cycles, and inactive_cycles attributes instead of in the input schema.

The two changes I requested are very small and are regarding the release notes.

@@ -1,16 +1,13 @@
{
"proc_input_file": "msbr_objects.json",
"dot_input_file": "msbr.dot",
"output_path": "./data",
"output_path": "data",
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for this change? Is it because you've added the output path as an input parameter to the Depcode class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change just cleans up the path itself. The ./ is not necessary.

Comment on lines +142 to +147
Nuclide code in Serpent2 format (`47310.09c`)

Returns
-------
nuc_name : str
Name of nuclide in human-readable notation (`Am-242m1`).
nuc_zzaaam : str
Name of nuclide in `zzaaam` form (`952421`).
Symbolic nuclide name (`Am242m1`).
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you using the nuclide code for Am-242m1? Just want to make sure you're being consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is correct.

Copy link
Contributor

@abachma2 abachma2 Dec 5, 2022

Choose a reason for hiding this comment

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

Ok. That's just a very unexpected nuclide code for Am-242m1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 3 in 47310 is Serpent's convention for metastable nuclides:

The library directory includes two entries for each nuclide, one using the standard MCNP convention (ZA.id) and another one using the element symbol and the isotope mass (e.g. 92235.03c and U-235.03c for U-235). Either name can be used to identify the nuclide in the material compositions.

The script assumes that nuclides in isomeric states are identified by setting the third digit in the ZA to 3 (e.g. 61348 for Pm-148m or 95342 for Am-242m). If other convention is used, the isomeric state number (5. entry) must be set manually.

Comment on lines +390 to +392
file_lines.insert(line_idx, # Insert on 9th line
'set power %5.9E dep daystep %7.5E\n' %
(current_power, step_length))
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these values hardcoded into the file lines? Is there any reason someone would need to use different 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.

The set power card is the only way to specify depletion steps in Serpent to my knowledge. Right now, we can only use the daystep option, but in #177 I fix this to enable use of every potential time unit a user might want to use.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense, but what about the 5.9E and 7.5E values in there? Are those values, or a way to read in a variable value?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is string formatting. The 5 in 5.9E indicates we want to display a maximum of 5 digits before the decimal, the 9 indicates we want to display 9 digits after the decimal, and the E indicates we display the number in scientific notation:

>>> '%5.9f' % (2.0e-2)
'0.020000000'
>>> '%5.9E' % (2.0e-2)
'2.000000000E-02'

Comment on lines +10 to +17
assert nuc_code_map[380880] == '38088.09c'
assert nuc_code_map[962400] == '96240.09c'
assert nuc_code_map[952421] == '95342.09c'
assert nuc_code_map[340831] == '340831'
assert nuc_code_map[300732] == '300732'
assert nuc_code_map[511262] == '511262'
assert nuc_code_map[420931] == '420931'
assert nuc_code_map[410911] == '410911'
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious. Is there any reason you chose to test these nuclides?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are holdovers from Andrei's tests.

doc/releasenotes/v0.5.0.rst Outdated Show resolved Hide resolved
doc/releasenotes/v0.5.0.rst Outdated Show resolved Hide resolved
Co-authored-by: Amanda Bachmann <amandab7@illinois.edu>
@yardasol yardasol requested a review from abachma2 December 5, 2022 19:42
@yardasol
Copy link
Contributor Author

yardasol commented Dec 5, 2022

@samgdotson bump

Co-authored-by: Amanda Bachmann <amandab7@illinois.edu>
Copy link
Contributor

@samgdotson samgdotson left a comment

Choose a reason for hiding this comment

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

There are still some changes to be addressed. In particular everywhere that forces a posix path. You're losing one of the key benefits of pathlib!

Comment on lines 76 to 78
{'geometry': (output_path / 'geometry.xml').resolve().as_posix(),
'settings': (output_path / 'settings.xml').resolve().as_posix()}
self.runtime_matfile = (output_path / 'materials.xml').resolve().as_posix()
Copy link
Contributor

Choose a reason for hiding this comment

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

Has this been changed? It's not showing up for me

Comment on lines +390 to +392
file_lines.insert(line_idx, # Insert on 9th line
'set power %5.9E dep daystep %7.5E\n' %
(current_power, step_length))
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

depcode.iter_inputfile = openmc_iter_inputfiles
depcode.iter_matfile = (openmc_input_path / 'materials.xml').as_posix()
depcode.runtime_inputfile = openmc_runtime_inputfiles
depcode.runtime_matfile = (openmc_input_path / 'materials.xml').as_posix()
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't catch this before, but this should also consider non-unix operating systems.

Suggested change
depcode.runtime_matfile = (openmc_input_path / 'materials.xml').as_posix()
depcode.runtime_matfile = str(openmc_input_path / 'materials.xml')

@@ -28,7 +28,7 @@ def serpent_depcode(cwd):
saltproc_input = (cwd / 'serpent_data' / 'tap_input.json').as_posix()
_, _, _, object_input = read_main_input(saltproc_input)
depcode = _create_depcode_object(object_input[0])
depcode.iter_inputfile = (cwd / 'serpent_data' / 'tap_reference').as_posix()
depcode.runtime_inputfile = (cwd / 'serpent_data' / 'tap_reference').as_posix()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
depcode.runtime_inputfile = (cwd / 'serpent_data' / 'tap_reference').as_posix()
depcode.runtime_inputfile = str(cwd / 'serpent_data' / 'tap_reference')

(openmc_input_path / openmc_iter_inputfiles[key]).as_posix()
for key in openmc_runtime_inputfiles:
openmc_runtime_inputfiles[key] = \
(openmc_input_path / openmc_runtime_inputfiles[key]).as_posix()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(openmc_input_path / openmc_runtime_inputfiles[key]).as_posix()
str(openmc_input_path / openmc_runtime_inputfiles[key])

j = json.load(f)
assert j['directory'] == Path(
openmc_depcode.iter_inputfile['settings']).parents[0].as_posix()
openmc_depcode.runtime_inputfile['settings']).parents[0].as_posix()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't suggest on non edited lines, but posix...

@yardasol
Copy link
Contributor Author

yardasol commented Dec 5, 2022

There are still some changes to be addressed. In particular everywhere that forces a posix path. You're losing one of the key benefits of pathlib!

That's weird, I fixed this in this commit. Try looking at it again?

Co-authored-by: Sam Dotson <sgd2@illinois.edu>
Copy link
Contributor

@samgdotson samgdotson 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 making changes

@samgdotson samgdotson merged commit 5b6bf0c into arfc:master Dec 6, 2022
github-actions bot pushed a commit that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Cleanup depcode.py and related files
3 participants