Skip to content

Commit

Permalink
Merging in main
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Dec 20, 2024
2 parents 34ba5be + f86ef61 commit d813695
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 63 deletions.
4 changes: 2 additions & 2 deletions armi/cases/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import ast
import cProfile
import glob
import io
import os
import pathlib
import pstats
Expand All @@ -38,7 +39,6 @@
import trace

import coverage
import six

from armi import context
from armi import getPluginManager
Expand Down Expand Up @@ -492,7 +492,7 @@ def _endProfiling(profiler=None):

profiler.disable()
profiler.dump_stats("profiler.{:0>3}.stats".format(context.MPI_RANK))
statsStream = six.StringIO()
statsStream = io.StringIO()
summary = pstats.Stats(profiler, stream=statsStream).sort_stats("cumulative")
summary.print_stats()
if context.MPI_SIZE > 0 and context.MPI_COMM is not None:
Expand Down
5 changes: 1 addition & 4 deletions armi/cli/entryPoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import argparse
from typing import Optional, Union

import six

from armi import context, runLog, settings


Expand All @@ -46,8 +44,7 @@ def __new__(mcs, name, bases, attrs):
return type.__new__(mcs, name, bases, attrs)


@six.add_metaclass(_EntryPointEnforcer)
class EntryPoint:
class EntryPoint(metaclass=_EntryPointEnforcer):
"""
Generic command line entry point.
Expand Down
7 changes: 1 addition & 6 deletions armi/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ def setMode(cls, mode):


try:
# Check for MPI. The mpi4py module uses cPickle to serialize python objects in preparation for
# network transmission. Sometimes, when cPickle fails, it gives very cryptic error messages that
# do not help much. If you uncomment th following line, you can trick mpi4py into using the
# pure-python pickle module in place of cPickle and now you will generally get much more
# meaningful and useful error messages Then comment it back out because it's slow.
# import sys, pickle; sys.modules['cPickle'] = pickle
# Check for MPI
from mpi4py import MPI

MPI_COMM = MPI.COMM_WORLD
Expand Down
7 changes: 3 additions & 4 deletions armi/mpiActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@
import collections
import gc
import math
import pickle
import timeit

from six.moves import cPickle

from armi import context
from armi import interfaces
from armi import runLog
Expand Down Expand Up @@ -138,7 +137,7 @@ def _mpiOperationHelper(self, obj, mpiFunction):
self.o = self.r = self.cs = None
try:
return mpiFunction(obj, root=0)
except cPickle.PicklingError as error:
except pickle.PicklingError as error:
runLog.error("Failed to {} {}.".format(mpiFunction.__name__, obj))
runLog.error(error)
raise
Expand Down Expand Up @@ -539,7 +538,7 @@ def invokeHook(self):
# or how the interfaces are distributed.
self.r._markSynchronized()

except (cPickle.PicklingError, TypeError) as error:
except (pickle.PicklingError, TypeError) as error:
runLog.error("Failed to transmit on distribute state root MPI bcast")
runLog.error(error)
# workers are still waiting for a reactor object
Expand Down
4 changes: 1 addition & 3 deletions armi/nuclearDataIO/cccc/tests/test_cccc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import io
import unittest

import six

from armi.nuclearDataIO import cccc


Expand Down Expand Up @@ -104,4 +102,4 @@ def setUpClass(cls):
cls.readerClass = cccc.AsciiRecordReader

def setUp(self):
self.streamCls = six.StringIO
self.streamCls = io.StringIO
8 changes: 4 additions & 4 deletions armi/nuclearDataIO/tests/test_xsLibraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import copy
import filecmp
import os
import pickle
import traceback
import unittest

import numpy as np
from six.moves import cPickle

from armi.nucDirectory import nuclideBases
from armi.nuclearDataIO import xsLibraries
Expand Down Expand Up @@ -87,15 +87,15 @@ def setUpClass(cls):
cls.xsLibGenerationErrorStack = traceback.format_exc()

def test_canPickleAndUnpickleISOTXS(self):
pikAA = cPickle.loads(cPickle.dumps(self.isotxsAA))
pikAA = pickle.loads(pickle.dumps(self.isotxsAA))
self.assertTrue(xsLibraries.compare(pikAA, self.isotxsAA))

def test_canPickleAndUnpickleGAMISO(self):
pikAA = cPickle.loads(cPickle.dumps(self.gamisoAA))
pikAA = pickle.loads(pickle.dumps(self.gamisoAA))
self.assertTrue(xsLibraries.compare(pikAA, self.gamisoAA))

def test_canPickleAndUnpicklePMATRX(self):
pikAA = cPickle.loads(cPickle.dumps(self.pmatrxAA))
pikAA = pickle.loads(pickle.dumps(self.pmatrxAA))
self.assertTrue(xsLibraries.compare(pikAA, self.pmatrxAA))

def test_compareWorks(self):
Expand Down
8 changes: 4 additions & 4 deletions armi/physics/neutronics/tests/test_crossSectionManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
"""
import copy
import os
import pickle
import unittest
from io import BytesIO
from unittest.mock import MagicMock

