Consistency in treatment of paths for files specified within the Model class #3153
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
There are a number of places where a model you're defining requires the path to a file, including:
CompiledSource
FileSource
.h5m
file for aDAGMCUniverse
Settings.surf_source_read
Right now, OpenMC will store the path exactly as the user specified it (either absolute or relative). There are two possible issues with this:
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 setFor 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