Skip to content

Commit 2ea535d

Browse files
Serialize QubitPermutationGate. (quantumlib#5092)
Step towards fixing quantumlib#5090
1 parent a5ae2c5 commit 2ea535d

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

cirq/json_resolver_cache.py

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def _parallel_gate_op(gate, qubits):
145145
'QasmUGate': cirq.circuits.qasm_output.QasmUGate,
146146
'_QubitAsQid': raw_types._QubitAsQid,
147147
'QuantumFourierTransformGate': cirq.QuantumFourierTransformGate,
148+
'QubitPermutationGate': cirq.QubitPermutationGate,
148149
'RandomGateChannel': cirq.RandomGateChannel,
149150
'TensoredConfusionMatrices': cirq.TensoredConfusionMatrices,
150151
'RepetitionsStoppingCriteria': cirq.work.RepetitionsStoppingCriteria,

cirq/ops/permutation_gate.py

+4
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,7 @@ def __repr__(self) -> str:
9696

9797
def _json_dict_(self) -> Dict[str, Any]:
9898
return protocols.obj_to_dict_helper(self, attribute_names=['permutation'])
99+
100+
@classmethod
101+
def _from_json_dict_(cls, permutation: Sequence[int], **kwargs):
102+
return cls(permutation)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"cirq_type": "QubitPermutationGate",
3+
"permutation": [
4+
0,
5+
5,
6+
2,
7+
1,
8+
6,
9+
3,
10+
4
11+
]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cirq.QubitPermutationGate([0, 5, 2, 1, 6, 3, 4])

cirq/protocols/json_test_data/spec.py

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
'QasmOutput',
6060
'QuantumState',
6161
'QubitOrder',
62-
'QubitPermutationGate',
6362
'QuilFormatter',
6463
'QuilOutput',
6564
'SimulationTrialResult',

0 commit comments

Comments
 (0)