armi.reactor.parameters.resolveCollections module
This module contains the magic that makes the Parameter system and ARMI composite model play nicely together.
The contained metaclass is useful for maintaining a hierarchy of ParameterCollection
classes, which mimic the hierarchy of ArmiObject
s to which they apply. Some
ArmiObject
subclasses define their own parameters, while others do not, so we do not
want to blindly create a ParameterCollectionClass
for each ArmiObject
subclass.
Instead, we want to be able to skip generations when no additional parameters were
requested for that level. For instance if we have a hierarchy like: ArmiObject
<-
A
<- B
, where ArmiObject
and B
define parameters, while A
does not
define any parameters of its own, we want to have a ArmiObjectParameterCollection
and a BParameterCollection
(with BParameterCollection
being a subclass of
ArmiObjectParameterCollection
). ArmiObject
and A
will both share the
ArmiObjectParameterCollection
, while B
will use BParameterCollection
.
BParameterCollection
will contain all of the parameters defined in
ArmiObjectParameterCollection
, plus whatever additional parameters were defined on
B
.
The above scenario should behave rather intuitively for someone used to classes and
inheritance, but maintaining this hierarchy by hand would be onerous and error-prone.
What if one day we decide to add some parameters to A
? We need to remember to add a
new class for its parameters, and make sure to make BParameterCollection
a subclass
of that new ParameterCollection
class. With the below metaclass, we needn’t worry
ourselves with any of that; it is taken care of automatically.
If you want to know how the sausage is made, the ResolveParametersMeta
metaclass is
responsible for forming a hierarchy of ParameterCollection
classes that correspond
to the related hierarchy of classes inheriting the root ArmiObject
class. It should
be rare for an ARMI developer not engaged directly with Framework development to need to
know exactly how this works, but a proficient ARMI developer must keep in mind the
following rules about how this system behaves in practice:
When defining subclasses of
ArmiObject
, defining a class attribute calledpDefs
of theParameterDefinitionCollection
type signals to the system that this is a Parameter Class.When defining a Parameter Class, it will trigger the creation of a new
ParameterCollection
class, which will be derived from theParameterCollection
class of the most immediate Parameter Class ancestor the new class’s inheritance tree.All classes derived from
ArmiObject
will receive an associated subclass ofParameterCollection
, which will ultimately include all of the relevant Parameters for that class. The specific class is theParameterCollection
subclass defined for the most immediate Parameter Class in the classes inheritance tree.Parameter definitions can be added to a Parameter Class’s
pDefs
until Parameters have been “compiled” for it. After compiling parameters, thepDefs
are locked, and any attempts at defining additional parameters will cause an error.ArmiObject
s cannot be instantiated until after parameters have been compiled.
- class armi.reactor.parameters.resolveCollections.ResolveParametersMeta(name, bases, attrs)[source]
Bases:
type
Metaclass for automatically defining associated ParameterCollection classes.
Any class invoking this metaclass will automatically create an associated sub-class of the
ParameterCollection
type, if it has a class attribute calledpDefs
that is an instance ofParameterDefinitionCollection
. This new class will itself be a subclass of theParameterCollection
class that is associated with the invoking class’s parent.If no
pDefs
class attribute is present, the invoking class will adopt theParameterCollection
class associated with it’s parent, orNone
if it cannot find one.The associated
ParameterCollection
will be stored on the new class’sparamCollectionType
attribute.For example, when this metaclass is applied to the
Block
class it will create a new class namedBlockParameterCollection
, and add it as a class attribute calledBlock.paramCollectionType
. TheBlockParameterCollection
class will itself be a subclass ofArmiObjectParameterCollection
, which it would have found from theComposite
class from which theBlock
class inherits. TheComposite
calss, on the other hand, would have obtained theArmiObjectParameterCollection
from it’s parent (ArmiObject
), since it does not have apDefs
attribute of its own.