Skip to content

Commit

Permalink
Merge branch 'master' into warnCopyFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Apr 29, 2022
2 parents cee8fc4 + a857635 commit 45f81b6
Show file tree
Hide file tree
Showing 112 changed files with 1,806 additions and 1,357 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Expand Up @@ -4,6 +4,11 @@ omit =
armi/cli/gridGui.py
armi/utils/gridEditor.py
armi/utils/tests/test_gridGui.py
venv/
source = armi

[coverage:run]
parallel = true

[report]
omit =
Expand Down
Empty file removed .gitattributes
Empty file.
2 changes: 1 addition & 1 deletion .github/workflows/black.yaml
Expand Up @@ -13,6 +13,6 @@ jobs:
with:
python-version: 3.9
- name: Install Black
run: pip install 'black==20.8b1'
run: pip install 'black==20.8b1' 'click==8.0.1'
- name: Run black --check .
run: black --check .
8 changes: 6 additions & 2 deletions .github/workflows/coverage.yaml
Expand Up @@ -22,6 +22,10 @@ jobs:
run: sudo apt-get -y install libopenmpi-dev
- name: Install Tox and any other packages
run: pip install tox
- name: Run Tox
run: tox -e cov,report
- name: Run Coverage Part 1
if: always()
run: tox -e cov1 || true
- name: Run Coverage Part 2
if: always()
run: tox -e cov2,report