from six.moves import cPickle

from armi import settings
from armi.physics.neutronics import crossSectionGroupManager
from armi.physics.neutronics.const import CONF_CROSS_SECTION
Expand Down Expand Up @@ -73,9 +72,9 @@ def test_getBlocksInGroup(self):
def test_is_pickleable(self):
self.bc.weightingParam = "test"
buf = BytesIO()
cPickle.dump(self.bc, buf)
pickle.dump(self.bc, buf)
buf.seek(0)
newBc = cPickle.load(buf)
newBc = pickle.load(buf)
self.assertEqual(self.bc.weightingParam, newBc.weightingParam)


Expand All @@ -85,6 +84,7 @@ def setUp(self):
for bi, b in enumerate(self.blockList):
b.setType("fuel")
b.p.percentBu = bi / 4.0 * 100

self.blockList[0], self.blockList[2] = self.blockList[2], self.blockList[0]
self.bc = MedianBlockCollection(
self.blockList[0].core.r.blueprints.allNuclidesInProblem
Expand Down
4 changes: 1 addition & 3 deletions armi/reactor/blockParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.

"""Parameter definitions for Blocks."""
import six

from armi import runLog
from armi.physics.neutronics import crossSectionGroupManager
from armi.reactor import parameters
Expand Down Expand Up @@ -207,7 +205,7 @@ def envGroup(self, envGroupChar):
)
self.envGroupNum = intValue
return
elif not isinstance(envGroupChar, six.string_types):
elif not isinstance(envGroupChar, str):
raise Exception(
f"Wrong type for envGroupChar {envGroupChar}: {type(envGroupChar)}"
)
Expand Down
6 changes: 2 additions & 4 deletions armi/reactor/composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from typing import Dict, List, Optional, Tuple, Type, Union

import numpy as np
import six

from armi import context, runLog, utils
from armi.nucDirectory import elements, nucDir, nuclideBases
Expand Down Expand Up @@ -759,10 +758,9 @@ def hasFlags(self, typeID: TypeSpec, exact=False):
"""
if not typeID:
return not exact
if isinstance(typeID, six.string_types):
if isinstance(typeID, str):
raise TypeError(
"Must pass Flags, or an iterable of Flags; Strings are no longer "
"supported"
"Must pass Flags, or an iterable of Flags; Strings are no longer supported"
)

elif not isinstance(typeID, Flags):
Expand Down
15 changes: 7 additions & 8 deletions armi/reactor/parameters/parameterCollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Optional, List, Set, Iterator, Callable
import copy
import pickle
from typing import Any, Optional, List, Set, Iterator, Callable
import sys

import numpy as np
import six

from armi import runLog
from armi.reactor.parameters import parameterDefinitions, exceptions
Expand All @@ -38,10 +37,10 @@
This is a counter of the number of instances of all types. They are useful for tracking items
through the history of a database.
.. warning::
This is not MPI safe. We also have not done anything to make it thread safe,
except that the GIL exists.
Warning
-------
This is not MPI safe. We also have not done anything to make it thread safe, except that the GIL
exists.
"""


Expand Down Expand Up @@ -365,7 +364,7 @@ def __setitem__(self, name, value):
)

def __delitem__(self, name):
if isinstance(name, six.string_types):
if isinstance(name, str):
pd = self.paramDefs[name]
if hasattr(self, pd.fieldName):
pd.assigned = SINCE_ANYTHING
Expand All @@ -374,7 +373,7 @@ def __delitem__(self, name):
del self._hist[name]

