armi.utils package

Generic ARMI utilities.

armi.utils.getFileSHA1Hash(filePath, digits=40)[source]

Generate a SHA-1 hash of input files.

Parameters:
  • filePath (str) – Path to file or directory to obtain the SHA-1 hash

  • digits (int, optional) – Number of digits to include in the hash (40 digit maximum for SHA-1)

armi.utils.getPowerFractions(cs)[source]

Return the power fractions for each cycle.

Parameters:

cs (case settings object) –

Returns:

powerFractions – A list with nCycles elements, where each element is itself a list of the power fractions at each step of the cycle.

Return type:

2-list

Notes

This is stored outside of the Operator class so that it can be easily called to resolve case settings objects in other contexts (i.e. in the preparation of restart runs).

armi.utils.getCycleNames(cs)[source]

Return the names of each cycle. If a name is omitted, it is None.

Parameters:

cs (case settings object) –

Returns:

cycleNames – A list of the availability factors.

Return type:

list

Notes

This is stored outside of the Operator class so that it can be easily called to resolve case settings objects in other contexts (i.e. in the preparation of restart runs).

armi.utils.getAvailabilityFactors(cs)[source]

Return the availability factors for each cycle.

Parameters:

cs (case settings object) –

Returns:

availabilityFactors – A list of the availability factors.

Return type:

list

Notes

This is stored outside of the Operator class so that it can be easily called to resolve case settings objects in other contexts (i.e. in the preparation of restart runs).

armi.utils.getStepLengths(cs)[source]

Return the length of each step in each cycle.

Parameters:

cs (case settings object) –

Returns:

stepLengths – A list with elements for each cycle, where each element itself is a list containing the step lengths in days.

Return type:

2-list

Notes

This is stored outside of the Operator class so that it can be easily called to resolve case settings objects in other contexts (i.e. in the preparation of restart runs).

armi.utils.getCycleLengths(cs)[source]

Return the lengths of each cycle in days.

Parameters:

cs (case settings object) –

Returns:

cycleLengths – A list of the cycle lengths in days.

Return type:

list

Notes

This is stored outside of the Operator class so that it can be easily called to resolve case settings objects in other contexts (i.e. in the preparation of restart runs).

armi.utils.getBurnSteps(cs)[source]

Return the number of burn steps for each cycle.

Parameters:

cs (case settings object) –

Returns:

burnSteps – A list of the number of burn steps.

Return type:

list

Notes

This is stored outside of the Operator class so that it can be easily called to resolve case settings objects in other contexts (i.e. in the preparation of restart runs).

armi.utils.hasBurnup(cs)[source]

Test if depletion is being modeled.

Parameters:

cs (case settings object) –

Returns:

Are there any burnup steps?

Return type:

bool

armi.utils.getMaxBurnSteps(cs)[source]
armi.utils.getCumulativeNodeNum(cycle, node, cs)[source]

Return the cumulative node number associated with a cycle and time node.

Note that a cycle with n time steps has n+1 nodes, and for cycle m with n steps, nodes (m, n+1) and (m+1, 0) are counted separately.

Parameters:
  • cycle (int) – The cycle number

  • node (int) – The intra-cycle time node (0 for BOC, etc.)

  • cs (Settings object) –

armi.utils.getCycleNodeFromCumulativeStep(timeStepNum, cs)[source]

Return the (cycle, node) corresponding to a cumulative time step number.

“Node” refers to the node at the start of the time step.

Parameters:
  • timeStepNum (int) – The cumulative number of time steps since the beginning

  • cs (case settings object) – A case settings object to get the steps-per-cycle from

Notes

Time steps are the spaces between time nodes, and are 1-indexed.

To get the (cycle, node) from a cumulative time node, see instead getCycleNodeFromCumulativeNode.

armi.utils.getCycleNodeFromCumulativeNode(timeNodeNum, cs)[source]

Return the (cycle, node) corresponding to a cumulative time node number.

Parameters:
  • timeNodeNum (int) – The cumulative number of time nodes since the beginning

  • cs (case settings object) – A case settings object to get the nodes-per-cycle from

Notes

Time nodes are the start/end of time steps, and are 0-indexed. For a cycle with n steps, there will be n+1 nodes (one at the start of the cycle and another at the end, plus those separating the steps). For cycle m with n steps, nodes (m, n+1) and (m+1, 0) are counted separately.

To get the (cycle, node) from a cumulative time step, see instead getCycleNodeFromCumulativeStep.

armi.utils.getNodesPerCycle(cs)[source]

