Repository navigation
Description
Short descriptions
When you serialize an Optimization Problem object the name is not also serialized. This would be useful for customers who want to save a problem they've created locally and reuse it later without having to specify the problem name again.
Repro steps
- Create a problem and serialize it:
problem = Problem(name="myProblem")
problem.terms = [
Term(c=3, indices=[1, 0]),
Term(c=5, indices=[2, 0]),
]
serialized_problem = problem.serialize()Observed behavior
The value of serialized_problem does not contain the name of the problem ("myProblem" in this case):
{
"cost_function": {
"version": "1.0",
"type": "ising",
"terms": [
{
"c": 3,
"ids": [
1,
0
]
},
{
"c": 5,
"ids": [
2,
0
]
}
]
}
}That forces the user to specify the problem name again when deserializing the problem:
deserialized_problem = Problem.deserialize(problem_as_json=serialized_problem,
name="myProblem")Expected behavior
When serializing the problem, the name should also be serialized, like the example below:
{
"metadata": {
"name": "myProblem"
},
"cost_function": {
"version": "1.0",
"type": "ising",
"terms": [
{
"c": 3,
"ids": [
1,
0
]
},
{
"c": 5,
"ids": [
2,
0
]
}
]
}
}And then, the user does not need to specify the problem name again when deserializing the problem:
deserialized_problem = Problem.deserialize(problem_as_json=serialized_problem)Backward compatibility
Still, in case we are deserializing a problem that does not contain the name of the problem, the user should be able to pass a problem name again or, if not passed, we should have a default problem name set.
deserialized_problem = Problem.deserialize(problem_as_json=serialized_problem,
name="myProblem")
Activity
vxfield commentedon Sep 30, 2021
Resolved with #64