Skip to content

Commit

Permalink
Add support for explicit Case dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
youngmit committed Sep 9, 2021
1 parent 6efb915 commit 75a73ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
21 changes: 20 additions & 1 deletion armi/cases/case.py
Expand Up @@ -33,7 +33,7 @@
import time
import textwrap
import ast
from typing import Dict, Optional, Sequence
from typing import Dict, Optional, Sequence, Set
import glob
import tabulate
import six
Expand Down Expand Up @@ -98,6 +98,7 @@ def __init__(self, cs, caseSuite=None, bp=None, geom=None):
self._startTime = time.time()
self._caseSuite = caseSuite
self._tasks = []
self._dependencies: Set[Case] = set()
self.enabled = True

# NOTE: in order to prevent slow submission times for loading massively large
Expand Down Expand Up @@ -196,10 +197,28 @@ def dependencies(self):
)
)
# ensure that a case doesn't appear to be its own dependency
dependencies.update(self._dependencies)
dependencies.discard(self)

return dependencies

def addExplicitDependency(self, case):
"""
Register an explicit dependency
When evaluating the ``dependency`` property, dynamic dependencies are probed
using the current case settings and plugin hooks. Sometimes, it is necessary to
impose dependencies that are not expressed through settings and hooks. This
method stores another case as an explicit dependency, which will be included
with the other, implicitly discovered, dependencies.
"""
if case in self._dependencies:
runLog.warn(
"The case {} is already explicity specified as a dependency of "
"{}".format(case, self)
)
self._dependencies.add(case)

def getPotentialParentFromSettingValue(self, settingValue, filePattern):
"""
Get a parent case based on a setting value and a pattern.
Expand Down
5 changes: 5 additions & 0 deletions armi/cases/tests/test_cases.py
Expand Up @@ -238,6 +238,11 @@ def test_dependencyFromExplictRepeatShuffles(self):
self.c2.cs["explicitRepeatShuffles"] = "c1-SHUFFLES.txt"
self.assertIn(self.c1, self.c2.dependencies)

def test_explicitDependency(self):
self.c1.addExplicitDependency(self.c2)

self.assertIn(self.c2, self.c1.dependencies)


class TestExtraInputWriting(unittest.TestCase):
"""Make sure extra inputs from interfaces are written."""
Expand Down

0 comments on commit 75a73ec

Please sign in to comment.