Return the number of nodes per cycle for the case settings object.

armi.utils.getPreviousTimeNode(cycle, node, cs)[source]

Return the (cycle, node) before the specified (cycle, node).

armi.utils.tryPickleOnAllContents(obj, ignore=None, verbose=False)[source]

Attempts to pickle all members of this object and identifies those who cannot be pickled.

Useful for debugging MPI-bcast errors

Not recursive yet. Would be nice to have it loop through nested objects (blocks in assems in reactors)

Parameters:
  • obj (object) – Any object to be tested.

  • ignore (iterable) – list of string variable names to ignore.

  • verbose (bool, optional) – Print all objects whether they fail or not

armi.utils.doTestPickleOnAllContents2(obj, ignore=None)[source]

Attempts to find one unpickleable object in a nested object.

Returns:

pickleChain – list of names in a chain that are unpickleable. Just one example per object e.g. [‘r’,’assemblies’,’A101’,’lib] means the lib is unpicklable.

Return type:

list

class armi.utils.MyPickler(file, protocol=None, fix_imports=True, buffer_callback=None)[source]

Bases: Pickler

This will find your pickle errors if all else fails.

Use with tryPickleOnAllContents3.

save(obj)[source]
armi.utils.tryPickleOnAllContents3(obj)[source]

Definitely find pickle errors.

Notes

In this form, this just finds one pickle error and then crashes. If you want to make it work like the other testPickle functions and handle errors, you could. But usually you just have to find one unpickleable SOB.

armi.utils.classesInHierarchy(obj, classCounts, visited=None)[source]

Count the number of instances of each class contained in an objects heirarchy.

armi.utils.slantSplit(val, ratio, nodes, order='low first')[source]

Returns a list of values whose sum is equal to the value specified.

The ratio between the highest and lowest value is equal to the specified ratio, and the middle values trend linearly between them.

armi.utils.prependToList(originalList, listToPrepend)[source]

Add a new list to the beginnning of an original list.

Parameters:
  • originalList (list) – The list to prepend to.

  • listToPrepend (list) – The list to add to the beginning of (prepend) the originalList.

Returns:

originalList – The original list with the listToPrepend at it’s beginning.

Return type:

list

armi.utils.capStrLen(s: str, length: int) str[source]

Truncates a string to a certain length.

Adds ‘…’ if it’s too long.

Parameters:
  • s (str) – The string to cap at length l.

  • length (int) – The maximum length of the string s.

armi.utils.list2str(strings, width=None, preStrings=None, fmt=None)[source]

Turn a list of strings into one string, applying the specified format to each.

Parameters:
  • strings (list) – The items to create centered strings in the line for. Can be str, float, int, etc.

  • width (int, optional) – The maximum width that the strings are allowed to take up. Only strings are affected by this parameter, because it does not make sense to truncate ints or floats.

  • preStrings (list of str, optional) – Any strings that come before the centered strings.

  • fmt (str, optional) – The format to apply to each string, such as ‘ >4d’, ‘^12.4E’.

armi.utils.createFormattedStrWithDelimiter(dataList, maxNumberOfValuesBeforeDelimiter=9, delimiter='\n')[source]

Return a formatted string with delimiters from a list of data.

Parameters:
  • dataList (list) – List of data that will be formatted into a string

  • maxNumberOfValuesBeforeDelimiter (int) – maximum number of values to have before the delimiter is added

  • delimiter (str) – A delimiter on the formatted string (default: “n”)

Notes

As an example:

>>> createFormattedStrWithDelimiter(['hello', 'world', '1', '2', '3', '4'],
...     maxNumberOfValuesBeforeDelimiter=3, delimiter = '\n')
"hello, world, 1, \n2, 3, \n4, 5\n"
armi.utils.plotMatrix(matrix, fName, minV=None, maxV=None, show=False, title=None, xlabel=None, ylabel=None, xticks=None, yticks=None, cmap=None, figsize=None)[source]

Plots a matrix.

armi.utils.userName() str[source]

Return a database-friendly username.

This will return the current user’s username, removing any prefix like pre-, if present.

Notes

ARMI uses the user name in a number of places, namely in the database names, which cannot contain hyphens.

class armi.utils.MergeableDict[source]

Bases: dict

Overrides python dictionary and implements a merge method.

Notes

Allows multiple dictionaries to be combined in a single line

merge(*otherDictionaries) None[source]
armi.utils.safeCopy(src: str, dst: str) None[source]

This copy overwrites shutil.copy and checks that copy operation is truly completed before continuing.

Subpackages

Submodules