Tuples get changed to lists
Tuples get changed to list. It did not find this behavior in the documentation, so I guess it might be undesired.
Here is a short example to reproduce it:
from sacred import Experiment
ex = Experiment('test')
@ex.config
def _config():
axis = (0, 1)
network = dict(
axis=(0, 1),
)
print('config', type(axis))
print('config', type(network['axis']))
@ex.automain
def main(axis, network):
print('main', type(axis))
print('main', type(network['axis']))
Hi! Thank you for this nice bug report.
At the moment said conversion is a technical limitation, since everything is converted to JSON for later storage in a database etc.. And unfortunately JSON doesn't distinguish between lists and tuples. This might change if jsonpickle gets integrated (see #111). But for the moment, conversion is the intended behavior.
That being said, I fully agree that it should be documented. I'll update the docs for the next release.
This should be resolved in the current 0.7b1 release.
Tuples are stilled converted to lists in version 0.7.4, at least in my observation.
Confirmed, tuples are still converted to lists in version 0.7.4.
This function in config/utils.py is causing the issue:
def normalize_or_die(obj):
if isinstance(obj, dict):
res = dict()
for key, value in obj.items():
assert_is_valid_key(key)
res[key] = normalize_or_die(value)
return res
elif isinstance(obj, (list, tuple)):
return list([normalize_or_die(value) for value in obj])
return normalize_numpy(obj)
Still converted to lists in 0.7.5. This issue shouldn't be closed.
@Qwlouse: is there any progress on resolving this issue? This behaviour is quite unexpected.
+1 for re-opening this issue - spent several hours today trying to track down this problem, and finally arrived at the function normalize_or_die and this issue.
Using the stable docs at https://sacred.readthedocs.io/ I couldn't see anything about tuples being converted to lists.
Submitted a PR to update the docs with some info about this. Hopefully saves future visitors a few hours de-bugging.