Closed victorventuri closed 3 months ago
Should we also have the ability to mark which variables are "updatable" vs which are not?
That's requirement 2 above, no?
Yep🤦
Adding here a simple code snippet of how it currently works for reference.
Code (Note: ignoring warnings because I chose to warn when model fields are reset, but that adds clutter here):
from asoh.models.base import HealthVariableCollection as HVCol
from asoh.models.base import HealthVariable as HV
import warnings
warnings.filterwarnings('ignore')
class DumHV(HV):
name: str
class DumHVCol(HVCol):
name: str
r0 = DumHV(base_values=[1,2], name='r0')
c0 = DumHV(base_values=3, name='c0', updatable=False)
r1 = DumHV(base_values=[4,5], name='r1')
c1 = DumHV(base_values=6, name='c1')
r2 = DumHV(base_values=[7,8], name='r2')
c2 = DumHV(base_values=[9,10], name='c2', updatable=False)
rc1 = DumHVCol(name='rc1')
rc1 += [r1, c1]
rc2 = DumHVCol(name='rc2')
rc2 += [r2, c2]
asoh = DumHVCol(name='asoh')
asoh += [r0, c0, rc1, rc2]
print('Updatable: ', asoh.updatable)
print('ASOH len: ', len(asoh))
print('Updatable values: ', asoh.get_updatable_parameter_values())
print('Changing values!')
asoh.update(new_values=[10,20,30,40,50,60,70])
print('New values: ', asoh.get_updatable_parameter_values())
for param_name in asoh.updatable:
print('-----------------')
print('Parameter ', param_name)
param = getattr(asoh, param_name)
if isinstance(param, DumHVCol):
print('Sub-parameters: ', param.updatable)
print('Updatable vals: ', param.get_updatable_parameter_values())
print('---------------------------------')
print('All accessible fields: ', list(asoh.model_fields.keys()))
Output:
Updatable: ('r0', 'rc1', 'rc2')
ASOH len: 7
Updatable values: [1, 2, 4, 5, 6.0, 7, 8]
Changing values!
New values: [10, 20, 30, 40, 50, 60, 70]
-----------------
Parameter r0
Updatable vals: [10, 20]
-----------------
Parameter rc1
Sub-parameters: ('r1', 'c1')
Updatable vals: [30, 40, 50]
-----------------
Parameter rc2
Sub-parameters: ('r2',)
Updatable vals: [60, 70]
---------------------------------
All accessible fields: ['updatable', 'name', 'r0', 'c0', 'rc1', 'rc2']
Going to try to summarize my thoughts here for a more streamline discussion over Teams:
It seems like, no matter what we do, we cannot escape the dynamic addition of more information for the HealthVariableCollection class. After all, we need to accommodate any natural number of RC components. If the need for dynamic allocation is not real, then we need to consider more than just these two options I am about to discuss below. Note: I will abbreviate HealthVariable
to HV
below
Pros:
Cons:
HealthVariable
will need to be re-written (__len__
, get_updatable_parameter_values
, _update_single_param
, update
), to the point that maybe it shouldn't even inherit from it, or we should change how HV
is defined. My thoughts:
HV
s is conceptually indistinguishable from a multivariate HV
(similar to how HV
has base_values
, the concept of resistance is conceptually equivalent to the concept of resistance at 50% SOC). This makes it hard for me to overlook Con#1 Pros:
HVCollection
is a collection of HV
and HVCollection
objectsHV
-like objects Cons:
My thoughts:
Final remarks:
update
, get_updatable_parameter_values
, __len__
, and force others (such as _update_single_param
) to be abstractmethod
s, and make most things that will be updated a child of thisBaseModel
children, use the extra
option, and then update the appropriate methods and properties to check model_fields.keys()
and model_extra.keys()
, though I am not sure what impact that would have on subsequent serialization__setitem__
and __getitem__
methods for looping through and setting attributes
Class to hold on to HealthVariable objects has is too complex. How can we rewrite it such that the following requirements are met
The questions that I have are:
Additional comments:
@WardLT What other things am I missing from this?