Repository: quantumlib/Cirq

Issue:
JSON backwards compatibility has been flushed
https://github.com/quantumlib/Cirq/pull/4099 cleared some deprecated classes. Serialized files have a much longer lifespan than code. It was always the intent to keep much longer-term backwards compatibility for data files, especially experimental results which likely have `cirq.TrialResult` classes.

1) the old TrialResult.json should be kept around like the "inward" files 
2) The resolver should re-direct "TrialResult" keys to `cirq.Result`. In some sense, this should have been done along with the initial rename. 


Discussion:
Oops, let's fix this ASAP.

Resolving patch:
diff --git a/cirq-core/cirq/json_resolver_cache.py b/cirq-core/cirq/json_resolver_cache.py
--- a/cirq-core/cirq/json_resolver_cache.py
+++ b/cirq-core/cirq/json_resolver_cache.py
@@ -128,6 +128,7 @@ def two_qubit_matrix_gate(matrix):
         'SwapPowGate': cirq.SwapPowGate,
         'SymmetricalQidPair': cirq.SymmetricalQidPair,
         'TaggedOperation': cirq.TaggedOperation,
+        'TrialResult': cirq.Result,  # keep support for Cirq < 0.11.
         'Result': cirq.Result,
         'Rx': cirq.Rx,
         'Ry': cirq.Ry,


Test patch:
diff --git a/cirq-core/cirq/protocols/json_test_data/TrialResult.json_inward b/cirq-core/cirq/protocols/json_test_data/TrialResult.json_inward
new file mode 100644
--- /dev/null
+++ b/cirq-core/cirq/protocols/json_test_data/TrialResult.json_inward
@@ -0,0 +1,297 @@
+[
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "d32a",
+        "binary": true,
+        "dtype": "bool",
+        "shape": [
+          3,
+          5
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "d32a",
+        "binary": true,
+        "dtype": "uint8",
+        "shape": [
+          3,
+          5
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "934e554d5059010076007b276465736372273a20277c6931272c2027666f727472616e5f6f72646572273a2046616c73652c20277368617065273a2028332c2033292c207d202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200a000102030405060708",
+        "binary": false,
+        "dtype": "int8",
+        "shape": [
+          3,
+          3
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "934e554d5059010076007b276465736372273a20273c6932272c2027666f727472616e5f6f72646572273a2046616c73652c20277368617065273a2028332c2033292c207d202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200a000001000200030004000500060007000800",
+        "binary": false,
+        "dtype": "int16",
+        "shape": [
+          3,
+          3
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "934e554d5059010076007b276465736372273a20273c6934272c2027666f727472616e5f6f72646572273a2046616c73652c20277368617065273a2028332c2033292c207d202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200a000000000100000002000000030000000400000005000000060000000700000008000000",
+        "binary": false,
+        "dtype": "int32",
+        "shape": [
+          3,
+          3
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "934e554d5059010076007b276465736372273a20273c6938272c2027666f727472616e5f6f72646572273a2046616c73652c20277368617065273a2028332c2033292c207d202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200a000000000000000001000000000000000200000000000000030000000000000004000000000000000500000000000000060000000000000007000000000000000800000000000000",
+        "binary": false,
+        "dtype": "int64",
+        "shape": [
+          3,
+          3
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "934e554d5059010076007b276465736372273a20277c7531272c2027666f727472616e5f6f72646572273a2046616c73652c20277368617065273a2028332c2033292c207d202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200a000102030405060708",
+        "binary": false,
+        "dtype": "uint8",
+        "shape": [
+          3,
+          3
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "934e554d5059010076007b276465736372273a20273c7532272c2027666f727472616e5f6f72646572273a2046616c73652c20277368617065273a2028332c2033292c207d202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200a000001000200030004000500060007000800",
+        "binary": false,
+        "dtype": "uint16",
+        "shape": [
+          3,
+          3
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "934e554d5059010076007b276465736372273a20273c7534272c2027666f727472616e5f6f72646572273a2046616c73652c20277368617065273a2028332c2033292c207d202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200a000000000100000002000000030000000400000005000000060000000700000008000000",
+        "binary": false,
+        "dtype": "uint32",
+        "shape": [
+          3,
+          3
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "934e554d5059010076007b276465736372273a20273c7538272c2027666f727472616e5f6f72646572273a2046616c73652c20277368617065273a2028332c2033292c207d202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200a000000000000000001000000000000000200000000000000030000000000000004000000000000000500000000000000060000000000000007000000000000000800000000000000",
+        "binary": false,
+        "dtype": "uint64",
+        "shape": [
+          3,
+          3
+        ]
+      }
+    }
+  },
+  {
+    "cirq_type": "TrialResult",
+    "params": {
+      "cirq_type": "ParamResolver",
+      "param_dict": [
+        [
+          {
+            "cirq_type": "sympy.Symbol",
+            "name": "a"
+          },
+          0.5
+        ]
+      ]
+    },
+    "measurements": {
+      "m": {
+        "packed_digits": "d32a",
+        "binary": true,
+        "dtype": "uint8",
+        "shape": [
+          3,
+          5
+        ]
+      },
+      "n": {
+        "packed_digits": "934e554d5059010076007b276465736372273a20273c6938272c2027666f727472616e5f6f72646572273a2046616c73652c20277368617065273a2028332c2033292c207d202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020200a000000000000000001000000000000000200000000000000030000000000000004000000000000000500000000000000060000000000000007000000000000000800000000000000",
+        "binary": false,
+        "dtype": "int64",
+        "shape": [
+          3,
+          3
+        ]
+      }
+    }
+  }
+]
\ No newline at end of file
diff --git a/cirq-core/cirq/protocols/json_test_data/TrialResult.repr_inward b/cirq-core/cirq/protocols/json_test_data/TrialResult.repr_inward
new file mode 100644
--- /dev/null
+++ b/cirq-core/cirq/protocols/json_test_data/TrialResult.repr_inward
@@ -0,0 +1 @@
+[cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[True, True, False, True, False], [False, True, True, False, False], [True, False, True, False, True]], dtype=np.bool)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[1, 1, 0, 1, 0], [0, 1, 1, 0, 0], [1, 0, 1, 0, 1]], dtype=np.uint8)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int8)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int16)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int32)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int64)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.uint8)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.uint16)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.uint32)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.uint64)}), cirq.Result(params=cirq.ParamResolver({sympy.Symbol('a'): 0.5}), measurements={'m': np.array([[1, 1, 0, 1, 0], [0, 1, 1, 0, 0], [1, 0, 1, 0, 1]], dtype=np.uint8), 'n': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int64)})]
\ No newline at end of file