uqfoundation / mystic

constrained nonlinear optimization for scientific machine learning, UQ, and AI
http://mystic.rtfd.io
Other
465 stars 50 forks source link

sample fails to write to cache for dict_archive in ouq_models #206

Open mmckerns opened 1 year ago

mmckerns commented 1 year ago

Use of a dict_archive in sample for an OUQModel fails to write back to the model cache when a dict_archive is used.

Python 3.8.17 (default, Jun 11 2023, 01:54:00) 
[Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ouq_models import WrapModel
>>> from emulators import cost4 as cost, bounds4 as bounds
>>> from mystic.cache.archive import dict_archive, read as create_db
>>> archive = create_db('truth', type=dict_archive)
>>> archive
dict_archive({}, cached=False)
>>> truth = WrapModel("truth", cost, nx=4, ny=None, cached=archive)
>>> truth([1,2,3,4])
1510.3774284161302
>>> archive
dict_archive({(1, 2, 3, 4): 1510.3774284161302}, cached=False)
>>> data = truth.sample(bounds, pts=[2, 1, 1, 1])
>>> archive
dict_archive({(1, 2, 3, 4): 1510.3774284161302}, cached=False)

This actually makes sense, as the archives used in sample is potentially different than the archive used as the model's cache... and one might specify the sampling archive to be different than the cache, or the cache might not exist.

However... if one explicitly specifies the same dict_archive as used with the model's cache, it still doesn't work... and this would seem to be a bug.

>>> data = truth.sample(bounds, pts=[2, 1, 1, 1], archive=archive)
>>> archive
dict_archive({(1, 2, 3, 4): 1510.3774284161302}, cached=False)