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

Consistency in treatment of paths for files specified within the Model class #3153

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

paulromano
Copy link
Contributor

Description

There are a number of places where a model you're defining requires the path to a file, including:

  • The path to a library for CompiledSource
  • The path to a source file for FileSource
  • A .h5m file for a DAGMCUniverse
  • The path to a surface source file for Settings.surf_source_read
  • The path to an unstructured mesh for tallying

Right now, OpenMC will store the path exactly as the user specified it (either absolute or relative). There are two possible issues with this:

  1. If the user gave a relative path, any function that relies on running the model in a temporary directory (e.g., in-line plotting) won't work because within the temporary directory, the relative path is incorrect.
  2. If the user gave an absolute path, moving the model files to a different directory or renaming the current directory will result in the path being invalid.

So there is no single solution that works for all scenarios. Always storing relative paths will break in scenario 1, and always storing absolute paths will break in scenario 2.

This PR provides a partial solution to this issue by introducing a new openmc.config['resolve_paths'] configuration variable that indicates whether paths should be resolved at the time they are set. Right now the default is True so that scenario 1 above works by default. For example, if a user is building a model that relies on a DAGMC .h5m file that was specified as a relative path, they can still do in-line plotting of it. However, if the user wants relative paths to be stored, they can always set

openmc.config['resolve_paths'] = False

For our test suite, we don't want absolute paths because they will end up getting stored in the reference input files and won't be same between any two systems, so I've introduced a session-scope fixture that sets the resolve_paths configuration variable to False.

Alternatives

Another option I thought of (and that was discussed with @pshriwise) was to have resolve_paths be an argument for any method that exports to XML. However, I decided not to go this route mostly because it would require changing a lot of method signatures relating to XML export. The configuration variable allowed me to achieve the same affect without modifying method signatures.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

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.

1 participant