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

Conversion to JSON failure #6769

Open
glanzz opened this issue Oct 15, 2024 · 0 comments
Open

Conversion to JSON failure #6769

glanzz opened this issue Oct 15, 2024 · 0 comments
Labels
kind/bug-report Something doesn't seem to work. triage/discuss Needs decision / discussion, bring these up during Cirq Cynque

Comments

@glanzz
Copy link

glanzz commented Oct 15, 2024

Description of the issue
Any circuit with the inverse QubitPermutation gate added will fail if it is loaded from JSON.
How to reproduce the issue

import cirq as c

qubits = c.LineQubit.range(3)
circuit = c.Circuit()

circuit.append(c.QubitPermutationGate(permutation=[0,1,2])(qubits[0], qubits[1], qubits[2])**-1)

print(circuit)
json_text = c.to_json(circuit)
print(json_text)
circuit = c.read_json(json_text=json_text)
print(circuit)
0: ───[0>0]──────
      │
1: ───[1>1]──────
      │
2: ───[2>2]^-1───
{
  "cirq_type": "Circuit",
  "moments": [
    {
      "cirq_type": "Moment",
      "operations": [
        {
          "cirq_type": "GateOperation",
          "gate": {
            "cirq_type": "_InverseCompositeGate"
          },
          "qubits": [
            {
              "cirq_type": "LineQubit",
              "x": 0
            },
            {
              "cirq_type": "LineQubit",
              "x": 1
            },
            {
              "cirq_type": "LineQubit",
              "x": 2
            }
          ]
        }
      ]
    }
  ]
}
Traceback (most recent call last):
  File "/Users/xxx/json_failure.py", line 11, in <module>
    circuit = c.read_json(json_text=json_text)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/cirqenv/lib/python3.11/site-packages/cirq/protocols/json_serialization.py", line 561, in read_json
    return json.loads(json_text, object_hook=obj_hook)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/cirqenv/lib/python3.11/site-packages/cirq/protocols/json_serialization.py", line 352, in __call__
    cls = factory_from_json(cirq_type, resolvers=self.resolvers)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/cirqenv/lib/python3.11/site-packages/cirq/protocols/json_serialization.py", line 431, in factory_from_json
    raise ValueError(f"Could not resolve type '{type_str}' during deserialization")
ValueError: Could not resolve type '_InverseCompositeGate' during deserialization

Cirq version
You can get the cirq version by printing cirq.__version__. From the command line:

Cirq: 1.4.1
@glanzz glanzz added the kind/bug-report Something doesn't seem to work. label Oct 15, 2024
@NoureldinYosri NoureldinYosri added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug-report Something doesn't seem to work. triage/discuss Needs decision / discussion, bring these up during Cirq Cynque
Projects
None yet
Development

No branches or pull requests

2 participants