Added IMetric and IRunner to JSON storage registries | Fix: Issue #4671 #4753
+6
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4671
Problem
When using
client.configure_metrics()withIMetricobjects to add tracking metrics,client.save_to_json_file()fails with aJSONEncodeErrorbecauseIMetricandIRunnerare not registered in the encoder/decoder registries.Solution
Added
IMetricandIRunnerto both registries inax/storage/json_store/registry.py:IMetricandIRunnerfromax.api.protocolsIMetric: metric_to_dicttoCORE_ENCODER_REGISTRYIRunner: runner_to_dicttoCORE_ENCODER_REGISTRY"IMetric": IMetrictoCORE_DECODER_REGISTRY"IRunner": IRunnertoCORE_DECODER_REGISTRYTesting
Verified using the reproduction script from the issue - save and load now work correctly with
IMetrictracking metrics.Run the following file:
Previous Behavior
The save operation fails with the following error:
ax.exceptions.storage.JSONEncodeError: Object IMetric('my_tracking_metric_1') passed to
object_to_json(of type <class 'ax.api.protocols.metric.IMetric'>, module: ax.api.protocols.metric) is not registered with a corresponding encoder in ENCODER_REGISTRY. Please see our JSON storage tutorial (https://ax.dev/docs/recipes/experiment-to-json) for more details. The 'Customizing the Serialization Process' section will be relevant for saving Ax object subclasses.New Behaviour
The client.save_to_json_file() successfully saves the Client state, including the configured tracking metrics, allowing the experiment to be resumed later.
Environment
Ax version: 1.2.1 (or latest)
Python version: 3.12
OS: Linux