2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -13,7 +13,7 @@ bin/*
/bin
dist/
dist-*/
doc/*.png
*.png
doc/_build
doc/user/tutorials
doc/tutorials/anl-afci-177*
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Expand Up @@ -38,7 +38,6 @@ include armi/nuclearDataIO/tests/library-file-generation/mc2v3-dlayxs.inp
include armi/nuclearDataIO/tests/longLivedRipleData.dat
include armi/nuclearDataIO/tests/simple_hexz.inp
include armi/nuclearDataIO/tests/z036.dat
include armi/settings/tests/old_xml_settings_input.xml
include armi/tests/1DslabXSByCompTest.yaml
include armi/tests/armiRun-SHUFFLES.txt
include armi/tests/armiRun.yaml
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -434,6 +434,6 @@ only use third-party Python libraries that have MIT or BSD licenses.
.. |Build Status| image:: https://github.com/terrapower/armi/actions/workflows/unittests.yaml/badge.svg?branch=master
:target: https://github.com/terrapower/armi/actions/workflows/unittests.yaml

.. |Code Coverage| image:: https://coveralls.io/repos/github/terrapower/armi/badge.svg?branch=master&kill_cache=2
.. |Code Coverage| image:: https://coveralls.io/repos/github/terrapower/armi/badge.svg?branch=master&kill_cache=3
:target: https://coveralls.io/github/terrapower/armi?branch=master

8 changes: 7 additions & 1 deletion armi/__init__.py
Expand Up @@ -101,6 +101,12 @@
_ignoreConfigures = False


def disableFutureConfigures():
"""Exposed function to ensure armi.configure() isn't called more than once"""
global _ignoreConfigures
_ignoreConfigures = True


def isStableReleaseVersion(version=None):
"""Determine if the version should be considered a stable release"""
version = version or __version__
Expand Down Expand Up @@ -322,13 +328,13 @@ def configure(app: Optional[apps.App] = None, permissive=False):
_ARMI_CONFIGURE_CONTEXT = "".join(traceback.format_stack())

_app = app
context.APP_NAME = app.name

if _liveInterpreter():
runLog.LOG.startLog(name=f"interactive-{app.name}")
cli.splash()

pm = app.pluginManager
context.APP_NAME = app.name
parameters.collectPluginParameters(pm)
parameters.applyAllParameters()
flags.registerPluginFlags(pm)
Expand Down
18 changes: 9 additions & 9 deletions armi/__main__.py
Expand Up @@ -20,17 +20,17 @@
"""
import sys

import armi
from armi import apps
from armi.cli import ArmiCLI
from armi import configure, isConfigured
from armi import context
from armi.cli import ArmiCLI


def main():
# Main entry point into ARMI
try:
if not armi.isConfigured():
armi.configure(apps.App())
if not isConfigured():
configure(apps.App())
code = ArmiCLI().run()
# sys exit interprets None as 0
sys.exit(code)
Expand All @@ -42,28 +42,28 @@ def main():
# TODO: change to critical after critical no longer throws an exception.
print(
"[CRIT {:03} ] Unhandled exception in __main__ on {}.".format(
armi.MPI_RANK, armi.MPI_NODENAME
context.MPI_RANK, context.MPI_NODENAME
),
file=sys.__stderr__,
)
print(
"[CRIT {:03} ] Stack trace: {}".format(
armi.MPI_RANK, traceback.format_exc()
context.MPI_RANK, traceback.format_exc()
),
file=sys.__stderr__,
)
if armi.MPI_SIZE > 1:
if context.MPI_SIZE > 1:
print(
"[CRIT {:03} ] killing all MPI tasks from __main__.\n".format(
armi.MPI_RANK
context.MPI_RANK
),
file=sys.__stderr__,
)
# cleanTempDirs has @atexit.register so it should be called at the end, but mpi.Abort in main
# will not allow for @atexit.register or except/finally code to be called so calling here as well
context.cleanTempDirs()
# .Abort will not allow for @atexit.register or except/finally code to be called
armi.MPI_COMM.Abort(errorcode=-1)
context.MPI_COMM.Abort(errorcode=-1)
raise SystemExit(1)


Expand Down
58 changes: 41 additions & 17 deletions armi/apps.py
Expand Up @@ -31,7 +31,7 @@
from typing import Dict, Optional, Tuple, List
import collections

from armi import plugins, pluginManager, meta, settings
from armi import context, plugins, pluginManager, meta, settings
from armi.reactor import parameters
from armi.settings import Setting
from armi.settings import fwSettings
Expand Down Expand Up @@ -96,10 +96,16 @@ def __init__(self):
self._paramRenames: Optional[Tuple[Dict[str, str], int]] = None

@property
def pluginManager(self) -> pluginManager.ArmiPluginManager:
"""
Return the App's PluginManager.
def version(self) -> str:
"""Grab the version of this app (defaults to ARMI version).
NOTE: This is designed to be over-ridable by Application developers.
"""
return meta.__version__

@property
def pluginManager(self) -> pluginManager.ArmiPluginManager:
"""Return the App's PluginManager."""
return self._pm

def getSettings(self) -> Dict[str, Setting]:
Expand Down Expand Up @@ -221,19 +227,37 @@ def splashText(self):
Return a textual splash screen.
Specific applications will want to customize this, but by default the ARMI one
is produced.
is produced, with extra data on the App name and version, if available.
"""
# Don't move the triple quotes from the beginning of the line
return r"""
---------------------------------------------------
| _ ____ __ __ ___ |
| / \ | _ \ | \/ | |_ _| |
| / _ \ | |_) | | |\/| | | | |
| / ___ \ | _ < | | | | | | |
| /_/ \_\ |_| \_\ |_| |_| |___| |
| Advanced Reactor Modeling Interface |
---------------------------------------------------
Version {0:10s}
""".format(
# typical ARMI splash text
splash = r"""
+===================================================+
| _ ____ __ __ ___ |
| / \ | _ \ | \/ | |_ _| |
| / _ \ | |_) | | |\/| | | | |
| / ___ \ | _ < | | | | | | |
| /_/ \_\ |_| \_\ |_| |_| |___| |
| Advanced Reactor Modeling Interface |
| |
| version {0:10s} |
| |""".format(
meta.__version__
)

# add the name/version of the current App, if it's not the default
if context.APP_NAME != "armi":
# pylint: disable=import-outside-toplevel # avoid cyclic import
from armi import getApp

splash += r"""
|---------------------------------------------------|
| {0:>17s} app version {1:10s} |""".format(
context.APP_NAME, getApp().version
)

# bottom border of the splash
splash += r"""
+===================================================+
"""

return splash
36 changes: 21 additions & 15 deletions armi/bookkeeping/db/database3.py
Expand Up @@ -62,12 +62,12 @@
import itertools
import os
import pathlib
from platform import uname
import re
import sys
import time
import shutil
import subprocess
import sys
import time
from platform import uname
from typing import (
Optional,
Tuple,
Expand All @@ -80,12 +80,13 @@
Generator,
)

import numpy
import h5py
import numpy

import armi
from armi import context
from armi import getApp
from armi import interfaces
from armi import meta
from armi import runLog
from armi import settings
from armi.reactor import parameters
Expand Down Expand Up @@ -294,7 +295,7 @@ def interactDistributeState(self) -> None:
DB is created and managed by the master node only but we can still connect to it
from workers to enable things like history tracking.
"""
if armi.MPI_RANK > 0:
if context.MPI_RANK > 0:
# DB may not exist if distribute state is called early.
if self._dbPath is not None and os.path.exists(self._dbPath):
self._db = Database3(self._dbPath, "r")
Expand Down Expand Up @@ -327,6 +328,7 @@ def prepRestartRun(self, dbCycle, dbNode):
self._db.mergeHistory(inputDB, self.cs["startCycle"], self.cs["startNode"])
self.loadState(dbCycle, dbNode)

# TODO: The use of "yield" here is suspect.
def _getLoadDB(self, fileName):
"""
Return the database to load from in order of preference.
Expand Down Expand Up @@ -366,7 +368,6 @@ def loadState(
If fileName is not specified and neither the database in memory, nor the
`cs["reloadDBName"]` have the time step specified.
"""

for potentialDatabase in self._getLoadDB(fileName):
with potentialDatabase as loadDB:
if loadDB.hasTimeStep(cycle, timeNode, statePointName=timeStepName):
Expand Down Expand Up @@ -581,13 +582,13 @@ def open(self):
runLog.info("Opening database file at {}".format(os.path.abspath(filePath)))
self.h5db = h5py.File(filePath, self._permission)
self.h5db.attrs["successfulCompletion"] = False
self.h5db.attrs["version"] = armi.__version__
self.h5db.attrs["version"] = meta.__version__
self.h5db.attrs["databaseVersion"] = self.version
self.h5db.attrs["user"] = armi.USER
self.h5db.attrs["user"] = context.USER
self.h5db.attrs["python"] = sys.version
self.h5db.attrs["armiLocation"] = os.path.dirname(armi.ROOT)
self.h5db.attrs["startTime"] = armi.START_TIME
self.h5db.attrs["machines"] = numpy.array(armi.MPI_NODENAMES).astype("S")
self.h5db.attrs["armiLocation"] = os.path.dirname(context.ROOT)
self.h5db.attrs["startTime"] = context.START_TIME
self.h5db.attrs["machines"] = numpy.array(context.MPI_NODENAMES).astype("S")
# store platform data
platform_data = uname()
self.h5db.attrs["platform"] = platform_data.system
Expand All @@ -596,7 +597,7 @@ def open(self):
self.h5db.attrs["platformVersion"] = platform_data.version
self.h5db.attrs["platformArch"] = platform_data.processor
# store app and plugin data
app = armi.getApp()
app = getApp()
self.h5db.attrs["appName"] = app.name
plugins = app.pluginManager.list_name_plugin()
ps = [
Expand Down Expand Up @@ -1095,7 +1096,12 @@ def load(
parameterCollections.GLOBAL_SERIAL_NUM, layout.serialNum.max()
)
root = comps[0][0]
return root # usually reactor object

# ensure the max assembly number is correct
updateGlobalAssemblyNum(root)

# usually a reactor object
return root

@staticmethod
def _assignBlueprintsParams(blueprints, groupedComps):
Expand Down Expand Up @@ -1298,7 +1304,7 @@ def _addHomogenizedNumberDensityParams(blocks, h5group):
def _readParams(h5group, compTypeName, comps, allowMissing=False):
g = h5group[compTypeName]

renames = armi.getApp().getParamRenames()
renames = getApp().getParamRenames()

pDefs = comps[0].pDefs

Expand Down
4 changes: 2 additions & 2 deletions armi/bookkeeping/db/tests/test_comparedb3.py
Expand Up @@ -30,15 +30,15 @@ def setUp(self):
def tearDown(self):
self.td.__exit__(None, None, None)

def test_outputWriter(self) -> None:
def test_outputWriter(self):
fileName = "test_outputWriter.txt"
with OutputWriter(fileName) as out:
out.writeln("Rubber Baby Buggy Bumpers")

txt = open(fileName, "r").read()
self.assertIn("Rubber", txt)

def test_diffResultsBasic(self) -> None:
def test_diffResultsBasic(self):
# init an instance of the class
dr = DiffResults(0.01)
self.assertEqual(len(dr._columns), 0)
Expand Down

0 comments on commit 45f81b6

Please sign in to comment.