question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ScalarizedObjective` serialization and storage

See original GitHub issue

Hello,

Ax version: 0.1.6

I am trying to save an experiment which looks like:

    experiment = Experiment(
        name="experiment_building_blocks",
        search_space=search_space(),
    )

    optimization_config = OptimizationConfig(
        objective=ScalarizedObjective(
            metrics=[AccuracyMetric(datasets, dataloaders,
                                    device, datasetsizes,
                                    epochs, name="accuracy"),
                     WeightMetric(datasets, bits, name="weight")],
            weights=[0.5, 0.5],
            minimize=True,
        ),
    )

    experiment.optimization_config = optimization_config
    experiment.runner = MyRunner()

As seen it is an Scalarized Objective with two metrics. When I try to save the experiment by registering both the runner and the metrics:

    register_metric(AccuracyMetric)
    register_metric(WeightMetric)
    register_runner(MyRunner)

    save(exp, path.join(root, name))

Then the following error appears:

optimization_config Traceback (most recent call last):
  File "main.py", line 172, in <module>
    root=parsed.root)
  File "main.py", line 113, in main
    save_data(exp, name, root)
  File "main.py", line 152, in save_data
    save(exp, path.join(root, name))
  File "/home/kostal/anaconda3/envs/deep/lib/python3.7/site-packages/ax/storage/json_store/save.py", line 22, in save_experiment
    json_experiment = object_to_json(experiment)
  File "/home/kostal/anaconda3/envs/deep/lib/python3.7/site-packages/ax/storage/json_store/encoder.py", line 74, in object_to_json
    print(k, v)
  File "/home/kostal/anaconda3/envs/deep/lib/python3.7/site-packages/ax/core/optimization_config.py", line 138, in __repr__
    objective=repr(self.objective),
  File "/home/kostal/anaconda3/envs/deep/lib/python3.7/site-packages/ax/core/objective.py", line 44, in __repr__
    self.metric.name, self.minimize
  File "/home/kostal/anaconda3/envs/deep/lib/python3.7/site-packages/ax/core/objective.py", line 84, in metric
    raise NotImplementedError("ScalarizedObjective is composed of multiple metrics")

Looks like that in the source of Scalarized Objective it has no __repr__method. I have tried to implement it as:

    def __repr__(self) -> str:
        base_str = 'Objective('
        for k, v in zip(self.metrics, self.weights):
            base_str += ' metric_name="{}", metric_weight="{}",'.format(
                                    k.name, v)
        base_str += ' minimize={})'.format(self.minimize)
        return base_str

With no luck because another appears, as this is not registered as an ENCODER_REGISTRY for JSON encoding.

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jelena-markoviccommented, Mar 11, 2020

Hi @BCJuan, storing scalarized objective has just been added (commit: 933bf4f44dd9287f8a8f6bbff182258bbd2f3499, branch: master, date: March 10th, 2020). Feel free to test it and let us know if there are more issues!

1reaction
sdsinghcommented, Nov 26, 2019

Good catch, let me add support for that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OutputSerialization - Amazon Simple Storage Service
Describes the serialization of CSV-encoded Select results. Type: CSVOutput data type. Required: No. JSON. Specifies JSON as request's output serialization ...
Read more >
Source code for ax.storage.json_store.encoders
Source code for ax.storage.json_store.encoders ... Objective, ScalarizedObjective from ax.core.optimization_config import ( MultiObjectiveOptimizationConfig ...
Read more >
Serialization (C#) | Microsoft Learn
Serialization converts an object into a stream of bytes to store the object or transmit it to memory, a database, or a file....
Read more >
Tuning - Spark 2.2.3 Documentation - Apache Spark
Java serialization: By default, Spark serializes objects using Java's ObjectOutputStream ... In Spark, execution and storage share a unified region (M).
Read more >
Serialization in Java - DigitalOcean
Serialization in Java allows us to convert an Object to stream that we can send over the network or save it as file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found