Skip to content

Commit 0115eb7

Browse files
committed
Pr comments
1 parent 30f19e3 commit 0115eb7

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/easyscience/Objects/variable/descriptor_number.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ def error(self, value: float) -> None:
240240
else:
241241
self._scalar.variance = None
242242

243+
# When we convert units internally, we dont want to notify observers as this can cause infinite recursion.
244+
# Therefore the convert_unit method is split into two methods, a private internal method and a public method.
243245
def _convert_unit(self, unit_str: str) -> None:
244246
"""
245247
Convert the value from one unit system to another.
@@ -271,6 +273,7 @@ def set_scalar(obj, scalar):
271273
# Update the scalar
272274
self._scalar = new_scalar
273275

276+
# When the user calls convert_unit, we want to notify observers of the change to propagate the change.
274277
@notify_observers
275278
def convert_unit(self, unit_str: str) -> None:
276279
"""

src/easyscience/Objects/variable/parameter.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(
6464
:param variance: The variance of the value
6565
:param min: The minimum value for fitting
6666
:param max: The maximum value for fitting
67-
:param fixed: Can the parameter vary?
67+
:param fixed: If the parameter is free to vary during fitting
6868
:param description: A brief summary of what this object is
6969
:param url: Lookup url for documentation/information
7070
:param display_name: The name of the object as it should be displayed
@@ -160,7 +160,15 @@ def make_dependent_on(self, dependency_expression: str, dependency_map: Optional
160160
"""
161161
Make this parameter dependent on another parameter. This will overwrite the current value, unit, variance, min and max.
162162
163-
:param dependency_expression: The dependency expression to evaluate. This should be a string which can be evaluated by the ASTEval interpreter.
163+
How to use the dependency map:
164+
If a parameter c has a dependency expression of 'a + b', where a and b are parameters belonging to the model class,
165+
then the dependency map needs to have the form {'a': model.a, 'b': model.b}, where model is the model class.
166+
I.e. the values are the actual objects, whereas the keys are how they are represented in the dependency expression.
167+
168+
The dependency map is not needed if the dependency expression uses the unique names of the parameters.
169+
Unique names in dependency expressions are defined by quotes, e.g. 'Parameter_0' or "Parameter_0" depending on the quotes used for the expression.
170+
171+
:param dependency_expression: The dependency expression to evaluate. This should be a string which can be evaluated by a python interpreter.
164172
:param dependency_map: A dictionary of dependency expression symbol name and dependency object pairs. This is inserted into the asteval interpreter to resolve dependencies.
165173
""" # noqa: E501
166174
if not isinstance(dependency_expression, str):
@@ -181,13 +189,13 @@ def make_dependent_on(self, dependency_expression: str, dependency_map: Optional
181189
self._dependency_string = dependency_expression
182190
self._dependency_map = dependency_map if dependency_map is not None else {}
183191
self._dependency_interpreter = Interpreter(minimal=True)
184-
self._dependency_interpreter.config['if'] = True
192+
self._dependency_interpreter.config['if'] = True # allows logical statements in the dependency expression
185193
self._dependency_updates = {} # Used to track update ids to avoid cyclic dependencies
186194

187195
self._process_dependency_unique_names(self._dependency_string)
188196
for key, value in self._dependency_map.items():
189197
self._dependency_interpreter.symtable[key] = value
190-
self._dependency_interpreter.readonly_symbols.add(key)
198+
self._dependency_interpreter.readonly_symbols.add(key) # Dont allow overwriting of the dependencies in the dependency expression # noqa: E501
191199
value._attach_observer(self)
192200
try:
193201
dependency_result = self._dependency_interpreter.eval(self._clean_dependency_string, raise_errors=True)
@@ -243,7 +251,7 @@ def independent(self, value: bool) -> None:
243251
raise AttributeError('This property is read-only. Use `make_independent` and `make_dependent_on` to change the state of the parameter.') # noqa: E501
244252

245253
@property
246-
def depedency_expression(self) -> str:
254+
def dependency_expression(self) -> str:
247255
"""
248256
Get the dependency expression of this parameter.
249257
@@ -254,7 +262,7 @@ def depedency_expression(self) -> str:
254262
else:
255263
raise AttributeError('This parameter is independent. It has no dependency expression.')
256264

257-
@depedency_expression.setter
265+
@dependency_expression.setter
258266
def depedency_expression(self, new_expression: str) -> None:
259267
raise AttributeError('Dependency expression is read-only. Use `make_dependent_on` to change the dependency expression.')
260268

0 commit comments

Comments
 (0)