diff --git a/cirq-core/cirq/json_resolver_cache.py b/cirq-core/cirq/json_resolver_cache.py index 0f866e39e54..f391431e584 100644 --- a/cirq-core/cirq/json_resolver_cache.py +++ b/cirq-core/cirq/json_resolver_cache.py @@ -281,4 +281,5 @@ def _symmetricalqidpair(qids): 'sympy.EulerGamma': lambda: sympy.EulerGamma, 'complex': complex, 'datetime.datetime': _datetime, + '_InverseCompositeGate': cirq.inverse, } diff --git a/cirq-core/cirq/ops/gate_operation_test.py b/cirq-core/cirq/ops/gate_operation_test.py index 46cf3cae1a5..d911c25261b 100644 --- a/cirq-core/cirq/ops/gate_operation_test.py +++ b/cirq-core/cirq/ops/gate_operation_test.py @@ -506,7 +506,6 @@ def all_subclasses(cls): cirq.transformers.measurement_transformers._ConfusionChannel, cirq.transformers.measurement_transformers._ModAdd, cirq.transformers.routing.visualize_routed_circuit._SwapPrintGate, - cirq.ops.raw_types._InverseCompositeGate, cirq.circuits.qasm_output.QasmTwoQubitGate, cirq.ops.MSGate, # Interop gates diff --git a/cirq-core/cirq/ops/raw_types.py b/cirq-core/cirq/ops/raw_types.py index 168c3cd1765..51555cbeb8a 100644 --- a/cirq-core/cirq/ops/raw_types.py +++ b/cirq-core/cirq/ops/raw_types.py @@ -985,6 +985,7 @@ class _InverseCompositeGate(Gate): def __init__(self, original: Gate) -> None: self._original = original + self.val = original def _qid_shape_(self): return protocols.qid_shape(self._original) @@ -1046,6 +1047,9 @@ def __repr__(self) -> str: def __str__(self) -> str: return f'{self._original!s}†' + def _json_dict_(self) -> Dict[str, Any]: + return protocols.obj_to_dict_helper(self, attribute_names=["val"]) + def _validate_qid_shape(val: Any, qubits: Sequence['cirq.Qid']) -> None: """Helper function to validate qubits for gates and operations. diff --git a/cirq-core/cirq/protocols/json_test_data/_InverseCompositeGate.json b/cirq-core/cirq/protocols/json_test_data/_InverseCompositeGate.json new file mode 100644 index 00000000000..65160b3d388 --- /dev/null +++ b/cirq-core/cirq/protocols/json_test_data/_InverseCompositeGate.json @@ -0,0 +1,10 @@ +{ + "cirq_type": "_InverseCompositeGate", + "val": { + "cirq_type": "QubitPermutationGate", + "permutation": [ + 0, + 1, + 2 + ]} +} \ No newline at end of file diff --git a/cirq-core/cirq/protocols/json_test_data/_InverseCompositeGate.repr b/cirq-core/cirq/protocols/json_test_data/_InverseCompositeGate.repr new file mode 100644 index 00000000000..cc68af6df87 --- /dev/null +++ b/cirq-core/cirq/protocols/json_test_data/_InverseCompositeGate.repr @@ -0,0 +1 @@ +(cirq.QubitPermutationGate(permutation=(0, 1, 2))**-1)