def __contains__(self, name):
if isinstance(name, six.string_types):
if isinstance(name, str):
return hasattr(self, "_p_" + name)
else:
return name in self._hist
Expand Down
4 changes: 2 additions & 2 deletions armi/reactor/tests/test_reactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import copy
import logging
import os
import pickle
import unittest
from math import sqrt
from unittest.mock import patch

from numpy.testing import assert_allclose, assert_equal
from six.moves import cPickle

from armi import operators
from armi import runLog
Expand Down Expand Up @@ -846,7 +846,7 @@ def test_getMass(self):
assert_allclose(mass1, mass2)

def test_isPickleable(self):
loaded = cPickle.loads(cPickle.dumps(self.r))
loaded = pickle.loads(pickle.dumps(self.r))

# ensure we didn't break the current reactor
self.assertIs(self.r.core.spatialGrid.armiObject, self.r.core)
Expand Down
7 changes: 3 additions & 4 deletions armi/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
This will not be a catch-all for random unit test functions. Be very sparing here.
"""
import os

from six.moves import cPickle
import pickle

from armi import operators, runLog, settings
from armi.reactor import reactors
Expand Down Expand Up @@ -72,7 +71,7 @@ def loadTestReactor(

if isPickeledReactor and _TEST_REACTOR:
# return test reactor only if no custom settings are needed.
o, r, assemNum = cPickle.loads(_TEST_REACTOR)
o, r, assemNum = pickle.loads(_TEST_REACTOR)
o.reattach(r, o.cs)
return o, r

Expand All @@ -95,7 +94,7 @@ def loadTestReactor(
if isPickeledReactor:
# cache it for fast load for other future tests protocol=2 allows for classes with __slots__
# but not __getstate__ to be pickled
_TEST_REACTOR = cPickle.dumps((o, o.r, o.r.p.maxAssemNum), protocol=2)
_TEST_REACTOR = pickle.dumps((o, o.r, o.r.p.maxAssemNum), protocol=2)

return o, o.r

Expand Down
14 changes: 7 additions & 7 deletions armi/tests/mockRunLogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module contains subclasses of the armi.runLog._RunLog class that can be used to determine whether or not
one of the specific methods were called. These should only be used in testing.
This module contains subclasses of the armi.runLog._RunLog class that can be used to determine
whether or not one of the specific methods were called. These should only be used in testing.
"""
import six
import io
import sys

from armi import runLog


class BufferLog(runLog._RunLog):
r"""Log which captures the output in attributes instead of emitting them.
"""Log which captures the output in attributes instead of emitting them.
Used mostly in testing to ensure certain things get output, or to prevent any output
from showing.
Used mostly in testing to ensure certain things get output, or to prevent any output from
showing.
"""

def __init__(self, *args, **kwargs):
Expand All @@ -34,7 +34,7 @@ def __init__(self, *args, **kwargs):
self._outputStream = ""
self._singleMessageCounts = {}
self._singleWarningMessageCounts = {}
self._errStream = six.StringIO()
self._errStream = io.StringIO()
sys.stderr = self._errStream
self.setVerbosity(0)

Expand Down
8 changes: 3 additions & 5 deletions armi/utils/iterables.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
# limitations under the License.

"""Module of utilities to help dealing with iterable objects in Python."""
from itertools import tee, chain
from itertools import chain, filterfalse, tee
import struct

from six.moves import filterfalse, map, xrange, filter

import numpy as np


Expand All @@ -43,7 +41,7 @@ def chunk(lst, n):
>>> list(chunk([1,2,3,4,5,6,7,8,9,10], 4))
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]
"""
for i in xrange(0, len(lst), n):
for i in range(0, len(lst), n):
yield lst[i : i + n]


Expand Down Expand Up @@ -84,7 +82,7 @@ def split(a, n, padWith=()):

k, m = divmod(N, n)
chunked = [
a[i * k + min(i, m) : (i + 1) * k + min(i + 1, m)] or padWith for i in xrange(n)
a[i * k + min(i, m) : (i + 1) * k + min(i + 1, m)] or padWith for i in range(n)
]
return chunked

Expand Down
Loading

0 comments on commit d813695

Please sign in to comment.