Skip to content

Commit

Permalink
Serialize QubitPermutationGate. (quantumlib#5092)
Browse files Browse the repository at this point in the history
Step towards fixing quantumlib#5090
  • Loading branch information
MichaelBroughton authored and rht committed May 1, 2023
1 parent d308676 commit f38e849
Show file tree
Hide file tree
Showing 5 changed files with 18 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 @@ -145,6 +145,7 @@ def _parallel_gate_op(gate, qubits):
'QasmUGate': cirq.circuits.qasm_output.QasmUGate,
'_QubitAsQid': raw_types._QubitAsQid,
'QuantumFourierTransformGate': cirq.QuantumFourierTransformGate,
'QubitPermutationGate': cirq.QubitPermutationGate,
'RandomGateChannel': cirq.RandomGateChannel,
'TensoredConfusionMatrices': cirq.TensoredConfusionMatrices,
'RepetitionsStoppingCriteria': cirq.work.RepetitionsStoppingCriteria,
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/ops/permutation_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ def __repr__(self) -> str:

def _json_dict_(self) -> Dict[str, Any]:
return protocols.obj_to_dict_helper(self, attribute_names=['permutation'])

@classmethod
def _from_json_dict_(cls, permutation: Sequence[int], **kwargs):
return cls(permutation)
12 changes: 12 additions & 0 deletions cirq-core/cirq/protocols/json_test_data/QubitPermutationGate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"cirq_type": "QubitPermutationGate",
"permutation": [
0,
5,
2,
1,
6,
3,
4
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cirq.QubitPermutationGate([0, 5, 2, 1, 6, 3, 4])
1 change: 0 additions & 1 deletion cirq-core/cirq/protocols/json_test_data/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
'QasmOutput',
'QuantumState',
'QubitOrder',
'QubitPermutationGate',
'QuilFormatter',
'QuilOutput',
'SimulationTrialResult',
Expand Down

0 comments on commit f38e849

Please sign in to comment.