Model Evaluation¶
Getter Functions¶
AttrGetter¶
- qsdsan.utils.AttrGetter(obj, attr, hook=<function AttrGetter.<lambda>>, hook_param=())¶
FuncGetter¶
- qsdsan.utils.FuncGetter(func, params=())¶
Setter Functions¶
AttrFuncSetter¶
- qsdsan.utils.AttrFuncSetter(obj, attrs, funcs)¶
AttrSetter¶
- qsdsan.utils.AttrSetter(obj, attrs)¶
DictAttrSetter¶
- qsdsan.utils.DictAttrSetter(obj, dict_attr, keys)¶
MethodSetter¶
- qsdsan.utils.MethodSetter(obj, method, key=None, **kwargs)¶
Sample Manipulation¶
copy_samples¶
- qsdsan.utils.copy_samples(original, new, exclude=(), only_same_baseline=False)¶
Copy samples of the shared parameters in the original model to the new model. Parameters in exclude will be excluded (i.e., will not be copied).
- Parameters:
original (obj) – Original model where the samples will be copied from.
new (obj) – New model whose samples of the shared parameters will be copied from the original model.
exclude (tuple(obj)) – Parameters that will be excluded from copying.
only_same_baseline (bool) – If True, will only copy parameters with the same name, units, and baseline values.
Examples
Create two models with shared and different parameters
>>> from qsdsan.utils import create_example_model, copy_samples >>> original = create_example_model() >>> # You might get some replacing warnings as we are making two exact systems, >>> # it's OK >>> new = create_example_model() >>> # Sort the parameter orders >>> for model in (original, new): ... model.parameters = sorted(model.parameters, key=lambda p: p.name)
Let’s make the 1st/2nd parameters of the original model the same as the 0th/1st parameters of the new model.
>>> original.parameters = original.parameters[:3] >>> original.parameters (<Parameter: [HXutility-H1] Heat exchanger temperature (K)>, <Parameter: [Mix tank-M1] Mix tank mixer power usage (kW/m3)>, <Parameter: [Mix tank-M1] Mix tank retention time (hr)>) >>> new.parameters = new.parameters[1:4] >>> new.parameters (<Parameter: [Mix tank-M1] Mix tank mixer power usage (kW/m3)>, <Parameter: [Mix tank-M1] Mix tank retention time (hr)>, <Parameter: [Pump-P1] Pump design head (kPa)>)
Before copying, samples of the shared parameter are not the same
>>> original_samples = original.sample(N=100, rule='L') >>> original.load_samples(original_samples) >>> new_samples = new.sample(N=100, rule='L') >>> new.load_samples(new_samples) >>> (original.table.values[:, 1:3]==new.table.values[:, 0:2]).all() False
Let’s copy the samples, but exclude the “Mix tank retention time”
>>> copy_samples(original, new, exclude=(original.parameters[2],)) >>> # After copying, all of the samples of the "Mix tank mixer power usage" >>> # parameter are the same >>> (original.table.values[:, 1]==new.table.values[:, 0]).all() True >>> # But the samples are not the same for the excluded parameter >>> # "Mix tank retention time" parameter >>> (original.table.values[:, 2]==new.table.values[:, 1]).all() False
When only_same_baseline is True, only values for samples with the same name and unit will not be copied if their baseline values are different.
>>> # Let's change the baseline values for the "Mix tank retention time" parameter >>> # to be different for the two models >>> new.parameters[1].baseline = original.parameters[2].baseline + 10 >>> copy_samples(original, new, exclude=(), only_same_baseline=True) >>> # Samples are not copied even if they have the same names due to the unequal baselines >>> (original.table.values[:, 2]==new.table.values[:, 1]).any() False