Skip to content

Commit

Permalink
Merge 317ddfd into 907f2b4
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science authored Apr 15, 2022
2 parents 907f2b4 + 317ddfd commit d2603d8
Show file tree
Hide file tree
Showing 39 changed files with 401 additions and 415 deletions.
6 changes: 6 additions & 0 deletions armi/__init__.py
Original file line number Diff line number Diff line change
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
18 changes: 9 additions & 9 deletions armi/__main__.py
Original file line number Diff line number Diff line change
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
27 changes: 14 additions & 13 deletions armi/bookkeeping/db/database3.py
Original file line number Diff line number Diff line change
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 @@ -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 @@ -1298,7 +1299,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/memoryProfiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import tabulate
from typing import Optional

import armi
from armi import context
from armi import interfaces
from armi import mpiActions
from armi import runLog
Expand Down Expand Up @@ -521,7 +521,7 @@ def invokeHook(self):

class SystemAndProcessMemoryUsage:
def __init__(self):
self.nodeName = armi.MPI_NODENAME
self.nodeName = context.MPI_NODENAME
# no psutil, no memory diagnostics. TODO: Ideally, we could just cut
# MemoryProfiler out entirely, but it is referred to directly by the standard
# operator and reports, so easier said than done.
Expand Down
18 changes: 9 additions & 9 deletions armi/bookkeeping/newReports.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from abc import ABC, abstractmethod
from enum import Enum
from enum import auto
import collections
import shutil
import os
import copy
from operator import itemgetter
from typing import Union, Dict
from abc import ABC, abstractmethod
import base64
from operator import itemgetter
import collections
import copy
import os
import shutil

import matplotlib.pyplot as plt
import htmltree
import matplotlib.pyplot as plt

import armi.context
from armi import context
from armi import runLog


Expand Down Expand Up @@ -56,7 +56,7 @@ def writeReports(self):
)
header.C.append(
htmltree.H1(
"{} Report".format(armi.context.APP_NAME.capitalize()),
"{} Report".format(context.APP_NAME.capitalize()),
_class="heading",
id="titleFont",
)
Expand Down
25 changes: 9 additions & 16 deletions armi/bookkeeping/report/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# limitations under the License.

"""
HTML-formatted reports
"""
import os
import html
import datetime
import base64
import datetime
import html
import os

import armi
from armi import context
from armi import settings


Expand Down Expand Up @@ -228,7 +228,9 @@ def writeStandardReportTemplate(f, report):
f,
attrs={
"src": encode64(
os.path.join(armi.RES, "images", "armiicon.ico")
os.path.join(
context.RES, "images", "armiicon.ico"
)
)
},
):
Expand All @@ -249,7 +251,7 @@ def writeStandardReportTemplate(f, report):
f, attrs={"class": "navbar-text navbar-version pull-left"}
):
with B(f):
f.write(armi.USER)
f.write(context.USER)

