Skip to content

Commit

Permalink
Support inverse gate JSON seralization (#6912)
Browse files Browse the repository at this point in the history
Implement serialization of `_InverseCompositeGate`.

Fixes #6769
  • Loading branch information
justinpan0 authored Jan 12, 2025
1 parent 5d317ba commit 3a13041
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions cirq-core/cirq/json_resolver_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def _symmetricalqidpair(qids):
'IdentityGate': cirq.IdentityGate,
'InitObsSetting': cirq.work.InitObsSetting,
'InsertionNoiseModel': InsertionNoiseModel,
'_InverseCompositeGate': raw_types._InverseCompositeGate,
'KeyCondition': cirq.KeyCondition,
'KrausChannel': cirq.KrausChannel,
'LinearDict': cirq.LinearDict,
Expand Down
1 change: 0 additions & 1 deletion cirq-core/cirq/ops/gate_operation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/ops/raw_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,9 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return f'{self._original!s}†'

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


def _validate_qid_shape(val: Any, qubits: Sequence['cirq.Qid']) -> None:
"""Helper function to validate qubits for gates and operations.
Expand Down
10 changes: 10 additions & 0 deletions cirq-core/cirq/protocols/json_test_data/_InverseCompositeGate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cirq_type": "_InverseCompositeGate",
"original": {
"cirq_type": "QubitPermutationGate",
"permutation": [
0,
1,
2
]}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(cirq.QubitPermutationGate(permutation=(0, 1, 2))**-1)

0 comments on commit 3a13041

Please sign in to comment.