Skip to content

Commit 3a13041

Browse files
authored
Support inverse gate JSON seralization (#6912)
Implement serialization of `_InverseCompositeGate`. Fixes #6769
1 parent 5d317ba commit 3a13041

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

cirq-core/cirq/json_resolver_cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def _symmetricalqidpair(qids):
150150
'IdentityGate': cirq.IdentityGate,
151151
'InitObsSetting': cirq.work.InitObsSetting,
152152
'InsertionNoiseModel': InsertionNoiseModel,
153+
'_InverseCompositeGate': raw_types._InverseCompositeGate,
153154
'KeyCondition': cirq.KeyCondition,
154155
'KrausChannel': cirq.KrausChannel,
155156
'LinearDict': cirq.LinearDict,

cirq-core/cirq/ops/gate_operation_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ def all_subclasses(cls):
506506
cirq.transformers.measurement_transformers._ConfusionChannel,
507507
cirq.transformers.measurement_transformers._ModAdd,
508508
cirq.transformers.routing.visualize_routed_circuit._SwapPrintGate,
509-
cirq.ops.raw_types._InverseCompositeGate,
510509
cirq.circuits.qasm_output.QasmTwoQubitGate,
511510
cirq.ops.MSGate,
512511
# Interop gates

cirq-core/cirq/ops/raw_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,9 @@ def __repr__(self) -> str:
10661066
def __str__(self) -> str:
10671067
return f'{self._original!s}†'
10681068

1069+
def _json_dict_(self) -> Dict[str, Any]:
1070+
return {'original': self._original}
1071+
10691072

10701073
def _validate_qid_shape(val: Any, qubits: Sequence['cirq.Qid']) -> None:
10711074
"""Helper function to validate qubits for gates and operations.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"cirq_type": "_InverseCompositeGate",
3+
"original": {
4+
"cirq_type": "QubitPermutationGate",
5+
"permutation": [
6+
0,
7+
1,
8+
2
9+
]}
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(cirq.QubitPermutationGate(permutation=(0, 1, 2))**-1)

0 commit comments

Comments
 (0)