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.

SingleQubitCliffordGate does not properly serialize to JSON

See original GitHub issue

Description of the issue

SingleQubitCliffordGates write incomplete information to JSON, and their type cannot be understood by the JSON deserializer.

How to reproduce the issue

>>> import cirq
>>> print(cirq.__version__)
0.10.0
>>> q = cirq.LineQubit(0)
>>> json_text = cirq.to_json(cirq.SingleQubitCliffordGate.X(q))
>>> print(json_text)
{
  "cirq_type": "GateOperation",
  "gate": {
    "cirq_type": "SingleQubitCliffordGate"
  },
  "qubits": [
    {
      "cirq_type": "LineQubit",
      "x": 0
    }
  ]
}
>>> deserialized_gate = cirq.read_json(json_text=json_text)
ValueError: Could not resolve type 'SingleQubitCliffordGate' during deserialization

Cirq version

0.10.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Aug 6, 2021

Yes, please take it. I will be able to contribute to Cirq from the month of September.

1reaction
balopatcommented, May 3, 2021

Hi @PoPaT1618 - thank you for volunteering!

I saw that you are new to the project, so, just to clarify, the following needs to be done:

    def _json_dict_(self) -> Dict[str, Any]:
        return protocols.obj_to_dict_helper(
            self, ['_rotation_map', '_inverse_map']
        )

At this point you might be ready to commit, and create a pull request, but ping us if you run into issues.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to Serialize JSON to Dictionary - Stack Overflow
I think your JSON which you are attempting to de-serialize is not conforming to your class definition. Try changing the way you are ......
Read more >
System.Text.Json source generator fallback - .NET
Json source generator will no longer implicitly fall back to reflection-based serialization for unrecognized types. Previous behavior. Consider ...
Read more >
Serialization Guide - Json.NET
The Json.NET serializer can serialize a wide variety of .NET objects. This guide looks at ... Array (properties on the collection will not...
Read more >
How to Serialize a Class Object to JSON in Python
TypeError : Object of type ImageLabel is not JSON serializable ... Outputs a proper JSON: Serialization results are proper JSON objects. print() just...
Read more >
JSON Serialization Usage
So it doesn't matter how deep your object path has gotten. An exclude of *.class will match to any path depth. So if...
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