with Span(
f, attrs={"class": "navbar-text navbar-version pull-left"}
Expand Down Expand Up @@ -285,12 +287,3 @@ def writeStandardReportTemplate(f, report):
f.write("ARMI docs")
with P(f):
f.write("Automatically generated by ARMI")

# with Script(f, attrs={"type": r"text/javascript"}):
# load jquery js here (through CDN?)
#
# pass

# with Script(f, attrs={"type": r"text/javascript"}):
# load boostrap.min.js here (prefer through CDN)
# pass
39 changes: 19 additions & 20 deletions armi/bookkeeping/report/reportingUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
A collection of miscellaneous functions used by ReportInterface to generate
various reports
"""
import re
import os
import collections
import os
import pathlib
import textwrap
import re
import sys
import time
import tabulate
import textwrap
import time
from copy import copy

import numpy

import armi
from armi import context
from armi import interfaces
from armi import runLog
from armi.bookkeeping import report
from armi.operators import RunTypes
from armi.reactor.components import ComponentType
from armi.reactor.flags import Flags
from armi.utils import getFileSHA1Hash
from armi.utils import iterables
from armi.utils import units
from armi.utils import textProcessors
from armi.utils import plotting
from armi.utils import textProcessors
from armi.utils import units
from armi.utils.mathematics import findClosest
from armi import interfaces
from armi.bookkeeping import report
from armi.reactor.flags import Flags
from armi.reactor.components import ComponentType
from armi.operators import RunTypes


# Set to prevent the image and text from being too small to read.
Expand Down Expand Up @@ -74,13 +74,13 @@ def _writeCaseInformation(o, cs):
Operator_TypeOfRun,
"{} - {}".format(cs["runType"], o.__class__.__name__),
),
(Operator_CurrentUser, armi.USER),
(Operator_ArmiCodebase, armi.ROOT),
(Operator_CurrentUser, context.USER),
(Operator_ArmiCodebase, context.ROOT),
(Operator_WorkingDirectory, os.getcwd()),
(Operator_PythonInterperter, sys.version),
(Operator_MasterMachine, os.environ.get("COMPUTERNAME", "?")),
(Operator_NumProcessors, armi.MPI_SIZE),
(Operator_Date, armi.START_TIME),
(Operator_NumProcessors, context.MPI_SIZE),
(Operator_Date, context.START_TIME),
]

runLog.header("=========== Case Information ===========")
Expand Down Expand Up @@ -155,8 +155,8 @@ def _writeInputFileInformation(cs):

def _writeMachineInformation():
"""Create a table that contains basic machine and rank information."""
if armi.MPI_SIZE > 1:
processorNames = armi.MPI_NODENAMES
if context.MPI_SIZE > 1:
processorNames = context.MPI_NODENAMES
uniqueNames = set(processorNames)
nodeMappingData = []
for uniqueName in uniqueNames:
Expand Down Expand Up @@ -196,7 +196,7 @@ def _writeReactorCycleInformation(o, cs):
runLog.header("=========== Reactor Cycle Information ===========")
runLog.info(tabulate.tabulate(operatingData, tablefmt="armi"))

if armi.MPI_RANK > 0:
if context.MPI_RANK > 0:
return # prevent the worker nodes from printing the same thing

_writeCaseInformation(o, cs)
Expand Down Expand Up @@ -403,7 +403,6 @@ def setNeutronBalancesReport(core):
core : armi.reactor.reactors.Core
"""

if not core.getFirstBlock().p.rateCap:
runLog.warning(
"No rate information (rateCap, rateAbs, etc.) available "
Expand Down
15 changes: 6 additions & 9 deletions armi/bookkeeping/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
# limitations under the License.

"""Test reports."""
import os
import collections
import os
import unittest

import htmltree

import armi
from armi.tests import TEST_ROOT
from armi.reactor.tests import test_reactors
from armi import getPluginManagerOrFail
from armi.bookkeeping import newReports
from armi.utils import directoryChangers
from armi.physics.neutronics.reports import neutronicsPlotting
import armi.bookkeeping.newReports
from armi.reactor.tests import test_reactors
from armi.tests import TEST_ROOT
from armi.utils import directoryChangers


class TestReportContentCreation(unittest.TestCase):
Expand Down Expand Up @@ -56,7 +55,6 @@ def testTimeSeries(self):
self.assertTrue(os.path.exists("ReactorName.plotexample.png"))

def testTableCreation(self):

header = ["item", "value"]
table = newReports.Table("Assembly Table", "table of assemblies", header)

Expand All @@ -70,7 +68,7 @@ def testReportContents(self):
with directoryChangers.TemporaryDirectoryChanger():
reportTest = newReports.ReportContent("Test")

armi.getPluginManagerOrFail().hook.getReportContents(
getPluginManagerOrFail().hook.getReportContents(
r=self.r,
cs=self.o.cs,
report=reportTest,
Expand All @@ -86,7 +84,6 @@ def testReportContents(self):
)

def testNeutronicsPlotFunctions(self):

reportTest = newReports.ReportContent("Test")

neutronicsPlotting(self.r, reportTest, self.o.cs)
Expand Down
Loading

0 comments on commit d2603d8

Please sign in to comment.