Skip to content

Ax is incompatible with SQLAlchemy 2.0+; incompatibility errors arise when using only JSON storage, too #1697

@ekurtgl

Description

@ekurtgl

Hi,

I am tryinng to save the NAS experiment presented here to a file, so that I can load it later on to do further analysis and visualization based on the results. I use the following code:

import ax.storage ax.storage.json_store.save.save_experiment(experiment, 'ax_nas_results.json')

However, it throws error:

`

JSONEncodeError Traceback (most recent call last)
Cell In[71], line 2
1 import ax.storage
----> 2 ax.storage.json_store.save.save_experiment(experiment, 'ax_nas_results.json')
3 # dir(ax.storage)

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/save.py:45, in save_experiment(experiment, filepath, encoder_registry, class_encoder_registry)
42 if not filepath.endswith(".json"):
43 raise ValueError("Filepath must end in .json")
---> 45 json_experiment = object_to_json(
46 experiment,
47 encoder_registry=encoder_registry,
48 class_encoder_registry=class_encoder_registry,
49 )
50 with open(filepath, "w+") as file:
51 file.write(json.dumps(json_experiment))

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:83, in object_to_json(obj, encoder_registry, class_encoder_registry)
81 if _type in encoder_registry:
82 obj_dict = encoder_registry_type
---> 83 return {
84 k: object_to_json(
85 v,
86 encoder_registry=encoder_registry,
87 class_encoder_registry=class_encoder_registry,
88 )
89 for k, v in obj_dict.items()
90 }
92 # Python built-in types + typing module types
93 if _type in (str, int, float, bool, type(None)):

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:84, in (.0)
81 if _type in encoder_registry:
82 obj_dict = encoder_registry_type
83 return {
---> 84 k: object_to_json(
85 v,
86 encoder_registry=encoder_registry,
87 class_encoder_registry=class_encoder_registry,
88 )
89 for k, v in obj_dict.items()
90 }
92 # Python built-in types + typing module types
93 if _type in (str, int, float, bool, type(None)):

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:83, in object_to_json(obj, encoder_registry, class_encoder_registry)
81 if _type in encoder_registry:
82 obj_dict = encoder_registry_type
---> 83 return {
84 k: object_to_json(
85 v,
86 encoder_registry=encoder_registry,
87 class_encoder_registry=class_encoder_registry,
88 )
89 for k, v in obj_dict.items()
90 }
92 # Python built-in types + typing module types
93 if _type in (str, int, float, bool, type(None)):

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:84, in (.0)
81 if _type in encoder_registry:
82 obj_dict = encoder_registry_type
83 return {
---> 84 k: object_to_json(
85 v,
86 encoder_registry=encoder_registry,
87 class_encoder_registry=class_encoder_registry,
88 )
89 for k, v in obj_dict.items()
90 }
92 # Python built-in types + typing module types
93 if _type in (str, int, float, bool, type(None)):

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:83, in object_to_json(obj, encoder_registry, class_encoder_registry)
81 if _type in encoder_registry:
82 obj_dict = encoder_registry_type
---> 83 return {
84 k: object_to_json(
85 v,
86 encoder_registry=encoder_registry,
87 class_encoder_registry=class_encoder_registry,
88 )
89 for k, v in obj_dict.items()
90 }
92 # Python built-in types + typing module types
93 if _type in (str, int, float, bool, type(None)):

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:84, in (.0)
81 if _type in encoder_registry:
82 obj_dict = encoder_registry_type
83 return {
---> 84 k: object_to_json(
85 v,
86 encoder_registry=encoder_registry,
87 class_encoder_registry=class_encoder_registry,
88 )
89 for k, v in obj_dict.items()
90 }
92 # Python built-in types + typing module types
93 if _type in (str, int, float, bool, type(None)):

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:96, in object_to_json(obj, encoder_registry, class_encoder_registry)
94 return obj
95 elif _type is list:
---> 96 return [
97 object_to_json(
98 x,
99 encoder_registry=encoder_registry,
100 class_encoder_registry=class_encoder_registry,
101 )
102 for x in obj
103 ]
104 elif _type is tuple:
105 return tuple(
106 object_to_json(
107 x,
(...)
111 for x in obj
112 )

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:97, in (.0)
94 return obj
95 elif _type is list:
96 return [
---> 97 object_to_json(
98 x,
99 encoder_registry=encoder_registry,
100 class_encoder_registry=class_encoder_registry,
101 )
102 for x in obj
103 ]
104 elif _type is tuple:
105 return tuple(
106 object_to_json(
107 x,
(...)
111 for x in obj
112 )

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:83, in object_to_json(obj, encoder_registry, class_encoder_registry)
81 if _type in encoder_registry:
82 obj_dict = encoder_registry_type
---> 83 return {
84 k: object_to_json(
85 v,
86 encoder_registry=encoder_registry,
87 class_encoder_registry=class_encoder_registry,
88 )
89 for k, v in obj_dict.items()
90 }
92 # Python built-in types + typing module types
93 if _type in (str, int, float, bool, type(None)):

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:84, in (.0)
81 if _type in encoder_registry:
82 obj_dict = encoder_registry_type
83 return {
---> 84 k: object_to_json(
85 v,
86 encoder_registry=encoder_registry,
87 class_encoder_registry=class_encoder_registry,
88 )
89 for k, v in obj_dict.items()
90 }
92 # Python built-in types + typing module types
93 if _type in (str, int, float, bool, type(None)):

File ~/anaconda3/envs/tpot/lib/python3.10/site-packages/ax/storage/json_store/encoder.py:185, in object_to_json(obj, encoder_registry, class_encoder_registry)
178 return {"_type": f"torch{_type.name}", "value": torch_type_to_str(obj)}
180 err = (
181 f"Object {obj} passed to object_to_json (of type {_type}, module: "
182 f"{_type.module}) is not registered with a corresponding encoder "
183 "in ENCODER_REGISTRY."
184 )
--> 185 raise JSONEncodeError(err)

JSONEncodeError: Object MyTensorboardMetric('val_acc') passed to object_to_json (of type , module: main) is not registered with a corresponding encoder in ENCODER_REGISTRY
`

As far as I understand, I need to encode my metrics, but I am not sure how to do it. Any ideas on this? Is this the best way to export the experiments after the optimization process is done? Thank you.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions