Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize the Optimization Problem name #153

Closed
vxfield opened this issue Sep 30, 2021 · 1 comment · Fixed by #64
Closed

Serialize the Optimization Problem name #153

vxfield opened this issue Sep 30, 2021 · 1 comment · Fixed by #64

Comments

@vxfield
Copy link
Member

vxfield commented Sep 30, 2021

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

  1. 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")
@vxfield
Copy link
Member Author

vxfield commented Sep 30, 2021

Resolved with #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant