Skip to content

Serialize the Optimization Problem name #153

Closed

Description

@vxfield

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")

Activity

  1. vxfield commented on Sep 30, 2021

    @vxfield
    MemberAuthor

    Resolved with #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions