Skip to content

Commit

Permalink
example
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhjames committed Oct 16, 2024
1 parent b535ac8 commit aa8401d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
10 changes: 9 additions & 1 deletion armi/reactor/parameters/parameterCollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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):
Expand Down
4 changes: 0 additions & 4 deletions armi/reactor/parameters/parameterDefinitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ def __init__(
self.categories = categories
self.assigned = NEVER
self._backup = None
self.readOnly = False

if self.default is not NoDefault:

Expand Down Expand Up @@ -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):
Expand Down
23 changes: 9 additions & 14 deletions armi/reactor/reactorParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit aa8401d

Please sign in to comment.