diff --git a/armi/reactor/parameters/parameterCollections.py b/armi/reactor/parameters/parameterCollections.py index 44cc06d30..2c6af073e 100644 --- a/armi/reactor/parameters/parameterCollections.py +++ b/armi/reactor/parameters/parameterCollections.py @@ -146,6 +146,8 @@ def __init__(self, _state: Optional[List[Any]] = None): should come from a call to __getstate__(). This should only be used internally to this model. """ + self._slots.add("readOnly") + self.readOnly = False if self.pDefs is None or not self.pDefs.locked: type(self).applyParameters() @@ -275,7 +277,13 @@ def __setattr__(self, key, value): "Trying to set undefined attribute `{}` on " "a ParameterCollection!".format(key) ) - + if getattr(self, "readOnly", False): + if key == "readOnly": + raise RuntimeError( + "Parameter Collections cannot be made writeable after being set to read only." + ) + else: + raise RuntimeError(f"Cannot set read-only parameter {key}") object.__setattr__(self, key, value) def __deepcopy__(self, memo): diff --git a/armi/reactor/parameters/parameterDefinitions.py b/armi/reactor/parameters/parameterDefinitions.py index a953ed377..c993a8bf5 100644 --- a/armi/reactor/parameters/parameterDefinitions.py +++ b/armi/reactor/parameters/parameterDefinitions.py @@ -283,7 +283,6 @@ def __init__( self.categories = categories self.assigned = NEVER self._backup = None - self.readOnly = False if self.default is not NoDefault: @@ -331,9 +330,6 @@ def __setstate__(self, state): def __set__(self, obj, val): """This is a property setter, see Python documentation for "descriptor".""" - if self.readOnly: - raise RuntimeError(f"Cannot set read-only parameter {self.name}.") - self._setter(obj, val) def __get__(self, obj, cls=None): diff --git a/armi/reactor/reactorParameters.py b/armi/reactor/reactorParameters.py index ad67a20bb..9997c3d7c 100644 --- a/armi/reactor/reactorParameters.py +++ b/armi/reactor/reactorParameters.py @@ -791,17 +791,12 @@ def makeParametersReadOnly(r, readOnly=True): ARMI. So if you run this function once with `readOnly=True`, and you want to move on to other things, run this method on your reactor again with `readOnly=False` to unclock ARMI. """ - for pdef0 in r.p.paramDefs: - pdef0.readOnly = readOnly - for system in r.getChildren(): - for pdef1 in system.p.paramDefs: - pdef1.readOnly = readOnly - for a in system.getChildren(): - for pdef2 in a.p.paramDefs: - pdef2.readOnly = readOnly - for b in a.getChildren(): - for pdef3 in b.p.paramDefs: - pdef3.readOnly = readOnly - for c in b.getChildren(): - for pdef4 in c.p.paramDefs: - pdef4.readOnly = readOnly + r.p.readOnly = readOnly + for system in r.getChildren(): + system.p.readOnly = readOnly + for a in system.getChildren(): + a.p.readOnly = readOnly + for b in a.getChildren(): + b.p.readOnly = readOnly + for c in b.getChildren(): + c.p.readOnly = readOnly